Exemplo n.º 1
0
 def gen_mask(self, lon, lat, arr, coord='lon/lat', **kw):
     """Creates a mask for given 2d array."""
     print "generating array's mask..."
     if np.ndim(lon) == 1:
         lon, lat = np.meshgrid(lon, lat)                 # 1d -> 2d
         lon, lat = lon.ravel(), lat.ravel()
     if coord == 'lon/lat':
         arr_x, arr_y = ll2xy(lon, lat, units='m', **kw)  # lon/lat -> x/y m
     else:
         arr_x, arr_y = lon, lat
     arr_x, arr_y = np.rint(arr_x), np.rint(arr_y)
     self.mask_x, self.mask_y, self.mask_z = self._get_subset(arr_x, arr_y)
     # if not monotonically increasing (usually the y-dim)
     if self.mask_y[0] > self.mask_y[-1]:
         self.mask_y = self.mask_y[::-1]
         self.mask_z = self.mask_z[::-1,:]
     jj, ii = self._digitize(arr_x, arr_y, self.mask_x, self.mask_y)
     self.arr_z = self.mask_z[ii,jj].reshape(arr.shape)  # 2d mask
     self.arr_x = arr_x
     self.arr_y = arr_y
     del arr_x, arr_y
     print 'done.'
Exemplo n.º 2
0
fnames1 = '/Users/fpaolo/data/gps/forShijieLiu/*.llh'
fnames2 = '/Users/fpaolo/data/gps/spider_web_groundtracks/*.llh'

files = glob(fnames1) + glob(fnames2)

# load all data files
t = lon = lat = h = []
for f in files:
    d = np.loadtxt(f)
    t = np.append(t, d[:,0])      # day
    lon = np.append(lon, d[:,1])  # lon
    lat = np.append(lat, d[:,2])  # lat
    h = np.append(h, d[:,3])      # elev

t = ap.day2year(t, since=(2000, 1, 1))
x, y = ap.ll2xy(lon, lat)
x, y = lon, lat

'''
# create hdf5 file
f = tb.openFile('amery_gps_all.h5', 'w')
f.createArray('/', 'time', t)
f.createArray('/', 'lon', lon)
f.createArray('/', 'lat', lat)
f.createArray('/', 'x', x)
f.createArray('/', 'y', y)
f.createArray('/', 'h', h)
f.close()
'''
#------------------------------------------------------------
Exemplo n.º 3
0
thickness_err = np.fromfile(FILE_THICKNESS_ERR, dtype='<f4').reshape(rows_err, cols_err)
x_err = np.linspace(left_err, right_err, cols_err)
y_err = np.linspace(bottom_err, top_err, rows_err)

freeboard = freeboard[::-1]  # flip y-dim
thickness = thickness[::-1]
thickness_err = thickness_err[::-1]
ind = np.where((freeboard == nodata) | (thickness == nodata))
freeboard[ind] = np.nan
thickness[ind] = np.nan
thickness_err[thickness_err==nodata] = np.nan

# grid coords in polar stere
xx, yy = np.meshgrid(lon, lat)
xx, yy = ap.ll2xy(xx, yy, units='m')
xx_bm, yy_bm = np.meshgrid(x_bm, y_bm)
xx_mask, yy_mask = np.meshgrid(x_mask, y_mask)

# regrid the error to match resolutions
thickness_err1 = interp(thickness_err, x_err, y_err, xx_bm, yy_bm, order=1)
thickness_err2 = interp(thickness_err, x_err, y_err, xx_bm, yy_bm, order=0)
thickness_err1[np.isnan(thickness_err1)] = thickness_err2[np.isnan(thickness_err1)]
thickness_err = thickness_err1

# mask ice shelves 
mask_bm = interp(mask, x_mask, y_mask, xx_bm, yy_bm, order=0)
freeboard[mask_bm!=4] = np.nan
thickness[mask_bm!=4] = np.nan
thickness_err[mask_bm!=4] = np.nan
Exemplo n.º 4
0
fnames1 = '/Users/fpaolo/data/gps/forShijieLiu/*.llh'
fnames2 = '/Users/fpaolo/data/gps/spider_web_groundtracks/*.llh'

files = glob(fnames1) + glob(fnames2)

# load all data files
t = lon = lat = h = []
for f in files:
    d = np.loadtxt(f)
    t = np.append(t, d[:, 0])  # day
    lon = np.append(lon, d[:, 1])  # lon
    lat = np.append(lat, d[:, 2])  # lat
    h = np.append(h, d[:, 3])  # elev

t = ap.day2year(t, since=(2000, 1, 1))
x, y = ap.ll2xy(lon, lat)
x, y = lon, lat
'''
# create hdf5 file
f = tb.openFile('amery_gps_all.h5', 'w')
f.createArray('/', 'time', t)
f.createArray('/', 'lon', lon)
f.createArray('/', 'lat', lat)
f.createArray('/', 'x', x)
f.createArray('/', 'y', y)
f.createArray('/', 'h', h)
f.close()
'''
#------------------------------------------------------------

fname1 = '/Users/fpaolo/data/gps/amery_gps_all.h5'