本文整理汇总了Python中netCDF4.Dataset.description方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.description方法的具体用法?Python Dataset.description怎么用?Python Dataset.description使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类netCDF4.Dataset
的用法示例。
在下文中一共展示了Dataset.description方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: netcdfSIC
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import description [as 别名]
def netcdfSIC(lats,lons,var):
directory = '/home/zlabe/Surtsey/seaice_obs/sic/'
name = 'nsidc_regrid_sic_19932015.nc'
filename = directory + name
ncfile = Dataset(filename,'w',format='NETCDF4')
ncfile.description = 'Sea Ice Concentrations from Nimbus-7 SMMR and' \
'DMSP SSM/I-SSMIS Passive Microwave Data,' \
'Version 1 -- files regridded with EASE25'
### Dimensions
ncfile.createDimension('years',var.shape[0])
ncfile.createDimension('months',var.shape[1])
ncfile.createDimension('lat',var.shape[2])
ncfile.createDimension('lon',var.shape[3])
### Variables
years = ncfile.createVariable('years','f4',('years'))
months = ncfile.createVariable('months','f4',('months'))
latitude = ncfile.createVariable('lat','f4',('lat','lat'))
longitude = ncfile.createVariable('lon','f4',('lon','lon'))
varns = ncfile.createVariable('sic','f4',('years','months','lat','lon'))
### Units
varns.units = 'fraction (%)'
### Data
years[:] = list(xrange(var.shape[0]))
months[:] = list(xrange(var.shape[1]))
latitude[:] = lats
longitude[:] = lons
varns[:] = var
ncfile.close()
print 'Completed: Created netCDF4 File!'
示例2: netcdfPiomas
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import description [as 别名]
def netcdfPiomas(lats,lons,var,directory):
name = 'piomas_regrid_March_19792015.nc'
filename = directory + name
ncfile = Dataset(filename,'w',format='NETCDF4')
ncfile.description = 'PIOMAS Sea ice thickness reanalysis from 1979-2015 ' \
'interpolated on a 180x180 grid (latxlon)' \
'of NSIDC EASE100'
### Dimensions
ncfile.createDimension('years',var.shape[0])
ncfile.createDimension('lat',var.shape[1])
ncfile.createDimension('lon',var.shape[2])
### Variables
years = ncfile.createVariable('years','f4',('years'))
latitude = ncfile.createVariable('lat','f4',('lat','lat'))
longitude = ncfile.createVariable('lon','f4',('lon','lon'))
varns = ncfile.createVariable('thick','f4',('years','lat','lon'))
### Metrics
varns.units = 'meters'
ncfile.title = 'PIOMAS March SIT'
ncfile.instituion = 'Dept. ESS at University of California, Irvine'
ncfile.source = 'University of Washington'
ncfile.references = '[Zhang and Rothrock, 2003]'
### Data
years[:] = list(xrange(var.shape[0]))
latitude[:] = lats
longitude[:] = lons
varns[:] = var
ncfile.close()
print 'Completed: Created netCDF4 File!'
示例3: netcdfPiomas
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import description [as 别名]
def netcdfPiomas(lats,lons,var,directory):
name = 'OceanFlux/piomas_regrid_oflux_19792004.nc'
filename = directory + name
ncfile = Dataset(filename,'w',format='NETCDF4')
ncfile.description = 'PIOMAS ocean heat flux reanalysis from 1979-2004 ' \
'interpolated on a 180x180 grid (latxlon)' \
'of NSIDC EASE100'
### Dimensions
ncfile.createDimension('years',var.shape[0])
ncfile.createDimension('months',var.shape[1])
ncfile.createDimension('lat',var.shape[2])
ncfile.createDimension('lon',var.shape[3])
### Variables
years = ncfile.createVariable('years','f4',('years'))
months = ncfile.createVariable('months','f4',('months'))
latitude = ncfile.createVariable('lat','f4',('lat','lat'))
longitude = ncfile.createVariable('lon','f4',('lon','lon'))
varns = ncfile.createVariable('oflux','f4',('years','months','lat','lon'))
### Units
varns.units = 'meters of ice per second (m/s)'
### Data
years[:] = list(xrange(var.shape[0]))
months[:] = list(xrange(var.shape[1]))
latitude[:] = lats
longitude[:] = lons
varns[:] = var
ncfile.close()
print 'Completed: Created netCDF4 File!'
示例4: netcdfSIT
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import description [as 别名]
def netcdfSIT(lats,lons,var):
directory = '/home/zlabe/Surtsey/seaice_obs/Thk/March/'
name = 'icesatG_regrid_March_20032008.nc'
filename = directory + name
ncfile = Dataset(filename,'w',format='NETCDF4')
ncfile.description = 'Sea ice thickness processed by NASA-G and now' \
'regridded on an EASE2.0 100 km grid for the' \
'period of March 2003-2008'
### Dimensions
ncfile.createDimension('years',var.shape[0])
ncfile.createDimension('lat',var.shape[1])
ncfile.createDimension('lon',var.shape[2])
### Variables
years = ncfile.createVariable('years','f4',('years'))
latitude = ncfile.createVariable('lat','f4',('lat','lat'))
longitude = ncfile.createVariable('lon','f4',('lon','lon'))
varns = ncfile.createVariable('sit','f4',('years','lat','lon'))
### Units
varns.units = 'meters'
ncfile.title = 'ICESat-G'
ncfile.instituion = 'Dept. ESS at University of California, Irvine'
ncfile.source = 'NASA-G'
ncfile.references = 'Donghui Yi, H. Zwally'
### Data
years[:] = list(xrange(var.shape[0]))
latitude[:] = lats
longitude[:] = lons
varns[:] = var
ncfile.close()
print 'Completed: Created netCDF4 File!'
示例5: write_netcdf
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import description [as 别名]
def write_netcdf(PCTLS, lons, lats, out_file):
print 'Writing netcdf file'
DS = Dataset(out_file, 'w', format='NETCDF3_64BIT')
DS.description = '''
At each livneh gridpoint in the Western United States
(BBOX: : -125, 31, -102, 49.1) the 5th percentile of tmin
is computed. The base period used was 1951 - 2005
'''
#Define the dimensions
nlons = lons.shape[0] #number of stations
nlats = lats.shape[0]
DS.createDimension('latitude', nlats)
DS.createDimension('longitude', nlons)
#Define the variables
'''
lat = DS.createVariable('lat', 'f4', ('latitude',), fill_value=-9999)
lon = DS.createVariable('lon', 'f4', ('longitude',), fill_value=-9999)
pctl = DS.createVariable('percentile', 'i4', ('latitude', 'longitude'), fill_value=-9999)
pctl.units = 'Deg Celsius'
'''
lat = DS.createVariable('lat', 'f4', ('latitude',))
lon = DS.createVariable('lon', 'f4', ('longitude',))
pctl = DS.createVariable('percentile', 'i4', ('latitude', 'longitude'))
pctl.units = 'Deg Celsius'
#Populate variable
lat[:] = lats
lon[:] = lons
pctl[:,:] = PCTLS
DS.close()
示例6: max
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import description [as 别名]
def max(time_0,x,y,n,set_point):# n is the periods in a day.
nc=Dataset('/Users/Bora/Desktop/REU/Bond/DDCode/03.nc','r')
for i in nc.variables:
print ([i,nc.variables[i].units,nc.variables[i].shape])
long = np.array(nc.variables['longitude'][:],dtype=np.float32) #Defining the variables in the netcdf file and assigning them
lats = np.array(nc.variables ['latitude'][:],dtype=np.float32)
time = np.array(nc.variables ['time'][:],dtype=np.float32)
x_new=((x%time_0)*(n*365)) #Finding the number of years from the base data (which is from 1996-2015)
y_new=((y%time_0)*(n*365))
number_of_years=y-x
time_period=time[x_new:y_new] # Creating an array with the time period specified
temperature = np.array(nc.variables['temp'][x_new:y_new][:][:],dtype=np.float32)
temperature_new= np.empty((len(time_period)/n, len(lats),len(long)), dtype=np.float32)
for i in range(len(temperature_new)):
temperature_new[i]= np.max(temperature[(i*n):((i+1)*n)],axis=0)
temperature_max=np.empty((365,len(lats),len(long)), dtype=np.float32)
for i in range(365):
for j in range(number_of_years):
temperature_max[i]= temperature_new[i+365*j]+temperature_max[i]
temperature_max=temperature_max/number_of_years
temperature_max = np.subtract(temperature_max,(273.16+set_point))
time_for_max=np.arange(1,366,1)
nc.close()
data4max= Dataset('/Users/Bora/Desktop/REU/Bond/DDCode/max_'+str(set_point)+'.nc', 'w', format='NETCDF4')
data4max.close()
data4max= Dataset('/Users/Bora/Desktop/REU/Bond/DDCode/max_'+str(set_point)+'.nc', 'a')
time= data4max.createDimension('time', None)
lat= data4max.createDimension('lat', 241)
lon= data4max.createDimension('lon', 480)
times= data4max.createVariable('time','f4',('time',))
latitudes= data4max.createVariable('latitude','f4',('lat',))
longitudes=data4max.createVariable('longitude','f4',('lon',))
temp= data4max.createVariable('temp','f4',('time','lat','lon',))
import time
data4max.description = 'Max Temperature values from 1996-2016 excluding February 29th'
data4max.source= 'netCDF4 python'
data4max.history= 'Created' +time.ctime(time.time())
latitudes.units= 'degrees north'
longitudes.units= 'degrees east'
temp.units = 'K'
times.units = 'days in a gregorian calendar'
latitudes[:]= lats
longitudes[:]=long
times[:]= time_for_max
temp[:]= temperature_max
data4max.close()
new_data= Dataset('/Users/Bora/Desktop/REU/Bond/DDCode/max_'+str(set_point)+'.nc', 'r')
for i in new_data.variables:
print([i,new_data.variables[i].units,new_data.variables[i].shape])
new_data.close()
示例7: fix_netcdf
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import description [as 别名]
def fix_netcdf(infile,outfile):
"""
Write a new netcdf but this time do the coordinate vars correctly
"""
rootgrp = Dataset(outfile,'w', format='NETCDF3_64BIT')
data, targetAttrs = read_netcdf(infile,vars=('Prec','Wind','Tmax','Tmin','time','nav_lat','nav_lon'))
res = 0.5
# set dimensions
lon = rootgrp.createDimension('lon',data['Prec'].shape[2])
lat = rootgrp.createDimension('lat',data['Prec'].shape[1])
time = rootgrp.createDimension('time',data['Prec'].shape[0])
# do vars
times = rootgrp.createVariable('time','f8',('time',))
times[:] = np.arange(data['Prec'].shape[0])*86400
times.units = targetAttrs['time']['units']
times.long_name = targetAttrs['time']['long_name']
lat = rootgrp.createVariable('lat','f8',('lat',))
lat[:] = np.arange(data['nav_lat'].min(),data['nav_lat'].max()+res,res)
lat.units = 'degrees_north'
lat.long_name = 'Latitude'
lon = rootgrp.createVariable('lon','f8',('lon',))
lon[:] = np.arange(data['nav_lon'].min(),data['nav_lon'].max()+res,res)
lon.units = 'degrees_east'
lon.long_name = 'Longitude'
Precip = rootgrp.createVariable('Precip','f8',('time','lat','lon',),fill_value=data['Prec'].fill_value)
Precip[:,:,:] = data['Prec']
Precip.units = targetAttrs['Prec']['units']
Precip.long_name = targetAttrs['Prec']['long_name']
Tmax = rootgrp.createVariable('Tmax','f8',('time','lat','lon',),fill_value=data['Tmax'].fill_value)
Tmax[:,:,:] = data['Tmax']
Tmax.units = targetAttrs['Tmax']['units']
Tmax.long_name = targetAttrs['Tmax']['long_name']
Tmin = rootgrp.createVariable('Tmin','f8',('time','lat','lon',),fill_value=data['Tmin'].fill_value)
Tmin[:,:,:] = data['Tmin']
Tmin.units = targetAttrs['Tmin']['units']
Tmin.long_name = targetAttrs['Tmin']['long_name']
Wind = rootgrp.createVariable('Wind','f8',('time','lat','lon',),fill_value=data['Wind'].fill_value)
Wind[:,:,:] = data['Wind']
Wind.units = targetAttrs['Wind']['units']
Wind.long_name = targetAttrs['Wind']['long_name']
rootgrp.description = 'Global 1/2 Degree Gridded Meteorological VIC Forcing Data Set '
rootgrp.history = 'Created: {}\n'.format(tm.ctime(tm.time()))
rootgrp.source = sys.argv[0] # prints the name of script used
rootgrp.institution = "University of Washington Dept. of Civil and Environmental Engineering"
rootgrp.sources = "UDel (Willmott and Matsuura 2007), CRU (Mitchell et al., 2004), NCEP/NCAR (Kalnay et al. 1996)"
rootgrp.projection = "Geographic"
rootgrp.surfSng_convention = "Traditional"
rootgrp.close()
示例8: convert_file
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import description [as 别名]
def convert_file(directory, filename, verbose):
""" Convert a DICOM file to netCDF.
Args:
directory: the directory where the file is.
filename: name of DICOM file to convert.
verbose: true to get printf statements.
Returns:
The name of the netCDF file.
"""
verbose = 1
if (verbose):
print('convert_file is converting file ' + filename);
ds = dicom.read_file(directory + '/' + filename, force=True)
netcdf_filename = filename + '.nc'
#pdb.set_trace()
rootgrp = Dataset(netcdf_filename, "w", format="NETCDF4")
rootgrp.description = "bogus example script"
for tag_name in ds.dir():
de = ds.data_element(tag_name)
VR_exists = True
print('data element ' + tag_name)
try:
de.VR
except AttributeError:
VR_exists = False
else:
VR_exists = True
if tag_name != 'PixelData':
if VR_exists:
print('data element ' + tag_name + ' ' + de.VR)
if de.VR != 'SQ':
setattr(rootgrp, tag_name, de.value)
else:
print('copying data')
if (verbose):
print('creating dimension row with len ' + str(ds.Rows))
rowdim = rootgrp.createDimension("row", ds.Rows)
if (verbose):
print('creating dimension col with len ' + str(ds.Columns))
coldim = rootgrp.createDimension("column", ds.Columns)
pixel_data = rootgrp.createVariable("pixel_data","i4",("row","column"))
pixel_data[:] = ds.pixel_array
#dataset.walk(PN_callback)
rootgrp.close()
return 'test.nc'
示例9: prep
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import description [as 别名]
def prep(infile,outfile):
"""
Function to preprocess FFDAS netCDF files
Converts from 24 hourly variables to one
flux variable varying in t dimension
"""
# read in input netCDF file
datain = Dataset(infile,'r')
# open output netCDF file
dataout = Dataset(outfile, "w", format="NETCDF4")
# get dimensions from input file
lat1 = datain.variables['latitude'][:]
lon1 = datain.variables['longitude'][:]
# get data from input file
flux = np.zeros((24,len(lat1),len(lon1)))
# read in each strange hourly variable and concatenate to one array
for i in range(1,25):
exec("tmpflux = datain.variables['flux_h%02d'][:]" % i)
flux[i-1,:,:] = tmpflux
# set up output file
timeout = dataout.createDimension("time", None)
lat2 = dataout.createDimension("latitude", len(lat1))
lon2 = dataout.createDimension("longitude", len(lon1))
times = dataout.createVariable("hour", "i2", ("time",))
latitudes = dataout.createVariable("latitude","f4",("latitude",))
longitudes = dataout.createVariable("longitude","f4",("longitude",))
outflux = dataout.createVariable("flux","f8",("time","latitude","longitude" ,))
timearr = np.arange(1,25,1)
# add some metadata
dataout.description = "Converted Hourly FFDAS flux netCDF file"
dataout.history = "Created " + time.ctime(time.time())
dataout.source = "convert_ffdas_hrly.py - C. Martin - Univ. of MD - 2/2016"
latitudes.units = "degrees north"
longitudes.units = "degrees east"
outflux.units = "kgC/cell/h"
times.units = "hour of day"
# write to file
latitudes[:] = lat1
longitudes[:] = lon1
times[:] = timearr
outflux[:] = flux
# close files
datain.close()
dataout.close()
示例10: writeCMIP5File
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import description [as 别名]
def writeCMIP5File(modelName,scenario,myvarname,lon,lat,time,mydata,mydataanomaly,outfilename):
myformat='NETCDF3_CLASSIC'
if os.path.exists(outfilename):
os.remove(outfilename)
print "Results written to netcdf file: %s"%(outfilename)
if myvarname=="sic": myvar="SIC"
f1 = Dataset(outfilename, mode='w', format=myformat)
f1.title = "IPCC AR5 %s"%(myvar)
f1.description = "IPCC AR5 running averages of %s for model %s for scenario %s"%(myvar,modelName,scenario)
f1.history = "Created " + str(datetime.now())
f1.source = "Trond Kristiansen ([email protected])"
f1.type = "File in NetCDF3 format created using iceExtract.py"
f1.Conventions = "CF-1.0"
"""Define dimensions"""
f1.createDimension('x', len(lon))
f1.createDimension('y', len(lat))
f1.createDimension('time', None)
vnc = f1.createVariable('longitude', 'd', ('x',),zlib=False)
vnc.long_name = 'Longitude'
vnc.units = 'degree_east'
vnc.standard_name = 'longitude'
vnc[:] = lon
vnc = f1.createVariable('latitude', 'd', ('y',),zlib=False)
vnc.long_name = 'Latitude'
vnc.units = 'degree_north'
vnc.standard_name = 'latitude'
vnc[:] = lat
v_time = f1.createVariable('time', 'd', ('time',),zlib=False)
v_time.long_name = 'Years'
v_time.units = 'Years'
v_time.field = 'time, scalar, series'
v_time[:]=time
v_temp=f1.createVariable('SIC', 'd', ('time', 'y', 'x',),zlib=False)
v_temp.long_name = "Sea-ice area fraction (%)"
v_temp.units = "%"
v_temp.time = "time"
v_temp.field="SIC, scalar, series"
v_temp.missing_value = 1e20
if myvarname=='sic':
f1.variables['SIC'][:,:,:] = mydata
f1.close()
示例11: write_orb
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import description [as 别名]
def write_orb(self, **kwargs):
'''Write swath location in Satellite grid file sgridfile.\n
Dimensions are x_al (along track distance), x_ac (across
track distance) and cycle (1). \n
Variables are longitude, latitude, number of days in a cycle,
distance crossed in a cycle, time, along track and across track
distances are stored.'''
## - Open Netcdf file in write mode
if netcdf4:
fid = Dataset(self.file, 'w', format='NETCDF4_CLASSIC')
else:
fid = Dataset(self.file, 'w' )
fid.description = "Orbit computed from SWOT simulator"
## - Create dimensions
#if (not os.path.isfile(self.file)):
fid.createDimension('time', numpy.shape(self.lon)[0])
fid.createDimension('cycle', 1)
## - Create and write Variables
vtime = fid.createVariable('time', 'f', ('time',))
vlon = fid.createVariable('lon', 'f4', ('time',))
vlat = fid.createVariable('lat', 'f4', ('time',))
vcycle = fid.createVariable('cycle', 'f4', ('cycle',))
valcycle = fid.createVariable('al_cycle', 'f4', ('cycle',))
vtimeshift = fid.createVariable('timeshift', 'f4', ('cycle',))
vx_al = fid.createVariable('x_al', 'f4', ('time',))
vtime[:]=self.time
vtime.units="days"
vlon[:]=self.lon
vlon.units="deg"
vlat[:]=self.lat
vlat.units="deg"
vcycle[:]=self.cycle
vcycle.units="days"
vcycle.long_name="Number of days during a cycle"
valcycle[:]=self.al_cycle
valcycle.units="km"
valcycle.long_name=" Distance travelled during the pass"
vtimeshift[:]=self.timeshift
vtimeshift.units="km"
vtimeshift.long_name="Shift time to match model time"
vx_al[:]=self.x_al
vx_al.units="km"
vx_al.long_name="Along track distance from the beginning of the pass"
fid.close()
return None
示例12: write_netcdf
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import description [as 别名]
def write_netcdf(INDICES, var_name, model, rcp, year, lons, lats, doys, out_dir):
print 'Writing netcdf file'
out_file = out_dir + var_name + '_' + rcp + '_5th_Indices_WUSA_' + str(year) + '.nc'
DS = Dataset(out_file, 'w', format='NETCDF3_64BIT')
DS.description = '''
At each livneh gridpoint in the Western United States
(BBOX: : -125, 31, -102, 49.1) for each DOY in Winter season(DJF),
the number degrees below the 5th percentile at that point are recorded
'''
#Define the dimensions
nlons = lons.shape[0]
nlats = lats.shape[0]
ndays = doys.shape[0]
DS.createDimension('latitude', nlats)
DS.createDimension('longitude', nlons)
DS.createDimension('day_in_season', ndays)
#Define the variables
'''
lat = DS.createVariable('lat', 'f4', ('latitude',), fill_value=1e20)
lon = DS.createVariable('lon', 'f4', ('longitude',), fill_value=1e20)
# FIX ME: save doys as ints
# OverflowError: Python int too large to convert to C long
doy = DS.createVariable('doy', 'f4', ('day_in_season',), fill_value=1e20)
ind = DS.createVariable('index', 'i4', ('day_in_season', 'latitude', 'longitude'), fill_value=1e20)
ind.units = 'DegC below 5th precentile'
'''
lat = DS.createVariable('lat', 'f4', ('latitude',))
lon = DS.createVariable('lon', 'f4', ('longitude',))
# FIX ME: save doys as ints
# OverflowError: Python int too large to convert to C long
doy = DS.createVariable('doy', 'f4', ('day_in_season',))
ind = DS.createVariable('index', 'i4', ('day_in_season', 'latitude', 'longitude'))
ind.units = 'DegC below 5th precentile'
#Populate variable
lat[:] = lats
lon[:] = lons
doy[:] = doys
ind[:,:,:] = INDICES
DS.close()
示例13: CreateNCDF
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import description [as 别名]
def CreateNCDF(fname, xcoords, ycoords, tcoords):
"""create a netcdf data file given x,y,t coordinates"""
rootgrp = Dataset(fname, 'w', format=NETCDF_FORMAT)
rootgrp.description = 'Urban Phenology Data'
x = rootgrp.createDimension('x', len(xcoords))
xcoord = rootgrp.createVariable('xcoord','i4',('x',))
xcoord[:] = xcoords
xcoord.units = 'meters east utm'
y = rootgrp.createDimension('y', len(ycoords))
ycoord = rootgrp.createVariable('ycoord','i4',('y',))
ycoord[:] = ycoords
ycoord.units = 'meters north utm'
t = rootgrp.createDimension('t', None)
times = rootgrp.createVariable('tcoord','i4',('t',))
times[:] = tcoords
times.units = '[YYYY][DayOfYear]'
print rootgrp
return rootgrp
示例14: netcdfSIT
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import description [as 别名]
def netcdfSIT(lats,lons,var,varmean):
directory = '/home/zlabe/Surtsey/seaice_obs/Thk/March/'
name = 'sub_regrid_March_19861994.nc'
filename = directory + name
ncfile = Dataset(filename,'w',format='NETCDF4')
ncfile.description = 'Sea ice thickness processed by submarine' \
'data although record is spotty throughout' \
'1986-1994 reference period. Mean thickness' \
'over the period is also included.'
### Dimensions
ncfile.createDimension('years',var.shape[0])
ncfile.createDimension('lat',var.shape[1])
ncfile.createDimension('lon',var.shape[2])
### Variables
years = ncfile.createVariable('years','f4',('years'))
latitude = ncfile.createVariable('lat','f4',('lat','lat'))
longitude = ncfile.createVariable('lon','f4',('lon','lon'))
varns = ncfile.createVariable('sit','f4',('years','lat','lon'))
varnsmean = ncfile.createVariable('meansit','f4',('lat','lon'))
### Units
varns.units = 'meters'
varnsmean.units = 'meters'
ncfile.title = 'Submarine Data'
ncfile.instituion = 'Dept. ESS at University of California, Irvine'
ncfile.source = 'NSIDC, J. Maslanik & A.P. Barrett'
ncfile.created_by = 'Zachary Labe ([email protected])'
# ncfile.references = ''
### Data
years[:] = list(xrange(var.shape[0]))
latitude[:] = lats
longitude[:] = lons
varns[:] = var
varnsmean[:] = varmean
ncfile.close()
print 'Completed: Created netCDF4 File!'
示例15: write_ll_file
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import description [as 别名]
def write_ll_file(netfile, outfile):
ds = Dataset(netfile, 'r')
lons = ds.variables['lon'][:]
lats = ds.variables['lat'][:]
print 'Writing netcdf file'
DS = Dataset(outfile, 'w', format='NETCDF3_64BIT')
DS.description = '''LOCA latitudes and longitudes'''
#Define the dimensions
nlons = lons.shape[0]
nlats = lats.shape[0]
DS.createDimension('latitude', nlats)
DS.createDimension('longitude', nlons)
#Define the variables
lat = DS.createVariable('lat', 'f4', ('latitude',), fill_value=1e20)
lon = DS.createVariable('lon', 'f4', ('longitude',), fill_value=1e20)
#Populate variable
lat[:] = lats
lon[:] = lons
DS.close()