base_loader#

Module for BaseLoader class for providing basic framework for loading and processing artof data.

class artof.base_loader.BaseLoader(path, transform_format, t0=None, work_func=4.14, artof_center_x=0.0, artof_center_y=0.0, sweep_type='Scienta')#

BaseLoader class as a framework for loading and processing artof data. Loader for specific usecases can inherit from this class and implement their own methods.

Parameters:
  • path (str)

  • transform_format (TransformFormat)

  • t0 (float | None)

  • work_func (float)

  • artof_center_x (float)

  • artof_center_y (float)

  • sweep_type (str)

add_binned_data(binned_data_to_add)#

Add binned data to existing binned data.

Parameters:

binned_data_to_add (dict) – Binned data to be added.

Return type:

None

add_event_counts(event_counts_to_add)#

Add new event counts to existing event counts.

Parameters:

event_counts_to_add (dict) – Dictionary containing event counts to be added.

Return type:

None

add_transformed_data(trans_data_to_add)#

Add transformed data to existing transformed data.

Parameters:

trans_data_to_add (dict) – Dictionary containing transformed data to be added.

Return type:

None

bin(transformed_data, norm_modes=None, win_config=None, cust_start_iter=None, cust_stop_iter=None, igor_binning=False)#

Bin loaded data into 3D histogram.

Parameters:
  • transformed_data (dict[int, list]) – Transformed data to be binned.

  • norm_modes (list | None) – Normalization mode for binned data (‘iterations’, ‘dwell_time’, ‘sweep’). Default is None. - iterations: Normalize data by number of iterations. - dwell_time: Normalize data by dwell time. - sweep: Normalize data by changing window size of sweep data.

  • win_config (tuple[int] | None) – Window size and delta for spectral evolution analysis. If None, no window size is set.

  • cust_start_iter (int | None) – Start iteration (including). Default is None, first run iteration.

  • cust_stop_iter (int | None) – Stop iteration (excluding). Default is None, last run iteration.

  • igor_binning (bool) – DEPRECATED. Igor-like binning is only meant for legacy support, only use for comparision. Bin edges shifted by half bin width, default False.

Returns:

Dictionary containing binned data for each window

Raises:
  • RuntimeError – If data is not loaded before binning or no binning config was set (see set_bin_configs).

  • ValueError – If win_size and win_delta are not set correctly.

Return type:

dict[str, ndarray]

count_events(sum_iters, start_step=None, stop_step=None)#

Count events in given range of iteration.

Parameters:
  • sum_iters (bool) – Sum counts of each iteration, instead of returning counts for each step.

  • start_step (tuple | None) – Start step of the lens iteration (iter, step) (including).

  • stop_step (tuple | None) – Stop step of the lens iteration (iter, step) (excluding).

Returns:

Dict containing the number of events for each lens iteration.

Return type:

dict

export(path, file_format, proj_axes=None, ranges=None, norm_step_size=False, binding_energy_scale=False, incident_energy=None, eln_path=None, delimiter=',')#

Export loaded data to file in ‘csv’ or ‘nxs’ format. If ‘csv’ is chosen, the data is needs to be projected at least along one axis.

Parameters:
  • path (str) – Path to which the data is saved. Including filename but excluding extension.

  • file_format (str) – Format of the file to which the data is saved (‘csv’ or ‘hdf5’).

  • proj_axes (list | None) – List containing all axes onto which the projection is performed, e.g., [0,1]. Default None, the data is not projected and saved as is (only for ‘hdf5’).

  • ranges – List containing ranges for axes (e.g., [[50, 101], [0,50], None]), if None entire range of axes is used (default entire range of each axis).

  • norm_step_size (bool) – Normalize data with step size before export (default False).

  • binding_energy_scale (bool) – Export binding energy instead of kinetic energy (default False).

  • incident_energy (float) – Custom incident energy in eV (default None, extract from metadata). If binding_energy_scale is False, this argument is ignored.

  • eln_path (str | None) – NeXus only: path to the ELN file where the metadata is stored. If None, standard metadata is used (default None, only relevant for ‘hdf5’ export).

  • delimiter (str) – Delimiter by which the data is separated (default ‘,’).

export_counts_to_csv(path, iter_range=None, delimiter=',')#

Export event counts to csv file.

