예제 #1
0
def load_daily_data_general(fname, varname, from_date, to_date,
                            slice_lon, slice_lat, level):

    # the daily data is stored in yearly files
    yr_start = from_date.year
    yr_end = to_date.year

    # load each NC dataset
    gflist = []
    Ndays = 0
    for yr in range(yr_start, yr_end+1):
        g = GeoField()
        g.load(fname % yr, varname)
        if level is not None:
            g.slice_level(level)
        g.slice_spatial(slice_lon, slice_lat)
        g.slice_date_range(from_date, to_date)
        Ndays += len(g.tm)
        gflist.append(g)

    # now append all of the records together
    g = GeoField()
    d = np.zeros((Ndays, len(gflist[0].lats), len(gflist[0].lons)))
    tm = np.zeros((Ndays,))
    n = 0
    for g_i in gflist:
        Ndays_i = len(g_i.tm)
        d[n:Ndays_i + n, :, :] = g_i.d
        tm[n:Ndays_i + n] = g_i.tm
        n += Ndays_i

    # load geo_fields and then append them together
    g.use_existing(d, gflist[0].lons, gflist[0].lats, tm)
    g.transform_to_anomalies()
    g.normalize_variance()

    return g