本文整理汇总了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 = []
示例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
示例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)
#.........这里部分代码省略.........