本文整理汇总了Python中cdo.Cdo.abs方法的典型用法代码示例。如果您正苦于以下问题:Python Cdo.abs方法的具体用法?Python Cdo.abs怎么用?Python Cdo.abs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cdo.Cdo
的用法示例。
在下文中一共展示了Cdo.abs方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: modelUncertaintyWorker
# 需要导入模块: from cdo import Cdo [as 别名]
# 或者: from cdo.Cdo import abs [as 别名]
def modelUncertaintyWorker(resource):
"""retuns the result
:param resource: list of pathes to netCDF files
"""
from cdo import Cdo
cdo = Cdo()
from flyingpigeon.utils import check_timestepps
# check resource for consistency
resource_qc = check_timestepps(resource)
try:
# ensemble mean and magnitude
nc_ensmean = cdo.ensmean(input = resource_qc, output = 'nc_ensmean.nc')
logger.info('ensmean calculations done')
except Exception as e:
logger.error('ensmean calculations failed: %s ' % e )
try:
#nc_delta = nc_ensmean(lastpt) - nc_ensmean(firstpt)
nc_laststep = cdo.seltimestep('-1', input = nc_ensmean, output = 'nc_laststep.nc')
nc_firststep = cdo.seltimestep(1, input = nc_ensmean, output = 'nc_firststep.nc')
nc_delta = cdo.sub(input = [nc_laststep, nc_firststep], output = 'nc_delta.nc')
nc_absdelta = cdo.abs(input = nc_delta, output = 'nc_absdelta.nc')
logger.info('delta calculation done')
except Exception as e:
logger.error('delta calculation failed: %s ' % e )
try:
# ensemble std
nc_ensstd = cdo.ensstd(input = resource_qc, output = 'nc_ensstd.nc')
logger.info('std calculation done')
except Exception as e:
logger.error('std calculation failed: %s ' % e )
try:
# compute mask: if nc_absdelta > nc_enssstd
nc_level = cdo.mulc(1, input = nc_ensstd, output = 'nc_level.nc')
nc_binmask = cdo.gt(input = [nc_absdelta, nc_level], output = 'nc_binmask.nc')
logger.info('calculated mask')
except Exception as e:
logger.error('mask calculation failed: %s ' % e )
#if > const
#cdo.gtc('arg', input=infile, ontput=outfile)
# mean + sigma as a mask
# sigma1 = cdo.fldstd(input = nc_ensmean, output = 'nc_sigma1.nc')
# mask
# mean + 2* sigma as a mask
# merge to on result netCDF
# cdo.merge(input=[file1, file2], output='result.nc')
result = nc_ensmean #ensemble mean
result2 = nc_ensstd #ensemble std
result3 = nc_absdelta #magnitude of model change
result4 = nc_binmask #absdelta > std
return result, result2, result3, result4
示例2: method_A
# 需要导入模块: from cdo import Cdo [as 别名]
# 或者: from cdo.Cdo import abs [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 #