Пример #1
0
def get_enso_indices(years,
                     inds=['ONI_MAM', 'ONI_JJA', 'MEI_MARAPR', 'MEI_JULAUG'],
                     ensofiles=None):
    """Return ENSO indices.
    """

    if ensofiles is None:
        ensodir = atm.homedir() + 'dynamics/calc/ENSO/'
        ensofiles = {'MEI' : ensodir + 'enso_mei.csv',
                     'ONI' : ensodir + 'enso_oni.csv'}


    enso_in = {}
    for key in ensofiles:
        enso_in[key] = pd.read_csv(ensofiles[key], index_col=0)

    enso = pd.DataFrame()
    for key in enso_in:
        for ssn in enso_in[key]:
            enso[key + '_' + ssn] = enso_in[key][ssn]

    enso = enso.loc[enso.index.isin(years)]
    enso = enso[inds]

    return enso
Пример #2
0
import matplotlib.pyplot as plt
import matplotlib as mpl
import collections
import pandas as pd

import atmos as atm
import indices
import utils

mpl.rcParams["font.size"] = 11

# ----------------------------------------------------------------------
version = "merra2"
years = np.arange(1980, 2016)
onset_nm = "CHP_MFC"
datadir = atm.homedir() + "datastore/%s/analysis/" % version
yearstr = "%d-%d.nc" % (min(years), max(years))
filestr = datadir + version + "_index_%s_" + yearstr
datafiles = {nm: filestr % nm for nm in ["CHP_MFC", "HOWI", "OCI"]}
datafiles["MOK"] = atm.homedir() + "dynamics/python/monsoon-onset/data/MOK.dat"

# ----------------------------------------------------------------------
# Read data
index = {}

for nm in datafiles:
    if nm == "MOK":
        mok = indices.onset_MOK(datafiles["MOK"], yearsub=years)
        index["MOK"] = xray.Dataset({"onset": mok})
    else:
        with xray.open_dataset(datafiles[nm]) as ds:
Пример #3
0
sys.path.append('/home/jwalker/dynamics/python/atmos-read')

import xray
import numpy as np
from datetime import datetime
import matplotlib.pyplot as plt
import pandas as pd
import atmos as atm
import precipdat
import merra

# ----------------------------------------------------------------------
#version, years = 'merra', np.arange(1979, 2015)
version, years = 'merra2', np.arange(1980, 2016)

datadir = atm.homedir() + 'datastore/%s/daily/' % version
months = np.arange(1, 13)
subset = '_40E-120E_90S-90N'

def get_var(datadir, version, varnm, subset, year):
    filenm = '%s%s_%s%s_%d.nc' % (datadir, version, varnm, subset, year)
    with xray.open_dataset(filenm) as ds:
        var = ds[varnm].load()
    return var

for year in years:
    print('Calculating MFC %d' % year)
    uq_int = get_var(datadir, version, 'UFLXQV', subset, year)
    vq_int = get_var(datadir, version, 'VFLXQV', subset, year)
    mfc = atm.moisture_flux_conv(uq_int, vq_int, already_int=True)
    mfc.attrs['long_name'] = mfc.name
Пример #4
0
import sys
sys.path.append('/home/jwalker/dynamics/python/atmos-tools')
sys.path.append('/home/jwalker/dynamics/python/atmos-read')

import xray
import numpy as np
from datetime import datetime
import matplotlib.pyplot as plt
import pandas as pd
import atmos as atm
import precipdat
import merra

# ----------------------------------------------------------------------

datadir = atm.homedir() + 'datastore/merra/daily/'
year = 2014
subset = '_40E-120E_90S-90N'


def get_var(datadir, varnm, subset, year):
    filenm = '%smerra_%s%s_%d.nc' % (datadir, varnm, subset, year)
    with xray.open_dataset(filenm) as ds:
        var = ds[varnm].load()
    return var


uq_int = get_var(datadir, 'UFLXQV', subset, year)
vq_int = get_var(datadir, 'VFLXQV', subset, year)

mfc = atm.moisture_flux_conv(uq_int, vq_int, already_int=True)
Пример #5
0
def savefile(year, mon, pmin, pmax):
    savedir = atm.homedir() + 'datastore/merra/daily/'
    filn = savedir + 'merra_T%d-%d_%d%02d.nc' % (pmin/100, pmax/100, year, mon)
    print('Saving to ' + filn)
    return filn
