Exemplo n.º 1
0
]

print 'loading data...'
fin = tb.openFile(DIR + FILE_IN)
try:
    time = ap.num2year(fin.root.time[:])
except:
    time = fin.root.time[:]
lon = fin.root.lon[:]
lat = fin.root.lat[:]
d = fin.root.dh_mean_mixed_const_xcal[:]
#d = fin.root.dg_mean_xcal[:]
#e = fin.root.dh_error_xcal[:]
#d = fin.root.n_ad_xcal[:]
nz, ny, nx = d.shape
dt = ap.year2date(time)

if 1:  # load area info
    df_temp = pd.read_csv('ice_shelf_area4.csv')
    df_area = df_temp['sampled_km2']
    df_area.index = df_temp['ice_shelf']

if 1:
    time, d = ap.time_filt(time, d, from_time=1994, to_time=2013)
    #time, e = time_filt(time, e, from_time=1992, to_time=20013)

# area-average
#---------------------------------------------------------------------

df = pd.DataFrame(index=time)
df2 = pd.DataFrame(index=time)
Exemplo n.º 2
0
    ]

print 'loading data...'
fin = tb.openFile(DIR + FILE_IN)
try:
    time = ap.num2year(fin.root.time[:])
except:
    time = fin.root.time[:]
lon = fin.root.lon[:]
lat = fin.root.lat[:]
d = fin.root.dh_mean_mixed_const_xcal[:]
#d = fin.root.dg_mean_xcal[:]
#e = fin.root.dh_error_xcal[:]
#d = fin.root.n_ad_xcal[:]
nz, ny, nx = d.shape
dt = ap.year2date(time)

if 1: # load area info
    df_temp = pd.read_csv('ice_shelf_area4.csv')
    df_area = df_temp['sampled_km2']
    df_area.index = df_temp['ice_shelf']

if 1:
    time, d = ap.time_filt(time, d, from_time=1994, to_time=2013)
    #time, e = time_filt(time, e, from_time=1992, to_time=20013)

# area-average
#---------------------------------------------------------------------

df = pd.DataFrame(index=time)
df2 = pd.DataFrame(index=time)
Exemplo n.º 3
0
def main():

    fname_in = sys.argv[1]

    din = GetData(fname_in, 'a')
    time = ap.num2date(getattr(din, T_NAME)[:])
    lon = din.lon[:]
    lat = din.lat[:]
    nrows = len(time)
    nt, ny, nx =  getattr(din, H_NAME).shape    # i,j,k = t,y,x

    RR = np.empty((nt,ny,nx), 'f8') * np.nan
    SS = np.empty((nt,ny,nx), 'f8') * np.nan

    if TINT:
        intervals = [ap.year2date(tt) for tt in INTERVALS]

    if TINT:
        print 'using time-interval correlation'
    elif TVAR:
        print 'using time-variable correlation'
    else:
        print 'using constant correlation'
    print 'processing time series:'
    isfirst = True

    # iterate over every grid cell (all times): i,j = y,x
    #-----------------------------------------------------------------

    for i in xrange(ny):
        for j in xrange(nx):
            print 'time series of grid-cell:', i, j

            dh = getattr(din, H_NAME)[:nrows,i,j]
            dg = getattr(din, G_NAME)[:nrows,i,j]

            if np.alltrue(np.isnan(dh)): continue

            #---------------------------------------------------------

            if TINT:
                # satellite-dependent R and S
                dh_cor, RR[:,i,j], SS[:,i,j] = \
                    ap.backscatter_corr3(dh, dg, time, intervals, 
                                         diff=DIFF, robust=True)
            elif TVAR:
                # time-varying R and S
                dh_cor, RR[:,i,j], SS[:,i,j] = \
                    ap.backscatter_corr2(dh, dg, diff=DIFF, 
                                         robust=True, npts=NPTS)
            else:
                # constant R and S
                dh_cor, RR[:,i,j], SS[:,i,j] = \
                    ap.backscatter_corr(dh, dg, diff=DIFF, robust=True)

            #---------------------------------------------------------

            # plot figures
            if PLOT_TS:
                dh_cor = ap.referenced(dh_cor, to='first')
                dh = ap.referenced(dh, to='first')
                dg = ap.referenced(dg, to='first')
                k, = np.where(~np.isnan(RR[:,i,j]))
                r = np.mean(RR[k,i,j])
                s = np.mean(SS[k,i,j])
                fig = plot_rs(time, RR[:,i,j], SS[:,i,j])
                fig = plot_ts(time, lon[j], lat[i], dh_cor, dh, dg, 
                              r, s, diff=DIFF)
                if fig is None: continue
                plt.show()

            # save one TS per grid cell at a time
            #---------------------------------------------------------

            if not SAVE_TO_FILE: continue

            if isfirst:
                # open or create output file
                isfirst = False
                atom = tb.Atom.from_type('float64', dflt=np.nan)
                filters = tb.Filters(complib='zlib', complevel=9)
                c1 = din.file.createCArray('/', SAVE_AS_NAME, atom, 
                                           (nt,ny,nx), '', filters)
                c2 = din.file.createCArray('/', R_NAME, atom, 
                                           (nt,ny,nx), '', filters)
                c3 = din.file.createCArray('/', S_NAME, atom, 
                                           (nt,ny,nx), '', filters)
            c1[:,i,j] = dh_cor

    if SAVE_TO_FILE:
        c2[:] = RR
        c3[:] = SS

    if PLOT_MAP:
        if TVAR:
            # 3D -> 2D
            RR = np.mean(RR[~np.isnan(RR)], axis=0)
            SS = np.mean(SS[~np.isnan(SS)], axis=0)
        plot_map(lon, lat, np.abs(RR), BBOX, MFILE, mres=1, vmin=0, vmax=1)
        plt.title('Correlation Coefficient, R')
        plt.savefig('map_r.png')
        plot_map(lon, lat, SS, BBOX, MFILE, mres=1, vmin=-0.2, vmax=0.7)
        plt.title('Correlation Gradient, S')
        plt.savefig('map_s.png')
        plt.show()

    din.file.close()

    if SAVE_TO_FILE:
        print 'out file -->', fname_in
