当前位置: 首页>>代码示例>>Python>>正文


Python Cdo.lt方法代码示例

本文整理汇总了Python中cdo.Cdo.lt方法的典型用法代码示例。如果您正苦于以下问题:Python Cdo.lt方法的具体用法?Python Cdo.lt怎么用?Python Cdo.lt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cdo.Cdo的用法示例。


在下文中一共展示了Cdo.lt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: method_A

# 需要导入模块: from cdo import Cdo [as 别名]
# 或者: from cdo.Cdo import lt [as 别名]
def method_A(resource=[], start=None, end=None, timeslice=20, 
  variable=None, title=None, cmap='seismic' ):
  """returns the result
  
  :param resource: list of paths to netCDF files
  :param start: beginning of reference period (if None (default), the first year of the consistent ensemble will be detected)
  :param end: end of comparison period (if None (default), the last year of the consistent ensemble will be detected)
  :param timeslice: period length for mean calculation of reference and comparison period
  :param variable: variable name to be detected in the netCDF file. If not set (not recommended), the variable name will be detected
  :param title: str to be used as title for the signal mal
  :param cmap: define the color scheme for signal map plotting 

  :return: signal.nc, low_agreement_mask.nc, high_agreement_mask.nc, graphic.png, text.txt
  """
  from os.path import split
  from cdo import Cdo
  cdo = Cdo()
  cdo.forceOutput = True 
  
  try: 
    # preparing the resource
#    from flyingpigeon.ocgis_module import call
    file_dic = sort_by_filename(resource, historical_concatination = True)
    #print file_dic
    logger.info('file names sorted experimets: %s' % len(file_dic.keys()))
  except Exception as e:
    msg = 'failed to sort the input files'
    logger.exception(msg)
    raise Exception(msg)
  

  try:
    mergefiles = []
    for key in file_dic.keys():
      
      if type(file_dic[key]) == list and len(file_dic[key]) > 1:
        input = []
        for i in file_dic[key]:
          print i 
          input.extend([i.replace(' ','\\\ ')])
        mergefiles.append(cdo.mergetime(input=input, output=key+'_mergetime.nc'))
      else:
        mergefiles.extend(file_dic[key])
#      files.append(cdo.selyear('%s/%s' % (start1,end2), input = tmpfile , output =  key+'.nc' )) #python version
    logger.info('datasets merged %s ' % mergefiles)
  except Exception as e:
    msg = 'seltime and mergetime failed %s' % e
    logger.exception(msg)
    raise Exception(e)    
  
  try: 
    text_src = open('infiles.txt', 'a')
    for key in file_dic.keys():
      text_src.write(key + '\n')
    text_src.close()
  except Exception as e:
    msg = 'failed to write source textfile'
    logger.exception(msg)
    raise Exception(msg)
    
  # configure reference and compare period
  try: 
    if start == None:
      st_set = set()
      en_set = set()
      for f in mergefiles:
        print f
        times = get_time(f)
        st_set.update([times[0].year])
        if end == None: 
          en_set.update([times[-1].year])
      start = max(st_set)
      if end == None:
        end = min(en_set)
    logger.info('Start and End: %s - %s ' % (start, end))
    if start >= end: 
      logger.error('ensemble is inconsistent!!! start year is later than end year')
  except Exception as e:
    msg = 'failed to detect start and end times of the ensemble'
    logger.exception(msg)
    raise Exception(msg)

  # set the periodes: 
  try: 
    start = int(start)
    end = int(end)
    if timeslice == None: 
      timeslice = int((end - start) / 3)
      if timeslice == 0: 
        timeslice = 1
    else: 
      timeslice = int(timeslice)
    start1 = start
    start2 = start1 + timeslice - 1 
    end1 = end - timeslice + 1
    end2 = end
    logger.info('timeslice and periodes set')
  except Exception as e:
    msg = 'failed to set the periodes'
    logger.exception(msg)
#.........这里部分代码省略.........
开发者ID:KatiRG,项目名称:flyingpigeon,代码行数:103,代码来源:ensembleRobustness.py


注:本文中的cdo.Cdo.lt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。