Пример #6
0
import collections
import pandas as pd
import scipy.signal
import atmos as atm
import precipdat
import merra
import indices
import utils

# ----------------------------------------------------------------------
isave = True
exts = ['png', 'eps', 'pdf']
index = collections.OrderedDict()

years = np.arange(1979, 2015)
datadir = atm.homedir() + 'datastore/merra/daily/'
#vimtfile = datadir + 'merra_vimt_ps-300mb_apr-sep_1979-2014.nc'
vimtfiles = [datadir + 'merra_vimt_ps-300mb_%d.nc' % yr for yr in years]
mfcfiles = [datadir + 'merra_MFC_ps-300mb_%d.nc' % yr for yr in years]
precipfiles = [datadir + 'merra_precip_%d.nc' % yr for yr in years]
#precipfile = datadir + 'merra_precip_40E-120E_60S-60N_days91-274_1979-2014.nc'
cmapfile = atm.homedir() + 'datastore/cmap/cmap.precip.pentad.mean.nc'
eraIfile = atm.homedir() + ('datastore/era_interim/analysis/'
                            'era_interim_JJAS_60-100E_index.csv')
ocifiles = [datadir + 'merra_uv850_40E-120E_60S-60N_%d.nc' % y for y in years]
ttfiles = [datadir + 'merra_T200-600_apr-sep_%d.nc' % yr for yr in years]
airfile = atm.homedir() + 'datastore/AIR/AIR_JJAS.csv'
uvfiles = [datadir + 'merra_uv200_40E-120E_60S-60N_%d.nc' % yr for yr in years]

# Lat-lon box for WLH method
lon1, lon2 = 60, 100
Пример #7
0
sys.path.append('/home/jwalker/dynamics/python/monsoon-onset')

import xray
import numpy as np
import collections
import pandas as pd
import scipy

import atmos as atm
import indices
import utils
import precipdat

# ----------------------------------------------------------------------
version, yearstr = 'merra2', '1980-2015'
datadir = atm.homedir() + 'datastore/%s/analysis/' % version
onset_nm = 'CHP_MFC'
indfile = atm.homedir() + ('datastore/%s/analysis/%s_index_%s_%s.nc' %
                           (version, version, onset_nm, yearstr))
ind_nm, npre, npost = 'onset', 140, 230
#ind_nm, npre, npost = 'retreat', 270, 100

pcp_nm = 'gpcp'
years = np.arange(1997, 2016)
#years = np.arange(1980, 2015) # CMAP last full year is 2014
#pcpfiles = atm.homedir() + 'datastore/cmap/cmap.enhanced.precip.pentad.mean.nc'
pcpfiles = [atm.homedir() + 'datastore/gpcp/gpcp_daily_%d.nc' % yr
            for yr in years]

savefile = datadir + '%s_dailyrel_%s_%s-%d.nc' % (pcp_nm, onset_nm, min(years),
                                                  max(years))
import sys
sys.path.append('/home/jwalker/dynamics/python/atmos-tools')
sys.path.append('/home/jwalker/dynamics/python/atmos-read')

import numpy as np
import xray
import pandas as pd
import matplotlib.pyplot as plt

import atmos as atm
import merra
from indices import onset_SJKE, summarize_indices, plot_index_years

# ----------------------------------------------------------------------
# Compute SJ indices (Boos and Emmanuel 2009)
datadir = atm.homedir() + 'datastore/merra/daily/'
years = np.arange(1979, 2015)
filestr = 'merra_uv850_40E-120E_60S-60N_'
datafiles = [datadir + filestr + '%d.nc' % y for y in years]

# Read daily data from each year
ds = atm.combine_daily_years(['U', 'V'], datafiles, years)

# Remove extra dimension from data
u = atm.squeeze(ds['U'])
v = atm.squeeze(ds['V'])

# Calculate OCI index
sjke = onset_SJKE(u, v)

# Summary plot and timeseries in individual years
Пример #9
0
def savefile(year, mon):
    savedir = atm.homedir() + 'datastore/merra/daily/'
    filn = savedir + 'merra_vimt_%d%02d.nc' % (year, mon)
    print('Saving to ' + filn)
    return filn
Пример #10
0
import atmos as atm
import merra
import precipdat
import utils

mpl.rcParams['font.size'] = 11

# ----------------------------------------------------------------------
onset_nm = 'CHP_MFC'
pcp_nm = 'CMAP'
theta_nm = 'THETA_E950'
dtheta_nm = theta_nm + '_DY'
years = np.arange(1979, 2015)