Exemplo n.º 4
0
FILE2 = "/Users/fpaolo/data/shelves/ross_19920715_20111015.h5"  # larsenc_19920715_20111015.h5'
FILE3 = "/Users/fpaolo/data/coastline/moa_coastfile_ll.h5"
FILE4 = "/Users/fpaolo/data/coastline/antarctica_gl_ll.h5"
# BBOX = (-71.3854, -73.0697, -58.0593, -63.0486)
BBOX = (-126.863, -46.7492, 53.2309, -47.0738)
# BBOX = (-33.4259, -46.9022, 147.058, -46.9198)

f1 = nc.Dataset(FILE1)
d1 = f1.variables
firn = d1["zs"]
year1 = d1["time"][:]
lons1 = d1["lon"][:]  # 2d
lats1 = d1["lat"][:]  # 2d
ism = d1["ism"][:]
lsm = d1["lsm"][:]
dt1 = ap.year2date(year1)
# dt1 = year1

f2 = tb.openFile(FILE2)
elev = f2.root.elev[:]
time2 = f2.root.time[:]
lon2 = f2.root.lon[:]  # 1d
lat2 = f2.root.lat[:]  # 1d
lon2 = ap.lon_180_360(lon2, inverse=True)
lons2, lats2 = np.meshgrid(lon2, lat2)
points2 = np.column_stack((lons2.ravel(), lats2.ravel()))
# points2 = (lons2[6,4], lats2[6,4])
dt2 = ap.num2date(time2)
# dt2 = ap.num2year(time2)

