The class geodate is designed to work with geophysical data stored in NetCDF file having the possible dimensions: ‘T’ : the time counter ‘Z’ : the vertical dimension ‘Y’ : the latitudinal dimension ‘X’ : the longitudinal dimension Dimension names and dimension variables names are stored for a lot of models and dataset. The class is able to recognize the appropriate type to use. It allows as easiest access to NetCDF file for which the dimension may be unkown and some functions are designed to rapidly create, duplicate and modify the NetCDF. The additional use of chunks may reveal very powerful when using it with the calculation class.
Attributes
filename | (str) The name of the netcdf file. |
iotype | ({‘r’, ‘w’}) Read or Write mode. |
dtype | (str) The type of the geophysical data |
dimensions | (str) A series of dimension keys (‘T’, ‘Z’, ‘Y’, ‘X’) |
time_unlimited | (bool) A boolean that tells if the record dimension is unlimited or not |
chk | (chunk) The default chunk on which perform operations |
format | (str) The netCDF format (‘NETCDF3’, ‘NETCDF3_64BIT’, ‘NETCDF4’, ‘NETCDF4_CLASSIC’) |
Methods
Construct a geovar instance from the corresponding variable in the netCDF file
Parameters: | varname : str
|
---|---|
Returns: | gvar : geovar
|
Examples
>>> gdat = example_geodata()
>>> gvar = gdat.build_gvar('exlon')
>>> print gvar
exlon (float32):
fill_value: -9999.0
axis: YX
Change the read/write mode of the netCDF file.
Parameters: | iotype : {‘r’, ‘w’}
|
---|
Examples
>>> gdat = example_geodata()
>>> print gdat.iotype
w
>>> gdat.changeIO('r')
>>> print gdat.iotype
r
Check if the chunk is consistent with the dimensions of the netCDF file otherwise reset the value to the min/max.
Parameters: | chk : chunk
|
---|
Copy all the coordinate variables from the instance gdat into the current instance
Parameters: | gdata : geodata
chk_in : chunk
chk_out : chunk
|
---|
Copy the dimensions from another geodata instance
Parameters: | gdat : geodata
|
---|
Examples
>>> gdat_in = example_geodata()
>>> gdat_out = geodata('../examples/example_copy.nc',
... iotype='w', dtype='example2d')
>>> print gdat_out
================================================================
Filename : ../examples/example_copy.nc
Format : NETCDF3_64BIT
I/O access : w
Data type : example2d
Dimensions : TZYX
Unlimited time dimension : True
================================================================
Default chunk:
--------------
None
Dimensions:
-----------
Variables:
----------
================================================================
>>> gdat_out.copy_dim(gdat_in)
>>> print gdat_out
================================================================
Filename : ../examples/example_copy.nc
Format : NETCDF3_64BIT
I/O access : w
Data type : example2d
Dimensions : TZYX
Unlimited time dimension : True
================================================================
Default chunk:
--------------
None
Dimensions:
-----------
T - t: 0
Z - z: 9
Y - y: 37
X - x: 73
Variables:
----------
================================================================
Copy the variables associated with the dimensions
Copy the structure of the variable in the geodata instance geodat to a new variable in self
Create all the dimension variables in the netCDF file
Create the dimension variables in the netCDF file
Create the variable with its attributes in the netCDF file
Parameters: | gvar : geovar or string
|
---|
Extract the structure and the variables of a netCDF file.
Parameters: | gdat : geodata
list_gvar_in : list of string or geovar
list_gvar_out: list of string or geovar, optional
chk_in : chunk, optional
chk_out : chunk, optional
fill_value : float, file
|
---|
Extract the structure of a netCDF file.
Parameters: | gdat : geodata
list_gvar_in : list of string or geovar
list_gvar_out: list of string or geovar, optional
chk_in : chunk, optional
chk_out : chunk, optional
fill_value : float, file
|
---|
Return the vertical 1d array, optionally a subset defined by a chunk
Parameters: | chk : chunk, optional
|
---|---|
Returns: | depth : 1darray
|
Get the size of a dimension int the netCDF4 instance nc_in along one dimension (T, Z, Y or X)
Return the dimension of the vertical axis
Returns: | n_z : int
|
---|
Return the dimension of the latitudinal axis
Returns: | n_lat : int
|
---|
Return the dimension of the latitudinal and longitudinal axis
Returns: | n_lon : int
n_lat : int
|
---|
Return the dimension of the longitudinal axis
Returns: | n_lon : int
|
---|
Get the dimension of the time axis
Returns: | n_t : int
|
---|
Return the coordinates associated with the dimension dim from the netCDF4 instance nc_in or only a subset optionally defined by a chunk instance
Return the latitudinal 1d/2d array, optionally a subset defined by a chunk chk
Parameters: | chk : chunk, optional
|
---|---|
Returns: | lat : 1darray/2darray
|
Return the latitudinal and longitudinal 1d/2d array, optionally a subset defined by a chunk
Parameters: | chk : chunk, optional
|
---|---|
Returns: | lat : 1darray/2darray
lon : 1darray/2darray
|
Parameters: | chk : chunk, optional
|
---|---|
Returns: | lon : 1darray/2darray
|
Return the time record, optionally a subset defined by a chunk
Parameters: | chk : chunk, optional
|
---|---|
Returns: | time : 1darray
|
Read a variable in the netCDF file
Parameters: | gvar : string or geovar
chk : chunk, optional
dtype : data-type, optional
|
---|---|
Returns: | out : ndarray
|
Return the value of the FillValue attribute
Parameters: | gvar : string or geovar
attr_name : string
|
---|---|
Returns: | out : unknown
|
Return the value of the variable attribute
Parameters: | gvar : string or geovar
attr_name : string
|
---|---|
Returns: | out : unknown
|
Return the axis attribute of the variable in the NetCDF file
Parameters: | gvar : string or geovar
|
---|---|
Returns: | axis : string
|
Return the type of the variable in the netcdf file
Parameters: | gvar : string or geovar
|
---|---|
Returns: | out : string
|
Return the list of the variable names without the dimension variables
Returns: | out : list of string
|
---|
Write the values of a dimension variable in the netCDF file