nd.io package¶
-
nd.io.
add_time
(ds, inplace=False)[source]¶ Add a time dimension to the dataset.
- Parameters
ds (xarray.Dataset) – The input dataset.
- Returns
A dataset that is guaranteed to contain the dimension time.
- Return type
xarray.Dataset
-
nd.io.
assemble_complex
(ds, inplace=False)[source]¶ Reassemble complex valued data.
NOTE: Changes the dataset (view) in place!
- Parameters
ds (xarray.Dataset) – The input dataset with complex variables split into real and imaginary parts.
inplace (bool, optional) – Whether to modify the dataset inplace (default: False).
- Returns
If inplace, returns None. Otherwise, returns a dataset where the real and imaginary parts have been combined into the respective complex variables.
- Return type
xarray.Dataset or None
-
nd.io.
disassemble_complex
(ds, inplace=False)[source]¶ Disassemble complex valued data into real and imag parts.
- Parameters
ds (xarray.Dataset) – The input dataset with complex variables.
inplace (bool, optional) – Whether to modify the dataset inplace (default: False).
- Returns
If inplace, returns None. Otherwise, returns a dataset where all complex variables have been split into their real and imaginary parts.
- Return type
xarray.Dataset or None
-
nd.io.
open_beam_dimap
(path, read_data=True, as_complex=True)[source]¶ Read a BEAM Dimap product into an xarray Dataset.
BEAM Dimap is the native file format of the SNAP software. It consists of a
*.dim
XML file and a*.data
directory containing the data.path
should point to the XML file.- Parameters
path (str) – The file path to the BEAM Dimap product.
read_data (bool, optional) – If True (default), read all data. Otherwise, read only the metadata.
- Returns
The same dataset converted into xarray.
- Return type
xarray.Dataset
-
nd.io.
open_dataset
(path, *args, **kwargs)[source]¶ The default way of reading a dataset from disk.
Determines the file format from the extension, and calls either
nd.io.open_netcdf()
,nd.io.open_beam_dimap()
, ornd.io.open_rasterio()
.- Parameters
path (str) – The file path.
*args (list) – Extra positional arguments passed on to the specialized
open_*
function.**kwargs (dict) – Extra keyword arguments passed on to the specialized
open_*
function.
- Returns
The opened dataset. In general, if the file is a NetCDF or BEAM-Dimap file the result will be an xarray Dataset, otherwise an xarray DataArray.
- Return type
xarray.Dataset or xarray.DataArray
- Raises
IOError – Raises an IOError if the Dataset could not be opened.
-
nd.io.
open_netcdf
(path, as_complex=False, *args, **kwargs)[source]¶ Read a NetCDF file into an xarray Dataset.
Wrapper function for
xarray.open_dataset
that preserves complex valued data.- Parameters
path (str) – The path of the NetCDF file to read.
as_complex (bool, optional) – Whether or not to assemble real and imaginary parts into complex (default: False).
*args (list) – Extra positional arguments passed on to
xarray.open_dataset
.**kwargs (dict) – Extra keyword arguments passed on to
xarray.open_dataset
.
- Returns
The opened dataset.
- Return type
xarray.Dataset
See also
xarray.open_dataset
-
nd.io.
to_netcdf
(ds, path, *args, **kwargs)[source]¶ Write an xarray Dataset to disk.
In addition to
xarray.to_netcdf
, this function allows to store complex valued data by converting it to a a pair of reals. This process is reverted when reading the file viafrom_netcdf
.- Parameters
ds (xarray.Dataset) – The dataset to be stored to disk.
path (str) – The path of the target NetCDF file.
*args (list) – Extra positional arguments for
xr.Dataset.to_netcdf
.**kwargs (dict) – Extra keyword arguments for
xr.Dataset.to_netcdf
.