示例#1
0
    files = collections.OrderedDict()
    for key in datafiles:
        files[key] = datafiles[key][y]
    d_onset = int(onset[y].values)
    d_retreat = int(retreat[y].values)
    d0 = int(index[ind_nm][y].values)
    dmin, dmax = d0 - npre, d0 + npost
    coords = {'year' : [year]}
    onset_var = xray.DataArray([d_onset], name='D_ONSET', coords=coords)
    retreat_var = xray.DataArray([d_retreat], name='D_RETREAT', coords=coords)
    for varnm in files:
        print('Reading daily data for ' + varnm)
        varid, plev = get_info(varnm)
        var = get_data_rel(varid, plev, year, files.get(varnm), data, d0, npre,
                           npost)
        var.attrs = atm.odict_delete(var.attrs, 'd_onset')
        var.name = varid
        data[varnm] = var
        savefile = get_savefile(version, savedir, varnm, onset_nm, ind_nm, year)
        print('Saving to ' + savefile)
        atm.save_nc(savefile, var, onset_var, retreat_var)

# ----------------------------------------------------------------------
# Compute climatologies and save
relfiles = {}
for key in datafiles:
    relfiles[key] = [get_savefile(version, savedir, key, onset_nm, ind_nm, yr)
                     % yr for yr in years]

for varnm in relfiles:
    varid, _ = get_info(varnm)
示例#2
0
# vertical mean
plev = None

# Read daily data from each year
if plev is None:
    T = atm.combine_daily_years('Tbar', ttfiles, years, yearname='year')
else:
    T = atm.combine_daily_years('T', ttfiles, years, yearname='year',
                                subset_dict={'plev' : (plev, plev)})
    # Remove extra dimension (vertical)
    pdim = atm.get_coord(T, 'plev', 'dim')
    pname = atm.get_coord(T, 'plev', 'name')
    name, attrs, coords, dims = atm.meta(T)
    dims = list(dims)
    dims.pop(pdim)
    coords = atm.odict_delete(coords, pname)
    T = xray.DataArray(np.squeeze(T.values), dims=dims, coords=coords,
                       name=name, attrs=attrs)

# Calculate index
north=(5, 30, 40, 100)
south=(-15, 5, 40, 100)
index['TT'] = indices.onset_TT(T, north=north, south=south)

# Some weirdness going on in 1991, for now just set to NaN
for nm in ['ttn', 'tts', 'tseries']:
    vals = index['TT'][nm].values
    vals = np.ma.masked_array(vals, abs(vals) > 1e30).filled(np.nan)
    index['TT'][nm].values = vals
index['TT'].attrs['title'] = 'TT'