prsctrl.data.prsdata.PrsData#

class PrsData(data_path: str | None = None, data: dict | None = None, metadata: dict | None = None, data_name: str | None = None, file_mode='r', exp_mode=None)[source]#

Bases: Data

Class managing data and metadata. Can be initialized from data directly, or from a file or directory path.

data is a dictionary with:
  • key: wavelength as int or float, or “offset_<name>”

  • value: dictionary with:
    • key: quantity as string: [“lock-in-R_raw”, “lock-in-theta”, “slock-in-theta”, “lock-in-aux_raw”, … ]

    • value: quantity value, or array if “_raw”

Keys for a given wavelength/offset:
  • dI: delta I, the change in reflectance/transmittance/absorbance. (This is the signal amplitude “R” from the lock-in)

  • I: the baseline reflectivity. (DC signal measured using Aux In of the lock-in)

  • theta: phase

  • theta-corr: theta between [-90, 90], assuming |theta| > 90 simply means lock-in-R is negative

  • lock-in-R: magnitude value of lock-in

  • lock-in-theta: phase value of lock-in

  • lock-in-aux: value if lock-in aux port

  • <qty>_raw: The raw measurement data (all individual samples)

  • s<qty>: Standard error of the quantity

Methods

get_column_color

get_column_label

get_column_label_with_unit

get_column_scale

get_column_tex_label

get_column_tex_label_with_unit

get_column_tex_label_with_unit_and_scale

get_column_tex_unit

get_column_unit

get_csv

get_for_wl

Return the value for <key> at a given wavelength <wl> (in nanometers)

get_spectrum_data

Return the spectral data for the specified keys and wavelengths as numpy array :param wavelengths: List of wavelengths, range of wavelenthgs (as tuple, with at least (min, max)), or None to use all wavelengths.

has_AC

has_DC

has_wavelengths

load_data_from_csv

Loads data from a single csv file.

load_data_from_dir

Load prs data from a directory path.

load_data_from_pkl

Loads data from a single pkl file. If the file is compressed with gzip, it must end with '.gz' extension. Parameters ---------- :param filepath Path to the file. :return data 2D numpy array with shape (n, 4) where n is the number of data points. metadata Dictionary with metadata.

plot_raw_for_wl

Plot raw data against index (time) for a particular wavelength.

remove_calculated_values

Delete all calculated data values

save_csv

save_csv_at

to_csv

Return a csv of the spectrum data as csv :param sep: csv separator :param columns: List of column names.

update_wavelengths

write_full_file

Write the entire data to a single pickle file in the data directory.

write_metadata

write_partial_file

Attributes

CALC_KEYS

OLD_KEYS

default_spectrum_columns

spectrum_columns_abs

spectrum_columns_reference

data_path

Absolute path to the data file or directory

dir_path

Absolute path to the data directory

dir_name

Name of the data directory

data_path#

Absolute path to the data file or directory

dir_name: str#

Name of the data directory

dir_path: str#

Absolute path to the data directory

get_for_wl(wl, key) float[source]#

Return the value for <key> at a given wavelength <wl> (in nanometers)

Parameters:
  • wl – Wavelength in nm

  • key – Key of the quantity to return.

if relative_time:
  • I: the DC signal (measured by lock-in aux port and calculated from the “lock-in-aux_raw” values)

  • dI: sqrt(dI-X^2 + dI-Y^2)

  • dI-X: delta I = I * cos(theta) where I is the I value from the lock-in (peak-peak, calculated from the “lock-in-R_raw” values)

  • dI-Y: delta I = I * sin(theta) where I is the I value from the lock-in (peak-peak, calculated from the “lock-in-R_raw” values)

  • theta: the phase (calculated from the “lock-in-theta_raw” values)

  • dI_I, dI-X_I, dI-Y_I: dI/I each

  • lock-in-<key>: mean (error) value calculated from the “lock-in-<key>_raw” values

Returns:

float, or np.ndarray if a _raw value was requested

get_spectrum_data(wavelengths=None, columns=None, Es=None, transforms: list[Callable[[ndarray[tuple[Any, ...], dtype[_ScalarT]], list[str]], tuple[ndarray[tuple[Any, ...], dtype[_ScalarT]], list[str]]]] | None = None) tuple[ndarray[tuple[Any, ...], dtype[_ScalarT]], list[str]][source]#

Return the spectral data for the specified keys and wavelengths as numpy array :param wavelengths: List of wavelengths, range of wavelenthgs (as tuple, with at least (min, max)), or None to use all wavelengths. Conflicts with Es. :param Es: List of energies (eV), range of energies (as tuple, with at least (min, max)), or None to use all wavelengths. Conflicts with wavelengths :param columns: List of column keys, or None to use default_spectrum_columns. :param transforms: List of transformations to apply to the data :return: numpy.ndarray where the first index is the wavelength/index and the second is the keys/columns. (wavelength=0, <keys>…=1…)

static load_data_from_csv(filepath: str, mode=None, **csv_kw) tuple[dict, dict][source]#

Loads data from a single csv file. :param filepath: Path to the csv file.

static load_data_from_dir(dirpath: str) tuple[dict, dict][source]#

Load prs data from a directory path. If PREFER_LOAD_FROM_FULL_FILE is True, the data is loaded from the FULL_DATA_FILENAME, if it exists. Otherwise all data files with the PARTIAL_PREFIX are loaded and combined.

:param dirpath Path to the data directory :return data, metadata

classmethod load_data_from_pkl(filepath: str) tuple[dict, dict][source]#

Loads data from a single pkl file. If the file is compressed with gzip, it must end with ‘.gz’ extension. Parameters ———- :param filepath Path to the file. :return

data

2D numpy array with shape (n, 4) where n is the number of data points.

metadata

Dictionary with metadata.

plot_raw_for_wl(wl, what=['lock-in-R', 'lock-in-aux', 'lock-in-theta'], fig=None, axs=None, **plot_kw)[source]#

Plot raw data against index (time) for a particular wavelength.

remove_calculated_values()[source]#

Delete all calculated data values

to_csv(columns=None, sep=',')[source]#

Return a csv of the spectrum data as csv :param sep: csv separator :param columns: List of column names. If None, uses the default_spectrum_columns :return: csv as string

write_full_file(compress=False)[source]#

Write the entire data to a single pickle file in the data directory. :param compress: If True, file is compressed using gzip