示例#1
0
文件: legacy.py 项目: aerler/GeoPy
def loadDataset(exp, prd, dom, grd, res, filetypes=None, varlist=None, lbackground=True, lWRFnative=True, 
                lautoregrid=False, WRF_exps=None, CESM_exps=None):
  ''' A function that loads a dataset, based on specified parameters '''
  if not isinstance(exp,basestring): raise TypeError
  if exp[0].isupper():
    if exp == 'Unity': 
      from datasets.Unity import loadUnity
      ext = loadUnity(resolution=res, period=prd, grid=grd, varlist=varlist, lautoregrid=lautoregrid)
      axt = 'Merged Observations'        
    elif exp == 'GPCC': 
      from datasets.GPCC import loadGPCC
      ext = loadGPCC(resolution=res, period=prd, grid=grd, varlist=varlist, lautoregrid=lautoregrid)
      axt = 'GPCC Observations'
    elif exp == 'CRU': 
      from datasets.CRU import loadCRU
      ext = loadCRU(period=prd, grid=grd, varlist=varlist, lautoregrid=lautoregrid)
      axt = 'CRU Observations' 
    elif exp == 'PCIC': # PCIC with some background field
      from datasets.PCIC import loadPCIC
      if lbackground:
        if all(var in ('precip','stations','lon2D','lat2D','landmask','landfrac') for var in varlist): 
          from datasets.GPCC import loadGPCC
          from datasets.PRISM import loadPRISM
          ext = (loadGPCC(grid=grd, varlist=varlist, lautoregrid=lautoregrid), 
                 loadPRISM(grid=grd, varlist=varlist, lautoregrid=lautoregrid),
                 loadPCIC(grid=grd, varlist=varlist, lautoregrid=lautoregrid),)
          axt = 'PCIC PRISM (and GPCC)'
        else:
          from datasets.PRISM import loadPRISM 
          from datasets.CRU import loadCRU
          ext = (loadCRU(period='1971-2001', grid=grd, varlist=varlist, lautoregrid=lautoregrid),
                 loadPRISM(grid=grd, varlist=varlist, lautoregrid=lautoregrid), 
                 loadPCIC(grid=grd, varlist=varlist, lautoregrid=lautoregrid)) 
          axt = 'PCIC PRISM (and CRU)'
      else:
        ext = loadPCIC(grid=grd, varlist=varlist, lautoregrid=lautoregrid); axt = 'PCIC PRISM'
    elif exp == 'PRISM': # PRISM with some background field
      from datasets.PRISM import loadPRISM
      if lbackground:
        if all(var in ('precip','stations','lon2D','lat2D','landmask','landfrac') for var in varlist): 
          from datasets.GPCC import loadGPCC
          ext = (loadGPCC(grid=grd, varlist=varlist, lautoregrid=lautoregrid), 
                 loadPRISM(grid=grd, varlist=varlist, lautoregrid=lautoregrid),)
          axt = 'PRISM (and GPCC)'
        else: 
          from datasets.CRU import loadCRU
          ext = (loadCRU(period='1979-2009', grid=grd, varlist=varlist, lautoregrid=lautoregrid), 
                 loadPRISM(grid=grd, varlist=varlist, lautoregrid=lautoregrid)) 
          axt = 'PRISM (and CRU)'
      else:
        ext = loadPRISM(grid=grd, varlist=varlist, lautoregrid=lautoregrid); axt = 'PRISM'
    elif exp == 'CFSR': 
      from datasets.CFSR import loadCFSR
      ext = loadCFSR(period=prd, grid=grd, varlist=varlist, lautoregrid=lautoregrid)
      axt = 'CFSR Reanalysis' 
    elif exp == 'NARR': 
      from datasets.NARR import loadNARR
      ext = loadNARR(period=prd, grid=grd, varlist=varlist, lautoregrid=lautoregrid)
      axt = 'NARR Reanalysis'
    elif exp[-5:] == '_CVDP':
      from datasets.CESM import loadCVDP, loadCVDP_Obs
      # load data generated by CVDP
      exp = exp[:-5]
      if exp in CESM_exps: # CESM experiments/ensembles
        exp = CESM_exps[exp]
        ext = loadCVDP(experiment=exp, period=prd, grid=grd, varlist=varlist, 
                       lautoregrid=lautoregrid, exps=CESM_exps)        
      else: # try observations
        ext = loadCVDP_Obs(name=exp, grid=grd, varlist=varlist, lautoregrid=lautoregrid)
      axt = ext.title
    else: # all other uppercase names are CESM runs
      from datasets.CESM import loadCESM
      exp = CESM_exps[exp]
      #print exp.name, exp.title
      ext = loadCESM(experiment=exp, period=prd, grid=grd, varlist=varlist, filetypes=filetypes, 
                     lautoregrid=lautoregrid, exps=CESM_exps)
      axt = exp.title
  else: 
    # WRF runs are all in lower case
    from datasets.WRF import loadWRF
    exp = WRF_exps[exp]      
    parent = None
    if isinstance(dom,(list,tuple)):
      if 0 == dom[0]:
        dom = dom[1:]
        parent, tmp = loadDataset(exp.parent, prd, dom, grd, res, varlist=varlist, lbackground=False, 
                                  lautoregrid=lautoregrid, WRF_exps=WRF_exps, CESM_exps=CESM_exps); del tmp    
    if lWRFnative: grd = None
    ext = loadWRF(experiment=exp, period=prd, grid=grd, domains=dom, filetypes=filetypes, 
                  varlist=varlist, varatts=None, lautoregrid=lautoregrid, exps=WRF_exps)
    if parent is not None: ext = (parent,) + tuple(ext)
    axt = exp.title # defaults to name...
  # return values
  return ext, axt    