Parameters:
  • path (str) – Path to which the data is saved. Including filename but excluding extension (csv).

  • iter_range (list | None) – Range of iterations to be exported (default None, all iterations).

  • delimiter (str) – Delimiter by which the data is separated (default ‘,’).

get_binned_data(proj_axes=None, ranges=None, norm_step_size=False, binding_energy_scale=False, incident_energy=None)#

Project loaded data onto given axes. Projections are possible onto 1 or 2 axes.

Parameters:
  • proj_axes (list | None) – List containing all axes onto which the projection is performed, e.g., [0,1].

  • ranges – List containing ranges for axes (e.g., [[50, 101], [0,50], None]), if None entire range of axes is used (default entire range of each axis).

  • norm_step_size (bool) – Normalize data with step size before plotting (default False).

  • binding_energy_scale (bool) – Export binding energy instead of kinetic energy (default False).

  • incident_energy (float) – Custom incident energy in eV (default None, extract from metadata). If binding_energy_scale is False, this argument is ignored.

Returns:

Axes values and list containing the projection (1 or 2D).

Return type:

tuple[list, list | dict]

get_event_counts(iter_range=None)#

Get the iterations and the corresponding counts.

Parameters:

iter_range (list | None) – Range of iterations to be exported (default None, all iterations).

Returns:

Tuple containing the iterations and the corresponding counts.

Return type:

tuple[ndarray, list]

load_and_transform(multithreading, start_step=None, stop_step=None, t0_list=None, wrap_low_energy=False, trigger_period=None, logging=True)#

Load raw data from file and transform to desired format.

Parameters:
  • multithreading (bool) – Use multithreading to load and transform data (True/False).

  • start_step (tuple | None) – Start step of the lens iteration (iter, step) (including).

  • stop_step (tuple | None) – Stop step of the lens iteration (iter, step) (excluding).

  • t0_list (list[float] | None) – List of custom t0s (default None, use previously set t0).

  • wrap_low_energy (bool) – Wrap low energy values to high energy values (default False). If True, the trigger period is read from ‘timing.txt’ file unless provided as trigger_period.

  • trigger_period (int | None) – Period between two trigger. When provided time of flight longer than one one trigger period can be loaded (default None).

  • logging (bool) – If True, log progress information (default True).

Raises:

RuntimeError – If the run was not initialized before loading data.

Returns:

Dictionary with iteration as key and list of transformed data for each given t0 as value

Return type:

dict[str, list[ndarray]]

load_transformed_data(path=None)#

Load transformed data from file. By default it is loaded from the path used for initialization of the loader.

Parameters:

path (str | None) – Path to file where transformed data is stored. If None, the path used for initialization is used.

log_metadata(pars=None)#

Get metadata of loaded data.

Parameters:

pars (list | None) – List of keys to be extracted from metadata (when ‘None’ all metadata will be returned), optional. Default is [‘analyzer.lensMode’, ‘analyzer.elementSet’, ‘analyzer.passEnergy’, ‘general.lensIterations’, ‘general.lensDwellTime’, ‘general.spectrumBeginEnergy’, ‘general.spectrumEndEnergy’, ‘general.centerEnergy’, ‘detector.t0’, ‘detector.t0Tolerance’]

Returns:

Dataframe consisting of metadata of loaded data.

Return type:

DataFrame

print_transform_stats()#

Print statistics of loaded and transformed data.

Return type:

None

save_transformed_data(path=None)#

Save transformed data to one file per iteration. Since to reload the data, the metadata needs to be loaded again. If changing the path, make sure the metadata is also in the new directory.

Parameters:

path (str | None) – Path where transformed data is saved. Deault is None, in this case the

set_bin_configs(cust_bin_confs, logging=True)#

Set custom binning configurations for the 3 parameters.

Parameters:
  • cust_bin_confs (list | None) – List of 3 custom binning configurations for the 3 parameters [min, max, edges], optional. F.e.: [[-1500, 1500, 101], [-1500, 1500, 101],[12000, 18000, 201]]

  • logging (bool) – Toggle progress information (default True).

set_iter_interval(start_iter, stop_iter)#

Set the interval of iterations to be loaded.

Parameters:
  • start_iter (int) – Start iteration (including).

  • stop_iter (int) – Stop iteration (excluding).

setup_counts_vars()#

Setup variables for event counts loading and processing.

setup_data_vars(t0=None, iter_interval=None)#

