Ejemplo n.º 1
0
cdutil.setTimeBoundsMonthly(u)
cdutil.setTimeBoundsMonthly(v)
cdutil.setTimeBoundsMonthly(ps)

field = cdutil.ANNUALCYCLE.departures(field)
sst = cdutil.ANNUALCYCLE.departures(sst)
u = cdutil.ANNUALCYCLE.departures(u)
v = cdutil.ANNUALCYCLE.departures(v)
ps = cdutil.ANNUALCYCLE.departures(ps)

CTIminlati = np.argmin(np.abs(lats - (-6)))
CTImaxlati = np.argmin(np.abs(lats - 6))
CTIminloni = np.argmin(np.abs(lons - 0))
CTImaxloni = np.argmin(np.abs(lons - 90))

CTI = spatial_ave(sst[:, CTIminlati:CTImaxlati, CTIminloni:CTImaxloni],
                  lats[CTIminlati:CTImaxlati])

#SUBTRACT COLD TONGUE INDEX FROM SST

#coarse grid lat/lon spacing
cstep = 1
lats = np.arange(minlat, maxlat + cstep, cstep)
lons = np.arange(0, 360 + cstep, cstep)

cgrid = cdms2.createGenericGrid(lats, lons)
#regridfunc = Regridder(ingrid, cgrid)
sst = sst.regrid(cgrid, regridTool="esmf", regridMethod="linear")
field = field.regrid(cgrid, regridTool="esmf", regridMethod="linear")
u = u.regrid(cgrid, regridTool="esmf", regridMethod="linear")
v = v.regrid(cgrid, regridTool="esmf", regridMethod="linear")
ps = ps.regrid(cgrid, regridTool="esmf", regridMethod="linear")
field = cdutil.ANNUALCYCLE.departures(field)
sst = cdutil.ANNUALCYCLE.departures(sst)

CTIminlati = np.argmin(np.abs(lats - (-6)))
CTImaxlati = np.argmin(np.abs(lats - 6))
CTIminloni = np.argmin(np.abs(lons - 0))
CTImaxloni = np.argmin(np.abs(lons - 90))

# CTI Filter requirements.
order = 5
fs = 1  # sample rate, (cycles per month)
Tn = 3.
cutoff = 1 / Tn  # desired cutoff frequency of the filter (cycles per month)

CTI = spatial_ave(sst[:, CTIminlati:CTImaxlati, CTIminloni:CTImaxloni],
                  lats[CTIminlati:CTImaxlati])

CTI = butter_lowpass_filter(CTI, cutoff, fs, order)

#TODO:  SUBTRACT COLD TONGUE INDEX FROM SST

#coarse grid lat/lon spacing
#cstep=1
#lats = np.arange(minlat,maxlat+cstep,cstep)
#lons = np.arange(0,360+cstep,cstep)
#
#
#cgrid = cdms2.createGenericGrid(lats,lons)
##regridfunc = Regridder(ingrid, cgrid)
#sst = sst.regrid(cgrid, regridTool="esmf", regridMethod = "linear")
#field = field.regrid(cgrid, regridTool="esmf", regridMethod = "linear")
if detr: 
 sst = detrend(sst)
 u = detrend(u)
 v = detrend(v)
 field = detrend(field)
 
 
lats = field.getLatitude()[:]
lons = field.getLongitude()[:]
 
CTIminlati = np.argmin(np.abs(lats - (-6)))
CTImaxlati = np.argmin(np.abs(lats - 6))
CTIminloni = np.argmin(np.abs(lons - 0))
CTImaxloni = np.argmin(np.abs(lons - 90))
 
CTI = spatial_ave(sst[:,CTIminlati:CTImaxlati,CTIminloni:CTImaxloni], lats[CTIminlati:CTImaxlati])

#lats = sst.getLatitude()[:]
#lons = sst.getLongitude()[:]
#nt = sst.shape[0]
#lons[0] = 0
#nlat = len(lats)
#nlon = len(lons)


t = sst.getTime().asRelativeTime("months since 1980")
t = np.array([x.value for x in t])
tyears = 1980 + t/12.

MMstarti = np.where(MMt == tyears[0])[0][0]
MMendi = np.where(MMt == tyears[-1])[0][0]
Ejemplo n.º 4
0
basetf = 10

sst = an_ave(sst)
#CRE_surf_an = an_ave(thf)
#ps_an = an_ave(ps)
field = an_ave(field)

nt = sst.shape[0]

#detrend annual fields instead of monthly? prevents thf from blowing up for some reason...
if detr:
    sst, params = detrend_separate(sst)
    #ps_an, params = detrend_separate(ps_an)
    field, params = detrend_separate(field)

sst_globe_an = spatial_ave(sst, lats)
field_globe_an = spatial_ave(field, lats)

#subtract global annual mean to isolate processes in NA
sstprime = sst.T - sst_globe_an
sstprime = sstprime.T

fieldprime = field.T - np.tile(field_globe_an.T, (nlon, nlat, 1, 1))
fieldprime = fieldprime.T

#CHANGE THIS TO MODIFY RM WINDOW LENGTH
N_map = 5
ci = (N_map - 1) / 2
ltlag = 5
stlag = 1
Ejemplo n.º 5
0
        units = r'W/m$^2$'
    
    for ll, lag in enumerate(lags):
        
        #print('lag',lag)
        
        print 
        
        if corr:
           lagcorrs[ll,:] = st2.cor(sst,field,lagx=-lag)
        else:
           # Standardize SST
           sst = (sst - sst.mean(dim='time'))/sst.std(dim='time')
           lagcorrs[ll,:], intercept = st2.reg(sst,field,lagx=-lag)
        
    avelagcorrs[jj,:] = st2.spatial_ave(np.ma.array(lagcorrs, mask = np.isnan(lagcorrs)), lats)
        

