コード例 #1
0
def pad_stack(s, dt_offset=timedelta(365.25)):
    o = s.ma_stack.shape
    new_ma_stack = np.ma.vstack((s.ma_stack[0:1], s.ma_stack, s.ma_stack[-1:]))
    new_date_list = np.ma.hstack((s.date_list[0:1] - dt_offset, s.date_list,
                                  s.date_list[-1:] + dt_offset))
    new_date_list_o = timelib.dt2o(new_date_list)
    return new_ma_stack, new_date_list_o
コード例 #2
0
def make_test():
    nt = 30 
    shp = (nt,40,60)
    res = 2000
    test = np.ma.masked_all(shp)
    init = np.full((shp[1], shp[2]), 300)
    #Some spatial distribution of dhdt
    dhdt = np.full((shp[1], shp[2]), -2/365.25)
    ti_min = timelib.dt2o(datetime(2008,1,1))
    ti_max = timelib.dt2o(datetime(2015,4,1))
    ti = np.sort(np.random.random(nt) * (ti_max - ti_min))
    for i,t in enumerate(ti):
        test[i] = init + dhdt * ti[i]
  
    tilt_factor = (110000/res)
    i = nt/2
    dx = 3./tilt_factor
    dy = 1./tilt_factor
    dz = -0.5
    print i, dx, dy, dz
    test[i] = apply_tilt(test[i], -dx, -dy, -dz)
    i = 2
    dx = -1.5/tilt_factor
    dy = 0.1/tilt_factor
    dz = 0.4
    print i, dx, dy, dz
    test[i] = apply_tilt(test[i], -dx, -dy, -dz)
    i = -2
    dx = 0.1/tilt_factor
    dy = 0.1/tilt_factor
    dz = 2.5 
    print i, dx, dy, dz
    test[i] = apply_tilt(test[i], -dx, -dy, -dz)
    #x,y,z = malib.get_xyz(test[nt/2])
    #d = (dx*x + dy*y + dz).reshape((shp[1], shp[2]))
    #test[nt/2] += d
    #Need to add t_min back to ti
    return test, (ti + ti_min), res
コード例 #3
0
ファイル: wv_tide.py プロジェクト: whigg/pig_dem_meltrate
#This is approx PIG shelf center
lat=-75.08865
lon=-100.38043

#dem_list_fn = '/scr/pig_stack_20151201_tworows_highcount/shelf_clip/20021204_1925_atm_mean-adj_20150223_1531_1040010008556800_104001000855E100-DEM_32m_trans-adj_stack_203_fn_list.txt'
#dem_list_fn = '/scr/pig_stack_20151201_tworows_highcount/shelf_clip/20071020_1438_glas_mean-adj_20150223_1531_1040010008556800_104001000855E100-DEM_32m_trans-adj_stack_189_fn_list.txt'
#dem_list_fn = '/scr/pig_stack_20151201_tworows_highcount/shelf_clip/20071020_1438_glas_mean-adj_20150223_1531_1040010008556800_104001000855E100-DEM_32m_trans-adj_stack_189_fn_list.txt'
#This includes individual GLAS orbits, individual ATM/LVIS flights, all WV+SPIRIT over shelf
#dem_list_fn = '/scr/pig_stack_20160307_tworows_highcount/shelf_clip/20021128_2050_atm_256m-DEM_20150223_1531_1040010008556800_104001000855E100-DEM_32m_trans_stack_417_fn_list.txt'
#dem_list_fn = '/scr/pig_stack_20160307_tworows_highcount/full_extent/20021128_2050_atm_256m-DEM_20150406_1519_103001003F89B700_1030010040D68600-DEM_32m_trans_stack_730_fn_list.txt'
dem_list_fn = sys.argv[1] 
out_fn = os.path.splitext(dem_list_fn)[0]+'_tides.csv'

fn_list = [os.path.split(line.strip())[-1] for line in open(dem_list_fn, 'r')]
dt_list = np.array([timelib.fn_getdatetime(fn) for fn in fn_list])
dt_list_o = timelib.dt2o(dt_list)
dt_list_mat = [timelib.dt2mat(dt) for dt in dt_list]

print "Running tide model for %i timestamps" % len(dt_list_mat)
tide_a = matlab.tmd_tide_pred('%s' % model, dt_list_mat, lat, lon, 'z')

print "Writing out"
out = zip(fn_list, dt_list, dt_list_o, tide_a)
with open(out_fn, 'w') as f:
    f.write('fn,date,date_o,tide\n')
    f.write('\n'.join('%s,%s,%0.6f,%0.2f' % x for x in out))

#Get continuous tidal record
dt1 = datetime(2002,1,1)
dt2 = datetime(2016,1,1)
dt_int = timedelta(days=1/24.)
コード例 #4
0
    X = np.tile(x, t.size)[idx]
    Y = np.tile(y, t.size)[idx]
    T = np.repeat(t, x.size)[idx]
    #These are coords
    pts = np.vstack((X,Y,T)).T

    #Normalized versions
    Xn = rangenorm(X)
    Yn = rangenorm(Y) 
    Tn = rangenorm(T) 
    ptsn = np.vstack((Xn,Yn,Tn)).T

