本文整理汇总了Python中nco.Nco.ncrcat方法的典型用法代码示例。如果您正苦于以下问题:Python Nco.ncrcat方法的具体用法?Python Nco.ncrcat怎么用?Python Nco.ncrcat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nco.Nco
的用法示例。
在下文中一共展示了Nco.ncrcat方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_use_list_options
# 需要导入模块: from nco import Nco [as 别名]
# 或者: from nco.Nco import ncrcat [as 别名]
def test_use_list_options(foo_nc):
nco = Nco(debug=True)
options = []
options.extend(['-a', 'units,time,o,c,days since 1999-01-01'])
options.extend(['-a', 'long_name,time,o,c,time'])
options.extend(['-a', 'calendar,time,o,c,noleap'])
nco.ncrcat(input=foo_nc, output='out.nc', options=options)
示例2: dailyAve
# 需要导入模块: from nco import Nco [as 别名]
# 或者: from nco.Nco import ncrcat [as 别名]
def dailyAve():
from nco import Nco
import datetime
nco = Nco()
for d in range(365):
dp = datetime.date(startY,1,1)+datetime.timedelta(d)
print "Averaging TRMM 3B42 for day "+dp.strftime('%j')+"..."
ifile = ' '.join("3B42_daily."+str(year)+"."+dp.strftime('%m')+"."+dp.strftime('%d')+".7.nc" for year in range(startY,endY))
ofile = "3B42_aver."+dp.strftime('%j')+".nc"
if not os.path.isfile(ofile):
nco.ncra(input=ifile, output=ofile)
nco.ncrcat(input="3B42_aver.*.nc", output="3B42_cat.nc", options="-d time,1,365")
nco.ncwa(input="3B42_cat.nc", output="3B42_MAP.nc", options='-N -a time')
return None
示例3: combine
# 需要导入模块: from nco import Nco [as 别名]
# 或者: from nco.Nco import ncrcat [as 别名]
def combine(self, members, output_file, dimension=None, start_index=None, stop_index=None, stride=None):
""" Combine many files into a single file on disk. Defaults to using the 'time' dimension. """
nco = None
try:
nco = Nco()
except BaseException:
raise ImportError("NCO not found. The NCO python bindings are required to use 'Collection.combine'.")
if len(members) > 0 and hasattr(members[0], 'path'):
# A member DotDoct was passed in, we only need the paths
members = [ m.path for m in members ]
options = ['-4'] # NetCDF4
options += ['-L', '3'] # Level 3 compression
options += ['-h'] # Don't append to the history global attribute
if dimension is not None:
if start_index is None:
start_index = 0
if stop_index is None:
stop_index = ''
if stride is None:
stride = 1
options += ['-d', '{0},{1},{2},{3}'.format(dimension, start_index, stop_index, stride)]
nco.ncrcat(input=members, output=output_file, options=options)
示例4: xgeo_multifile_load
# 需要导入模块: from nco import Nco [as 别名]
# 或者: from nco.Nco import ncrcat [as 别名]
def xgeo_multifile_load(nc_wildcard, nc_dir=None):
"""
Read data from multiple (e.g. hourly xgeo data) netcdf files
:param nc_wildcard: common section of the filenams, e.g. mf_files*.nc
:return:
"""
if dir:
nc_path = os.path.join(nc_dir, nc_wildcard)
else:
nc_path = nc_wildcard
nco = Nco()
nc_temp = nco.ncrcat(input=nc_path)
nc = netCDF4.Dataset(nc_temp)
#add function to restrict dates and times
return nc
示例5: goesr_nc_concat
# 需要导入模块: from nco import Nco [as 别名]
# 或者: from nco.Nco import ncrcat [as 别名]
def goesr_nc_concat(fn_list, fn_concat=None, read_only=True, global_attrs=None, debug=False):
""" Returns a NetCDF object representing a concatenation of multiple files using NCO bindings.
Args:
fn_list (list): List of files.
e.g.: ['OR_SEIS-L1b-MPSL_G16_20032991650000_20032991650290_20151252148107.nc',
'OR_SEIS-L1b-MPSL_G16_20032991650300_20032991650590_20151252148107.nc']
Keyword Args:
fn_concat (string): Optionally save new NetCDF file permanently to this path (relative is ok).
e.g.: '/tmp/test_goesr_nc_concat.nc'
read_only (True): Only effective if 'fn_concat' supplied. True: returned NC object is writable.
False: returned NC object is read only.
global_attrs (list): Returns list of global attributes for each file concatenated. This is
a temporary step toward figuring out what to do with time varying global attributes.
debug (True): True: print debug on STDOUT. False: no STDOUT.
Returns:
NetCDF object reference to aggregated result.
None if an exception occurs.
Examples (also, see main() below):
1) Get MPS-LO:
>>> import glob, numpy as np, goesr_nc_concat
>>> fn_list = sorted( glob.glob(
... 'OR_SEIS-L1b-MPSL_G??_??????????????_??????????????_??????????????.nc') )
>>> nc_all = goesr_nc_concat.goesr_nc_concat( fn_list, debug=True )
2) Print Global Attributes:
>>> print( 'Global Attributes:' )
>>> nc_all_dict = nc_all.__dict__
>>> for attr in nc_all_dict: print( '\t%s: %s' % (attr, nc_all_dict[ attr ]) )
3) Save concatenation to file system permanently:
>>> fn_concat = '/tmp/test_goesr_nc_concat.nc'
>>> nc_all = goesr_nc_concat.goesr_nc_concat( fn_list, fn_concat=fn_concat, debug=True )
4) Use data:
>>> print( 'Mean Diff-e-flux: %f, %s' %
... ( np.mean( nc_all.variables['DiffElectronFluxes'] ),
... nc_all.variables['DiffElectronFluxes'].units ) )
Authors: R. Redmon (NOAA/NCEI),
"""
# TODO: Handle time varying global attributes. As sidecar dictionary? As new variables in returned object?
# TODO: Replace STDOUT debug with logger.
try:
' CONFIG '
my_name = 'goesr_nc_concat'
file_rw_access = 'r' if read_only else 'r+' # Read Only or Writable?
if 0 == len(fn_list): return None
' Imports '
import shutil, traceback
from netCDF4 import Dataset as NCDataset
from nco import Nco
' Concatenate to a Temporary File '
nco = Nco()
fn_tmp = nco.ncrcat(input=fn_list, options='--create_ram')
if debug: print(my_name + ': Aggregated %d files to temporary file: %s' % (len(fn_list), fn_tmp))
' Save Temporary File Permanently (User Choice) '
if fn_concat != None:
shutil.copy2(fn_tmp, fn_concat)
if debug: print(my_name + ': Saved aggregated file permanently as: %s' % fn_concat)
fn_tmp = fn_concat
' Open Concatenate as netcdf4-python::Dataset '
nc_all = NCDataset(fn_tmp, file_rw_access)
' Keep Global Attributes as Ordered List (User Choice) '
if global_attrs != None:
for fn in fn_list:
global_attrs.append(NCDataset(fn).__dict__)
' Return NC Object Reference '
return nc_all
except Exception as e:
# TODO: Exception prints stack trace.
print(my_name + ': EXCEPTION: %s' % str(e))
print(repr(traceback.format_stack()))
return None
示例6: test_use_list_inputs
# 需要导入模块: from nco import Nco [as 别名]
# 或者: from nco.Nco import ncrcat [as 别名]
def test_use_list_inputs(foo_nc, bar_nc):
nco = Nco(debug=True)
infiles = [foo_nc, bar_nc]
nco.ncrcat(input=infiles, output="out.nc")