reldir = atm.homedir() + 'datastore/merra/analysis/'
datadir = atm.homedir() + 'datastore/merra/daily/'
filestr = datadir + 'merra_MFC_40E-120E_90S-90N_%d.nc'
indfiles = [filestr % yr for yr in years]
pcpfile = atm.homedir() + '/datastore/cmap/cmap.enhanced.precip.pentad.mean.nc'

lon1, lon2 = 60, 100
lat1, lat2 = 10, 30
npre, npost = 120, 200
pmid = 500
nroll = 7
plot_yearly = False

varnms = ['precip', 'U200', 'U850', 'V200', 'V850', 'PSI', 'T200', theta_nm,
          dtheta_nm, 'HFLUX', 'VFLXMSE', 'VFLXCPT', 'VFLXPHI',
          'VFLXLQV']
Пример #11
0
import sys
sys.path.append('/home/jwalker/dynamics/python/atmos-tools')
sys.path.append('/home/jwalker/dynamics/python/atmos-read')

import xray
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import collections
import pandas as pd

import atmos as atm
import indices
import utils

style = atm.homedir() + 'dynamics/python/mpl-styles/grl_article.mplstyle'
plt.style.use(style)
figwidth = 7.48
fontsize = mpl.rcParams['font.size']
labelsize = fontsize + 3
dashes = [6, 2]

# ----------------------------------------------------------------------
version = 'merra2'
years = np.arange(1980, 2016)
datadir = atm.homedir() + 'datastore/%s/analysis/' % version
onset_nm = 'CHP_MFC'
onset_nms = ['CHP_MFC', 'MOK', 'HOWI', 'OCI']
#pts_nm = 'CHP_PCP'
pts_nm = 'CHP_GPCP'
#pcp_nm = 'PRECTOT'
import sys
sys.path.append('/home/jwalker/dynamics/python/atmos-tools')
sys.path.append('/home/jwalker/dynamics/python/atmos-read')

import xray
import numpy as np
from datetime import datetime
import matplotlib.pyplot as plt
import pandas as pd
import atmos as atm
import precipdat
from indices import onset_WLH, onset_WLH_1D

datadir = atm.homedir() + 'datastore/cmap/'
cmap_file = datadir + 'cmap.precip.pentad.mean.nc'

def all_WLH(cmap_file, yearmin=None, yearmax=None, climatology=False,
            kmax=12, threshold=5.0, onset_min=20):
    precip = precipdat.read_cmap(cmap_file, yearmin, yearmax)
    lat = atm.get_coord(precip, 'lat')
    lon = atm.get_coord(precip, 'lon')
    years = precip.year
    if climatology:
        precip = precip.mean(dim='year')
        axis = 0
    else:
        axis = 1
    wlh = onset_WLH(precip, axis, kmax, threshold, onset_min)
    wlh['precip'] = precip
    wlh['lat'] = lat
    wlh['lon'] = lon
Пример #13
0
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import collections
import pandas as pd

import atmos as atm
import utils  # monsoon-onset

mpl.rcParams['font.size'] = 10

# ----------------------------------------------------------------------

onset_nm = 'CHP_MFC'
years = np.arange(1979, 2015)
datadir = atm.homedir() + 'datastore/merra/analysis/'

varnms = ['U200', 'T200']

datafiles = collections.OrderedDict()
filestr = datadir + 'merra_%s_dailyrel_%s_%d.nc'
for nm in varnms:
    datafiles[nm] = [filestr % (nm, onset_nm, yr) for yr in years]

# ----------------------------------------------------------------------
# Read data

data = collections.OrderedDict()
for nm in datafiles:
    var, onset, retreat = utils.load_dailyrel(datafiles[nm])
    data[nm] = var
Пример #14
0
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import collections
import pandas as pd

import atmos as atm
import utils

mpl.rcParams['font.size'] = 10

# ----------------------------------------------------------------------

onset_nm = 'CHP_MFC'
years = np.arange(1979, 2015)
datadir = atm.homedir() + 'datastore/merra/analysis/'
savedir = 'figs/'

varnms = ['U200', 'V200', 'T200', 'H200', 'U850', 'V850', 'T850', 'H850',
          'THETA950', 'THETA_E950', 'QV950', 'T950', 'HFLUX', 'EFLUX',
          'EVAP', 'precip']
