erlab.io.utils

General-purpose I/O utilities.

Functions

get_files(directory[, extensions, contains, ...])

Return file names in a directory with the given extension(s).

load_hdf5(filename, **kwargs)

Load data from an HDF5 file saved with save_as_hdf5.

open_hdf5(filename, **kwargs)

Open data from an HDF5 file saved with save_as_hdf5.

save_as_hdf5(data, filename[, igor_compat])

Save data in HDF5 format.

save_as_netcdf(data, filename, **kwargs)

Save data in netCDF4 format.

showfitsinfo(path)

Print raw metadata from a .fits file.

erlab.io.utils.get_files(directory, extensions=None, contains=None, notcontains=None, exclude=None)[source]

Return file names in a directory with the given extension(s).

Directories are ignored.

Parameters:
  • directory (str | PathLike) – Target directory.

  • extensions (Iterable[str] | str | None, default: None) – List of extensions to filter for. If not provided, all files are returned.

  • contains (str | None, default: None) – String to filter for in the file names.

  • notcontains (str | None, default: None) – String to filter out of the file names.

  • exclude (str | Iterable[str] | None, default: None) – Glob patterns to exclude from the search.

Returns:

files (set of pathlib.Path) – Set of file objects in the directory.

Return type:

set[Path]

erlab.io.utils.load_hdf5(filename, **kwargs)[source]

Load data from an HDF5 file saved with save_as_hdf5.

This is a thin wrapper around xarray.load_dataarray and xarray.load_dataset.

Deprecated since version 3.14.0: Use xarray.load_dataarray or xarray.load_dataset directly.

Parameters:
Returns:

xarray.DataArray or xarray.Dataset – The loaded data.

Return type:

DataArray | Dataset

erlab.io.utils.open_hdf5(filename, **kwargs)[source]

Open data from an HDF5 file saved with save_as_hdf5.

This is a thin wrapper around xarray.open_dataarray and xarray.open_dataset.

Deprecated since version 3.14.0: Use xarray.open_dataarray or xarray.open_dataset directly.

Parameters:
Returns:

xarray.DataArray or xarray.Dataset – The opened data.

Return type:

DataArray | Dataset

erlab.io.utils.save_as_hdf5(data, filename, igor_compat=True, **kwargs)[source]

Save data in HDF5 format.

Deprecated since version 3.14.0: Use xarray.DataArray.to_netcdf or xarray.Dataset.to_netcdf directly. To save data in a format compatible with Igor, use erlab.io.igor.save_wave().

Parameters:
erlab.io.utils.save_as_netcdf(data, filename, **kwargs)[source]

Save data in netCDF4 format.

Deprecated since version 3.14.0: Use xarray.DataArray.to_netcdf or xarray.Dataset.to_netcdf directly.

Discards invalid netCDF4 attributes and produces a warning.

Parameters:
erlab.io.utils.showfitsinfo(path)[source]

Print raw metadata from a .fits file.

Deprecated since version 3.14.0: Use astropy.io.fits directly to handle FITS files.

Parameters:

path (str | PathLike) – Local path to .fits file.