Skip to content

Instantly share code, notes, and snippets.

@jklymak
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save jklymak/db6ee318c03176aa5bf1 to your computer and use it in GitHub Desktop.

Select an option

Save jklymak/db6ee318c03176aa5bf1 to your computer and use it in GitHub Desktop.
# 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')
fin.close()
# mercator projection!
rad = np.pi/180.
arg2 = np.log(np.tan(rad*(45.-80.738/2.)))
inds = np.arange(nlat)+1.
arg1=rad*(nlat-inds+0.5)*1./60.
lat = 2.*np.arctan(np.exp(arg1+arg2))/rad-90.
lat = lat[::-1]
lon=np.linspace(0,360.-1./60.,nlon)+0.5/60.
dat = dat.reshape([nlat,nlon])
dat = np.flipud(dat)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment