Skip to content

Instantly share code, notes, and snippets.

View jklymak's full-sized avatar

Jody Klymak jklymak

View GitHub Profile
@jklymak
jklymak / latlonformatters.py
Last active August 29, 2015 14:06
matplotlib lat and lon formatters
# 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 August 29, 2015 14:06
Dissipation colormap
# 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 August 29, 2015 14:06
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 March 5, 2015 00:11
Change format of cursor co-ordinates in figures to map projection
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 August 29, 2015 14:16
Clicking x and y
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 March 18, 2015 22:03
Get cot colormaps
from jmkfigure import *
cmap=gmtcmap('BlueWhiteOrangeRed')
@jklymak
jklymak / adcp.py
Created March 24, 2015 21:40
Process RDI data using COADS
#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.
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')
# 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')
try:
print a+'1'
except:
traceback.print_exc()
print 'hi'