本文整理汇总了Python中netCDF4.Dataset.delncattr方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.delncattr方法的具体用法?Python Dataset.delncattr怎么用?Python Dataset.delncattr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类netCDF4.Dataset
的用法示例。
在下文中一共展示了Dataset.delncattr方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: updateNCattrs_single
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import delncattr [as 别名]
def updateNCattrs_single(self, ncName):
"""on a single file: run when ONLY nc METADATA needs updating, NOT any data
:param str ncName: filename of netCDF to be made, with path
.. note::
Function uses metaDict variables set in various levels of __init__.
.. todo::
- Shouldn't delete global attributes set in ``NCtimeMeta`` :
time_coverage_duration, date_issued, date_modified, time_coverage_start, time_coverage_end
- Except SASS object now sets ``metaDict`` in ``createNCshell``. Therefore,
these global attributes won't work with this function.
These include: title, date_created, history, geospatial_lat/lon/vertical_min/max,
institution, comment.
"""
print ncName
ncfile = Dataset(ncName, 'a', format='NETCDF4')
#print ncfile.variables.keys()
#print ncfile.ncattrs()
print ncfile.__dict__
ncfile.setncatts(self.metaDict)
print "EDITED"
#print ncfile.__dict__.keys()
#take out attributes that are no longer in the meta dictionary
for k in ncfile.__dict__.keys():
if k not in self.metaDict:
print 'DELETED', k
ncfile.delncattr(k)
self.NCtimeMeta(ncfile)
print "DONE"
print ncfile.__dict__#.keys()
ncfile.close()
示例2: set_dynamic_md
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import delncattr [as 别名]
def set_dynamic_md(resource):
"""
Dynamic meta data like time frequency, spatial extent, start/end time, etc.
:param resource: netCDF file where basic meta data should be set
"""
from flyingpigeon.utils import get_timerange, get_time
frequency = get_frequency(resource)
time_coverage_start, time_coverage_end = get_timerange(resource)
time_number_steps = len(get_time(resource))
# max_lat, min_lat, max_lon, min_lat = get_extent(resource)
ds = Dataset(resource, mode='a')
try:
driving_experiment = ds.driving_experiment
ds.delncattr('driving_experiment')
except Exception as e:
logger.error(e)
driving_experiment = ''
try:
driving_experiment_name = ds.driving_experiment_name
ds.delncattr('driving_experiment_name')
except Exception as e:
logger.error(e)
driving_experiment_name = ''
try:
driving_model_ensemble_member = ds.driving_model_ensemble_member
ds.delncattr('driving_model_ensemble_member')
except Exception as e:
logger.error(e)
driving_model_ensemble_member = ''
try:
experiment = ds.experiment
ds.delncattr('experiment')
except Exception as e:
logger.error(e)
experiment = ''
try:
tracking_id = ds.tracking_id
ds.delncattr('tracking_id')
except Exception as e:
logger.error(e)
tracking_id = ''
try:
experiment_id = ds.experiment_id
ds.delncattr('experiment_id')
except Exception as e:
logger.error(e)
experiment_id = ''
try:
project_id = ds.project_id
ds.delncattr('project_id')
except Exception as e:
logger.error(e)
project_id = ''
try:
institution_id = ds.institution_id
ds.delncattr('institution_id')
except Exception as e:
logger.error(e)
institution_id = ''
try:
model_version_id = ds.model_version_id
ds.delncattr('model_version_id')
except Exception as e:
logger.error(e)
model_version_id = ''
try:
driving_model_id = ds.driving_model_id
ds.delncattr('driving_model_id')
except Exception as e:
logger.error(e)
driving_model_id = ''
try:
driving_ensemble_member = ds.driving_ensemble_member
ds.delncattr('driving_ensemble_member')
except Exception as e:
logger.error(e)
driving_ensemble_member = ''
try:
driving_model_id = ds.driving_model_id
ds.delncattr('driving_model_id')
except Exception as e:
logger.error(e)
driving_model_id = ''
try:
model_id = ds.model_id
#.........这里部分代码省略.........
示例3: Dataset
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import delncattr [as 别名]
# except:
# print "not a mask_rho?"
# sys.exit()
if args.field:
if not args.outf:
nc = Dataset(args.inf+"_vert", 'w', format='NETCDF3_64BIT')
else:
nc = Dataset(args.outf, 'w', format='NETCDF3_64BIT')
for i in f.ncattrs():
print i, f.getncattr(i)
nc.setncattr(i, f.getncattr(i))
nc.delncattr('history')
nc.setncattr('history', f.getncattr('history')+'\n Modified by '+str(os.path.basename(__file__))+' '+str(tm.strftime("%c")))
for i in f.dimensions.keys():
print i
nc.createDimension(i, len(f.dimensions[i]))
for i in f.variables.keys():
print i, f.variables[i].dimensions
w = nc.createVariable(i, 'f8', f.variables[i].dimensions)
for j in f.variables[i].ncattrs():
# print j, ": ", f.variables[i].getncattr(j), f.variables[i].dimensions
w.setncattr(j, f.variables[i].getncattr(j))
示例4: Dataset
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import delncattr [as 别名]
img_file = sys.argv[2]
dst_file = sys.argv[3]
timestamp_str = dst_file.split("-")[0] + "Z"
timestamp = datetime.strptime(timestamp_str, DATE_TIME_FORMAT)
shutil.copy(src_file, dst_file)
ds_out = Dataset(dst_file, mode='r+')
for attr in time_attributes:
print "Setting time attribut '%s' -> '%s'" % (attr, timestamp_str)
ds_out.setncattr(attr, timestamp_str)
for attr in attrs_remove:
print "Removing attribute '%s'" % attr
ds_out.delncattr(attr)
for attr in attrs_add:
print "Setting attribute '%s' -> '%s'" % (attr[0], attr[1])
ds_out.setncattr(attr[0], attr[1])
print "Plainting image '%s'" % img_file
img_data = np.full((image_height, image_width), fill_value=target_variable_fill_value, dtype=target_variable_type)
image = np.asarray(Image.open(img_file))
iTransparent = np.all(image == [0, 0, 0, 0], axis=2)
img_data[~iTransparent] = target_variable_value
ds_out['l2p_flags'].delncattr('flag_masks') # Make CF compliant!