本文整理匯總了Python中cdo.Cdo.fldmean方法的典型用法代碼示例。如果您正苦於以下問題:Python Cdo.fldmean方法的具體用法?Python Cdo.fldmean怎麽用?Python Cdo.fldmean使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cdo.Cdo
的用法示例。
在下文中一共展示了Cdo.fldmean方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: normalize
# 需要導入模塊: from cdo import Cdo [as 別名]
# 或者: from cdo.Cdo import fldmean [as 別名]
def normalize(resource, grouping='year', region='AUT', start_date="1971-01-01", end_date="2010-12-31", out_dir=None):
"""
noramlize netcdf file for region and timeperiod
:param resource: netcdf filename
:param start_date: string with start date
:param end_date: string with end date
:param out_dir: output directory for result file (netcdf)
:return: normalized netcdf file
"""
rd = ocgis.RequestDataset(resource)
variable = rd.variable
from dateutil import parser as date_parser
time_range=[ date_parser.parse(start_date) , date_parser.parse(end_date) ]
calc = [{'func':'mean','name':'ref_' + variable }]
filename = drs_filename(resource)
filename = filename.replace("EUR", region)
from os.path import join
output = join(out_dir, filename)
prefix = "ref_%s" % filename
prefix = prefix.replace('.nc', '')
try:
reference = ocgis.OcgOperations(
dataset=rd,
geom=COUNTRY_SHP,
dir_output=out_dir,
output_format="nc",
select_ugid=select_ugid(region),
prefix=prefix,
add_auxiliary_files=False,
calc=calc,
calc_grouping=calc_grouping(grouping),
time_range=time_range ).execute()
from tempfile import mkstemp
from cdo import Cdo
cdo = Cdo()
_,out_resource = mkstemp(prefix="out_resource_", dir=out_dir)
cdo.fldmean(input = resource , output = out_resource)
_,out_ref = mkstemp(prefix="out_ref_", dir=out_dir)
cdo.fldmean(input = reference , output = out_ref )
cdo.sub(input = "%s %s" % (out_resource, out_ref) , output = output)
except:
msg = 'normalize failed for file : %s ' % filename
logger.exception(msg)
raise CalculationException(msg)
return output