# Plotting
    
vmin=-0.6
vmax=0.6
cbstep=0.2
if not(corr):
   vmin=-15.0
   vmax=15.0
   cbstep=5.0
   
lagoffset = np.diff(lags)[0]/2.

nlags = len(lags)
Ejemplo n.º 6
0
dLW_q_surf_cs = np.ma.sum(q_LW_kernel_surf_cs * dq * pdiff, axis=1)

#TODO: Calculate surface albedo component of TOA, ATM, and surface radiation

#TODO: Compute cloud component of TOA, ATM and surface radiation

############## SELECT REGION FOR ANALYSIS
nlats = len(lats)
lindx = nlats / 2
uindx = np.where(lats > 60)[0][0]
reglats = lats[lindx:uindx]

#dLW_t_TOA_globalmean = spatial_ave(-dLW_ta_TOA-dLW_ts_TOA, lats)
#dLW_t_surf_globalmean = spatial_ave(-dLW_ta_surf-dLW_ts_surf, lats)

dLW_t_TOA_cs_globalmean = spatial_ave(-dLW_ta_TOA_cs - dLW_ts_TOA_cs, lats)
dLW_t_surf_cs_globalmean = spatial_ave(-dLW_ta_surf_cs - dLW_ts_surf_cs, lats)

dLW_q_TOA_cs_globalmean = spatial_ave(-dLW_q_TOA_cs, lats)
dLW_q_surf_cs_globalmean = spatial_ave(-dLW_q_surf_cs, lats)

#dLW_t_TOA_NHmean = spatial_ave(-dLW_ta_TOA[:,lindx:uindx,:]-dLW_ts_TOA[:,lindx:uindx,:], reglats)
#dLW_t_surf_NHmean = spatial_ave(-dLW_ta_surf[:,lindx:uindx,:]-dLW_ts_surf[:,lindx:uindx,:], reglats)

dLW_t_TOA_cs_NHmean = spatial_ave(
    -dLW_ta_TOA_cs[:, lindx:uindx, :] - dLW_ts_TOA_cs[:, lindx:uindx, :],
    reglats)
dLW_t_surf_cs_NHmean = spatial_ave(
    -dLW_ta_surf_cs[:, lindx:uindx, :] - dLW_ts_surf_cs[:, lindx:uindx, :],
    reglats)
field = cdutil.ANNUALCYCLE.departures(field)
sst = cdutil.ANNUALCYCLE.departures(sst)

CTIminlati = np.argmin(np.abs(lats - (-6)))
CTImaxlati = np.argmin(np.abs(lats - 6))
CTIminloni = np.argmin(np.abs(lons - 0))
CTImaxloni = np.argmin(np.abs(lons - 90))

# CTI Filter requirements.
order = 5
fs = 1  # sample rate, (cycles per month)
Tn = 3.
cutoff = 1 / Tn  # desired cutoff frequency of the filter (cycles per month)

CTI = spatial_ave(sst[:, CTIminlati:CTImaxlati, CTIminloni:CTImaxloni],
                  lats[CTIminlati:CTImaxlati])

CTI = butter_lowpass_filter(CTI, cutoff, fs, order)

#TODO:  SUBTRACT COLD TONGUE INDEX FROM SST

#coarse grid lat/lon spacing
#cstep=1
#lats = np.arange(minlat,maxlat+cstep,cstep)
#lons = np.arange(0,360+cstep,cstep)
#
#
#cgrid = cdms2.createGenericGrid(lats,lons)
##regridfunc = Regridder(ingrid, cgrid)
#sst = sst.regrid(cgrid, regridTool="esmf", regridMethod = "linear")
#field = field.regrid(cgrid, regridTool="esmf", regridMethod = "linear")
#AMO = signal.detrend(AMO)

#NAthf2 = signal.detrend(NAthf2)
#thfanom_globe_an = signal.detrend(thfanom_globe_an)
#thfanom_na_an = signal.detrend(thfanom_na_an)

sstcorrs = MV.zeros((nlat, nlon))
sstpvals = MV.zeros((nlat, nlon))
thfcorrs_lt = MV.zeros((nlat, nlon))
thfcorrs_st = MV.zeros((nlat, nlon))
pscorrs_lt = MV.zeros((nlat, nlon))
pscorrs_st = MV.zeros((nlat, nlon))
pscorrs = MV.zeros((nlat, nlon))
thfcorrs = MV.zeros((nlat, nlon))

thf_globe_an = spatial_ave(thf_an, lats)
ps_globe_an = spatial_ave(ps_an, lats)
sst_globe_an = spatial_ave(sst_an, lats)

#subtract global annual mean to isolate processes in NA
thfprime = thf_an.T - thf_globe_an
thfprime = thfprime.T

#thfprime = signal.detrend(thfprime, axis=0)
#thfprime = thf_an

psprime = ps_an.T - ps_globe_an
psprime = psprime.T

#psprime = signal.detrend(psprime, axis=0)
Ejemplo n.º 9
0
thf = shf + lhf

#ERAi has thf positive down
thf = -thf

maxlat = 70
minlat = -70

maxlon = 360
minlon = 0

thf = thf.subRegion(latitude=(minlat, maxlat), longitude=(minlon, maxlon))

lats = thf.getLatitude()[:]

plt.plot(spatial_ave(thf, lats))
plt.show()

ts = np.array([])
thfs = np.array([])

fnames = glob.glob(fin + 'era_*new.nc')

for fname in fnames:
    fthf = cdms2.open(fname)
    lhf = fthf('slhf')
    lhf = lhf / (12 * 3600)
    shf = fthf('sshf')
    #sshf is accumulated
    shf = shf / (12 * 3600)
    thf = shf + lhf