Setup variables for data loading and processing.

Parameters:
  • t0 (float | None) – Offset for t ticks (optional).

  • iter_interval (tuple[int, int] | None) – Interval of iterations to be loaded (start incl., stop excl.) (optional).

class artof.base_loader.TransformFormat(*values)#

Enum for data transformation formats. - raw: Load raw data in ticks (x,y,t). - raw_SI: Load raw data in SI units (x: m,y: m,t: s). - cylindrical: Load data in cylindrical coordinates (r: m, phi: rad, t: s). - spherical: Load data in spherical coordinates and associated energy (E: eV, theta: rad, phi: rad). - bipolar: Load data in bipolar coordinates (E: eV, alpha: rad, beta: rad). - kspace: Load data in kspace coordinates (E: eV, kx: 1/Å, ky: 1/Å).

BIPOLAR = 'bipolar'#
CYLINDRICAL = 'cylindrical'#
KSPACE = 'kspace'#
RAW = 'raw'#
RAW_SI = 'raw_SI'#
SPHERICAL = 'spherical'#
capitalize()#

Return a capitalized version of the string.

More specifically, make the first character have upper case and the rest lower case.

casefold()#

Return a version of the string suitable for caseless comparisons.

center(width, fillchar=' ', /)#

Return a centered string of length width.

Padding is done using the specified fill character (default is a space).

count()#

Return the number of non-overlapping occurrences of substring sub in string S[start:end].

Optional arguments start and end are interpreted as in slice notation.

encode(encoding='utf-8', errors='strict')#

Encode the string using the codec registered for encoding.

encoding

The encoding in which to encode the string.

errors

The error handling scheme to use for encoding errors. The default is ‘strict’ meaning that encoding errors raise a UnicodeEncodeError. Other possible values are ‘ignore’, ‘replace’ and ‘xmlcharrefreplace’ as well as any other name registered with codecs.register_error that can handle UnicodeEncodeErrors.

endswith()#

Return True if the string ends with the specified suffix, False otherwise.

suffix

A string or a tuple of strings to try.

start

Optional start position. Default: start of the string.

end

Optional stop position. Default: end of the string.

expandtabs(tabsize=8)#

Return a copy where all tab characters are expanded using spaces.

If tabsize is not given, a tab size of 8 characters is assumed.

find()#

Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].

Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.

format(*args, **kwargs)#

Return a formatted version of the string, using substitutions from args and kwargs. The substitutions are identified by braces (‘{’ and ‘}’).

format_map(mapping, /)#

Return a formatted version of the string, using substitutions from mapping. The substitutions are identified by braces (‘{’ and ‘}’).

index()#

Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].

Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.

isalnum()#

Return True if the string is an alpha-numeric string, False otherwise.

A string is alpha-numeric if all characters in the string are alpha-numeric and there is at least one character in the string.

isalpha()#

Return True if the string is an alphabetic string, False otherwise.

A string is alphabetic if all characters in the string are alphabetic and there is at least one character in the string.

isascii()#

Return True if all characters in the string are ASCII, False otherwise.

ASCII characters have code points in the range U+0000-U+007F. Empty string is ASCII too.

isdecimal()#

Return True if the string is a decimal string, False otherwise.

A string is a decimal string if all characters in the string are decimal and there is at least one character in the string.

isdigit()#

Return True if the string is a digit string, False otherwise.

A string is a digit string if all characters in the string are digits and there is at least one character in the string.

isidentifier()#

Return True if the string is a valid Python identifier, False otherwise.

Call keyword.iskeyword(s) to test whether string s is a reserved identifier, such as “def” or “class”.

islower()#

Return True if the string is a lowercase string, False otherwise.

A string is lowercase if all cased characters in the string are lowercase and there is at least one cased character in the string.

isnumeric()#

Return True if the string is a numeric string, False otherwise.

A string is numeric if all characters in the string are numeric and there is at least one character in the string.

isprintable()#

Return True if all characters in the string are printable, False otherwise.

A character is printable if repr() may use it in its output.

isspace()#

Return True if the string is a whitespace string, False otherwise.

A string is whitespace if all characters in the string are whitespace and there is at least one character in the string.

istitle()#

Return True if the string is a title-cased string, False otherwise.

In a title-cased string, upper- and title-case characters may only follow uncased characters and lowercase characters only cased ones.

