Class Variable
object --+
|
Variable
Variable(self, dset, name, datatype, dimensions=(),
fill_value=None)
A netCDF Variable is used to read and write netCDF data. They
are analagous to numpy array objects.
Variable
instances should be created using the createVariable method of a Dataset instance, not
using this class directly.
Parameters:
dset
- Dataset instance.
name
- Name of the variable.
datatype
- Variable data type. Can be specified by providing a
numpy dtype object, or a string that describes a numpy dtype object.
Supported values, corresponding to str
attribute of numpy
dtype objects, include 'f4'
(32-bit floating point),
'f8'
(64-bit floating point), 'i4'
(32-bit
signed integer), 'i2'
(16-bit signed integer),
'i4'
(8-bit singed integer), 'i1'
(8-bit signed
integer), or 'S1'
(single-character string). From
compatibility with Scientific.IO.NetCDF, the old Numeric single character
typecodes can also be used ('f'
instead of
'f4'
, 'd'
instead of 'f8'
,
'h'
or 's'
instead of 'i2'
,
'b'
or 'B'
instead of 'i1'
,
'c'
instead of 'S1'
, and 'i'
or
'l'
instead of 'i4'
).
Keywords:
dimensions
- a tuple containing the variable's
dimension names (defined previously with createDimension
).
Default is an empty tuple which means the variable is a scalar (and
therefore has no dimensions).
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.
Returns:
a Variable
instance. All further operations on the netCDF Variable are accomplised
via Variable
instance methods.
A list of attribute names corresponding to netCDF attributes defined
for the variable can be obtained with the ncattrs()
method.
These attributes can be created by assigning to an attribute of the Variable instance. A
dictionary containing all the netCDF attribute name/value pairs is
provided by the __dict__
attribute of a Variable
instance.
The instance variables dimensions, dtype, ndim, shape
are
read-only (and should not be modified by the user).
|
|
|
__delitem__(x,
y)
del x[y] |
|
|
|
|
|
|
|
|
|
__init__(self,
dset,
name,
datatype,
dimensions=(),
fill_value=None)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature |
|
|
|
|
a new object with type S, a subtype of T
|
|
|
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value |
|
|
|
__setitem__(x,
i,
y)
x[i]=y |
|
|
|
assignValue(self,
val)
assign a value to a scalar variable. |
|
|
|
delncattr(self,
name,
value)
delete a netCDF variable attribute. |
|
|
|
getValue(self)
get the value of a scalar variable. |
|
|
|
getncattr(self,
name)
retrievel a netCDF variable attribute. |
|
|
|
ncattrs(self)
return netCDF attribute names for this Variable in a
list. |
|
|
|
set_auto_maskandscale(self,
maskandscale)
turn on or off automatic conversion of variable data to and from
masked arrays and automatic packing/unpacking of variable data using
scale_factor and add_offset attributes. |
|
|
|
setncattr(self,
name,
value)
set a netCDF variable attribute using name,value pair. |
|
|
Inherited from object :
__format__ ,
__hash__ ,
__reduce__ ,
__reduce_ex__ ,
__repr__ ,
__sizeof__ ,
__str__ ,
__subclasshook__
|
|
dimensions
A tuple containing the names of the dimensions associated with this
variable.
|
|
dtype
A numpy dtype object describing the variable's data type.
|
|
ndim
The number of variable dimensions.
|
|
shape
a tuple describing the current size of all the variable's dimensions.
|
|
maskandscale
|
|
size
Return the number of stored elements.
|
Inherited from object :
__class__
|
x.__delattr__('name') <==> del x.name
- Overrides:
object.__delattr__
|
x.__getattribute__('name') <==> x.name
- Overrides:
object.__getattribute__
|
__init__(self,
dset,
name,
datatype,
dimensions=(),
fill_value=None)
(Constructor)
|
|
x.__init__(...) initializes x; see x.__class__.__doc__ for
signature
- Overrides:
object.__init__
|
- Returns: a new object with type S, a subtype of T
- Overrides:
object.__new__
|
x.__setattr__('name', value) <==> x.name = value
- Overrides:
object.__setattr__
|
assign a value to a scalar variable. Provided for compatibility with
Scientific.IO.NetCDF, can also be done by assigning to a slice ([:]).
|
delncattr(self,
name,
value)
|
|
delete a netCDF variable attribute. Only use if you need to delete a
netCDF attribute with the same name as one of the reserved python
attributes.
|
get the value of a scalar variable. Provided for compatibility with
Scientific.IO.NetCDF, can also be done by slicing ([:]).
|
retrievel a netCDF variable attribute. Only use if you need to set a
netCDF attribute with the same name as one of the reserved python
attributes.
|
set_auto_maskandscale(self,
maskandscale)
|
|
turn on or off automatic conversion of variable data to and from
masked arrays and automatic packing/unpacking of variable data using
scale_factor and add_offset attributes.
If maskandscale is set to True , when data is
read from a variable it is converted to a masked array if any of the
values are exactly equal to the either the netCDF _FillValue or the value
specified by the missing_value variable attribute. The fill_value of the
masked array is set to the missing_value attribute (if it exists),
otherwise the netCDF _FillValue attribute (which has a default value for
each data type). When data is written to a variable, the masked array is
converted back to a regular numpy array by replacing all the masked
values by the fill_value of the masked array.
If maskandscale is set to True , and the
variable has a scale_factor and an add_offset
attribute, then data read from that variable is unpacked using:
data = self.scale_factor*data + self.add_offset
When data is written to a variable it is packed using:
data = (data - self.add_offset)/self.scale_factor
For more information on how scale_factor and
add_offset can be used to provide simple compression, see http://www.cdc.noaa.gov/cdc/conventions/cdc_netcdf_standard.shtml.
The default value of maskandscale is True
(automatic conversions are performed).
|
setncattr(self,
name,
value)
|
|
set a netCDF variable attribute using name,value pair. Only use if
you need to set a netCDF attribute with the same name as one of the
reserved python attributes.
|