Skip to content

Instantly share code, notes, and snippets.

Avatar

Jody Klymak jklymak

View GitHub Profile
@jklymak
jklymak / latlonformatters.py
Last active Aug 29, 2015
matplotlib lat and lon formatters
View latlonformatters.py
# Format axes for lat and lon
ax.xaxis.set_major_locator(ticker.MultipleLocator(base=2./60.))
ax.yaxis.set_major_locator(ticker.MultipleLocator(base=2./60.))
def latformatter(x, pos):
'The two args are the value and tick position'
if x<0:
x=-x
minus=True
else:
minus=False
@jklymak
jklymak / disscmap.py
Last active Aug 29, 2015
Dissipation colormap
View disscmap.py
# make a good dissipation color map
cdict = {'red': ((0., 1, 1),
(0.05, 1, 1),
(0.11, 1, 1),
(0.4, 0, 0),
(0.66, 1, 1),
(0.89, 1, 1),
(1, 0.5, 0.5)),
'green': ((0., 1, 1),
@jklymak
jklymak / adjusting for colorbars
Last active Aug 29, 2015
adjusting for colorbars
View adjusting for colorbars
import numpy as np
import matplotlib.pyplot as plt
fig,ax=plt.subplots(2,1)
pcm0=ax[0].pcolormesh(np.random.randn(20,30))
fig.colorbar(pcm0,ax=ax[0],shrink=0.75)
pcm1=ax[1].pcolormesh(np.random.randn(20,30))
fig.colorbar(pcm1,ax=ax[1],shrink=0.75)
# or if you want one beside a bunch, you can make a list to steal from:
@jklymak
jklymak / mapcursor
Created Mar 5, 2015
Change format of cursor co-ordinates in figures to map projection
View mapcursor
map=Basemap()
ax = plt.gca()
def format_coord(x, y):
return 'x=%.4f, y=%.4f'%(map(x, y, inverse = True))
ax.format_coord = format_coord
@jklymak
jklymak / clickxy.py
Last active Aug 29, 2015
Clicking x and y
View clickxy.py
fig=figure(figsize=(10,12))
def onclick(event):
print 'button=%d, x=%d, y=%d, xdata=%f, ydata=%f'%(
event.button, event.x, event.y, event.xdata, event.ydata)
cid = fig.canvas.mpl_connect('button_press_event', onclick)
@jklymak
jklymak / cptcolormaps.py
Created Mar 18, 2015
Get cot colormaps
View cptcolormaps.py
from jmkfigure import *
cmap=gmtcmap('BlueWhiteOrangeRed')
@jklymak
jklymak / adcp.py
Created Mar 24, 2015
Process RDI data using COADS
View adcp.py
#I have /Users/jklymak/codas/programs/: in my PYTHONPATH
from pycurrents.adcp.rdiraw import Multiread
# of course you need an ENX file from vmdas!
m = Multiread('March10-2015-03/ADCP029*.ENX','wh')
# ENX should already be in earth co-ordinates, but you may have to adjust the heading as below:
data = m.read()
from pycurrents.adcp.transform import heading_rotate
from pycurrents.adcp.transform import rdi_xyz_enu
dhead = -44.
View read_smith_sandwell.py
# read a smith and sandwell image file:
# http://topex.ucsd.edu/marine_topo/
import numpy as np
nlon=21600
nlat=17280
fin = open('topo_18.1.img','rb')
dat = np.fromfile(fin,dtype='i2')
dat.byteswap('True')
View writemat7.py
import hdf5storage
import numpy as np
D =dict()
D['boo']=np.arange(10)
D['who']=np.arange(20)*2.
hdf5storage.savemat('Boo.mat',D)
Dread = hdf5storage.loadmat('Boo.mat')
View try-except.py
try:
print a+'1'
except:
traceback.print_exc()
print 'hi'