示例#2
0
      exps, titles, nlist = loadDatasets(explist, n=None, varlist=loadlist,
					                               titles=titles, periods=period, 
                                         domains=domains, grids=grid,
                                         resolutions='025', filetypes=allfiletypes,                                          
                                         lWRFnative=False, ltuple=True,
                                         lbackground=False,lautoregrid=True,
                                         WRF_exps=WRF_exps, CESM_exps=CESM_exps)
      ref = exps[0][0]; nlen = len(exps)
      # observations  
      if period == 9: period = 10 # nine is only because some experiments don't have 10 yet...
      if lCRU: cru = loadCRU(period=obsprd, grid=grid, varlist=loadlist, varatts=varatts)
      if lGPCC: gpcc = loadGPCC(period=None, grid=grid, varlist=loadlist, varatts=varatts)
      if lPRISM: prism = loadPRISM(period=None, grid=grid, varlist=loadlist, varatts=varatts)
      if lPCIC: pcic = loadPCIC(period=None, grid=grid, varlist=loadlist, varatts=varatts)
      if lUnity: unity = loadUnity(period=obsprd, grid=grid, varlist=loadlist, varatts=varatts)
      if lCFSR: cfsr = loadCFSR(period=period, grid=grid, varlist=loadlist, varatts=varatts)
      if lNARR: narr = loadNARR(period=period, grid=grid, varlist=loadlist, varatts=varatts)  
      print ref
      print ref.name
      
      ## create averaging mask
      if area == 'athabasca': 
        areaname = 'ARB'; subarea = 'WholeARB'; areatitle = 'ARB'
      elif area == 'fraser': 
        areaname = 'FRB'; subarea = 'WholeFRB'; areatitle = 'FRB'
      elif area == 'northcoast': 
        areaname = 'PSB'; subarea = 'NorthernPSB'; areatitle = 'Northern PSB'
      elif area == 'southcoast': 
        areaname = 'PSB'; subarea = 'SouthernPSB'; areatitle = 'Southern PSB'
      else: 
        raise ValueError, 'Have to specify a river area or other shapefile to use as mask!'
