deltametrics.io.NetCDFIO¶
- class deltametrics.io.NetCDFIO(data_path, io_type, write=False)¶
Utility for consistent IO with netCDF4 files.
This module wraps calls to the netCDF4 python module in a consistent API, so the user can work seamlessly with either netCDF4 files or HDF5 files. The public methods of this class are consistent with
HDFIO
.Note that the netCDF4, netCDF4-classic, and HDF5 file standards are very similar and (almost) interchangable. This means that the same data loader can be used to handle these files. We use the xarray data reader which supports the netCDF4/HDF5 file-format.
Older file formats such as netCDF3 or HDF4 are unsupported. For more information about the netCDF4 format, visit the netCDF4 docs.
- __init__(data_path, io_type, write=False)¶
Initialize the NetCDFIO handler.
Initialize a connection to a NetCDF file.
- Parameters:
data_path (str) – Path to file to read or write to.
io_type (str) – Stores the type of output file loaded, either a netCDF4 file, ‘netcdf’ or an HDF5 file, ‘hdf5’.
write (bool, optional) – Whether to allow writing to an existing file. Set to False by default, if a file already exists at
data_path
, writing is disabled, unlesswrite
is set to True.
Methods
__init__
(data_path, io_type[, write])Initialize the NetCDFIO handler.
connect
()Connect to the data file.
List known coordinates.
List known variables.
read
(var)Read variable from file and into memory.
write
()Write data to file.
Attributes
Path to data file.
Variable names in file.
- connect()¶
Connect to the data file.
Initialize the file if it does not exist, or simply
return
if the file already exists. This connection to the data file is “lazy” loading, meaning that array values are not being loaded into memory.Note
This function is automatically called during initialization of any IO object, so it is not necessary to call it directly.
- property data_path¶
Path to data file.
- Parameters:
data_path (str) – path to data file for IO operations.
Notes
The setter method validates the path, and returns a
FileNotFoundError
if the file is not found.- Type:
str
- get_known_coords()¶
List known coordinates.
These coordinates are pulled from the loaded dataset.
- get_known_variables()¶
List known variables.
These variables are pulled from the loaded dataset.
- property keys¶
Variable names in file.
- read(var)¶
Read variable from file and into memory.
Converts variables in data file to xarray objects for coersion into a
Cube
instance.- Parameters:
var (str) – Which variable to load from the file.
- write()¶
Write data to file.
Take a
Cube
and write it to file.Warning
Not Implemented.