def get_filenames(datadir, varnm, onset_nm, years, lon1, lon2, nroll):
    if nroll is not None:
        varnm = varnm + '_nroll%d' % nroll
    lonstr = atm.latlon_str(lon1, lon2, 'lon')
    yearstr = '_%d-%d.nc' % (min(years), max(years))
    filestr = datadir + 'merra_%s_reg_%s_onset_' + onset_nm + yearstr
    filenames = {}
    filenames['latlon'] = filestr % (varnm, 'latlon')
    filenames['sector'] = filestr % (varnm, lonstr)
    return filenames
Пример #2
0
def get_filenames(datadir, varnms, onset_nm, years, lon1, lon2, nroll):
    lonstr = atm.latlon_str(lon1, lon2, 'lon')
    yearstr = '_%d-%d.nc' % (min(years), max(years))
    filestr = datadir + 'merra_%s'
    if nroll is not None:
        filestr = filestr + '_nroll%d' % nroll
    filestr = filestr + '_reg_%s_onset_' + onset_nm + yearstr
    filestr2 = datadir + 'merra_%s_dailyrel_' + onset_nm + yearstr
    filenames = {}
    for varnm in varnms:
        filenames[varnm] = {'latlon_reg' : filestr % (varnm, 'latlon'),
                            'sector_reg' : filestr % (varnm, lonstr),
                            'latlon_clim' : filestr2 % varnm,
                            'sector_clim' : filestr2 % varnm}
    return filenames
Пример #3
0
def sector_mean(var, lon1, lon2):
    """Return the sector mean of a variable."""
    name = var.name
    lonstr = atm.latlon_str(lon1, lon2, 'lon')
    if (lon2 - lon1) == 360:
        lon1, lon2 = None, None
        name_out = name + '_ZON'
    else:
        name_out = name + '_SEC'
    varbar = atm.dim_mean(var, 'lon', lon1, lon2)
    varbar.name = name_out
    varbar.attrs['varnm'] = name
    varbar.attrs['lonstr'] = lonstr
    varbar.attrs['filestr'] = '%s_sector_%s' % (name, lonstr)
    return varbar
    with xray.open_dataset(files[nm]) as ds:
        data[nm] = ds[nm].load()

lat = atm.get_coord(data, 'lat')
lon = atm.get_coord(data, 'lon')
psfile = atm.homedir() + 'dynamics/python/atmos-tools/data/topo/ncep2_ps.nc'
ps = atm.get_ps_clim(lat, lon, psfile)
ps = ps / 100

figsize = (7, 9)
omitzero = False

for ssn in ['ANN', 'DJF', 'JJA', 'MAR']:
    for lonlims in [(0, 360), (60, 100)]:
        lon1, lon2 = lonlims
        lonstr = atm.latlon_str(lon1, lon2, 'lon')
        suptitle = ssn + ' ' + lonstr
        months = atm.season_months(ssn)
        v = data['V'].sel(month=months)
        if (lon2 - lon1) < 360:
            v = atm.subset(v, {'lon' : (lon1, lon2)})
            sector_scale = (lon2 - lon1) / 360.0
            psbar = atm.dim_mean(ps, 'lon', lon1, lon2)
            clev = 10
        else:
            sector_scale = None
            psbar = atm.dim_mean(ps, 'lon')
            clev = 20
        vssn = v.mean(dim='month')
        vssn_bar = atm.dim_mean(vssn, 'lon')
        psi1 = atm.streamfunction(vssn, sector_scale=sector_scale)
Пример #5
0
def get_savefile(version, savedir, varnm, onset_nm, ind_nm, year):
    filenm = savedir + version + '_%s_dailyrel' % varnm
    if ind_nm == 'retreat':
        filenm = filenm + '_retreat'
    filenm = filenm + '_%s_%d.nc' % (onset_nm, year)
    return filenm

# Lat-lon data files
datafiles = collections.OrderedDict()
for nm in varnms:
    datafiles[nm] = [yrlyfile(version, datadir, nm, yr) for yr in years]

# Zonal and sector mean data
for lonlims in [(0, 360), (60, 100)]:
    lonstr = atm.latlon_str(lonlims[0], lonlims[1], 'lon')
    subset1 = 'sector_' + lonstr
    for nm in sector_varnms:
        key = nm + '_' + subset1
        datafiles[key] = [yrlyfile(version, datadir, nm, yr, subset1)
                          for yr in years]

# ----------------------------------------------------------------------
# Onset index for each year

with xray.open_dataset(indfile) as index:
    index.load()
onset = index['onset']
retreat = index['retreat']

# ----------------------------------------------------------------------
Пример #6
0
def savefile(version, savedir, year, ndays, lon1, lon2, plev):
    lonstr =  atm.latlon_str(lon1, lon2, 'lon')
    filenm = savedir + version + '_ubudget%d_ndays%d_%s_%d.nc'
    filenm = filenm % (plev, ndays, lonstr, year)
    return filenm
Пример #7
0
def latlon_filestr(lat1, lat2, lon1, lon2):
    """Return nicely formatted string for lat-lon range."""
    latstr = atm.latlon_str(lat1, lat2, 'lat')
    lonstr = atm.latlon_str(lon1, lon2, 'lon')
    return lonstr + '_' + latstr
    with xray.open_dataset(files[nm]) as ds:
        data[nm] = ds[nm].load()

lat = atm.get_coord(data, 'lat')
lon = atm.get_coord(data, 'lon')
psfile = atm.homedir() + 'dynamics/python/atmos-tools/data/topo/ncep2_ps.nc'
ps = atm.get_ps_clim(lat, lon, psfile)
ps = ps / 100

figsize = (7, 9)
omitzero = False

for ssn in ['ANN', 'DJF', 'JJA', 'MAR']:
    for lonlims in [(0, 360), (60, 100)]:
        lon1, lon2 = lonlims
        lonstr = atm.latlon_str(lon1, lon2, 'lon')
        suptitle = ssn + ' ' + lonstr
        months = atm.season_months(ssn)
        v = data['V'].sel(month=months)
        if (lon2 - lon1) < 360:
            v = atm.subset(v, {'lon': (lon1, lon2)})
            sector_scale = (lon2 - lon1) / 360.0
            psbar = atm.dim_mean(ps, 'lon', lon1, lon2)
            clev = 10
        else:
            sector_scale = None
            psbar = atm.dim_mean(ps, 'lon')
            clev = 20
        vssn = v.mean(dim='month')
        vssn_bar = atm.dim_mean(vssn, 'lon')
        psi1 = atm.streamfunction(vssn, sector_scale=sector_scale)