From e08438b72ce18cae21e70f24c2416f04ee516f43 Mon Sep 17 00:00:00 2001
From: Jeff Whitaker
@@ -475,7 +474,7 @@
Introduction
and should be familiar to users of that module.
Most new features of netCDF 4 are implemented, such as multiple -unlimited dimensions, groups and data compression. All the new +unlimited dimensions, groups and zlib data compression. All the new numeric data types (such as 64 bit and unsigned integer types) are implemented. Compound (struct), variable length (vlen) and enumerated (enum) data types are supported, but not the opaque data type. @@ -577,7 +576,7 @@
Here's an example:
->>> from netCDF4 import Dataset
+>>> from netCDF4 import Dataset
>>> rootgrp = Dataset("test.nc", "w", format="NETCDF4")
>>> print(rootgrp.data_model)
NETCDF4
@@ -606,7 +605,7 @@ Groups in a netCDF file
NETCDF4
formatted files support Groups, if you try to create a Group
in a netCDF 3 file you will get an error message.
->>> rootgrp = Dataset("test.nc", "a")
+>>> rootgrp = Dataset("test.nc", "a")
>>> fcstgrp = rootgrp.createGroup("forecasts")
>>> analgrp = rootgrp.createGroup("analyses")
>>> print(rootgrp.groups)
@@ -630,7 +629,7 @@ Groups in a netCDF file
that group. To simplify the creation of nested groups, you can
use a unix-like path as an argument to Dataset.createGroup
.
->>> fcstgrp1 = rootgrp.createGroup("/forecasts/model1")
+>>> fcstgrp1 = rootgrp.createGroup("/forecasts/model1")
>>> fcstgrp2 = rootgrp.createGroup("/forecasts/model2")
@@ -644,7 +643,7 @@ Groups in a netCDF file
to walk the directory tree. Note that printing the Dataset
or Group
object yields summary information about it's contents.
->>> def walktree(top):
+>>> def walktree(top):
... yield top.groups.values()
... for value in top.groups.values():
... yield from walktree(value)
@@ -694,7 +693,7 @@ Dimensions in a netCDF file
dimension is a new netCDF 4 feature, in netCDF 3 files there may be only
one, and it must be the first (leftmost) dimension of the variable.
->>> level = rootgrp.createDimension("level", None)
+>>> level = rootgrp.createDimension("level", None)
>>> time = rootgrp.createDimension("time", None)
>>> lat = rootgrp.createDimension("lat", 73)
>>> lon = rootgrp.createDimension("lon", 144)
@@ -702,7 +701,7 @@ Dimensions in a netCDF file
All of the Dimension
instances are stored in a python dictionary.
->>> print(rootgrp.dimensions)
+>>> print(rootgrp.dimensions)
{'level': <class 'netCDF4._netCDF4.Dimension'> (unlimited): name = 'level', size = 0, 'time': <class 'netCDF4._netCDF4.Dimension'> (unlimited): name = 'time', size = 0, 'lat': <class 'netCDF4._netCDF4.Dimension'>: name = 'lat', size = 73, 'lon': <class 'netCDF4._netCDF4.Dimension'>: name = 'lon', size = 144}
@@ -711,7 +710,7 @@ Dimensions in a netCDF file
Dimension.isunlimited
method of a Dimension
instance
be used to determine if the dimensions is unlimited, or appendable.
->>> print(len(lon))
+>>> print(len(lon))
144
>>> print(lon.isunlimited())
False
@@ -723,7 +722,7 @@ Dimensions in a netCDF file
provides useful summary info, including the name and length of the dimension,
and whether it is unlimited.
->>> for dimobj in rootgrp.dimensions.values():
+>>> for dimobj in rootgrp.dimensions.values():
... print(dimobj)
<class 'netCDF4._netCDF4.Dimension'> (unlimited): name = 'level', size = 0
<class 'netCDF4._netCDF4.Dimension'> (unlimited): name = 'time', size = 0
@@ -768,7 +767,7 @@ Variables in a netCDF file
method returns an instance of the Variable
class whose methods can be
used later to access and set variable data and attributes.
->>> times = rootgrp.createVariable("time","f8",("time",))
+>>> times = rootgrp.createVariable("time","f8",("time",))
>>> levels = rootgrp.createVariable("level","i4",("level",))
>>> latitudes = rootgrp.createVariable("lat","f4",("lat",))
>>> longitudes = rootgrp.createVariable("lon","f4",("lon",))
@@ -780,7 +779,7 @@ Variables in a netCDF file
To get summary info on a Variable
instance in an interactive session,
just print it.
->>> print(temp)
+>>> print(temp)
<class 'netCDF4._netCDF4.Variable'>
float32 temp(time, level, lat, lon)
units: K
@@ -791,7 +790,7 @@ Variables in a netCDF file
You can use a path to create a Variable inside a hierarchy of groups.
->>> ftemp = rootgrp.createVariable("/forecasts/model1/temp","f4",("time","level","lat","lon",))
+>>> ftemp = rootgrp.createVariable("/forecasts/model1/temp","f4",("time","level","lat","lon",))
If the intermediate groups do not yet exist, they will be created.
@@ -799,7 +798,7 @@ Variables in a netCDF file
You can also query a Dataset
or Group
instance directly to obtain Group
or
Variable
instances using paths.
->>> print(rootgrp["/forecasts/model1"]) # a Group instance
+>>> print(rootgrp["/forecasts/model1"]) # a Group instance
<class 'netCDF4._netCDF4.Group'>
group /forecasts/model1:
dimensions(sizes):
@@ -817,7 +816,7 @@ Variables in a netCDF file
All of the variables in the Dataset
or Group
are stored in a
Python dictionary, in the same way as the dimensions:
->>> print(rootgrp.variables)
+>>> print(rootgrp.variables)
{'time': <class 'netCDF4._netCDF4.Variable'>
float64 time(time)
unlimited dimensions: time
@@ -860,7 +859,7 @@ Attributes in a netCDF file
variables. Attributes can be strings, numbers or sequences. Returning to
our example,
->>> import time
+>>> import time
>>> rootgrp.description = "bogus example script"
>>> rootgrp.history = "Created " + time.ctime(time.time())
>>> rootgrp.source = "netCDF4 python module tutorial"
@@ -878,7 +877,7 @@ Attributes in a netCDF file
built-in dir
Python function will return a bunch of private methods
and attributes that cannot (or should not) be modified by the user.
->>> for name in rootgrp.ncattrs():
+>>> for name in rootgrp.ncattrs():
... print("Global attr {} = {}".format(name, getattr(rootgrp, name)))
Global attr description = bogus example script
Global attr history = Created Mon Jul 8 14:19:41 2019
@@ -889,7 +888,7 @@ Attributes in a netCDF file
instance provides all the netCDF attribute name/value pairs in a python
dictionary:
->>> print(rootgrp.__dict__)
+>>> print(rootgrp.__dict__)
{'description': 'bogus example script', 'history': 'Created Mon Jul 8 14:19:41 2019', 'source': 'netCDF4 python module tutorial'}
@@ -902,7 +901,7 @@ Writing data
Now that you have a netCDF Variable
instance, how do you put data
into it? You can just treat it like an array and assign data to a slice.
->>> import numpy as np
+>>> import numpy as np
>>> lats = np.arange(-90,91,2.5)
>>> lons = np.arange(-180,180,2.5)
>>> latitudes[:] = lats
@@ -922,7 +921,7 @@ Writing data
objects with unlimited dimensions will grow along those dimensions if you
assign data outside the currently defined range of indices.
->>> # append along two unlimited dimensions by assigning to slice.
+>>> # append along two unlimited dimensions by assigning to slice.
>>> nlats = len(rootgrp.dimensions["lat"])
>>> nlons = len(rootgrp.dimensions["lon"])
>>> print("temp shape before adding data = {}".format(temp.shape))
@@ -942,7 +941,7 @@ Writing data
along the level
dimension of the variable temp
, even though no
data has yet been assigned to levels.
->>> # now, assign data to levels dimension variable.
+>>> # now, assign data to levels dimension variable.
>>> levels[:] = [1000.,850.,700.,500.,300.,250.,200.,150.,100.,50.]
@@ -955,7 +954,7 @@ Writing data
allowed, and these indices work independently along each dimension (similar
to the way vector subscripts work in fortran). This means that
->>> temp[0, 0, [0,1,2,3], [0,1,2,3]].shape
+>>> temp[0, 0, [0,1,2,3], [0,1,2,3]].shape
(4, 4)
@@ -973,14 +972,14 @@ Writing data
For example,
->>> tempdat = temp[::2, [1,3,6], lats>0, lons>0]
+>>> tempdat = temp[::2, [1,3,6], lats>0, lons>0]
will extract time indices 0,2 and 4, pressure levels
850, 500 and 200 hPa, all Northern Hemisphere latitudes and Eastern
Hemisphere longitudes, resulting in a numpy array of shape (3, 3, 36, 71).
->>> print("shape of fancy temp slice = {}".format(tempdat.shape))
+>>> print("shape of fancy temp slice = {}".format(tempdat.shape))
shape of fancy temp slice = (3, 3, 36, 71)
@@ -1013,7 +1012,7 @@ Dealing with time coordinates
provided by cftime to do just that.
Here's an example of how they can be used:
->>> # fill in times.
+>>> # fill in times.
>>> from datetime import datetime, timedelta
>>> from cftime import num2date, date2num
>>> dates = [datetime(2001,3,1)+n*timedelta(hours=12) for n in range(temp.shape[0])]
@@ -1053,7 +1052,7 @@ Reading data from a multi
NETCDF4_CLASSIC
format (NETCDF4
formatted multi-file
datasets are not supported).
->>> for nf in range(10):
+>>> for nf in range(10):
... with Dataset("mftest%s.nc" % nf, "w", format="NETCDF4_CLASSIC") as f:
... _ = f.createDimension("x",None)
... x = f.createVariable("x","i",("x",))
@@ -1062,7 +1061,7 @@ Reading data from a multi
Now read all the files back in at once with MFDataset
->>> from netCDF4 import MFDataset
+>>> from netCDF4 import MFDataset
>>> f = MFDataset("mftest*nc")
>>> print(f.variables["x"][:])
[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
@@ -1079,9 +1078,9 @@ Efficient compression of netC
Data stored in netCDF 4 Variable
objects can be compressed and
decompressed on the fly. The parameters for the compression are
-determined by the compression
, complevel
and shuffle
keyword arguments
+determined by the zlib
, complevel
and shuffle
keyword arguments
to the Dataset.createVariable
method. To turn on
-compression, set compression=zlib
. The complevel
keyword regulates the
+compression, set zlib=True
. The complevel
keyword regulates the
speed and efficiency of the compression (1 being fastest, but lowest
compression ratio, 9 being slowest but best compression ratio). The
default value of complevel
is 4. Setting shuffle=False
will turn
@@ -1101,7 +1100,7 @@
Efficient compression of netC
If your data only has a certain number of digits of precision (say for
example, it is temperature data that was measured with a precision of
-0.1 degrees), you can dramatically improve compression by
+0.1 degrees), you can dramatically improve zlib compression by
quantizing (or truncating) the data. There are two methods supplied for
doing this. You can use the least_significant_digit
keyword argument to Dataset.createVariable
to specify
@@ -1124,22 +1123,22 @@
Efficient compression of netC
In our example, try replacing the line
->>> temp = rootgrp.createVariable("temp","f4",("time","level","lat","lon",))
+>>> temp = rootgrp.createVariable("temp","f4",("time","level","lat","lon",))
with
->>> temp = rootgrp.createVariable("temp","f4",("time","level","lat","lon",),compression='zlib')
+>>> temp = rootgrp.createVariable("temp","f4",("time","level","lat","lon",),zlib=True)
and then
->>> temp = rootgrp.createVariable("temp","f4",("time","level","lat","lon",),compression='zlib',least_significant_digit=3)
+>>> temp = rootgrp.createVariable("temp","f4",("time","level","lat","lon",),zlib=True,least_significant_digit=3)
or with netcdf-c >= 4.8.2
->>> temp = rootgrp.createVariable("temp","f4",("time","level","lat","lon",),compression='zlib',significant_digits=4)
+>>> temp = rootgrp.createVariable("temp","f4",("time","level","lat","lon",),zlib=True,significant_digits=4)
and see how much smaller the resulting files are.
@@ -1160,7 +1159,7 @@ Beyond ho
Since there is no native complex data type in netcdf, compound types are handy
for storing numpy complex arrays. Here's an example:
->>> f = Dataset("complex.nc","w")
+>>> f = Dataset("complex.nc","w")
>>> size = 3 # length of 1-d complex array
>>> # create sample complex data.
>>> datac = np.exp(1j*(1.+np.linspace(0, np.pi, size)))
@@ -1196,7 +1195,7 @@ Beyond ho
in a Python dictionary, just like variables and dimensions. As always, printing
objects gives useful summary information in an interactive session:
->>> print(f)
+>>> print(f)
<class 'netCDF4._netCDF4.Dataset'>
root group (NETCDF4 data model, file format HDF5):
dimensions(sizes): x_dim(3)
@@ -1221,7 +1220,7 @@ Variable-length (vlen) data types
data type, use the Dataset.createVLType
method
method of a Dataset
or Group
instance.
->>> f = Dataset("tst_vlen.nc","w")
+>>> f = Dataset("tst_vlen.nc","w")
>>> vlen_t = f.createVLType(np.int32, "phony_vlen")
@@ -1231,7 +1230,7 @@ Variable-length (vlen) data types
but compound data types cannot.
A new variable can then be created using this datatype.
->>> x = f.createDimension("x",3)
+>>> x = f.createDimension("x",3)
>>> y = f.createDimension("y",4)
>>> vlvar = f.createVariable("phony_vlen_var", vlen_t, ("y","x"))
@@ -1244,7 +1243,7 @@ Variable-length (vlen) data types
In this case, they contain 1-D numpy int32
arrays of random length between
1 and 10.
->>> import random
+>>> import random
>>> random.seed(54321)
>>> data = np.empty(len(y)*len(x),object)
>>> for n in range(len(y)*len(x)):
@@ -1284,7 +1283,7 @@ Variable-length (vlen) data types
with fixed length greater than 1) when calling the
Dataset.createVariable
method.
->>> z = f.createDimension("z",10)
+>>> z = f.createDimension("z",10)
>>> strvar = f.createVariable("strvar", str, "z")
@@ -1292,7 +1291,7 @@ Variable-length (vlen) data types
random lengths between 2 and 12 characters, and the data in the object
array is assigned to the vlen string variable.
->>> chars = "1234567890aabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
+>>> chars = "1234567890aabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
>>> data = np.empty(10,"O")
>>> for n in range(10):
... stringlen = random.randint(2,12)
@@ -1331,7 +1330,7 @@ Enum data type
values and their names are used to define an Enum data type using
Dataset.createEnumType
.
->>> nc = Dataset('clouds.nc','w')
+>>> nc = Dataset('clouds.nc','w')
>>> # python dict with allowed values and their names.
>>> enum_dict = {'Altocumulus': 7, 'Missing': 255,
... 'Stratus': 2, 'Clear': 0,
@@ -1349,7 +1348,7 @@ Enum data type
is made to write an integer value not associated with one of the
specified names.
->>> time = nc.createDimension('time',None)
+>>> time = nc.createDimension('time',None)
>>> # create a 1d variable of type 'cloud_type'.
>>> # The fill_value is set to the 'Missing' named value.
>>> cloud_var = nc.createVariable('primary_cloud',cloud_type,'time',
@@ -1386,7 +1385,7 @@ Parallel IO
available. To use parallel IO, your program must be running in an MPI
environment using mpi4py.
->>> from mpi4py import MPI
+>>> from mpi4py import MPI
>>> import numpy as np
>>> from netCDF4 import Dataset
>>> rank = MPI.COMM_WORLD.rank # The process ID (integer 0-3 for 4-process run)
@@ -1398,7 +1397,7 @@ Parallel IO
when a new dataset is created or an existing dataset is opened,
use the parallel
keyword to enable parallel access.
->>> nc = Dataset('parallel_test.nc','w',parallel=True)
+>>> nc = Dataset('parallel_test.nc','w',parallel=True)
The optional comm
keyword may be used to specify a particular
@@ -1406,7 +1405,7 @@
Parallel IO
can now write to the file indepedently. In this example the process rank is
written to a different variable index on each task
->>> d = nc.createDimension('dim',4)
+>>> d = nc.createDimension('dim',4)
>>> v = nc.createVariable('var', np.int64, 'dim')
>>> v[rank] = rank
>>> nc.close()
@@ -1473,7 +1472,7 @@ Dealing with strings
stringtochar
is used to convert the numpy string array to an array of
characters with one more dimension. For example,
->>> from netCDF4 import stringtochar
+>>> from netCDF4 import stringtochar
>>> nc = Dataset('stringtest.nc','w',format='NETCDF4_CLASSIC')
>>> _ = nc.createDimension('nchars',3)
>>> _ = nc.createDimension('nstrings',None)
@@ -1506,7 +1505,7 @@ Dealing with strings
character array dtype under the hood when creating the netcdf compound type.
Here's an example:
->>> nc = Dataset('compoundstring_example.nc','w')
+>>> nc = Dataset('compoundstring_example.nc','w')
>>> dtype = np.dtype([('observation', 'f4'),
... ('station_name','S10')])
>>> station_data_t = nc.createCompoundType(dtype,'station_data')
@@ -1551,7 +1550,7 @@ In-memory (diskless) Datasets
object representing the Dataset. Below are examples illustrating both
approaches.
->>> # create a diskless (in-memory) Dataset,
+>>> # create a diskless (in-memory) Dataset,
>>> # and persist the file to disk when it is closed.
>>> nc = Dataset('diskless_example.nc','w',diskless=True,persist=True)
>>> d = nc.createDimension('x',None)
@@ -1613,7 +1612,7 @@ In-memory (diskless) Datasets
the parallel IO example, which is in examples/mpi_example.py
.
Unit tests are in the test
directory.
-contact: Jeffrey Whitaker jeffrey.s.whitaker@noaa.gov
+contact: Jeffrey Whitaker jeffrey.s.whitaker@noaa.gov
copyright: 2008 by Jeffrey Whitaker.
@@ -1626,7 +1625,7 @@ In-memory (diskless) Datasets
View Source
- # init for netCDF4. package
+ # init for netCDF4. package
# Docstring comes from extension module _netCDF4.
from ._netCDF4 import *
# Need explicit imports for names beginning with underscores
@@ -1652,7 +1651,7 @@ In-memory (diskless) Datasets
Dataset:
-
+
A netCDF Dataset
is a collection of dimensions, groups, variables and
attributes. Together they describe the meaning of data and relations among
data fields stored in a netCDF file. See Dataset.__init__
for more
@@ -1730,7 +1729,7 @@
In-memory (diskless) Datasets
Dataset()
-
+
__init__(self, filename, mode="r", clobber=True, diskless=False,
persist=False, keepweakref=False, memory=None, encoding=None,
parallel=False, comm=None, info=None, format='NETCDF4')
@@ -1836,7 +1835,7 @@ In-memory (diskless) Datasets
filepath(unknown):
-
+
filepath(self,encoding=None)
Get the file system path (or the opendap URL) which was used to
@@ -1855,7 +1854,7 @@
In-memory (diskless) Datasets
close(unknown):
-
+
close(self)
Close the Dataset.
@@ -1871,7 +1870,7 @@ In-memory (diskless) Datasets
isopen(unknown):
-
+
isopen(self)
Is the Dataset open or closed?
@@ -1887,7 +1886,7 @@ In-memory (diskless) Datasets
sync(unknown):
-
+
sync(self)
Writes all buffered data in the Dataset
to the disk file.
@@ -1903,7 +1902,7 @@ In-memory (diskless) Datasets
set_fill_on(unknown):
-
+
set_fill_on(self)
Sets the fill mode for a Dataset
open for writing to on
.
@@ -1927,7 +1926,7 @@ In-memory (diskless) Datasets
set_fill_off(unknown):
-
+
set_fill_off(self)
Sets the fill mode for a Dataset
open for writing to off
.
@@ -1947,7 +1946,7 @@ In-memory (diskless) Datasets
createDimension(unknown):
-
+
createDimension(self, dimname, size=None)
Creates a new dimension with the given dimname
and size
.
@@ -1971,7 +1970,7 @@ In-memory (diskless) Datasets
renameDimension(unknown):
-
+
renameDimension(self, oldname, newname)
rename a Dimension
named oldname
to newname
.
@@ -1987,7 +1986,7 @@ In-memory (diskless) Datasets
createCompoundType(unknown):
-
+
createCompoundType(self, datatype, datatype_name)
Creates a new compound data type named datatype_name
from the numpy
@@ -2012,7 +2011,7 @@
In-memory (diskless) Datasets
createVLType(unknown):
-
+
createVLType(self, datatype, datatype_name)
Creates a new VLEN data type named datatype_name
from a numpy
@@ -2032,7 +2031,7 @@
In-memory (diskless) Datasets
createEnumType(unknown):
-
+
createEnumType(self, datatype, datatype_name, enum_dict)
Creates a new Enum data type named datatype_name
from a numpy
@@ -2053,11 +2052,10 @@
In-memory (diskless) Datasets
createVariable(unknown):
-
- createVariable(self, varname, datatype, dimensions=(), compression=None, zlib=False,
+
+ createVariable(self, varname, datatype, dimensions=(), zlib=False,
complevel=4, shuffle=True, fletcher32=False, contiguous=False, chunksizes=None,
-endian='native', least_significant_digit=None, significant_digits=None, quantize_mode='BitGroom',
-fill_value=None, chunk_cache=None)
+endian='native', least_significant_digit=None, significant_digits=None, fill_value=None, chunk_cache=None)
Creates a new variable with the given varname
, datatype
, and
dimensions
. If dimensions are not given, the variable is assumed to be
@@ -2089,17 +2087,11 @@
In-memory (diskless) Datasets
previously using Dataset.createDimension
. The default value
is an empty tuple, which means the variable is a scalar.
-If the optional keyword argument compression
is set, the data will be
-compressed in the netCDF file using the specified compression algorithm.
-Currently only 'zlib' is supported. Default is None
(no compression).
-
If the optional keyword zlib
is True
, the data will be compressed in
-the netCDF file using zlib compression (default False
). The use of this option is
-deprecated in favor of compression='zlib'
.
+the netCDF file using gzip compression (default False
).
-The optional keyword complevel
is an integer between 0 and 9 describing
-the level of compression desired (default 4). Ignored if compression=None
.
-A value of zero disables compression.
+The optional keyword complevel
is an integer between 1 and 9 describing
+the level of compression desired (default 4). Ignored if zlib=False
.
If the optional keyword shuffle
is True
, the HDF5 shuffle filter
will be applied before compressing the data (default True
). This
@@ -2133,17 +2125,17 @@
In-memory (diskless) Datasets
opposite format as the one used to create the file, there may be
some performance advantage to be gained by setting the endian-ness.
-The compression, zlib, complevel, shuffle, fletcher32, contiguous, chunksizes
and endian
+
The zlib, complevel, shuffle, fletcher32, contiguous, chunksizes
and endian
keywords are silently ignored for netCDF 3 files that do not use HDF5.
The optional keyword fill_value
can be used to override the default
netCDF _FillValue
(the value that the variable gets filled with before
-any data is written to it, defaults given in the dict netCDF4.default_fillvals
).
+any data is written to it, defaults given in the dict netCDF4.default_fillvals
).
If fill_value is set to False
, then the variable is not pre-filled.
If the optional keyword parameters least_significant_digit
or significant_digits
are
specified, variable data will be truncated (quantized). In conjunction
-with compression='zlib'
this produces 'lossy', but significantly more
+with zlib=True
this produces 'lossy', but significantly more
efficient compression. For example, if least_significant_digit=1
,
data will be quantized using numpy.around(scale*data)/scale
, where
scale = 2**bits, and bits is determined so that a precision of 0.1 is
@@ -2153,9 +2145,9 @@
In-memory (diskless) Datasets
in unpacked data that is a reliable value." Default is None
, or no
quantization, or 'lossless' compression. If significant_digits=3
then the data will be quantized so that three significant digits are retained, independent
-of the floating point exponent. The keyword argument quantize_mode
controls
-the quantization algorithm (default 'BitGroom'). The alternate 'GranularBitRound'
-algorithm may result in better compression for typical geophysical datasets.
+of the floating point exponent. If significant_digits
is given as a negative
+number, then an alternate algorithm for quantization ('granular bitgrooming') is used
+that may result in better compression for typical geophysical datasets.
This significant_digits
kwarg is only available with netcdf-c >= 4.8.2, and
only works with NETCDF4
or NETCDF4_CLASSIC
formatted files.
@@ -2205,7 +2197,7 @@ In-memory (diskless) Datasets
renameVariable(unknown):
-
+
renameVariable(self, oldname, newname)
rename a Variable
named oldname
to newname
@@ -2221,7 +2213,7 @@ In-memory (diskless) Datasets
createGroup(unknown):
-
+
createGroup(self, groupname)
Creates a new Group
with the given groupname
.
@@ -2247,7 +2239,7 @@ In-memory (diskless) Datasets
ncattrs(unknown):
-
+
ncattrs(self)
return netCDF global attribute names for this Dataset
or Group
in a list.
@@ -2263,7 +2255,7 @@ In-memory (diskless) Datasets
setncattr(unknown):
-
+
setncattr(self,name,value)
set a netCDF dataset or group attribute using name,value pair.
@@ -2281,7 +2273,7 @@
In-memory (diskless) Datasets
setncattr_string(unknown):
-
+
setncattr_string(self,name,value)
set a netCDF dataset or group string attribute using name,value pair.
@@ -2299,7 +2291,7 @@
In-memory (diskless) Datasets
setncatts(unknown):
-
+
setncatts(self,attdict)
set a bunch of netCDF dataset or group attributes at once using a python dictionary.
@@ -2318,7 +2310,7 @@
In-memory (diskless) Datasets
getncattr(unknown):
-
+
getncattr(self,name)
retrieve a netCDF dataset or group attribute.
@@ -2339,7 +2331,7 @@
In-memory (diskless) Datasets
delncattr(unknown):
-
+
delncattr(self,name,value)
delete a netCDF dataset or group attribute. Use if you need to delete a
@@ -2357,7 +2349,7 @@
In-memory (diskless) Datasets
renameAttribute(unknown):
-
+
renameAttribute(self, oldname, newname)
rename a Dataset
or Group
attribute named oldname
to newname
.
@@ -2373,7 +2365,7 @@ In-memory (diskless) Datasets
renameGroup(unknown):
-
+
renameGroup(self, oldname, newname)
rename a Group
named oldname
to newname
(requires netcdf >= 4.3.1).
@@ -2389,7 +2381,7 @@ In-memory (diskless) Datasets
set_auto_chartostring(unknown):
-
+
set_auto_chartostring(self, True_or_False)
Call Variable.set_auto_chartostring
for all variables contained in this Dataset
or
@@ -2414,7 +2406,7 @@
In-memory (diskless) Datasets
set_auto_maskandscale(unknown):
-
+
set_auto_maskandscale(self, True_or_False)
Call Variable.set_auto_maskandscale
for all variables contained in this Dataset
or
@@ -2437,7 +2429,7 @@
In-memory (diskless) Datasets
set_auto_mask(unknown):
-
+
set_auto_mask(self, True_or_False)
Call Variable.set_auto_mask
for all variables contained in this Dataset
or
@@ -2461,7 +2453,7 @@
In-memory (diskless) Datasets
set_auto_scale(unknown):
-
+
set_auto_scale(self, True_or_False)
Call Variable.set_auto_scale
for all variables contained in this Dataset
or
@@ -2484,7 +2476,7 @@
In-memory (diskless) Datasets
set_always_mask(unknown):
-
+
set_always_mask(self, True_or_False)
Call Variable.set_always_mask
for all variables contained in
@@ -2512,7 +2504,7 @@
In-memory (diskless) Datasets
set_ncstring_attrs(unknown):
-
+
set_ncstring_attrs(self, True_or_False)
Call Variable.set_ncstring_attrs
for all variables contained in
@@ -2537,7 +2529,7 @@
In-memory (diskless) Datasets
get_variables_by_attributes(unknown):
-
+
get_variables_by_attribute(self, **kwargs)
Returns a list of variables that match specific conditions.
@@ -2545,7 +2537,7 @@ In-memory (diskless) Datasets
Can pass in key=value parameters and variables are returned that
contain all of the matches. For example,
->>> # Get variables with x-axis attribute.
+>>> # Get variables with x-axis attribute.
>>> vs = nc.get_variables_by_attributes(axis='X')
>>> # Get variables with matching "standard_name" attribute
>>> vs = nc.get_variables_by_attributes(standard_name='northward_sea_water_velocity')
@@ -2556,7 +2548,7 @@ In-memory (diskless) Datasets
the attribute value. None is given as the attribute value when the
attribute does not exist on the variable. For example,
->>> # Get Axis variables
+>>> # Get Axis variables
>>> vs = nc.get_variables_by_attributes(axis=lambda v: v in ['X', 'Y', 'Z', 'T'])
>>> # Get variables that don't have an "axis" attribute
>>> vs = nc.get_variables_by_attributes(axis=lambda v: v is None)
@@ -2575,7 +2567,7 @@ In-memory (diskless) Datasets
fromcdl(unknown):
-
+
fromcdl(cdlfilename, ncfilename=None, mode='a',format='NETCDF4')
call ncgen via subprocess to create Dataset from CDL
@@ -2605,7 +2597,7 @@
In-memory (diskless) Datasets
tocdl(unknown):
-
+
tocdl(self, coordvars=False, data=False, outfile=None)
call ncdump via subprocess to create CDL
@@ -2624,10 +2616,9 @@
In-memory (diskless) Datasets
-
string name of Group instance
@@ -2636,121 +2627,109 @@ In-memory (diskless) Datasets
-
-
-
#  
- disk_format
+ disk_format = <attribute 'disk_format' of 'netCDF4._netCDF4.Dataset' objects>
-
-
-
#  
- file_format
+ file_format = <attribute 'file_format' of 'netCDF4._netCDF4.Dataset' objects>
-
-
-
-
-
#  
- keepweakref
+ keepweakref = <attribute 'keepweakref' of 'netCDF4._netCDF4.Dataset' objects>
-
@@ -2763,7 +2742,7 @@ In-memory (diskless) Datasets
Variable:
-
+
A netCDF Variable
is used to read and write netCDF data. They are
analogous to numpy array objects. See Variable.__init__
for more
details.
@@ -2809,20 +2788,16 @@ In-memory (diskless) Datasets
truncated to this decimal place when it is assigned to the Variable
instance. If None
, the data is not truncated.
-significant_digits
: New in version 1.6.0. Describes the number of significant
+
significant_digits
: New in version 1.6.0. Describes the number of significant
digits in the data the contains a reliable value. Data is
truncated to retain this number of significant digits when it is assigned to the
Variable
instance. If None
, the data is not truncated.
+If specified as a negative number, an alternative quantization algorithm is used
+that often produces better compression.
Only available with netcdf-c >= 4.8.2,
and only works with NETCDF4
or NETCDF4_CLASSIC
formatted files.
The number of significant digits used in the quantization of variable data can be
-obtained using the Variable.significant_digits
method. Default None
-
-no quantization done.
-
-quantize_mode
: New in version 1.6.0. Controls
-the quantization algorithm (default 'BitGroom'). The alternate 'GranularBitRound'
-algorithm may result in better compression for typical geophysical datasets.
-Ignored if significant_digts
not specified.
+obtained using the Variable.significant_digits
method.
__orthogonal_indexing__
: Always True
. Indicates to client code
that the object supports 'orthogonal indexing', which means that slices
@@ -2845,8 +2820,8 @@
In-memory (diskless) Datasets
Variable()
-
- __init__(self, group, name, datatype, dimensions=(), compression=None, zlib=False,
+
+ __init__(self, group, name, datatype, dimensions=(), zlib=False,
complevel=4, shuffle=True, fletcher32=False, contiguous=False,
chunksizes=None, endian='native',
least_significant_digit=None,fill_value=None,chunk_cache=None)
@@ -2880,19 +2855,15 @@ In-memory (diskless) Datasets
(defined previously with createDimension
). Default is an empty tuple
which means the variable is a scalar (and therefore has no dimensions).
-compression
: compression algorithm to use. Default None. Currently
-only 'zlib' is supported.
-
zlib
: if True
, data assigned to the Variable
-instance is compressed on disk. Default False
. Deprecated - use
-compression='zlib'
instead.
+instance is compressed on disk. Default False
.
-complevel
: the level of compression to use (1 is the fastest,
+
complevel
: the level of zlib compression to use (1 is the fastest,
but poorest compression, 9 is the slowest but best compression). Default 4.
-Ignored if compression=None
. A value of 0 disables compression.
+Ignored if zlib=False
.
shuffle
: if True
, the HDF5 shuffle filter is applied
-to improve compression. Default True
. Ignored if compression=None
.
+to improve compression. Default True
. Ignored if zlib=False
.
fletcher32
: if True
(default False
), the Fletcher32 checksum
algorithm is used for error detection.
@@ -2922,33 +2893,30 @@ In-memory (diskless) Datasets
some performance advantage to be gained by setting the endian-ness.
For netCDF 3 files (that don't use HDF5), only endian='native'
is allowed.
-The compression, zlib, complevel, shuffle, fletcher32, contiguous
and chunksizes
+
The zlib, complevel, shuffle, fletcher32, contiguous
and chunksizes
keywords are silently ignored for netCDF 3 files that do not use HDF5.
-least_significant_digit
: If this or significant_digits
are specified,
+
least_significant_digit
: If this or significant_digits
are specified,
variable data will be truncated (quantized).
-In conjunction with compression='zlib'
this produces
+In conjunction with zlib=True
this produces
'lossy', but significantly more efficient compression. For example, if
least_significant_digit=1
, data will be quantized using
around(scaledata)/scale, where scale = 2*bits, and bits is determined
so that a precision of 0.1 is retained (in this case bits=4). Default is
None
, or no quantization.
-significant_digits
: New in version 1.6.0.
+
significant_digits
: New in version 1.6.0.
As described for least_significant_digit
except the number of significant digits retained is prescribed independent
-of the floating point exponent. Default None
- no quantization done.
-
-quantize_mode
: New in version 1.6.0. Controls
-the quantization algorithm (default 'BitGroom'). The alternate 'GranularBitRound'
-algorithm may result in better compression for typical geophysical datasets.
-Ignored if significant_digts
not specified.
+of the floating point exponent. If specified as a negative number,
+an alternative quantization algorithm is used that often produces
+better compression. Only available with netcdf-c >= 4.8.2.
fill_value
: If specified, the default netCDF _FillValue
(the
value that the variable gets filled with before any data is written to it)
is replaced with this value. If fill_value is set to False
, then
the variable is not pre-filled. The default netCDF fill values can be found
-in the dictionary netCDF4.default_fillvals
.
+in the dictionary netCDF4.default_fillvals
.
chunk_cache
: If specified, sets the chunk cache size for this variable.
Persists as long as Dataset is open. Use set_var_chunk_cache
to
@@ -2969,7 +2937,7 @@
In-memory (diskless) Datasets
group(unknown):
-
+
group(self)
return the group that this Variable
is a member of.
@@ -2985,7 +2953,7 @@ In-memory (diskless) Datasets
ncattrs(unknown):
-
+
ncattrs(self)
return netCDF attribute names for this Variable
in a list.
@@ -3001,7 +2969,7 @@ In-memory (diskless) Datasets
setncattr(unknown):
-
+
setncattr(self,name,value)
set a netCDF variable attribute using name,value pair. Use if you need to set a
@@ -3019,7 +2987,7 @@
In-memory (diskless) Datasets
setncattr_string(unknown):
-
+
setncattr_string(self,name,value)
set a netCDF variable string attribute using name,value pair.
@@ -3038,7 +3006,7 @@
In-memory (diskless) Datasets
setncatts(unknown):
-
+
setncatts(self,attdict)
set a bunch of netCDF variable attributes at once using a python dictionary.
@@ -3057,7 +3025,7 @@
In-memory (diskless) Datasets
getncattr(unknown):
-
+
getncattr(self,name)
retrieve a netCDF variable attribute. Use if you need to set a
@@ -3078,7 +3046,7 @@
In-memory (diskless) Datasets
delncattr(unknown):
-
+
delncattr(self,name,value)
delete a netCDF variable attribute. Use if you need to delete a
@@ -3096,7 +3064,7 @@
In-memory (diskless) Datasets
filters(unknown):
-
+
filters(self)
return dictionary containing HDF5 filter parameters.
@@ -3104,19 +3072,20 @@ In-memory (diskless) Datasets
-
- #  
+
+
-
- quantization(self)
+
+ significant_digits(self)
-return number of significant digits and the algorithm used in quantization.
-Returns None if quantization not active.
+return number of significant digits used in quantization.
+if returned value is negative, alternate quantization method
+('granular bitgrooming') is used.
@@ -3129,7 +3098,7 @@ In-memory (diskless) Datasets
endian(unknown):
-
+
endian(self)
return endian-ness (little,big,native
) of variable (as stored in HDF5 file).
@@ -3145,7 +3114,7 @@ In-memory (diskless) Datasets
chunking(unknown):
-
+
chunking(self)
return variable chunking information. If the dataset is
@@ -3164,7 +3133,7 @@
In-memory (diskless) Datasets
get_var_chunk_cache(unknown):
-
+
get_var_chunk_cache(self)
return variable chunk cache information in a tuple (size,nelems,preemption).
@@ -3182,7 +3151,7 @@
In-memory (diskless) Datasets
set_var_chunk_cache(unknown):
-
+
set_var_chunk_cache(self,size=None,nelems=None,preemption=None)
change variable chunk cache settings.
@@ -3200,7 +3169,7 @@
In-memory (diskless) Datasets
renameAttribute(unknown):
-
+
renameAttribute(self, oldname, newname)
rename a Variable
attribute named oldname
to newname
.
@@ -3216,7 +3185,7 @@ In-memory (diskless) Datasets
assignValue(unknown):
-
+
assignValue(self, val)
assign a value to a scalar variable. Provided for compatibility with
@@ -3233,7 +3202,7 @@
In-memory (diskless) Datasets
getValue(unknown):
-
+
getValue(self)
get the value of a scalar variable. Provided for compatibility with
@@ -3250,7 +3219,7 @@
In-memory (diskless) Datasets
set_auto_chartostring(unknown):
-
+
set_auto_chartostring(self,chartostring)
turn on or off automatic conversion of character variable data to and
@@ -3281,7 +3250,7 @@
In-memory (diskless) Datasets
use_nc_get_vars(unknown):
-
+
use_nc_get_vars(self,_use_get_vars)
enable the use of netcdf library routine nc_get_vars
@@ -3301,7 +3270,7 @@
In-memory (diskless) Datasets
set_auto_maskandscale(unknown):
-
+
set_auto_maskandscale(self,maskandscale)
turn on or off automatic conversion of variable data to and
@@ -3365,7 +3334,7 @@
In-memory (diskless) Datasets
set_auto_scale(unknown):
-
+
set_auto_scale(self,scale)
turn on or off automatic packing/unpacking of variable
@@ -3414,7 +3383,7 @@
In-memory (diskless) Datasets
set_auto_mask(unknown):
-
+
set_auto_mask(self,mask)
turn on or off automatic conversion of variable data to and
@@ -3449,7 +3418,7 @@
In-memory (diskless) Datasets
set_always_mask(unknown):
-
+
set_always_mask(self,always_mask)
turn on or off conversion of data without missing values to regular
@@ -3472,7 +3441,7 @@
In-memory (diskless) Datasets
set_ncstring_attrs(unknown):
-
+
set_always_mask(self,ncstring_attrs)
turn on or off creating NC_STRING string attributes.
@@ -3494,7 +3463,7 @@ In-memory (diskless) Datasets
set_collective(unknown):
-
+
set_collective(self,True_or_False)
turn on or off collective parallel IO access. Ignored if file is not
@@ -3511,7 +3480,7 @@
In-memory (diskless) Datasets
get_dims(unknown):
-
+
get_dims(self)
return a tuple of Dimension
instances associated with this
@@ -3523,10 +3492,9 @@
In-memory (diskless) Datasets
-
string name of Variable instance
@@ -3535,10 +3503,9 @@ In-memory (diskless) Datasets
-
numpy data type (for primitive data types) or
VLType/CompoundType/EnumType instance
(for compound, vlen or enum data types)
@@ -3549,10 +3516,9 @@ In-memory (diskless) Datasets
-
find current sizes of all variable dimensions
@@ -3561,10 +3527,9 @@ In-memory (diskless) Datasets