本文整理匯總了Python中geodata.netcdf.DatasetNetCDF.replaceAxis方法的典型用法代碼示例。如果您正苦於以下問題:Python DatasetNetCDF.replaceAxis方法的具體用法?Python DatasetNetCDF.replaceAxis怎麽用?Python DatasetNetCDF.replaceAxis使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類geodata.netcdf.DatasetNetCDF
的用法示例。
在下文中一共展示了DatasetNetCDF.replaceAxis方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: loadGPCC_TS
# 需要導入模塊: from geodata.netcdf import DatasetNetCDF [as 別名]
# 或者: from geodata.netcdf.DatasetNetCDF import replaceAxis [as 別名]
def loadGPCC_TS(name=dataset_name, grid=None, varlist=None, resolution='25', varatts=None, filelist=None,
folder=None, lautoregrid=None):
''' Get a properly formatted dataset with the monthly GPCC time-series. '''
if grid is None:
# load from original time-series files
if folder is None: folder = orig_ts_folder
# prepare input
if resolution not in ('05', '10', '25'): raise DatasetError, "Selected resolution '%s' is not available!"%resolution
# translate varlist
if varatts is None: varatts = tsvaratts.copy()
if varlist is None: varlist = varatts.keys()
if varlist and varatts: varlist = translateVarNames(varlist, varatts)
if filelist is None: # generate default filelist
filelist = []
if 'p' in varlist: filelist.append(orig_ts_file.format('precip',resolution))
if 's' in varlist: filelist.append(orig_ts_file.format('statio',resolution))
# load dataset
dataset = DatasetNetCDF(name=name, folder=folder, filelist=filelist, varlist=varlist, varatts=varatts, multifile=False, ncformat='NETCDF4_CLASSIC')
# replace time axis with number of month since Jan 1979
data = np.arange(0,len(dataset.time),1, dtype='int16') + (1901-1979)*12 # month since 1979 (Jan 1979 = 0)
timeAxis = Axis(name='time', units='month', coord=data, atts=dict(long_name='Month since 1979-01'))
dataset.replaceAxis(dataset.time, timeAxis, asNC=False, deepcopy=False)
# add GDAL info
dataset = addGDALtoDataset(dataset, projection=None, geotransform=None)
# N.B.: projection should be auto-detected as geographic
else:
# load from neatly formatted and regridded time-series files
if folder is None: folder = avgfolder
grid, resolution = checkGridRes(grid, resolution, period=None, lclim=False)
dataset = loadObservations(name=name, folder=folder, projection=None, resolution=resolution, grid=grid,
period=None, varlist=varlist, varatts=varatts, filepattern=tsfile,
filelist=filelist, lautoregrid=lautoregrid, mode='time-series')
# return formatted dataset
return dataset
示例2: loadNARR_TS
# 需要導入模塊: from geodata.netcdf import DatasetNetCDF [as 別名]
# 或者: from geodata.netcdf.DatasetNetCDF import replaceAxis [as 別名]
def loadNARR_TS(name=dataset_name, grid=None, varlist=None, resolution=None, varatts=None, filelist=None,
folder=None, lautoregrid=None):
''' Get a properly formatted NARR dataset with monthly mean time-series. '''
if grid is None:
# load from original time-series files
if folder is None: folder = orig_ts_folder
# translate varlist
if varatts is None: varatts = tsvaratts.copy()
if varlist is None: varlist = tsvarlist
if varlist and varatts: varlist = translateVarNames(varlist, varatts)
if filelist is None: # generate default filelist
filelist = [orig_ts_file.format(special[var]) if var in special else orig_ts_file.format(var) for var in varlist
if var not in nofile and var in varatts]
# load dataset
dataset = DatasetNetCDF(name=name, folder=folder, filelist=filelist, varlist=varlist, varatts=varatts,
atts=projdict, multifile=False, ncformat='NETCDF4_CLASSIC')
# replace time axis with number of month since Jan 1979
data = np.arange(0,len(dataset.time),1, dtype='int16') # month since 1979 (Jan 1979 = 0)
timeAxis = Axis(name='time', units='month', coord=data, atts=dict(long_name='Month since 1979-01'))
dataset.replaceAxis(dataset.time, timeAxis, asNC=False, deepcopy=False)
# add projection
projection = getProjFromDict(projdict, name='{0:s} Coordinate System'.format(name))
dataset = addGDALtoDataset(dataset, projection=projection, geotransform=None, gridfolder=grid_folder)
else:
# load from neatly formatted and regridded time-series files
if folder is None: folder = avgfolder
dataset = loadObservations(name=name, folder=folder, projection=None, resolution=None, grid=grid,
period=None, varlist=varlist, varatts=varatts, filepattern=tsfile,
filelist=filelist, lautoregrid=lautoregrid, mode='time-series')
# return formatted dataset
return dataset
示例3: loadCRU_TS
# 需要導入模塊: from geodata.netcdf import DatasetNetCDF [as 別名]
# 或者: from geodata.netcdf.DatasetNetCDF import replaceAxis [as 別名]
def loadCRU_TS(name=dataset_name, grid=None, varlist=None, resolution=None, varatts=None, filelist=None,
folder=None, lautoregrid=None):
''' Get a properly formatted CRU dataset with monthly mean time-series. '''
if grid is None:
# load from original time-series files
if folder is None: folder = orig_ts_folder
# translate varlist
if varatts is None: varatts = tsvaratts.copy()
if varlist is None: varlist = varatts.keys()
if varlist and varatts: varlist = translateVarNames(varlist, varatts)
# assemble filelist
if filelist is None: # generate default filelist
filelist = [orig_ts_file.format(var) for var in varlist if var not in nofile]
# load dataset
dataset = DatasetNetCDF(name=name, folder=folder, filelist=filelist, varlist=varlist, varatts=varatts,
multifile=False, ncformat='NETCDF4_CLASSIC')
# replace time axis with number of month since Jan 1979
data = np.arange(0,len(dataset.time),1, dtype='int16') + (1901-1979)*12 # month since 1979 (Jan 1979 = 0)
timeAxis = Axis(name='time', units='month', coord=data, atts=dict(long_name='Month since 1979-01'))
dataset.replaceAxis(dataset.time, timeAxis, asNC=False, deepcopy=False)
# add projection
dataset = addGDALtoDataset(dataset, projection=None, geotransform=None, gridfolder=grid_folder)
# N.B.: projection should be auto-detected as geographic
else:
# load from neatly formatted and regridded time-series files
if folder is None: folder = avgfolder
dataset = loadObservations(name=name, folder=folder, projection=None, resolution=None, grid=grid,
period=None, varlist=varlist, varatts=varatts, filepattern=tsfile,
filelist=filelist, lautoregrid=lautoregrid, mode='time-series')
# return formatted dataset
return dataset
示例4: loadCFSR_TS
# 需要導入模塊: from geodata.netcdf import DatasetNetCDF [as 別名]
# 或者: from geodata.netcdf.DatasetNetCDF import replaceAxis [as 別名]
def loadCFSR_TS(name=dataset_name, grid=None, varlist=None, varatts=None, resolution='hires',
filelist=None, folder=None, lautoregrid=None):
''' Get a properly formatted CFSR dataset with monthly mean time-series. '''
if grid is None:
# load from original time-series files
if folder is None: folder = orig_ts_folder
# translate varlist
if varatts is None: varatts = tsvaratts.copy()
if varlist is None:
if resolution == 'hires' or resolution == '03' or resolution == '031': varlist = varlist_hires
elif resolution == 'lowres' or resolution == '05': varlist = varlist_lowres
if varlist and varatts: varlist = translateVarNames(varlist, varatts)
if filelist is None: # generate default filelist
if resolution == 'hires' or resolution == '03' or resolution == '031':
files = [hiresfiles[var] for var in varlist if var in hiresfiles]
elif resolution == 'lowres' or resolution == '05':
files = [lowresfiles[var] for var in varlist if var in lowresfiles]
# load dataset
dataset = DatasetNetCDF(name=name, folder=folder, filelist=files, varlist=varlist, varatts=varatts,
check_override=['time'], multifile=False, ncformat='NETCDF4_CLASSIC')
# load static data
if filelist is None: # generate default filelist
if resolution == 'hires' or resolution == '03' or resolution == '031':
files = [hiresstatic[var] for var in varlist if var in hiresstatic]
elif resolution == 'lowres' or resolution == '05':
files = [lowresstatic[var] for var in varlist if var in lowresstatic]
# load constants, if any (and with singleton time axis)
if len(files) > 0:
staticdata = DatasetNetCDF(name=name, folder=folder, filelist=files, varlist=varlist, varatts=varatts,
axes=dict(lon=dataset.lon, lat=dataset.lat), multifile=False,
check_override=['time'], ncformat='NETCDF4_CLASSIC')
# N.B.: need to override the axes, so that the datasets are consistent
if len(staticdata.variables) > 0:
for var in staticdata.variables.values():
if not dataset.hasVariable(var.name):
var.squeeze() # remove time dimension
dataset.addVariable(var, copy=False) # no need to copy... but we can't write to the netcdf file!
# replace time axis with number of month since Jan 1979
data = np.arange(0,len(dataset.time),1, dtype='int16') # month since 1979 (Jan 1979 = 0)
timeAxis = Axis(name='time', units='month', coord=data, atts=dict(long_name='Month since 1979-01'))
dataset.replaceAxis(dataset.time, timeAxis, asNC=False, deepcopy=False)
# add projection
dataset = addGDALtoDataset(dataset, projection=None, geotransform=None, gridfolder=grid_folder)
# N.B.: projection should be auto-detected as geographic
else:
# load from neatly formatted and regridded time-series files
if folder is None: folder = avgfolder
grid, resolution = checkGridRes(grid, resolution)
dataset = loadObservations(name=name, folder=folder, projection=None, resolution=resolution, grid=grid,
period=None, varlist=varlist, varatts=varatts, filepattern=tsfile,
filelist=filelist, lautoregrid=lautoregrid, mode='time-series')
# return formatted dataset
return dataset
示例5: __init__
# 需要導入模塊: from geodata.netcdf import DatasetNetCDF [as 別名]
# 或者: from geodata.netcdf.DatasetNetCDF import replaceAxis [as 別名]
#.........這裏部分代碼省略.........
filepath = '{:s}/{:s}'.format(folder,filename)
if not os.path.exists(filepath):
nativename = fileformat.format('',periodstr) # original filename (before regridding)
nativepath = '{:s}/{:s}'.format(folder,nativename)
if os.path.exists(nativepath):
if lautoregrid:
from processing.regrid import performRegridding # causes circular reference if imported earlier
griddef = loadPickledGridDef(grid=grid, res=None, folder=grid_folder)
dataargs = dict(experiment=experiment, filetypes=[filetype], period=period)
print("The '{:s}' (CESM) dataset for the grid ('{:s}') is not available:\n Attempting regridding on-the-fly.".format(name,filename,grid))
if performRegridding('CESM','climatology' if lclim else 'time-series', griddef, dataargs): # default kwargs
raise IOError, "Automatic regridding failed!"
print("Output: '{:s}'".format(name,filename,grid,filepath))
else: raise IOError, "The '{:s}' (CESM) dataset '{:s}' for the selected grid ('{:s}') is not available - use the regrid module to generate it.".format(name,filename,grid)
else: raise IOError, "The '{:s}' (CESM) dataset file '{:s}' does not exits!\n({:s})".format(name,filename,folder)
# load dataset
#print varlist, filenames
if experiment: title = experiment.title
else: title = name
dataset = DatasetNetCDF(name=name, folder=folder, filelist=filenames, varlist=varlist, axes=None,
varatts=atts, title=title, multifile=False, ignore_list=ignore_list,
ncformat='NETCDF4', squeeze=True, mode=ncmode, check_vars=check_vars)
# replace time axis
if lreplaceTime:
if lts or lcvdp:
# check time axis and center at 1979-01 (zero-based)
if experiment is None: ys = period[0]; ms = 1
else: ys,ms,ds = [int(t) for t in experiment.begindate.split('-')]; assert ds == 1
if dataset.hasAxis('time'):
ts = (ys-1979)*12 + (ms-1); te = ts+len(dataset.time) # month since 1979 (Jan 1979 = 0)
atts = dict(long_name='Month since 1979-01')
timeAxis = Axis(name='time', units='month', coord=np.arange(ts,te,1, dtype='int16'), atts=atts)
dataset.replaceAxis(dataset.time, timeAxis, asNC=False, deepcopy=False)
if dataset.hasAxis('year'):
ts = ys-1979; te = ts+len(dataset.year) # month since 1979 (Jan 1979 = 0)
atts = dict(long_name='Years since 1979-01')
yearAxis = Axis(name='year', units='year', coord=np.arange(ts,te,1, dtype='int16'), atts=atts)
dataset.replaceAxis(dataset.year, yearAxis, asNC=False, deepcopy=False)
elif lclim:
if dataset.hasAxis('time') and not dataset.time.units.lower() in monthlyUnitsList:
atts = dict(long_name='Month of the Year')
timeAxis = Axis(name='time', units='month', coord=np.arange(1,13, dtype='int16'), atts=atts)
assert len(dataset.time) == len(timeAxis), dataset.time
dataset.replaceAxis(dataset.time, timeAxis, asNC=False, deepcopy=False)
elif dataset.hasAxis('year'): raise NotImplementedError, dataset
# rename SST
if lSST: dataset['SST'] = dataset.Ts
# correct ordinal number of shape (should start at 1, not 0)
if lshape:
# mask all shapes that are incomplete in dataset
if lencl and 'shp_encl' in dataset: dataset.mask(mask='shp_encl', invert=True)
if dataset.hasAxis('shapes'): raise AxisError, "Axis 'shapes' should be renamed to 'shape'!"
if not dataset.hasAxis('shape'): raise AxisError
if dataset.shape.coord[0] == 0: dataset.shape.coord += 1
# check
if len(dataset) == 0: raise DatasetError, 'Dataset is empty - check source file or variable list!'
# add projection, if applicable
if not ( lstation or lshape ):
dataset = addGDALtoDataset(dataset, griddef=griddef, gridfolder=grid_folder, lwrap360=True, geolocator=True)
# return formatted dataset
return dataset
## Dataset API
dataset_name = 'CMIP5' # dataset name