示例#3
0
def loadDataset(exp, prd, dom, grd, res, filetypes=None, varlist=None, lbackground=True, lWRFnative=True, 
                lautoregrid=False, WRF_exps=None, CESM_exps=None):
  ''' A function that loads a dataset, based on specified parameters '''
  if not isinstance(exp,basestring): raise TypeError
  if exp[0].isupper():
    if exp == 'Unity': 
      from datasets.Unity import loadUnity
      ext = loadUnity(resolution=res, period=prd, grid=grd, varlist=varlist, lautoregrid=lautoregrid)
      axt = 'Merged Observations'        
    elif exp == 'GPCC': 
      from datasets.GPCC import loadGPCC
      ext = loadGPCC(resolution=res, period=prd, grid=grd, varlist=varlist, lautoregrid=lautoregrid)
      axt = 'GPCC Observations'
    elif exp == 'CRU': 
      from datasets.CRU import loadCRU
      ext = loadCRU(period=prd, grid=grd, varlist=varlist, lautoregrid=lautoregrid)
      axt = 'CRU Observations' 
    elif exp == 'PCIC': # PCIC with some background field
      from datasets.PCIC import loadPCIC
      if lbackground:
        if all(var in ('precip','stations','lon2D','lat2D','landmask','landfrac') for var in varlist): 
          from datasets.GPCC import loadGPCC
          from datasets.PRISM import loadPRISM
          ext = (loadGPCC(grid=grd, varlist=varlist, lautoregrid=lautoregrid), 
                 loadPRISM(grid=grd, varlist=varlist, lautoregrid=lautoregrid),
                 loadPCIC(grid=grd, varlist=varlist, lautoregrid=lautoregrid),)
          axt = 'PCIC PRISM (and GPCC)'
        else:
          from datasets.PRISM import loadPRISM 
          from datasets.CRU import loadCRU
          ext = (loadCRU(period='1971-2001', grid=grd, varlist=varlist, lautoregrid=lautoregrid),
                 loadPRISM(grid=grd, varlist=varlist, lautoregrid=lautoregrid), 
                 loadPCIC(grid=grd, varlist=varlist, lautoregrid=lautoregrid)) 
          axt = 'PCIC PRISM (and CRU)'
      else:
        ext = loadPCIC(grid=grd, varlist=varlist, lautoregrid=lautoregrid); axt = 'PCIC PRISM'
    elif exp == 'PRISM': # PRISM with some background field
      from datasets.PRISM import loadPRISM
      if lbackground:
        if all(var in ('precip','stations','lon2D','lat2D','landmask','landfrac') for var in varlist): 
          from datasets.GPCC import loadGPCC
          ext = (loadGPCC(grid=grd, varlist=varlist, lautoregrid=lautoregrid), 
                 loadPRISM(grid=grd, varlist=varlist, lautoregrid=lautoregrid),)
          axt = 'PRISM (and GPCC)'
        else: 
          from datasets.CRU import loadCRU
          ext = (loadCRU(period='1979-2009', grid=grd, varlist=varlist, lautoregrid=lautoregrid), 
                 loadPRISM(grid=grd, varlist=varlist, lautoregrid=lautoregrid)) 
          axt = 'PRISM (and CRU)'
      else:
        ext = loadPRISM(grid=grd, varlist=varlist, lautoregrid=lautoregrid); axt = 'PRISM'
    elif exp == 'CFSR': 
      from datasets.CFSR import loadCFSR
      ext = loadCFSR(period=prd, grid=grd, varlist=varlist, lautoregrid=lautoregrid)
      axt = 'CFSR Reanalysis' 
    elif exp == 'NARR': 
      from datasets.NARR import loadNARR
      ext = loadNARR(period=prd, grid=grd, varlist=varlist, lautoregrid=lautoregrid)
      axt = 'NARR Reanalysis'
    elif exp[-5:] == '_CVDP':
      from datasets.CESM import loadCVDP, loadCVDP_Obs
      # load data generated by CVDP
      exp = exp[:-5]
      if exp in CESM_exps: # CESM experiments/ensembles
        exp = CESM_exps[exp]
        ext = loadCVDP(experiment=exp, period=prd, grid=grd, varlist=varlist, 
                       lautoregrid=lautoregrid, exps=CESM_exps)        
      else: # try observations
        ext = loadCVDP_Obs(name=exp, grid=grd, varlist=varlist, lautoregrid=lautoregrid)
      axt = ext.title
    else: # all other uppercase names are CESM runs
      from datasets.CESM import CESM_exps, loadCESM
      exp = CESM_exps[exp]
      #print exp.name, exp.title
      ext = loadCESM(experiment=exp, period=prd, grid=grd, varlist=varlist, filetypes=filetypes, 
                     lautoregrid=lautoregrid, exps=CESM_exps)
      axt = exp.title
  else: 
    # WRF runs are all in lower case
    from datasets.WRF import loadWRF
    exp = WRF_exps[exp]      
    parent = None
    if isinstance(dom,(list,tuple)):
      if 0 == dom[0]:
        dom = dom[1:]
        parent, tmp = loadDataset(exp.parent, prd, dom, grd, res, varlist=varlist, lbackground=False, lautoregrid=lautoregrid); del tmp    
    if lWRFnative: grd = None
    ext = loadWRF(experiment=exp, period=prd, grid=grd, domains=dom, filetypes=filetypes, 
                  varlist=varlist, varatts=None, lautoregrid=lautoregrid, exps=WRF_exps)
    if parent is not None: ext = (parent,) + tuple(ext)
    axt = exp.title # defaults to name...
  # return values
  return ext, axt    
示例#4
0
                                  grid=grid,
                                  varlist=loadlist,
                                  varatts=varatts)
            if lPCIC:
                pcic = loadPCIC(period=None,
                                grid=grid,
                                varlist=loadlist,
                                varatts=varatts)
            if lUnity:
                unity = loadUnity(period=obsprd,
                                  grid=grid,
                                  varlist=loadlist,
                                  varatts=varatts)
            if lCFSR:
                cfsr = loadCFSR(period=period,
                                grid=grid,
                                varlist=loadlist,
                                varatts=varatts)
            if lNARR:
                narr = loadNARR(period=period,
                                grid=grid,
                                varlist=loadlist,
                                varatts=varatts)
            print ref
            print ref.name

            ## create averaging mask
            if area == 'athabasca':
                areaname = 'ARB'
                subarea = 'WholeARB'
                areatitle = 'ARB'
            elif area == 'fraser':