def climatologize_ncdt(ncdt): climdt={} for ckey in ncdt.keys(): dat = ncdt[ckey] cdat,_ = cutl.climatologize(dat) climdt[ckey] = cdat return climdt
def load_LE(fdict,casename='historical',conv=1,season=None,timesel1='1979-01-01,1989-12-31',timesel2='2002-01-01,2012-12-31'): ledatc = le.load_LEdata(fdict,casename,timesel=timesel1, rettype='ndarray',conv=conv,ftype='fullts',local=True,verb=False) ledatp = le.load_LEdata(fdict,casename,timesel=timesel2, rettype='ndarray',conv=conv,ftype='fullts',local=True,verb=False) lediff = ledatp-ledatc print lediff.shape leclimo,_ = cutl.climatologize(lediff.T) print leclimo.shape return leclimo
cansicnc = cansicnc[:,:,0:-1] cansicnp = cansicnp[:,:,0:-1] cansicnd = cansicnp - cansicnc else: # SST (var names are sic still...) field = 'gt' if doBCs: bcstr='BC' # use the actual BC files for the simulations fhadsic = basepath + 'HadISST/hadisst_kemhadctl_128x64_0001_0125_gt.nc' fhadsicp = basepath + 'HadISST/hadisst_kemhadpert_128x64_0001_0125_gt.nc' # or GTadjusted_BC_HadISST_2002-2011_0000120100-0125120100_abs10thresh.nc hadsicc,hadsiccstd = cutl.climatologize(cnc.getNCvar(fhadsic,'GT')) # I think, K? hadsicp,hadsicpstd = cutl.climatologize(cnc.getNCvar(fhadsicp,'GT')) # @@ Hurrell files are same as not doBCs fhurrsic = basepath + 'HURRELL/MODEL_SST.T42_' + timeper + 'climo.nc' #SST, degC, 128x64 fhurrsicp = basepath + 'HURRELL/MODEL_SST.T42_' + timeperp2 + 'climo.nc' #SST, degC, 128x64 else: fhadsic = basepath + 'HadISST/hadisst1.1_bc_128_64_1870_2013m03_gt_' + timeper + 'climo.nc' #GT, K, 129x64 fhurrsic = basepath + 'HURRELL/MODEL_SST.T42_' + timeper + 'climo.nc' #SST, degC, 128x64 fhadsicp = basepath + 'HadISST/hadisst1.1_bc_128_64_1870_2013m03_gt_' + timeperp + 'climo.nc' #GT, K, 129x64 fhurrsicp = basepath + 'HURRELL/MODEL_SST.T42_' + timeperp2 + 'climo.nc' #SST, degC, 128x64 hadsicc = cnc.getNCvar(fhadsic,'GT') # I think, K? hadsicp = cnc.getNCvar(fhadsicp,'GT')
for eii in range(1,ensnum+1): skey = etype + str(eii) casenamec = bcasenamec + skey casenamep = bcasenamep + skey fnamec = basepath + casenamec+ subdir + casenamec + '_' + field + '_001-121_ts.nc' fnamep = basepath + casenamep+ subdir + casenamep + '_' + field + '_001-121_ts.nc' # monthly calc fldc = cnc.getNCvar(fnamec,ncfield,timesel=timesel)*conv fldp = cnc.getNCvar(fnamep,ncfield,timesel=timesel)*conv fldd = fldp-fldc # take the pattern correlation flddclimo,flddstd = cutl.climatologize(fldd) # climo first (don't need to do for BCs technically) flddcclimo,flddcstd = cutl.climatologize(flddc) # climo first. baseline diff data diffdict[skey] = flddclimo # for each month, compute pattern corr pc = np.zeros((12)) for mii,mon in enumerate(con.get_mon()): tmp = np.squeeze(flddclimo[mii,lat>latlim,...]) tmpcmp = np.squeeze(flddcclimo[mii,lat>latlim,...]) pc[mii] = cutl.pattcorr(tmp.flatten()*weights.flatten(),tmpcmp.flatten()*weights.flatten()) pcmeandict[skey] = pc # monthly # seasonal calc fldcsea = np.zeros((4,len(lat),len(lon)))
def getNCvar(filename,field,timesel=None,levsel=None,monsel=None,seas=None,calc=None,remlon=1,sqz=True,att=False): """ gets a variable from netcdf file. Time is assumed to be the 1st dimension, Lon is assumed to be the last. If any calculations are requested to be performed on the data, the user needs to make sure that the requested operations can be performed (b/c some of the other functions only handle certain # of dims, etc. My bad.) filename: full path to file field: NC variable to read in timesel: comma-delim string of date range in 'YYYY-MM-DD' fmt to select (a la CDO) levsel: select level in Pa (e.g. 50000 for 500hPa) monsel: select month from timeseries seas: seasonally (annually) average or return climatology {climo|ANN|DJF|JJA|NDJ|MAM|SON} calc: zm (zonal mean), remlon: removes extra wrap-around longitude for zonal mean. default is 1, remove it sqz: squeeze the data if 'getting all data'. Default True. Trying to avoid situation where need singular dims and squeeze them out (e.g. MOC variable in CCSM4) att: if True, include the full netcdf variable (including attributes). Most useful for time. returns fld """ # IF ON MAC: CDO bindings don't work yet, use old function 3/25/2014 ######### plat = platform.system() if False: #@@@@TESTING 9/20/2016 plat == 'Darwin': # means I'm on my mac # Call old func if calc != None: print '@@ not sure calc will work on mac. calc=' + calc if levsel!=None: plev= np.array([100, 200, 300, 500, 700, 1000, 2000, 3000, 5000, 7000, 10000, 12500, 15000, 17500, 20000, 22500, 25000, 30000, 35000, 40000, 45000, 50000, 55000, 60000, 65000, 70000, 75000, 77500, 80000, 82500, 85000, 87500, 90000, 92500, 95000, 97500, 100000]) level=cutl.find_nearest(plev,levsel) else: level=None if timesel == '0002-01-01,0061-12-31': print 'hard-coded skipping of first year of 61-yr chunk @@' fld = getNCvar_old(filename,field,seas=seas, monsel=monsel,timechunk=(12,),level=level,calc=calc,sqz=sqz) else: # if timesel=='0002-01-01,0121-12-31' then just don't set timechunk because # files on the mac are already selected to skip first year, and they reside # in the 'timsel' subdirectory. Check for that? if timesel=='0002-01-01,0121-12-31': if 'timsel/' not in filename: print 'On mac, use files in timsel/ subdirectory! @@ NEEDS TESTING' fld = getNCvar_old(filename,field,seas=seas,monsel=monsel,level=level,calc=calc,sqz=sqz,timesel=timesel) # doesn't work with all arguments yet @@ return fld else: # on linux workstation in Vic ncfile = openNC(filename) ndims = len(ncfile.dimensions) ncvar = ncfile.variables[field] #print ncvar # @@@@@ #### READ VARIABLE FROM NC FILE ######## if timesel == None and calc == None: if levsel !=None: if monsel != None: fld = np.squeeze(cdo.sellevel(levsel,input = cdo.selmon(monsel,input = filename),returnMaArray = field)) else: fld = np.squeeze(cdo.sellevel(levsel,input = filename, returnMaArray = field)) os.system('rm -rf /tmp/cdoPy*') else: if monsel != None: #print 'timesel==None and calc==None and monsel !=None' fld = np.squeeze(cdo.selmon(monsel,input = filename, returnMaArray = field)) #print fld.shape os.system('rm -rf /tmp/cdoPy*') else: # get everything if sqz: #print field + ': squeezing data upon read all' # @@@ # for most situations, this is what we want. @@@@ fld=np.squeeze(ncfile.variables[field][...]) else: fld = ncfile.variables[field][...] elif timesel != None and calc == 'zm': # have to remove the lon before zonal mean, which means have to separate the # select dates and zm. thus can't use CDO for zm (unless can pass it data instead of a file?) #fld = np.squeeze(cdo.zonmean( input = cdo.seldate(timesel,input = filename), returnMaArray = field)) print 'assuming T42(63) 64x128 resolution for zonal mean' if levsel != None: if monsel != None: fld = np.squeeze(cdo.seldate(timesel,input = cdo.zonmean( input = cdo.selindexbox(1,128,1,64,input = cdo.sellevel(levsel,input = cdo.selmon(monsel, input = filename)))), returnMaArray = field))# @@@@ else: fld = np.squeeze(cdo.seldate(timesel,input = cdo.zonmean( input = cdo.selindexbox(1,128,1,64,input = cdo.sellevel(levsel,input = filename))), returnMaArray = field)) else: if monsel != None: fld = np.squeeze(cdo.seldate(timesel,input = cdo.zonmean( input = cdo.selindexbox(1,128,1,64,input = cdo.selmon(monsel,input = filename))), returnMaArray = field)) else: fld = np.squeeze(cdo.seldate(timesel,input = cdo.zonmean(input = cdo.selindexbox(1,128,1,64,input = filename)), returnMaArray = field)) os.system('rm -rf /tmp/cdoPy*') ## if remlon: ## # remove extra lon ## fld = np.squeeze(fld[...,0:-1]) ## lastdimidx = ndims-1 ## fld = np.mean(fld,lastdimidx) elif timesel != None and calc != None: if levsel != None and monsel == None: fld = np.squeeze(cdo.seldate(timesel,input = cdo.sellevel(levsel,input = filename), returnMaArray = field)) elif levsel != None and monsel != None: fld = np.squeeze( cdo.seldate(timesel,input = cdo.sellevel(levsel,input = cdo.selmon(monsel,input = filename)), returnMaArray = field)) elif levsel == None and monsel != None: fld = np.squeeze(cdo.seldate(timesel,input = cdo.selmon(monsel,input = filename), returnMaArray = field)) else: # levsel and monsel are both None fld = np.squeeze(cdo.seldate(timesel,input = filename, returnMaArray = field)) os.system('rm -rf /tmp/cdoPy*') print "only calc='zm' is implemented now. Returning only selected date range/level/month." elif timesel != None: if levsel != None and monsel == None: fld = np.squeeze(cdo.seldate(timesel,input = cdo.sellevel(levsel,input = filename),returnMaArray = field)) elif levsel != None and monsel != None: fld = np.squeeze( cdo.seldate(timesel,input = cdo.sellevel(levsel,input = cdo.selmon(monsel,input = filename)), returnMaArray = field)) elif levsel == None and monsel != None: fld = np.squeeze(cdo.seldate(timesel,input = cdo.selmon(monsel,input = filename), returnMaArray = field)) else: # levsel and monsel are both None fld = np.squeeze(cdo.seldate(timesel,input = filename, returnMaArray = field)) os.system('rm -rf /tmp/cdoPy*') elif calc == 'zm': # and timesel must be None print 'assuming T42(63) 64x128 resolution for zonal mean' if levsel != None and monsel == None: fld = np.squeeze(cdo.sellevel(levsel,input = cdo.zonmean(input = cdo.selindexbox(1,128,1,64,input = filename)), returnMaArray = field)) elif levsel != None and monsel != None: fld = np.squeeze( cdo.sellevel(levsel,input = cdo.zonmean(input = cdo.selindexbox(1,128,1,64,input = cdo.selmon(monsel,input = filename))), returnMaArray = field)) elif levsel == None and monsel != None: fld = np.squeeze(cdo.zonmean(input = cdo.selindexbox(1,128,1,64,input = cdo.selmon(monsel,input = filename)), returnMaArray = field)) else: # get all data fld = np.squeeze(cdo.zonmean(input = cdo.selindexbox(1,128,1,64,input = filename), returnMaArray = field)) #print '@@ getting memory errors here...try using CDO to select appropriate lons for the zm calc' #fld = ncfile.variables[field][...] # have to get field before removing lon os.system('rm -rf /tmp/cdoPy*') ## if remlon: ## # remove extra lon ## if ndims==4: ## fld = np.squeeze(fld[:,:,:,0:-1]) ## elif ndims==3: ## fld = np.squeeze(fld[:,:,0:-1]) ## else: # shouldn't really get here, not expecting 2D (time x lon?) ## fld = np.squeeze(fld[:,0:-1]) ## lastdimidx = ndims-1 ## fld = np.mean(fld,lastdimidx) else: print "huh? timesel and calc combo doesn't make sense" ####### TIME AVERAGE the VARIABLE ########## # fld has to be 3d by the time it is passed to func # (time,lev,lat) or (time,lat,lon) if seas != None: #print 'getNCvar(): seas!=None: fld.shape: ' + str(fld.shape) # @@@ ## if fld.ndim != 3: ## ## if 1 in fld.shape: ## ## fld=fld.squeeze() # attempting to deal with spurious dims of 1 @@@ ## ## if fld.ndim != 3: ## ## print 'data must be 3 dimensional to seasonalize()' ## ## return ## ## else: ## print 'data must be 3 dimensional to seasonalize()' ## return if monsel != None: print "Can't do seasonal average when monsel != None" return elif seas == 'climo': fld,stddev = cutl.climatologize(fld) elif type(seas) == int: # @@ does this work? #elif seas not in ('ANN','DJF','JJA','MAM','SON','NDJ'): # means seas is an int value for a month #fld = cutl.seasonalize_monthlyts(fld,mo=seas) fld = cutl.seasonalize(fld,mo=seas) else: #print 'seasonalizing' #fld = cutl.seasonalize_monthlyts(fld,season=seas) fld = cutl.seasonalize(fld,season=seas) #print fld.shape # Apply any scaling and offsetting needed: try: var_offset = ncvar.add_offset except: var_offset = 0 try: var_scale = ncvar.scale_factor print 'var_scale ' + str(var_scale) except: var_scale = 1 fld = fld*var_scale + var_offset ncfile.close() return fld
plat = platform.system() if plat == 'Darwin': # means I'm on my mac basepath = '/Users/kelly/CCCma/CanSISE/RUNS/' # @@ needs updating subdir = '/' else: # on linux workstation in Vic basepath = '/home/rkm/work/DATA/' + model + '/' subdir = '/ts/' # get sea ice concentration for averaging purposes field = 'sicn' fnamec = basepath + casenamec + subdir + casenamec + '_' + field + '_' + timstr + '_ts.nc' sicnc = cnc.getNCvar(fnamec,field.upper(),timesel=timesel) sicnc,siccstd = cutl.climatologize(sicnc) # use to mask the flux region fnamep = basepath + casenamep + subdir + casenamep + '_' + field + '_' + timstr + '_ts.nc' sicnp = cnc.getNCvar(fnamep,field.upper(),timesel=timesel) sicnp,sicpstd = cutl.climatologize(sicnp) # use to mask the flux region # get second set of sims: fnamecb = basepath + casenamecb + subdir + casenamecb + '_' + field + '_' + timstrb + '_ts.nc' sicncb = cnc.getNCvar(fnamecb,field.upper(),timesel=timeselb) sicncb,siccstdb = cutl.climatologize(sicncb) # use to mask the flux region fnamepb = basepath + casenamepb + subdir + casenamepb + '_' + field + '_' + timstrb + '_ts.nc' sicnpb = cnc.getNCvar(fnamepb,field.upper(),timesel=timeselb) sicnpb,sicpbstd = cutl.climatologize(sicnpb) # use to mask the flux region
plt.figure() plt.plot(mons,pvalp1,'b') plt.plot(mons,pvalp2,'r') plt.plot(mons,pvalp3,'g') plt.plot((1,12),(siglevel,siglevel),'k') plt.xlim((1,12)) plt.title('pval') # first try just the polar mean fldcclimpm = cutl.polar_mean_areawgted3d(fldcclim,lat,lon,latlim=latlim) fldp1climpm = cutl.polar_mean_areawgted3d(fldp1clim,lat,lon,latlim=latlim) fldp2climpm = cutl.polar_mean_areawgted3d(fldp2clim,lat,lon,latlim=latlim) fldp3climpm = cutl.polar_mean_areawgted3d(fldp3clim,lat,lon,latlim=latlim) # get stddev of the already polar averaged data! tmpc,fldcstdpm = cutl.climatologize(fldcpm) tmpp1,fldp1stdpm = cutl.climatologize(fldp1pm) tmpp2,fldp2stdpm = cutl.climatologize(fldp2pm) tmpp3,fldp3stdpm = cutl.climatologize(fldp3pm) ## fldcstdpm = cutl.polar_mean_areawgted3d(fldcstd,lat,lon,latlim=latlim) # this is wrong metric ## fldp1stdpm = cutl.polar_mean_areawgted3d(fldp1std,lat,lon,latlim=latlim) ## fldp2stdpm = cutl.polar_mean_areawgted3d(fldp2std,lat,lon,latlim=latlim) ## fldp3stdpm = cutl.polar_mean_areawgted3d(fldp3std,lat,lon,latlim=latlim) # mean values fig = plt.figure() plt.plot(mons,fldcclimpm,'k',linewidth=2) plt.plot(mons,fldp1climpm,'b',linewidth=2) plt.plot(mons,fldp2climpm,'r',linewidth=2)
def pattcorr_ensemble(ename, field, latlim=60): # @@@@@@@@@@@@ is this fully implemented? Don't think so. 12/2/14 if ename=='ANT': ename='HistIC' elif ename=='TOT': ename='HistBC' enssims = con.build_ensemblesims(ename) ensnum=len(enssims) # ======= copied from Canam4_BCpatterncorr-Copy0.py =========== #ensnum=5 diffdict = {} pcmeandict = {} # fldp-fldc pattern corr compared to mean BC pchaddict = {} # fldp-fldc pattern corr compared to hadisst seadiffdict = {} # seasonal mean pcseameandict = {} pcsea2meandict = {} # to test the other pattern corr calc pcsea2pvalmeandict = {} # to test the other pattern corr calc # generate weights for the pattern corr lat = con.get_t63lat() lon = con.get_t63lon() areas = cutl.calc_cellareas(lat,lon) areas = areas[lat>latlim,:] weights = areas / np.sum(np.sum(areas,axis=1),axis=0) #for eii in range(1,ensnum+1): for skey in enssims: #skey = etype + str(eii) #casenamec = bcasenamec + skey #casenamep = bcasenamep + skey #fnamec = basepath + casenamec+ subdir + casenamec + '_' + field + '_001-121_ts.nc' #fnamep = basepath + casenamep+ subdir + casenamep + '_' + field + '_001-121_ts.nc' fnamec,fnamep = con.build_filepathpair(skey,field) # monthly calc fldc = cnc.getNCvar(fnamec,ncfield,timesel=timesel)*conv fldp = cnc.getNCvar(fnamep,ncfield,timesel=timesel)*conv fldd = fldp-fldc # take the pattern correlation flddclimo,flddstd = cutl.climatologize(fldd) # climo first (don't need to do for BCs technically) flddcclimo,flddcstd = cutl.climatologize(flddc) # climo first. baseline diff data diffdict[skey] = flddclimo # for each month, compute pattern corr pc = np.zeros((12)) for mii,mon in enumerate(con.get_mon()): tmp = np.squeeze(flddclimo[mii,lat>latlim,...]) tmpcmp = np.squeeze(flddcclimo[mii,lat>latlim,...]) pc[mii] = cutl.pattcorr(tmp.flatten()*weights.flatten(),tmpcmp.flatten()*weights.flatten()) pcmeandict[skey] = pc # monthly # seasonal calc fldcsea = np.zeros((4,len(lat),len(lon))) fldpsea = np.zeros((4,len(lat),len(lon))) flddsea = np.zeros((4,len(lat),len(lon))) pcsea = np.zeros((4)) pcsea2 = np.zeros((4)) # test pattcorr_pearson() @@ pcsea2pval = np.zeros((4)) # test pattcorr_pearson() for seaii,sea in enumerate(seasons): fldcsea[seaii,...] = np.mean(cnc.getNCvar(fnamec,ncfield,timesel=timesel,seas=sea)*conv,axis=0) fldpsea[seaii,...] = np.mean(cnc.getNCvar(fnamep,ncfield,timesel=timesel,seas=sea)*conv,axis=0) flddsea[seaii,...] = fldpsea[seaii,...]-fldcsea[seaii,...] tmp = np.squeeze(flddsea[seaii,lat>latlim,...]) tmpcmp = np.squeeze(flddcsea[seaii,lat>latlim,...]) pcsea[seaii] = cutl.pattcorr(tmp.flatten()*weights.flatten(), tmpcmp.flatten()*weights.flatten()) pcsea2[seaii],pcsea2pval[seaii] = cutl.pattcorr_pearson(tmp.flatten()*weights.flatten(), tmpcmp.flatten()*weights.flatten()) seadiffdict[skey] = flddsea pcseameandict[skey] = pcsea pcsea2meandict[skey] = pcsea2 pcsea2pvalmeandict[skey] = pcsea2pval
def pattcorr_withinensemble(ename,fdict,latlim=60,timesel='0002-01-01,0121-12-31'): """ pattcorr_withinensemble(ename,field,latlim=60) pattern corr each member of ensemble with each other one return pctable, pctablesea (DataFrames) """ # @@ need diffdict field=fdict['field'] ncfield=fdict['ncfield'] conv=fdict['conv'] seasons=('SON','DJF','MAM','JJA') if ename=='ANT': ename='histIC' elif ename=='TOT': ename='histBC' enssims = con.build_ensemblesims(ename) ensnum=len(enssims) print 'ENSSIMS: ' # @@@ print enssims # @@ # generate weights for the pattern corr lat = con.get_t63lat() lon = con.get_t63lon() areas = cutl.calc_cellareas(lat,lon) areas = areas[lat>latlim,:] weights = areas / np.sum(np.sum(areas,axis=1),axis=0) # ========= create diffdict first ===== diffdict={} seadiffdict={} for skey in enssims: fnamec,fnamep = con.build_filepathpair(skey,field) # monthly calc fldc = cnc.getNCvar(fnamec,ncfield,timesel=timesel)*conv fldp = cnc.getNCvar(fnamep,ncfield,timesel=timesel)*conv fldd = fldp-fldc # Monthly flddclimo,flddstd = cutl.climatologize(fldd) # climo first (don't need to do for BCs technically) #flddcclimo,flddcstd = cutl.climatologize(flddc) # climo first. baseline diff data diffdict[skey] = flddclimo print skey + ' ' + str(flddclimo.shape) # @@@ # Seasonal flddsea = np.zeros((4,len(lat),len(lon))) for seaii,sea in enumerate(seasons): fldcsea = np.mean(cnc.getNCvar(fnamec,ncfield,timesel=timesel,seas=sea)*conv,axis=0) fldpsea = np.mean(cnc.getNCvar(fnamep,ncfield,timesel=timesel,seas=sea)*conv,axis=0) flddsea[seaii,...] = fldpsea-fldcsea seadiffdict[skey] = flddsea # ======= Now do pattern corrs within ensemble ==== # ======= copied from Canam4_BCpatterncorr-Copy0.py =========== outterdict= dict.fromkeys(enssims) for skey1 in enssims: outfld = diffdict[skey1] innerdict = dict.fromkeys(enssims) for skey2 in enssims: #print skey1 + ' compared to ' + skey2 infld = diffdict[skey2] # for each month, compute pattern corr pc = np.zeros((12)) for mii,mon in enumerate(con.get_mon()): tmp = np.squeeze(infld[mii,lat>latlim,...]) tmpcmp = np.squeeze(outfld[mii,lat>latlim,...]) pc[mii] = cutl.pattcorr(tmp.flatten()*weights.flatten(), tmpcmp.flatten()*weights.flatten()) innerdict[skey2] = pc outterdict[skey1] = innerdict pctable = pd.DataFrame(outterdict) # 5x5 # seasonal outterdictsea= dict.fromkeys(enssims) for skey1 in enssims: outfld = seadiffdict[skey1] innerdictsea = dict.fromkeys(enssims) for skey2 in enssims: #print skey1 + ' compared to ' + skey2 infld = seadiffdict[skey2] # for each season, compute pattern corr pcsea = np.zeros((4)) for seaii,sea in enumerate(seasons): tmp = np.squeeze(infld[seaii,lat>latlim,...]) tmpcmp = np.squeeze(outfld[seaii,lat>latlim,...]) pcsea[seaii] = cutl.pattcorr(tmp.flatten()*weights.flatten(), tmpcmp.flatten()*weights.flatten()) innerdictsea[skey2] = pcsea outterdictsea[skey1] = innerdictsea pctablesea = pd.DataFrame(outterdictsea) # 5x5 return pctable, pctablesea
# # Compare 2xco2 with the 2xco2 nudge: RMSE # calculate RMSE rmsedt = {} rmseclimdt = {} annrmseclimdt = {} climrmsedt = {} region = "polcap60" fldclimdt = {} flddiffdt = {} flddiffclimdt = {} # get controls fldc2x = flddt["gregory_2xco2"] fldc2xclim, std = cutl.climatologize(fldc2x) # climo mean (2xco2) fldclimdt["gregory_2xco2"] = fldc2xclim fldc = flddt["iga"] fldcclim, std = cutl.climatologize(fldc) # climo mean (iga) fldclimdt["iga"] = fldcclim for skey in sims[2:10]: # Group I fld = flddt[skey] # timeseries flddiffdt[skey] = fldc2x - fld # climos fldclimdt[skey], std = cutl.climatologize(fld) flddiffclimdt[skey] = fldc2xclim - fldclimdt[skey] rmse = np.sqrt(np.square(flddiffdt[skey]))
ctldt = dict.fromkeys(models) p1dt = dict.fromkeys(models) # 2002-2005 for mod in cm5.models: print mod meta=cm5.allmodeldt[mod] if meta==None: print mod + ' not yet implemented!' # @@@ elif type(meta['fyears'])!=str: # skip print ' skipping models w/ annoying years for now' else: fyears=meta['fyears'] enum=meta['numens'] # number of ens members ctlmoddt={}; p1moddt={} for eii in range(1,enum+1): if 'skipens' in meta.keys() and eii in meta['skipens']: print 'skipping ensemble: ' + str(eii) else: fname=bp+mod+'/r'+str(eii)+'i1p1/' + field + '_' + comp + '_' +\ mod + '_historical_r' + str(eii)+'i1p1_' + fyears +'.nc' print fname ctlmoddt[eii],junk = cutl.climatologize(cnc.getNCvar(fname,field,timesel=timeselc)) p1moddt[eii],junk = cutl.climatologize(cnc.getNCvar(fname,field,timesel=timeselp1)) ctldt[mod]=ctlmoddt p1dt[mod]=p1moddt