本文整理汇总了Python中netCDF4.Dataset.author方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.author方法的具体用法?Python Dataset.author怎么用?Python Dataset.author使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类netCDF4.Dataset
的用法示例。
在下文中一共展示了Dataset.author方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: makenetcdf_
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import author [as 别名]
#.........这里部分代码省略.........
if fields[4] == "":
sals[i, 0] = -9999
else:
sals[i, 0] = fields[4]
if fields[5] == "":
fco2s[i, 0] = -9999
else:
fco2s[i, 0] = fields[5]
if len(fields[6]) == 0:
fco2qcs[i, 0] = -128
else:
fco2qcs[i, 0] = makeqcvalue_(int(fields[6]))
depthvar[:,:] = depths
positionvar[:,:] = positions
sstvar[:,:] = temps
sssvar[:,:] = sals
fco2var[:,:] = fco2s
fco2qcvar[:,:] = fco2qcs
depthdmvar[:,:] = dms
sstdmvar[:,:] = dms
sssdmvar[:,:] = dms
fco2dmvar[:,:] = dms
# Global attributes
nc.id = filenameroot
nc.data_type = "OceanSITES trajectory data"
nc.netcdf_version = "netCDF-4 classic model"
nc.format_version = "1.2"
nc.Conventions = "CF-1.6 OceanSITES-Manual-1.2 Copernicus-InSituTAC-SRD-1.3 "\
+ "Copernicus-InSituTAC-ParametersList-3.1.0"
nc.cdm_data_type = "Trajectory"
nc.data_mode = "R"
nc.area = "Global Ocean"
nc.geospatial_lat_min = str(minlat)
nc.geospatial_lat_max = str(maxlat)
nc.geospatial_lon_min = str(minlon)
nc.geospatial_lon_max = str(maxlon)
nc.geospatial_vertical_min = "5.00"
nc.geospatial_vertical_max = "5.00"
nc.last_latitude_observation = lats[-1]
nc.last_longitude_observation = lons[-1]
nc.last_date_observation = endtime.strftime("%Y-%m-%dT%H:%M:%SZ")
nc.time_coverage_start = starttime.strftime("%Y-%m-%dT%H:%M:%SZ")
nc.time_coverage_end = endtime.strftime("%Y-%m-%dT%H:%M:%SZ")
#datasetdate = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
#nc.date_update = datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
#nc.history = datasetdate + " : Creation"
nc.update_interval = "daily"
nc.data_assembly_center = "BERGEN"
nc.institution = "University of Bergen / Geophysical Institute"
nc.institution_edmo_code = "4595"
nc.institution_references = " "
nc.contact = "[email protected]"
nc.title = "Global Ocean - In Situ near-real time carbon observation"
nc.author = "cmems-service"
nc.naming_authority = "Copernicus"
nc.platform_code = getplatformcallsign_(platform_code)
nc.site_code = getplatformcallsign_(platform_code)
# For buoys -> Mooring observation.
platform_category_code = getplatformcategorycode_(platform_code)
nc.platform_name = getplatformname_(platform_code)
nc.source_platform_category_code = platform_category_code
nc.source = PLATFORM_CODES[platform_category_code]
nc.quality_control_indicator = "6" # "Not used"
nc.quality_index = "0"
nc.comment = " "
nc.summary = " "
nc.reference = "http://marine.copernicus.eu/, https://www.icos-cp.eu/"
nc.citation = "These data were collected and made freely available by the " \
+ "Copernicus project and the programs that contribute to it."
nc.distribution_statement = "These data follow Copernicus standards; they " \
+ "are public and free of charge. User assumes all risk for use of data. " \
+ "User must display citation in any publication or product using data. " \
+ "User must contact PI prior to any commercial use of data."
# Write the netCDF
nc.close()
# Read the netCDF file into memory
with open(ncpath, "rb") as ncfile:
ncbytes = ncfile.read()
# Delete the temp netCDF file
os.remove(ncpath)
return [filenameroot, ncbytes]
示例2: write_netcdf
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import author [as 别名]
def write_netcdf(filename,varnames,data,title):
r"""
Parameters
----------
filename: string
path + filename of netCDF file e. g., '~/Desktop/netcdf_file.nc'
varnames: list
names of the variables names e.g., ['var1','var2','var3'] (names should be exactly the same of
the data.varnames)
data: class
class containing the variables to be saved
title: string
Title or any brief description of the data set
"""
from netCDF4 import Dataset
import numpy as np
# Opening file
filenc = Dataset(filename,'w',clobber=True)
# Global Attributes of the file
filenc.title = title
filenc.institution = 'The Rosenstiel School of Marine and Atmospheric Science, University of Miami'
filenc.author = 'MSc Tiago Carrilho Bilo'
## Creating variables
for v in xrange(len(varnames)):
exec("tp = data."+varnames[v]+".dtype")
exec("d = len(data."+varnames[v]+".shape)")
if d == 1:
exec("filenc.createDimension('i"+np.str(v)+"', None)")
exec("var"+np.str(v)+" = filenc.createVariable(varnames[v], tp.name, ('i"+np.str(v)+"'), zlib=True)")
exec("var"+np.str(v)+"[:] = data."+varnames[v])
elif d == 2:
exec("filenc.createDimension('i"+np.str(v)+"', None)")
exec("filenc.createDimension('j"+np.str(v)+"', None)")
exec("var"+np.str(v)+" = filenc.createVariable(varnames[v], tp.name, ('i"+np.str(v)+"','j"+np.str(v)+"'), zlib=True)")
exec("var"+np.str(v)+"[:,:] = data."+varnames[v])
elif d == 3:
exec("filenc.createDimension('i"+np.str(v)+"', None)")
exec("filenc.createDimension('j"+np.str(v)+"', None)")
exec("filenc.createDimension('k"+np.str(v)+"', None)")
exec("var"+np.str(v)+" = filenc.createVariable(varnames[v], tp.name, ('i"+np.str(v)+"','j"+np.str(v)+"','k"+np.str(v)+"'), zlib=True)")
exec("var"+np.str(v)+"[:,:,:] = data."+varnames[v])
elif d == 4:
exec("filenc.createDimension('i"+np.str(v)+"', None)")
exec("filenc.createDimension('j"+np.str(v)+"', None)")
exec("filenc.createDimension('k"+np.str(v)+"', None)")
exec("filenc.createDimension('t"+np.str(v)+"', None)")
exec("var"+np.str(v)+" = filenc.createVariable(varnames[v], tp.name, ('i"+np.str(v)+"','j"+np.str(v)+"','k"+np.str(v)+"','t"+np.str(v)+"'), zlib=True)")
exec("var"+np.str(v)+"[:,:,:,:] = data."+varnames[v])
filenc.close()
print "File "+filename+" created"
return
示例3: modify_aims_netcdf
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import author [as 别名]
def modify_aims_netcdf(netcdf_file_path, channel_id_info):
""" Modify the downloaded netCDF file so it passes both CF and IMOS checker
input:
netcdf_file_path(str) : path of netcdf file to modify
channel_id_index(dict) : information from xml for the channel
"""
imos_env_path = os.path.join(os.environ.get('DATA_SERVICES_DIR'), 'lib', 'netcdf', 'imos_env')
if not os.path.isfile(imos_env_path):
logger = logging_aims()
logger.error('%s is not accessible' % imos_env_path)
close_logger(logger)
sys.exit(1)
dotenv.load_dotenv(imos_env_path)
netcdf_file_obj = Dataset(netcdf_file_path, 'a', format='NETCDF4')
netcdf_file_obj.naming_authority = 'IMOS'
# add gatts to NetCDF
netcdf_file_obj.aims_channel_id = int(channel_id_info['channel_id'])
if not (channel_id_info['metadata_uuid'] == 'Not Available'):
netcdf_file_obj.metadata_uuid = channel_id_info['metadata_uuid']
if not netcdf_file_obj.instrument_serial_number:
del(netcdf_file_obj.instrument_serial_number)
# add CF gatts, values stored in lib/netcdf/imos_env
netcdf_file_obj.Conventions = os.environ.get('CONVENTIONS')
netcdf_file_obj.data_centre_email = os.environ.get('DATA_CENTRE_EMAIL')
netcdf_file_obj.data_centre = os.environ.get('DATA_CENTRE')
netcdf_file_obj.project = os.environ.get('PROJECT')
netcdf_file_obj.acknowledgement = os.environ.get('ACKNOWLEDGEMENT')
netcdf_file_obj.distribution_statement = os.environ.get('DISTRIBUTION_STATEMENT')
netcdf_file_obj.date_created = strftime("%Y-%m-%dT%H:%M:%SZ", gmtime())
netcdf_file_obj.quality_control_set = 1
imos_qc_convention = 'IMOS standard set using the IODE flags'
netcdf_file_obj.author = 'laurent besnard'
netcdf_file_obj.author_email = '[email protected]'
rename_netcdf_attribute(netcdf_file_obj, 'geospatial_LAT_max', 'geospatial_lat_max')
rename_netcdf_attribute(netcdf_file_obj, 'geospatial_LAT_min', 'geospatial_lat_min')
rename_netcdf_attribute(netcdf_file_obj, 'geospatial_LON_max', 'geospatial_lon_max')
rename_netcdf_attribute(netcdf_file_obj, 'geospatial_LON_min', 'geospatial_lon_min')
# variables modifications
time = netcdf_file_obj.variables['time']
time.calendar = 'gregorian'
time.axis = 'T'
time.valid_min = 0.0
time.valid_max = 9999999999.0
netcdf_file_obj.renameDimension('time', 'TIME')
netcdf_file_obj.renameVariable('time', 'TIME')
netcdf_file_obj.time_coverage_start = num2date(time[:], time.units, time.calendar).min().strftime('%Y-%m-%dT%H:%M:%SZ')
netcdf_file_obj.time_coverage_end = num2date(time[:], time.units, time.calendar).max().strftime('%Y-%m-%dT%H:%M:%SZ')
# latitude longitude
latitude = netcdf_file_obj.variables['LATITUDE']
latitude.axis = 'Y'
latitude.valid_min = -90.0
latitude.valid_max = 90.0
latitude.reference_datum = 'geographical coordinates, WGS84 projection'
latitude.standard_name = 'latitude'
latitude.long_name = 'latitude'
longitude = netcdf_file_obj.variables['LONGITUDE']
longitude.axis = 'X'
longitude.valid_min = -180.0
longitude.valid_max = 180.0
longitude.reference_datum = 'geographical coordinates, WGS84 projection'
longitude.standard_name = 'longitude'
longitude.long_name = 'longitude'
# handle masked arrays
lon_array = longitude[:]
lat_array = latitude[:]
if type(lon_array) != numpy.ma.core.MaskedArray or len(lon_array) == 1:
netcdf_file_obj.geospatial_lon_min = min(lon_array)
netcdf_file_obj.geospatial_lon_max = max(lon_array)
else:
netcdf_file_obj.geospatial_lon_min = numpy.ma.MaskedArray.min(lon_array)
netcdf_file_obj.geospatial_lon_max = numpy.ma.MaskedArray.max(lon_array)
if type(lat_array) != numpy.ma.core.MaskedArray or len(lat_array) == 1:
netcdf_file_obj.geospatial_lat_min = min(lat_array)
netcdf_file_obj.geospatial_lat_max = max(lat_array)
else:
numpy.ma.MaskedArray.min(lat_array)
netcdf_file_obj.geospatial_lat_min = numpy.ma.MaskedArray.min(lat_array)
netcdf_file_obj.geospatial_lat_max = numpy.ma.MaskedArray.max(lat_array)
# Change variable name, standard name, longname, untis ....
if 'Seawater_Intake_Temperature' in netcdf_file_obj.variables.keys():
var = netcdf_file_obj.variables['Seawater_Intake_Temperature']
var.units = 'Celsius'
netcdf_file_obj.renameVariable('Seawater_Intake_Temperature', 'TEMP')
netcdf_file_obj.renameVariable('Seawater_Intake_Temperature_quality_control', 'TEMP_quality_control')
var.ancillary_variables = 'TEMP_quality_control'
#.........这里部分代码省略.........
示例4: Dataset
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import author [as 别名]
field[field<0.0]=np.nan
SSTmatrix[tindex]=field
tindex+=1
SSTmatrix2=np.ma.masked_where(np.isnan(SSTmatrix ),SSTmatrix)
SSTavg2=np.mean(SSTmatrix2,axis=0)
nlat,nlon=SSTavg2.shape
if dowrite==1:
print 'Write into new NetCDF file'
rootgrp = Dataset(outputdir+outputfile,'w', format='NETCDF4')
#print rootgrp.file_format
rootgrp.author = 'ctroupin'
rootgrp.institute = 'SOCIB'
# Create dimensions
lat = rootgrp.createDimension('lat', nlat)
lon = rootgrp.createDimension('lon', nlon)
# Create variables
latitudes = rootgrp.createVariable('latitude','f4',('lat','lon'))
longitudes = rootgrp.createVariable('longitude','f4',('lat','lon'))
SST = rootgrp.createVariable('SST','f4',('lat','lon',))
# Put attributes
latitudes.units = 'degrees north'
longitudes.units = 'degrees east'
SST.units = 'degrees celsius'
示例5: write_netcdf
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import author [as 别名]
def write_netcdf(xargs, meta, dates, xvar):
''' Write a netCDF file '''
# unpack args
outFil = xargs[0]
var = xargs[1]
rcp = xargs[2]
pattern = xargs[3]
residual = xargs[4]
quant = xargs[5]
set = str(xargs[6])
if len(dates[0]) == 7:
units = { 'tas': 'K', 'tasmin': 'K','tasmax': 'K', 'pr': 'mm'}
long_name = { 'tas': 'daily avg. temperature', 'tasmin': 'daily minimum temperature',
'tasmax': 'daily maximum temperature', 'pr': 'daily precipitation total'}
elif len(dates[0]) == 6:
units = { 'tas': 'K', 'tasmin': 'K','tasmax': 'K', 'pr': 'mm/d'}
long_name = { 'tas': 'monthly avg. temperature', 'tasmin': 'monthly avg. daily minimum temperature',
'tasmax': 'monthly avg. daily maximum temperature', 'pr': 'monthly avg. daily precip. rate'}
rootgrp = Dataset(outFil, 'w')
# some global attributes
rootgrp.history = 'Created '+strftime("%Y-%m-%d %H:%M:%S")
rootgrp.author = 'Processed by DJ Rasmussen for Rhodium Group, LLC; email: '\
'[email protected]'
rootgrp.address = 'Rhodium Group, LLC; 312 Clay St.; Oakland, Calif. 94607'
rootgrp.copyright = 'Commercial use of this data with out the written consent of' \
' Rhodium Group, LLC is prohibited; (c) Rhodium Group, LLC, 2014'
rootgrp.experiment = rcp
rootgrp.pattern = pattern
rootgrp.residual = residual
if len(dates[0]) == 7:
rootgrp.frequency = 'daily'
rootgrp.reference = 'Daily data from monthly using method from Wood et al. (2002) ' \
'(section 2.3.2) from JGR-atmospheres'
elif len(dates[0]) == 6:
rootgrp.frequency = 'monthly'
rootgrp.quantile = str(quant)
rootgrp.set = set.zfill(3)
rootgrp.contents = 'Anomalies at GHCN station level'
# time dimension (UNLIMITED)
rootgrp.createDimension('time', None)
time = rootgrp.createVariable('time', np.dtype('int32'), dimensions=['time'], fill_value=-999)
time.calendar = 'noleap'
if len(dates[0]) == 7:
time.units = 'yyyyddd'
elif len(dates[0]) == 6:
time.units = 'yyyymm'
time[:] = dates
del dates, time
# county dimension
nstn = xvar.shape[1]
rootgrp.createDimension('station', nstn)
# lat
lat = rootgrp.createVariable('lat', np.dtype('float32'), dimensions=['station'], fill_value=-999.99)
lat.units = 'degrees_north'
lat.long_name = 'latitude of station'
lat[:] = np.array(meta[1][:], dtype='float')
del lat
# lon
lon = rootgrp.createVariable('lon', np.dtype('float32'), dimensions=['station'], fill_value=-999.99)
lon.units = 'degrees_east'
lon.long_name = ' longitude of station'
lon[:] = np.array(meta[2][:], dtype='float')
del lon
# code
code = rootgrp.createVariable('code', np.dtype('|S'), dimensions=['station'])
code.long_name = ' station code'
code[:] = np.array(meta[0][:], dtype='|S')
del code
# state
state = rootgrp.createVariable('state', np.dtype('|S'), dimensions=['station'])
state.long_name = ' station state'
state[:] = np.array(meta[3][:], dtype='|S')
del state
# name
name = rootgrp.createVariable('name', np.dtype('|S'), dimensions=['station'])
name.long_name = ' station name'
name[:] = np.array(meta[4][:], dtype='|S')
del name
xout = rootgrp.createVariable(var, np.dtype('float32'), dimensions=['time','station'], fill_value=-999.99)
xout.actual_range = [np.min(xvar), np.max(xvar)]
xout.domain_avg = np.mean(xvar)
try:
xout.long_name = long_name[var]
xout.units = units[var]
#.........这里部分代码省略.........