本文整理汇总了Python中cdo.Cdo.timmean方法的典型用法代码示例。如果您正苦于以下问题:Python Cdo.timmean方法的具体用法?Python Cdo.timmean怎么用?Python Cdo.timmean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cdo.Cdo
的用法示例。
在下文中一共展示了Cdo.timmean方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cdo_general
# 需要导入模块: from cdo import Cdo [as 别名]
# 或者: from cdo.Cdo import timmean [as 别名]
def test_cdo_general(self):
# test if cdos work in general
cdo = Cdo()
out_file = self._tmpdir + os.sep + 'cdo_test.nc'
if os.path.exists(out_file):
os.remove(out_file)
cdo.timmean(options='-f nc', output=out_file, input=self.file)
self.assertTrue(os.path.exists(out_file))
if os.path.exists(out_file):
os.remove(out_file)
示例2: method_A
# 需要导入模块: from cdo import Cdo [as 别名]
# 或者: from cdo.Cdo import timmean [as 别名]
#.........这里部分代码省略.........
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)
raise Exception(msg)
try:
files = []
for i, mf in enumerate(mergefiles):
files.append(cdo.selyear('{0}/{1}'.format(start1,end2), input=[mf.replace(' ','\ ')] , output='file_{0}_.nc'.format(i) )) #python version
logger.info('timeseries selected from defined start to end year')
except Exception as e:
msg = 'seltime and mergetime failed'
logger.exception(msg)
raise Exception(msg)
try:
# ensemble mean
nc_ensmean = cdo.ensmean(input=files , output='nc_ensmean.nc')
logger.info('ensemble mean calculation done')
except Exception as e:
msg = 'ensemble mean failed'
logger.exception(msg)
raise Exception(msg)
try:
# ensemble std
nc_ensstd = cdo.ensstd(input=files , output='nc_ensstd.nc')
logger.info('ensemble std and calculation done')
except Exception as e:
msg = 'ensemble std or failed'
logger.exception(msg)
raise Exception(msg)
# get the get the signal as difference from the beginning (first years) and end period (last years), :
try:
selyearstart = cdo.selyear('%s/%s' % (start1,start2), input = nc_ensmean, output = 'selyearstart.nc' )
selyearend = cdo.selyear('%s/%s' % (end1,end2), input = nc_ensmean, output = 'selyearend.nc' )
meanyearst = cdo.timmean(input = selyearstart, output= 'meanyearst.nc')
meanyearend = cdo.timmean(input = selyearend, output= 'meanyearend.nc')
signal = cdo.sub(input=[meanyearend, meanyearst], output = 'signal.nc')
logger.info('Signal calculation done')
except Exception as e:
msg = 'calculation of signal failed'
logger.exception(msg)
raise Exception(msg)
# get the intermodel standard deviation (mean over whole period)
try:
#std_selyear = cdo.selyear('%s/%s' % (end1,end2), input=nc_ensstd, output='std_selyear.nc')
#std = cdo.timmean(input = std_selyear, output = 'std.nc')
std = cdo.timmean(input = nc_ensstd, output = 'std.nc')
std2 = cdo.mulc('2', input = std, output = 'std2.nc')
logger.info('calculation of internal model std for time period done')
except Exception as e:
msg = 'calculation of internal model std failed'
logger.exception(msg)
raise Exception(msg)
try:
absolut = cdo.abs(input=signal, output='absolut_signal.nc')
high_agreement_mask = cdo.gt(input=[absolut,std2], output= 'large_change_with_high_model_agreement.nc')
low_agreement_mask = cdo.lt(input=[absolut,std], output= 'small_signal_or_low_agreement_of_models.nc')
logger.info('high and low mask done')
except Exception as e:
msg = 'calculation of robustness mask failed'
logger.exception(msg)
raise Exception(msg)
try:
if variable == None:
variable = get_variable(signal)
logger.info('variable to be plotted: %s' % variable)
if title == None:
title='Change of %s (difference of mean %s-%s to %s-%s)' % (variable, end1, end2, start1, start2)
graphic = None
graphic = map_ensembleRobustness(signal, high_agreement_mask, low_agreement_mask,
variable=variable,
cmap=cmap,
title = title)
logger.info('graphic generated')
except Exception as e:
msg('graphic generation failed: %s' % e)
logger.debug(msg)
raise Exception(msg)
return signal, low_agreement_mask, high_agreement_mask, graphic, text_src #