regdays = [-60, -30, 0]
seasons = ['JJAS']
lon1, lon2 = 60, 100
nstd = 2.0 # Number of stdev for strong/weak composites
nroll = 5
savestr = savedir + 'reg_'
if nroll is not None:
    savestr = savestr + 'nroll%d_' % nroll

# ----------------------------------------------------------------------
import numpy as np
import matplotlib.pyplot as plt
import xray

import atmos as atm

# ----------------------------------------------------------------------
# Monthly climatology

yearstr = '1979-2015'
varnms = ['U', 'V']
datadir = atm.homedir() + 'datastore/merra/monthly/'
filestr = datadir + 'merra_%s_%s.nc'
files = {nm: filestr % (nm, yearstr) for nm in varnms}

data = xray.Dataset()
for nm in varnms:
    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)]:
import collections

import atmos as atm
import merra
import indices
import utils

# ----------------------------------------------------------------------
version = 'merra2'
years = np.arange(1980, 2016)
onset_nm = 'CHP_MFC'
plevs = [1000,925,850,775,700,600,500,400,300,250,200,150,100,70,50,30,20]
ind_nm, npre, npost = 'onset', 140, 230
#ind_nm, npre, npost = 'retreat', 270, 100

datadir = atm.homedir() + 'datastore/%s/analysis/' % version
savedir = atm.homedir() + 'eady/datastore/%s/analysis/' % version
filestr = datadir + version + '_ubudget%d_ndays5_60E-100E_%d.nc'
savestr = (savedir + version + '_ubudget%d_dailyrel_' + onset_nm +
           '_ndays5_60E-100E')
datafiles, savefiles = {}, {}
for plev in plevs:
    datafiles[plev] = [filestr % (plev, yr) for yr in years]
    savefiles[plev] = [savestr % plev + '_%d.nc' % yr for yr in years]
yearstr = '%d-%d' % (min(years), max(years))
indfile = savedir + version + '_index_%s_%s.nc' % (onset_nm, yearstr)

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

with xray.open_dataset(indfile) as index:
Пример #17
0
import time
import matplotlib.pyplot as plt
import pandas as pd
import atmos as atm
import precipdat
import merra

# ----------------------------------------------------------------------
# Download daily data

version = 'merra'
years = range(1979, 1986)
#version = 'merra2'
#years = np.arange(1980, 2016)

datadir = atm.homedir() + 'datastore/' + version + '/daily/'
months = np.arange(1, 13)

varnms = ['QLML', 'TLML', 'UFLXCPT', 'UFLXPHI']

latlon=(-90, 90, 40, 120)
plevs = [1000,925,850,775,700,600,500,400,300,250,200,150,100,70,50,30,20]
#plevs=(850, 200)
sector_lons=(60, 100)
#dp_vars = ['U', 'OMEGA']
dp_vars = []


def group_variables(varnms, version):
    """Group variables together according to URL."""
    def get_group(varnm, version):
import numpy as np
import matplotlib.pyplot as plt
import xray

import atmos as atm

# ----------------------------------------------------------------------
# Monthly climatology

yearstr = '1979-2015'
varnms = ['U', 'V']
datadir = atm.homedir() + 'datastore/merra/monthly/'
filestr = datadir + 'merra_%s_%s.nc'
files = {nm : filestr % (nm, yearstr) for nm in varnms}

data = xray.Dataset()
for nm in varnms:
    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)]:
import numpy as np
import xray
import pandas as pd
import matplotlib.pyplot as plt

import atmos as atm
import merra
from indices import onset_changepoint_merged

# ----------------------------------------------------------------------
# Onset changepoint
years = range(1979, 2015)
lon1, lon2 = 60, 100
lat1, lat2 = 10, 30
varnms = ["MFC", "precip"]
datadir = atm.homedir() + "datastore/merra/daily/"
savedir = atm.homedir() + "datastore/merra/analysis/"
icalc = False
isavefigs = True

if icalc:
    subset_dict = {"lat": (lat1, lat2), "lon": (lon1, lon2)}
    for varnm in varnms:
        if varnm == "MFC":
            varid, filestr = "MFC", "MFC_ps-300mb"
        elif varnm == "precip":
            varid, filestr = "PRECTOT", "precip"

        files = [datadir + "merra_%s_%d.nc" % (filestr, year) for year in years]
        data = atm.combine_daily_years(varid, files, years, yearname="year", subset_dict=subset_dict)
        data = atm.mean_over_geobox(data, lat1, lat2, lon1, lon2)