shnitsel.data.helpers

Attributes

T

Functions

dataclass_from_dict(datatype, d)

Helper function to restore a Dataclass object from its dict representation.

ts_to_time(data[, delta_t, old])

setup_frames(ds, *[, to_time, convert_to_eV, ...])

Performs several frequent setup tasks.

validate(frames)

split_for_saving(frames[, bytes_per_chunk])

save_split(frames, path_template[, bytes_per_chunk, ...])

Module Contents

T
dataclass_from_dict(datatype, d)

Helper function to restore a Dataclass object from its dict representation.

Mainly used for serialization or storage of data in the DataTree db structure.

Parameters:
  • datatype (Type[T]) – The dataclass type to restore

  • d (List|Dict|T) – The datasource to convert back into the Dataclass instance.

Raises:
  • ValueError – If value decoding fails during reconstruction

  • TypeError – If some type mismatch occurs between the provided dict and the target type

Returns:

A resonstructed datatype instance.

Return type:

T

ts_to_time(data, delta_t=None, old='drop')
Parameters:
  • data (shnitsel.core.typedefs.DatasetOrArray)

  • delta_t (float | None)

  • old (Literal['drop', 'to_var', 'keep'])

Return type:

shnitsel.core.typedefs.DatasetOrArray

setup_frames(ds, *, to_time=None, convert_to_eV=None, convert_e_kin_to_eV=None, relativize_energy=None, relativize_selector=None)

Performs several frequent setup tasks. Each task can be skipped (by setting the corresponding parameter to False), carried out if appropriate (None), or forced in the sense that an error is thrown if the task is redundant (True).

Parameters:
  • ds (xarray.Dataset) – The frames-like xr.Dataset to setup.

  • to_time (bool | None) – Whether to convert a ‘ts’ (timestep) coordinate to a ‘time’ coordinate, by default None

  • optional – Whether to convert a ‘ts’ (timestep) coordinate to a ‘time’ coordinate, by default None

  • convert_to_eV (bool | None) – Whether to convert the ‘energy’ variable to eV, by default None

  • optional – Whether to convert the ‘energy’ variable to eV, by default None

  • convert_e_kin_to_eV (bool | None) – Whether to convert the ‘e_kin’ (kinetic energy) variable to eV, by default None

  • optional – Whether to convert the ‘e_kin’ (kinetic energy) variable to eV, by default None

  • relativize_energy (bool | None) – Whether to relativize energies, by default None

  • optional – Whether to relativize energies, by default None

  • relativize_selector – This argument is passed to relativize, by default None

  • optional – This argument is passed to relativize, by default None

Return type:

A modified frames-like xr.Dataset

Raises:

ValueError – If a task should be forced (i.e. the corresponding parameter is set to True) but cannot be carried out (e.g. because the dataset was already processed previously)

validate(frames)
Parameters:

frames (shnitsel.core.typedefs.Frames)

Return type:

numpy.ndarray

split_for_saving(frames, bytes_per_chunk=50000000.0)
Parameters:

frames (shnitsel.core.typedefs.Frames)

save_split(frames, path_template, bytes_per_chunk=50000000.0, complevel=9, ignore_errors=False)