earth2studio.io
.NetCDF4Backend#
- class earth2studio.io.NetCDF4Backend(file_name, diskless=False, persist=False)[source]#
A backend that supports the NetCDF4 format.
- Parameters:
file_name (str,) – File name to provide for creating the netcdf4 store.
diskless (bool, optional) – Whether to store the Dataset in memory buffer Default value is False.
persist (bool, optional) – Whether to save in-memory diskless buffer to disk upon close. Default value is False.
- add_array(coords, array_name, data=None)[source]#
Add an array to the existing netcdf Dataset.
- Parameters:
coords (CoordSystem) – Ordered dict of coordinate information.
array_name (str) – Name to add to netcdf Dataset for the new array. Can optionally be a list of array_names.
data (torch.Tensor | list[torch.Tensor], optional) – Optional data to initialize the array with. If None, then the netcdf array is initialized with zeros. Can also pass a list of tensors, which must match in length to the list of array_names passed. If a list of tensors is passed, it is assumed that each tensor share coords.
- Return type:
None
- write(x, coords, array_name)[source]#
Write data to the current netCDF group using the passed array_name.
- Parameters:
x (torch.Tensor | list[torch.Tensor]) – Tensor(s) to be written to netCDF group.
coords (OrderedDict) – Coordinates of the passed data.
array_name (str | list[str]) – Name(s) of the array(s) that will be written to.
- Return type:
None