isupper()#

Return True if the string is an uppercase string, False otherwise.

A string is uppercase if all cased characters in the string are uppercase and there is at least one cased character in the string.

join(iterable, /)#

Concatenate any number of strings.

The string whose method is called is inserted in between each given string. The result is returned as a new string.

Example: ‘.’.join([‘ab’, ‘pq’, ‘rs’]) -> ‘ab.pq.rs’

ljust(width, fillchar=' ', /)#

Return a left-justified string of length width.

Padding is done using the specified fill character (default is a space).

lower()#

Return a copy of the string converted to lowercase.

lstrip(chars=None, /)#

Return a copy of the string with leading whitespace removed.

If chars is given and not None, remove characters in chars instead.

static maketrans()#

Return a translation table usable for str.translate().

If there is only one argument, it must be a dictionary mapping Unicode ordinals (integers) or characters to Unicode ordinals, strings or None. Character keys will be then converted to ordinals. If there are two arguments, they must be strings of equal length, and in the resulting dictionary, each character in x will be mapped to the character at the same position in y. If there is a third argument, it must be a string, whose characters will be mapped to None in the result.

partition(sep, /)#

Partition the string into three parts using the given separator.

This will search for the separator in the string. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.

If the separator is not found, returns a 3-tuple containing the original string and two empty strings.

removeprefix(prefix, /)#

Return a str with the given prefix string removed if present.

If the string starts with the prefix string, return string[len(prefix):]. Otherwise, return a copy of the original string.

removesuffix(suffix, /)#

Return a str with the given suffix string removed if present.

If the string ends with the suffix string and that suffix is not empty, return string[:-len(suffix)]. Otherwise, return a copy of the original string.

replace(old, new, /, count=-1)#

Return a copy with all occurrences of substring old replaced by new.

count

Maximum number of occurrences to replace. -1 (the default value) means replace all occurrences.

If the optional argument count is given, only the first count occurrences are replaced.

rfind()#

Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].

Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.

rindex()#

Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].

Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.

rjust(width, fillchar=' ', /)#

Return a right-justified string of length width.

Padding is done using the specified fill character (default is a space).

rpartition(sep, /)#

Partition the string into three parts using the given separator.

This will search for the separator in the string, starting at the end. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.

If the separator is not found, returns a 3-tuple containing two empty strings and the original string.

rsplit(sep=None, maxsplit=-1)#

Return a list of the substrings in the string, using sep as the separator string.

sep

The separator used to split the string.

When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.

maxsplit

Maximum number of splits. -1 (the default value) means no limit.

Splitting starts at the end of the string and works to the front.

rstrip(chars=None, /)#

Return a copy of the string with trailing whitespace removed.

If chars is given and not None, remove characters in chars instead.

split(sep=None, maxsplit=-1)#

Return a list of the substrings in the string, using sep as the separator string.

sep

The separator used to split the string.

When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.

maxsplit

Maximum number of splits. -1 (the default value) means no limit.

Splitting starts at the front of the string and works to the end.

Note, str.split() is mainly useful for data that has been intentionally delimited. With natural text that includes punctuation, consider using the regular expression module.

splitlines(keepends=False)#

Return a list of the lines in the string, breaking at line boundaries.

Line breaks are not included in the resulting list unless keepends is given and true.

startswith()#

Return True if the string starts with the specified prefix, False otherwise.

prefix

A string or a tuple of strings to try.

start

Optional start position. Default: start of the string.

end

Optional stop position. Default: end of the string.

strip(chars=None, /)#

Return a copy of the string with leading and trailing whitespace removed.

If chars is given and not None, remove characters in chars instead.

swapcase()#

Convert uppercase characters to lowercase and lowercase characters to uppercase.

title()#

Return a version of the string where each word is titlecased.

More specifically, words start with uppercased characters and all remaining cased characters have lower case.

translate(table, /)#

Replace each character in the string using the given translation table.

table

Translation table, which must be a mapping of Unicode ordinals to Unicode ordinals, strings, or None.

The table must implement lookup/indexing via __getitem__, for instance a dictionary or list. If this operation raises LookupError, the character is left untouched. Characters mapped to None are deleted.

upper()#

Return a copy of the string converted to uppercase.

zfill(width, /)#

Pad a numeric string with zeros on the left, to fill a field of the given width.

The string is never truncated.