"""
Exemplo n.º 5
0
t4 = dt.datetime(1, 1, 1, 1, 0, 0)
t5 = dt.datetime(2013, 1, 1, 0, 0, 0)
t6 = dt.datetime(2013, 1, 1, 0, 0, 1)
t7 = dt.datetime(2013, 1, 1, 0, 1, 0)
t8 = dt.datetime(2013, 1, 1, 1, 0, 0)

y1 = ap.date2year(t1)
y2 = ap.date2year(t2)
y3 = ap.date2year(t3)
y4 = ap.date2year(t4)
y5 = ap.date2year(t5)
y6 = ap.date2year(t6)
y7 = ap.date2year(t7)
y8 = ap.date2year(t8)

d1 = ap.year2date(y1)
d2 = ap.year2date(y2)
d3 = ap.year2date(y3)
d4 = ap.year2date(y4)
d5 = ap.year2date(y5)
d6 = ap.year2date(y6)
d7 = ap.year2date(y7)
d8 = ap.year2date(y8)

print '(def date -> date2year -> year2date)'
print 'original_date    converted_date      converted_year'
print t1, ' ', d1[0], ' ', y1[0]
print t2, ' ', d2[0], ' ', y2[0]
print t3, ' ', d3[0], ' ', y3[0]
print t4, ' ', d4[0], ' ', y4[0]
print t5, ' ', d5[0], ' ', y5[0]
Exemplo n.º 6
0
def main():

    fname_in = sys.argv[1]

    din = GetData(fname_in, 'a')
    time = ap.num2date(getattr(din, T_NAME)[:])
    lon = din.lon[:]
    lat = din.lat[:]
    nrows = len(time)
    nt, ny, nx = getattr(din, H_NAME).shape  # i,j,k = t,y,x

    RR = np.empty((nt, ny, nx), 'f8') * np.nan
    SS = np.empty((nt, ny, nx), 'f8') * np.nan

    if TINT:
        intervals = [ap.year2date(tt) for tt in INTERVALS]

    if TINT:
        print 'using time-interval correlation'
    elif TVAR:
        print 'using time-variable correlation'
    else:
        print 'using constant correlation'
    print 'processing time series:'
    isfirst = True

    # iterate over every grid cell (all times): i,j = y,x
    #-----------------------------------------------------------------

    for i in xrange(ny):
        for j in xrange(nx):
            print 'time series of grid-cell:', i, j

            dh = getattr(din, H_NAME)[:nrows, i, j]
            dg = getattr(din, G_NAME)[:nrows, i, j]

            if np.alltrue(np.isnan(dh)): continue

            #---------------------------------------------------------

            if TINT:
                # satellite-dependent R and S
                dh_cor, RR[:,i,j], SS[:,i,j] = \
                    ap.backscatter_corr3(dh, dg, time, intervals,
                                         diff=DIFF, robust=True)
            elif TVAR:
                # time-varying R and S
                dh_cor, RR[:,i,j], SS[:,i,j] = \
                    ap.backscatter_corr2(dh, dg, diff=DIFF,
                                         robust=True, npts=NPTS)
            else:
                # constant R and S
                dh_cor, RR[:,i,j], SS[:,i,j] = \
                    ap.backscatter_corr(dh, dg, diff=DIFF, robust=True)

            #---------------------------------------------------------

            # plot figures
            if PLOT_TS:
                dh_cor = ap.referenced(dh_cor, to='first')
                dh = ap.referenced(dh, to='first')
                dg = ap.referenced(dg, to='first')
                k, = np.where(~np.isnan(RR[:, i, j]))
                r = np.mean(RR[k, i, j])
                s = np.mean(SS[k, i, j])
                fig = plot_rs(time, RR[:, i, j], SS[:, i, j])
                fig = plot_ts(time,
                              lon[j],
                              lat[i],
                              dh_cor,
                              dh,
                              dg,
                              r,
                              s,
                              diff=DIFF)
                if fig is None: continue
                plt.show()

            # save one TS per grid cell at a time
            #---------------------------------------------------------

            if not SAVE_TO_FILE: continue

            if isfirst:
                # open or create output file
                isfirst = False
                atom = tb.Atom.from_type('float64', dflt=np.nan)
                filters = tb.Filters(complib='zlib', complevel=9)
                c1 = din.file.createCArray('/', SAVE_AS_NAME, atom,
                                           (nt, ny, nx), '', filters)
                c2 = din.file.createCArray('/', R_NAME, atom, (nt, ny, nx), '',
                                           filters)
                c3 = din.file.createCArray('/', S_NAME, atom, (nt, ny, nx), '',
                                           filters)
            c1[:, i, j] = dh_cor

    if SAVE_TO_FILE:
        c2[:] = RR
        c3[:] = SS

    if PLOT_MAP:
        if TVAR:
            # 3D -> 2D
            RR = np.mean(RR[~np.isnan(RR)], axis=0)
            SS = np.mean(SS[~np.isnan(SS)], axis=0)
        plot_map(lon, lat, np.abs(RR), BBOX, MFILE, mres=1, vmin=0, vmax=1)
        plt.title('Correlation Coefficient, R')
        plt.savefig('map_r.png')
        plot_map(lon, lat, SS, BBOX, MFILE, mres=1, vmin=-0.2, vmax=0.7)
        plt.title('Correlation Gradient, S')
        plt.savefig('map_s.png')
        plt.show()

    din.file.close()

    if SAVE_TO_FILE:
        print 'out file -->', fname_in