Ejemplo n.º 1
0
def interp_nc(nc,
              var,
              stations,
              time=True,
              tz=False,
              method='linear',
              map=None):
    m = mp.basemap(nc) if map is None else map
    xy = m.xy()
    ij = m(*hh.lonlat(stations))
    x = nc.variables[var][:].squeeze()
    if time:
        t = pd.DatetimeIndex(hh.get_time(nc))
        if tz:
            t = t.tz_localize('UTC').tz_convert(hh.CEAZAMetTZ())
        else:
            t -= np.timedelta64(4, 'h')
        return sp.grid_interp(xy, x, ij, stations.index, t, method=method)
    else:
        return sp.grid_interp(xy, hh.g2d(x), ij, stations.index, method=method)
Ejemplo n.º 2
0
def interp4D():
    nc = Dataset('data/wrf/d02_2014-09-10.nc')
    m = mp.basemap(nc)
    xy = m(*hh.lonlat(nc))
    ij = m(*hh.lonlat(sta))
    t = hh.get_time(nc) - np.timedelta64(4, 'h')

    z = sp.grid_interp(xy,
                       nc.variables['HGT'][:],
                       ij,
                       sta.index,
                       method='linear')
    TH2 = sp.grid_interp(xy,
                         nc.variables['TH2'][:],
                         ij,
                         sta.index,
                         t,
                         method='linear')
    TSK = sp.grid_interp(xy,
                         nc.variables['TSK'][:],
                         ij,
                         sta.index,
                         t,
                         method='linear')
    GP = sp.interp4D(xy, nc.variables['PH'][:], ij, sta.index, t, 'linear')
    GPB = sp.interp4D(xy, nc.variables['PHB'][:], ij, sta.index, t, 'linear')
    P = sp.interp4D(xy, nc.variables['P'][:], ij, sta.index, t, 'linear')
    PB = sp.interp4D(xy, nc.variables['PB'][:], ij, sta.index, t, 'linear')
    TH = sp.interp4D(xy, nc.variables['T'][:], ij, sta.index, t, 'linear')

    V = pd.HDFStore('data/d02_4D.h5')
    V['GP'] = GPB.add(GP)
    V['P'] = PB.add(P)
    V['T'] = TH
    V['TH2'] = TH2
    V['TSK'] = TSK
    V['z'] = z
Ejemplo n.º 3
0
def interp_grib(grb, stations, method='linear', transf=False):
    """
If transf=True, first project geographical coordinates to map, then use map coordinates
to interpolate using an unstructured array of points. Otherwise interpret lat/lon as regular
(enough) grid and use grid interpolation.
	"""
    x, t, lon, lat = hh.ungrib(grb)
    if transf:
        m = mp.basemap((lat, lon))
        return sp.irreg_interp(m(lon, lat),
                               x,
                               m(*hh.lonlat(stations)),
                               stations.index,
                               t,
                               method=method)
    else:
        lon -= 360
        return sp.grid_interp((lon, lat),
                              x,
                              hh.lonlat(stations),
                              stations.index,
                              t,
                              method=method)
Ejemplo n.º 4
0
def interp2D(method='nearest', zmethod='nearest'):
    T0 = st.interp_grib(pygrib.open('data/fnl/T2.grib2'), sta, method=method)
    T0.sort_index(inplace=True)

    z, lat, lon = pygrib.open('data/fnl/oro.grb2')[1].data()
    lon -= 360
    # cut off +/- 90 latitude
    z0 = sp.grid_interp((lon[1:-1, :], lat[1:-1, :]),
                        z[1:-1, :],
                        hh.lonlat(sta),
                        sta.index,
                        method=zmethod)

    print('d01')
    g1 = Dataset('data/wrf/d01_T2_2014-09-10.nc')
    T1 = st.interp_nc(g1, 'T2', sta, method=method)
    z1 = st.interp_nc(g1, 'HGT', sta, time=False, method=zmethod)

    print('d02')
    g2 = Dataset('data/wrf/d02_2014-09-10.nc')
    T2 = st.interp_nc(g2, 'T2', sta, method=method)
    z2 = st.interp_nc(g2, 'HGT', sta, time=False, method=zmethod)

    print('d03')
    g3 = Dataset('data/orlando/T2.nc')
    T3 = st.interp_nc(g3, 'T2', sta, method=method)
    z3 = st.interp_nc(g3, 'HGT', sta, time=False, method=zmethod)

    Z = pd.DataFrame({'d01': z1, 'd02': z2, 'd03': z3, 'fnl': z0})
    V = pd.Panel.from_dict({
        'd01': T1,
        'd02': T2,
        'd03': T3,
        'fnl': T0
    },
                           orient='minor')
    return V, Z
Ejemplo n.º 5
0
# v = nc.variables['V'][:]
# w = nc.variables['W'][:]
# gp = (nc.variables['PHB']+nc.variables['PH'])/9.81
# 
# uT = .5 * u[:,:,1:-1,1:-1]*(T[:,:,1:-1,:-1]+T[:,:,1:-1,1:])
# vT = .5 * v[:,:,1:-1,1:-1]*(T[:,:,:-1,1:-1]+T[:,:,1:,1:-1])
# wT = .5 * w[:,1:-1,1:-1,1:-1]*(T[:,:-1,1:-1,1:-1]+T[:,1:,1:-1,1:-1])
# 
# ad = np.diff(uT,1,3)/10000 + np.diff(vT,1,2)/10000
# dw = np.diff(wT,1,1)/np.diff(gp[:,1:-1,1:-1,1:-1],1,1)


D = pd.HDFStore('../data/station_data.h5')
S = pd.HDFStore('../data/LinearLinear.h5')

T = hh.extract(D['ta_c'],'prom',1)
Tm = S['T2']['d02']
sta = D['sta']
b = Tm-T

nc = Dataset('../data/wrf/d02_2014-09-10.nc')
t = pd.DatetimeIndex(hh.get_time(nc)) - np.timedelta64(4,'h')

ma = basemap(nc)
ij = ma(*hh.lonlat(sta))
lon,lat = ma.lonlat()
xy = (lon[1:-1,1:-1],lat[1:-1,1:-1])
ad = sp.grid_interp(xy, np.load('adv.npy'), ij, sta.index, t, method='linear')

d = pd.Panel({'adv':ad,'bias':b})
dm = d.groupby(d.major_axis.date,'major').mean().to_frame()