當前位置: 首頁>>代碼示例>>Python>>正文


Python Cdo.forceOutput方法代碼示例

本文整理匯總了Python中cdo.Cdo.forceOutput方法的典型用法代碼示例。如果您正苦於以下問題:Python Cdo.forceOutput方法的具體用法?Python Cdo.forceOutput怎麽用?Python Cdo.forceOutput使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cdo.Cdo的用法示例。


在下文中一共展示了Cdo.forceOutput方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_forceOutput

# 需要導入模塊: from cdo import Cdo [as 別名]
# 或者: from cdo.Cdo import forceOutput [as 別名]
    def test_forceOutput(self):
        cdo = Cdo()
        cdo.debug = DEBUG
        outs = []
        # tempfiles
        outs.append(cdo.stdatm("0,10,20"))
        outs.append(cdo.stdatm("0,10,20"))
        self.assertNotEqual(outs[0],outs[1])
        outs = []

        # deticated output, force = true (=defaut setting)
        ofile = 'test_force_{0}'.format( random.randrange(1,100000))
        outs.append(cdo.stdatm("0,10,20",output = ofile))
        mtime0 = os.stat(ofile).st_mtime
        #to make it compatible with systems providing no nanos.
        time.sleep(1)
        outs.append(cdo.stdatm("0,10,20",output = ofile))
        mtime1 = os.stat(ofile).st_mtime
        self.assertNotEqual(mtime0,mtime1)
        self.assertEqual(outs[0],outs[1])
        os.remove(ofile)
        outs = []

        # dedicated output, force = false
        ofile = 'test_force_false_{0}'.format( random.randrange(1,100000))
        outs.append(cdo.stdatm("0,10,20",output = ofile,force=False))
        mtime0 = os.stat(outs[0]).st_mtime
        outs.append(cdo.stdatm("0,10,20",output = ofile,force=False))
        mtime1 = os.stat(outs[1]).st_mtime
        self.assertEqual(mtime0,mtime1)
        self.assertEqual(outs[0],outs[1])
        os.remove(ofile)
        outs = []

        # dedicated output, global force setting
        ofile = 'test_force_global_{0}'.format( random.randrange(1,100000))
        cdo.forceOutput = False
        outs.append(cdo.stdatm("0,10,20",output = ofile))
        mtime0 = os.stat(outs[0]).st_mtime
        outs.append(cdo.stdatm("0,10,20",output = ofile))
        mtime1 = os.stat(outs[1]).st_mtime
        self.assertEqual(mtime0,mtime1)
        self.assertEqual(outs[0],outs[1])
        os.remove(ofile)
        outs = []
開發者ID:Try2Code,項目名稱:cdo-bindings,代碼行數:47,代碼來源:test_cdo.py

示例2: Cdo

# 需要導入模塊: from cdo import Cdo [as 別名]
# 或者: from cdo.Cdo import forceOutput [as 別名]
""" processing of timeseries """
import logging
logger = logging.getLogger(__name__)

from netCDF4 import  Dataset

from cdo import *   # python version
cdo = Cdo()

cdo.forceOutput = True 

def fldmean(resource, prefix=None, dir_output = None ):
  from os import path # join, basename , curdir
  from os import mkdir
  """
  retuns a str or list of netCDF filepathes containing the 
  field mean over the whole domain of the resource file
  
  :param resources: string or list of input file path(es)
  :param dir_output: string for path of output dircetory. in None (default) 
  temporare directory will be created
  :param prefix: prefix of the output file. If None (default) is set, 
  basename of infile will be set as basename
  """  
  print 'start'
  if dir_output == None:
    if not path.exists('fldmeans'):
      dir_output = mkdir('fldmeans')
    else:
      dir_output = 'fldmeans'
  print dir_output
開發者ID:sradanov,項目名稱:flyingpigeon,代碼行數:33,代碼來源:timeseries.py

示例3: method_A

# 需要導入模塊: from cdo import Cdo [as 別名]
# 或者: from cdo.Cdo import forceOutput [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.forceOutput方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。