erlab.io.igor

Backend for Igor Pro files.

Functions

load_experiment(filename[, folder, prefix, ...])

Load waves from an Igor experiment file(pxp and pxt).

load_igor_hdf5(filename)

Load a HDF5 file exported by Igor Pro into an xarray.Dataset.

load_text(filename[, dtype, without_values])

Load an itx file containing a single wave into a xarray.DataArray.

load_wave(wave[, data_dir])

Load a wave from Igor binary format.

save_wave(darr, filename)

Save a wave to an Igor binary file.

set_scale(darr, method, dim, num1, num2[, ...])

Apply a scale to the specified dimension of the DataArray.

Classes

IgorBackendEntrypoint()

Backend for Igor Pro files.

class erlab.io.igor.IgorBackendEntrypoint[source]

Bases: BackendEntrypoint

Backend for Igor Pro files.

This backend supports “.pxt”, “.pxp”, and “.ibw” files through igor2.

Partial support for Igor Pro text files (itx) is also provided, allowing loading itx files that contain a single wave and well-defined SetScale commands.

HDF5 files exported from Igor Pro are also partially supported.

description: typing.ClassVar[str] = 'Open Igor Pro files (.pxt, .pxp, .ibw, and .itx) in Xarray'
url: typing.ClassVar[str] = 'https://erlabpy.readthedocs.io/en/stable/generated/erlab.io.igor.html'
supports_groups: typing.ClassVar[bool] = True
open_dataset(filename_or_obj, *, drop_variables=None, recursive=False)[source]
guess_can_open(filename_or_obj)[source]
open_datatree(filename_or_obj, *, recursive=True, **kwargs)[source]
open_groups_as_dict(filename_or_obj, *, recursive=True, **kwargs)[source]
erlab.io.igor.load_experiment(filename, folder=None, *, prefix=None, ignore=None, recursive=False, **kwargs)[source]

Load waves from an Igor experiment file(pxp and pxt).

Use xarray.load_dataset() with backend="erlab-igor" for consistency.

Parameters:
  • filename (str | PathLike) – The experiment file.

  • folder (str | None, default: None) – Target folder within the experiment, given as a slash-separated string. If None, defaults to the root.

  • prefix (str | None, default: None) – If given, only include waves with names that starts with the given string.

  • ignore (Iterable[str] | None, default: None) – List of wave names to ignore.

  • recursive (bool, default: False) – If True, includes waves in child directories.

  • **kwargs – Extra arguments to load_wave().

Returns:

xarray.Dataset – Dataset containing the waves.

Return type:

Dataset

erlab.io.igor.load_igor_hdf5(filename)[source]

Load a HDF5 file exported by Igor Pro into an xarray.Dataset.

Use xarray.load_dataset() with backend="erlab-igor" for consistency.

Parameters:

filename (str | PathLike) – The path to the file.

Returns:

xarray.Dataset – The loaded data.

Return type:

Dataset

erlab.io.igor.load_text(filename, dtype=float, *, without_values=False)[source]

Load an itx file containing a single wave into a xarray.DataArray.

This function reads basic itx files exported from Igor Pro. Currently, it only supports files with a single wave and does not handle complex structures like multiple waves or nested structures.

Parameters:
  • filename (str | PathLike) – The path to the itx file.

  • dtype (default: float) – The data type to use for the values. Defaults to float.

  • without_values (bool, default: False) – If True, the returned DataArray values will be filled with zeros. Use this to check the coords or attrs quickly without loading in the full data.

Returns:

DataArray – The loaded data.

Return type:

DataArray

erlab.io.igor.load_wave(wave, data_dir=None)[source]

Load a wave from Igor binary format.

Use xarray.load_dataarray() with backend="erlab-igor" for consistency.

Parameters:
  • wave (dict | WaveRecord | str | PathLike) – The wave to load. It can be provided as a dictionary, an instance of igor2.record.WaveRecord, or a string representing the path to the wave file.

  • data_dir (str | PathLike | None, default: None) – The directory where the wave file is located. This parameter is only used if wave is a string or PathLike object. If None, wave must be a valid path.

Returns:

xarray.DataArray – The loaded wave.

Raises:
  • ValueError – If the wave file cannot be found or loaded.

  • TypeError – If the wave argument is of an unsupported type.

Return type:

DataArray

erlab.io.igor.save_wave(darr, filename)[source]

Save a wave to an Igor binary file.

This function saves a single DataArray to an Igor binary file. It is the inverse of load_wave(). Only supports simple 1D, 2D, 3D, and 4D DataArrays without any associated coordinates and non-dimensional coordinates.

Parameters:
  • darr (DataArray) – The DataArray to save as a wave.

  • filename (str | PathLike) – The path to the output file.

Example

>>> import xarray as xr
>>> import erlab
>>> darr = xr.DataArray([1, 2, 3], dims=["x"], coords={"x": [0, 1, 2]})
>>> erlab.io.igor.save_wave(darr, "output.ibw")
erlab.io.igor.set_scale(darr, method, dim, num1, num2, units_str=None, wave_name=None)[source]

Apply a scale to the specified dimension of the DataArray.

This is the Python equivalent of Igor Pro’s SetScale command.

Parameters:
  • darr (DataArray) – The DataArray to which the scale will be applied.

  • method ('/I', '/P', or None) – The method of scaling. See the Igor Pro documentation for details.

  • dim ('d', 't', 'x', 'y', or 'z') – The dimension to which the scale will be applied. For ‘d’, nothing is done.

  • num1 (str or float) – The first number for the scale. If a string, it will be converted to float.

  • num2 (str or float) – The second number for the scale. If a string, it will be converted to float.

  • units_str (str, optional) – If provided, the dimension will be renamed to this string.

  • wave_name (str, optional) – Has no effect in this implementation, but can be used for consistency with Igor Pro.

Returns:

DataArray – The DataArray with the scale applied to the specified dimension.

Return type:

DataArray