def plot_allregions(ptype='nh'): """ plot_allregions(ptype='nh'): plot all defined regions """ regdict = con.get_regiondict() nreg = len(regdict) rem = np.mod(nreg,2) rows = 2 if rem==0: cols = nreg/rows else: cols = nreg/rows + rem # rem will always be 1 if dividing by 2 if cols>8: rows = 3 cols = nreg/rows + np.mod(nreg,rows)/2 print 'nrows: ' + str(rows) + ' ncols: ' + str(cols) # @@@ lat = con.get_t63lat() lon = con.get_t63lon() fig,spax = plt.subplots(rows,cols) fig.set_size_inches(cols*2,rows*3) for aii,ax in enumerate(spax.flat): dummy = con.get_t63landmask() # dummy data regkey = regdict.keys()[aii] limsdict = regdict[regkey] # mask the dummy data dummym,dmask = cutl.mask_region(dummy,lat,lon,regkey,limsdict=limsdict) kemmap(dummym,lat,lon,ptype=ptype,axis=ax,suppcb=1,cmin=-11,cmax=2,cmap='blue2blue_w10') ax.set_title(regkey) ax.set_xlabel(str(limsdict['latlims']) + ',' +str(limsdict['lonlims']) ) if aii==nreg-1: break # get out of loop if done with regions
fnamec, fnamep = con.build_filepathpair(sim, field) fldc = cnc.getNCvar(fnamec, ncfield, seas=sea) fldp = cnc.getNCvar(fnamep, ncfield, seas=sea) lon = cnc.getNCvar(fnamec, "lon") lat = cnc.getNCvar(fnamec, "lat") fldca = np.squeeze(fldc - np.mean(fldc, axis=0)) # remove time mean fldpa = np.squeeze(fldp - np.mean(fldp, axis=0)) if subset: msk1 = con.get_t63regionmask("other", limsdict=limsdict) fldca, msk = cutl.mask_region(fldca, lat, lon, "other", limsdict=limsdict) fldpa, msk = cutl.mask_region(fldpa, lat, lon, "other", limsdict=limsdict) oshape = fldca.shape # original shape print fldca.shape fldca1 = fldca[~fldca.mask] # @@@ why do I have to invert it. so dumb. # fldca2=fldca[msk] fldpa1 = fldpa[~fldpa.mask] nshape = fldca1.shape # new shape print fldca1.shape # print fldca2.shape # only keep region of interest? lato = lat
def load_ncfield(field, ncfield, zonal=True,conv=1,mo=0,season=None,last='last100',includeyr1=False,verb=False): """ If zonal=True, compute zonal mean. zonal can also be a region, defined in regiondict in constants.py returns dictionaries: full field w/ time, zonal mean w/ time """ timepers,timesels = get_timeinfo(last,includeyr1) seasonalizedt = {'mo':mo, 'season': season} ncflddt={}; ncfldtmdt={}; ncfldzmdt={} for casename in casenames: fname= basedir + casename +'/ts/' + casename + '_' + field + '_' + timepers[casename] + '_ts.nc' timesel=timesels[casename] if verb: print fname try: fld=cnc.getNCvar(fname,ncfield,timesel=timesel)*conv # remlon not operational??? why commented out?? if verb: print fname + ', fld.shape ' + str(fld.shape) # @@@ except IOError as rte: # previously this was a RuntimeError. Not sure what changed. 10/14/2016 print rte if 'No such file or directory' in rte.args: # Here the problem is most likely that pico2ipulse filename fails b/c # there is no NH version of it (for when last200=True). Remove the NH and try again. # @@ Of course this could be a problem too b/c now we have full globe for just this run. if field[-2:] != 'NH': print 'not an NH versus global problem...File really not found' raise fname= basedir + casename +'/ts/' + casename + '_' + field[:-2] + '_' + timepers[casename] + '_ts.nc' print 'Try again: ' + fname fld=cnc.getNCvar(fname,ncfield,timesel=timesel)*conv tmplat=cnc.getNCvar(fname,'lat') if last=='last200': # how to tell which spot lat is? if zonal: # then it is likely time x lat x lon #print 'zonal is true. fld dims? ' + str(fld.shape) fld=fld[...,tmplat>0,:] else: # likely time x lev x lat fld=fld[...,tmplat>0] else: raise # just get the full timeseries, and zonal mean if asked. if 1: #timeseries: # do not time average (actually save time average anyway) if (season==None and mo==0): pass else: fld = cutl.seasonalize(fld,**seasonalizedt) #fldtm = fld # zonal average if zonal==True: fldzm = fld[...,:-1].mean(axis=2) # remove extra lon elif zonal in con.get_regiondict().keys(): print 'lat,lon shapes ' + str(lat.shape),str(lon.shape) tempo, _ = cutl.mask_region(fld,lat,lon,region=zonal) fldzm = tempo.mean(axis=2) else: fldzm = None #fldtm = fldtmzm.mean(axis=0) # else: # # seasonal & time mean # fldtm = np.mean(cutl.seasonalize(fld,**seasonalizedt),axis=0) # # zonal average # if zonal: # fldtmzm = fldtm[...,:-1].mean(axis=1) # elif zonal in con.get_regiondict().keys(): # tempo, _ = cutl.mask_region(fldtm,lat,lon,region=zonal) # fldtmzm = tempo.mean(axis=1) # else: # fldtmzm = fldtm print 'fld.shape: ' + str(fld.shape) if fldzm!=None: print 'fldzm.shape: ' + str(fldzm.shape) ncflddt[casename] = fld # keep all dims #ncfldtmdt[casename] = fldtm # time mean ncfldzmdt[casename] = fldzm # zonal mean (w/ time dim) return ncflddt, ncfldzmdt
def load_ncfield(field, ncfield, zonal=True,conv=1,mo=0,season=None,last='last100', includeyr1=False,verb=False,local=False,seacyc=False,pulse=False): """ If zonal=True, compute zonal mean. zonal can also be a region, defined in regiondict in constants.py If local, use local data (which is limited) If seacycle, return the 12 month climo average, which only exists 1. locally (as of Mar 24 2017) and 2. is only avail for the last200 returns dictionaries: full field w/ time, zonal mean w/ time """ timepers,timesels = get_timeinfo(last,includeyr1) if local: #bd='/Users/kelly/DropboxWork/UWashCanSISE/DATA/relaxationruns/' #limited fields here bd='/Users/kelly/DATA/DataDisk/' # limited but not shared so there are more data subdir='/' else: bd=basedir subdir='/ts/' seasonalizedt = {'mo':mo, 'season': season} ncflddt={}; ncfldtmdt={}; ncfldzmdt={} for casename in casenames: if pulse==False and ('pulse' in casename): continue if seacyc: if last!='last200': raise Exception('load_ncfield(): if seacyc=True, last must = last200') if local!=True: raise Exception('load_ncfield(): if seacyc=True, local must be True (as of Mar 24 2017)') fname = bd + casename+subdir+casename + '_' + field + '_' + timepers[casename] + '_seacycle.nc' else: fname= bd + casename +subdir + casename + '_' + field + '_' + timepers[casename] + '_ts.nc' timesel=timesels[casename] if verb: print fname try: fld=cnc.getNCvar(fname,ncfield,timesel=timesel)*conv # remlon not operational??? why commented out?? if verb: print fname + ', fld.shape ' + str(fld.shape) # @@@ except IOError as rte: # previously this was a RuntimeError. Not sure what changed. 10/14/2016 print rte if 'No such file or directory' in rte.args: # Here the problem is most likely that pico2ipulse filename fails b/c # there is no NH version of it (for when last200=True). Remove the NH and try again. # @@ Of course this could be a problem too b/c now we have full globe for just this run. if field[-2:] != 'NH': print 'not an NH versus global problem...File really not found' raise fname= basedir + casename +'/ts/' + casename + '_' + field[:-2] + '_' + timepers[casename] + '_ts.nc' print 'Try again: ' + fname fld=cnc.getNCvar(fname,ncfield,timesel=timesel)*conv tmplat=cnc.getNCvar(fname,'lat') if last=='last200': # how to tell which spot lat is? if zonal: # then it is likely time x lat x lon #print 'zonal is true. fld dims? ' + str(fld.shape) fld=fld[...,tmplat>0,:] else: # likely time x lev x lat fld=fld[...,tmplat>0] else: raise # just get the full timeseries, and zonal mean if asked. if 1: #timeseries: # do not time average (actually save time average anyway) if (season==None and mo==0): pass else: fld = cutl.seasonalize(fld,**seasonalizedt) #fldtm = fld # zonal average if zonal==True: fldzm = fld[...,:-1].mean(axis=2) # remove extra lon elif zonal in con.get_regiondict().keys(): print 'lat,lon shapes ' + str(lat.shape),str(lon.shape) tempo, _ = cutl.mask_region(fld,lat,lon,region=zonal) fldzm = tempo.mean(axis=2) else: fldzm = None #fldtm = fldtmzm.mean(axis=0) # else: # # seasonal & time mean # fldtm = np.mean(cutl.seasonalize(fld,**seasonalizedt),axis=0) # # zonal average # if zonal: # fldtmzm = fldtm[...,:-1].mean(axis=1) # elif zonal in con.get_regiondict().keys(): # tempo, _ = cutl.mask_region(fldtm,lat,lon,region=zonal) # fldtmzm = tempo.mean(axis=1) # else: # fldtmzm = fldtm print 'fld.shape: ' + str(fld.shape) if fldzm!=None: print 'fldzm.shape: ' + str(fldzm.shape) ncflddt[casename] = fld # keep all dims #ncfldtmdt[casename] = fldtm # time mean ncfldzmdt[casename] = fldzm # zonal mean (w/ time dim) # try this: add coords # @@@@@@@@@@ lat,lon = load_nclatlon(field,last=last,includeyr1=includeyr1,verb=verb,local=local) ncflddt['lat'] = lat; ncflddt['lon'] = lon; try: lev = load_nclev(field,last=last,includeyr1=includeyr1,verb=verb) ncflddt['lev'] = lev except: print "No lev coord. Leave it" ncfldzmdt['lat'] = lat return ncflddt, ncfldzmdt