コード例 #1
0
lat1, lat2 = 10, 30
subset_dict = {'lat' : (lat1, lat2), 'lon' : (lon1, lon2)}

# ----------------------------------------------------------------------
# Read data
ts = xray.Dataset()
for nm in files:
    var = atm.combine_daily_years(nm, files[nm], years, yearname='year',
                                  subset_dict=subset_dict)
    var = atm.mean_over_geobox(var, lat1, lat2, lon1, lon2)
    units = var.attrs.get('units')
    if units in ['kg/m2/s', 'kg m-2 s-1']:
        var = atm.precip_convert(var, units, 'mm/day')
    elif units in ['kg/m2', 'kg m-2']:
        var.attrs['units'] = 'mm'
    long_name = var.attrs.get('long_name')
    var.attrs = {'units' : units, 'long_name' : long_name}
    ts[nm] = utils.wrapyear_all(var, daymin, daymax)

# dW/dt
dwdt = atm.gradient(ts['TQV'], ts['day'].values, axis=-1)
dwdt.attrs['units'] = 'mm/day'
dwdt.attrs['long_name'] = 'd/dt of ' + ts['TQV'].attrs.get('long_name')
ts['DWDT'] = dwdt
ts = ts.rename({'DQVDT_ANA' : 'DWDT_ANA'}).drop('TQV')
for nm, val in zip(['lat1', 'lat2', 'lon1', 'lon2'], [lat1, lat2, lon1, lon2]):
    ts.attrs[nm] = val

print('Saving to ' + savefile)
ts.to_netcdf(savefile)
コード例 #2
0
    index.load()
index = index.sel(year=years)
d0 = index[ind_nm].values

# Precip data
if pcp_nm == 'cmap':
    pcp = precipdat.read_cmap(pcpfiles, yearmin=min(years), yearmax=max(years))

    # Interpolate to daily resolution
    name, attrs, coords, dimnames = atm.meta(pcp)
    days = np.arange(3, 364)
    interp_func = scipy.interpolate.interp1d(pcp['day'], pcp, axis=1)
    vals = interp_func(days)
    coords['day'] = xray.DataArray(days, coords={'day' : days})
    pcp = xray.DataArray(vals, dims=dimnames, coords=coords, name=name,
                         attrs=attrs)
else:
    pcp = atm.combine_daily_years(None, pcpfiles, years, yearname='year',
                                  subset_dict=subset_dict)


# Wrap from following year to get extended daily range
daymin = min(d0) - npre
daymax = max(d0) + npost
pcp = utils.wrapyear_all(pcp, daymin=daymin, daymax=daymax)

# Daily relative to onset/withdrawal
pcp_rel = utils.daily_rel2onset(pcp, d0, npre, npost)
print('Saving to ' + savefile)
atm.save_nc(savefile, pcp_rel)