#Interpoalte at these times
#ti = np.arange(t.min(), t.max(), 90.0)
ti_min = timelib.dt2o(datetime(2008,1,1))
#ti_min = timelib.dt2o(datetime(2012,1,1))
#ti_max = timelib.dt2o(datetime(2009,1,1))
#ti_max = timelib.dt2o(datetime(2014,9,1))
#ti_max = timelib.dt2o(datetime(2015,4,1))
ti_max = timelib.dt2o(datetime(2015,6,1))
#ti_dt = 120 
#ti_dt = 121.75 
ti_dt = 91.3125
#ti_dt = 365.25 

#Interpolate at these times 
ti = np.arange(ti_min, ti_max, ti_dt)
#ti = t
#Annual - use for discharge analysis?
#ti = timelib.dt2o([datetime(2008,1,1), datetime(2009,1,1), datetime(2010,1,1), datetime(2011,1,1), datetime(2012,1,1), datetime(2013,1,1), datetime(2014,1,1), datetime(2015,1,1)])
コード例 #5
0
t_scale = t.ptp()*t_factor
t_offset = t.min()

xn = rangenorm(x, xy_offset, xy_scale)
yn = rangenorm(y, xy_offset, xy_scale)
tn = rangenorm(t, t_offset, t_scale)

X = np.tile(xn, t.size)[idx]
Y = np.tile(yn, t.size)[idx]
T = np.repeat(tn, x.size)[idx]
#These are coords
pts = np.vstack((X,Y,T)).T

#Interpoalte at these times
#ti = np.arange(t.min(), t.max(), 90.0)
ti_min = timelib.dt2o(datetime(2008,1,1))
#ti_min = timelib.dt2o(datetime(2006,9,1))
#ti_min = timelib.dt2o(datetime(2012,1,1))
#ti_max = timelib.dt2o(datetime(2009,1,1))
#ti_max = timelib.dt2o(datetime(2014,9,1))
#ti_max = timelib.dt2o(datetime(2015,4,1))
#ti_max = timelib.dt2o(datetime(2015,6,1))
ti_max = timelib.dt2o(datetime(2015,1,1))
#ti_dt = 120 
#ti_dt = 121.75 
#ti_dt = 91.3125
ti_dt = 365.25 
#ti_dt = 365.25/2.0

#Interpolate at these times 
ti = np.arange(ti_min, ti_max, ti_dt)
コード例 #6
0
ファイル: ecmwf_proc.py プロジェクト: whigg/pig_dem_meltrate
def get_dem_list(dem_list_fn):
    dem_fn_list = np.array([os.path.split(line.strip())[-1] for line in open(dem_list_fn, 'r')])
    dem_dt_list = np.array([timelib.fn_getdatetime(fn) for fn in dem_fn_list])
    dem_dt_list_o = timelib.dt2o(dem_dt_list)
    return dem_fn_list, dem_dt_list, dem_dt_list_o
コード例 #7
0
ファイル: ecmwf_proc.py プロジェクト: whigg/pig_dem_meltrate
#dem_fn_list, dem_dt_list, dem_dt_list_o = get_dem_list(dem_list_fn)

#ecmwf_fn = '/Volumes/insar3/dshean/ECMWF/PIG_ECMWF_Pmsl_2012-2015.nc'
#ecmwf_fn = '/Volumes/insar3/dshean/ECMWF/PIG_ECMWF_Pmsl_2002-2016.nc'
ecmwf_fn = '/Users/dshean/Documents/UW/Shean_iceshelf_paper/PIG_ECMWF_all_1979-2016_t2m_skt.nc'
ecmwf_nc = netCDF4.Dataset(ecmwf_fn)

lat = -75.0
lon = -101.5

#All dates are days since Jan 1, 1900
refdate=datetime(1900,1,1)
lat_i, lon_i = get_closest_idx(lat, lon, ecmwf_nc) 
ecmwf_dt = [refdate+timedelta(days=i) for i in ecmwf_nc.variables['time'][:]/24.0]
ecmwf_dt_o = timelib.dt2o(ecmwf_dt)

key = 't2m'
ecmwf_Pmsl = ecmwf_nc.variables[key][:] 
#Pmsl = sample(ecmwf_Pmsl, lat_i, lon_i, pad=0)/100.
Pmsl = sample(ecmwf_Pmsl, lat_i, lon_i, pad=0)
Pmslref = np.median(Pmsl)
print "Median Pmsl: %0.2f" % Pmslref
#Note: output will be the expected displacement due to IB
#To remove, need to subtract from observation
Pmsl_IB = (Pmsl - Pmslref)*-0.01
Pmsl_IB = Pmsl - 273.15

lw = 0.5
f, ax = plt.subplots()
ax.axhline(0, color='k', linestyle='--')