2. Helpers
This script contains helper functions used by the specsscan class
- specsscan.helpers.get_scan_path(path, scan, basepath)
Returns the path to the given scan.
- Parameters:
path (Path | str) – Path under which to search. If empty, the basepath will be queried
scan (int) – Scan number
basepath (Path | str) – Default base path to search for scans under
- Raises:
FileNotFoundError – Raised if the path or scan cannot be found.
- Returns:
Path object to the given scan directory
- Return type:
Path
- specsscan.helpers.load_images(scan_path, df_lut=None, iterations=None, delays=None, tqdm_enable_nested=False)
Loads a 2D/3D numpy array of images for the given scan path with an optional averaging over the given iterations/delays. The function provides functionality to both load_scan and check_scan methods of the SpecsScan class. When iterations/delays is provided, average is performed over the iterations/delays for all delays/iterations.
- Parameters:
scan_path (Path) – object of class Path pointing to the scan folder
df_lut (pd.DataFrame, optional) – Pandas dataframe containing the contents of LUT.txt as obtained from parse_lut_to_df(). Defaults to None.
iterations (np.ndarray | slice | Sequence[int] | Sequence[slice], optional) – A 1-D array of the indices of iterations over which the images are to be averaged. The array can be a list, numpy array or a Tuple consisting of slice objects and integers. For ex.,
np.s_[1:10, 15, -1]
would be a valid input. Defaults to None.delays (np.ndarray | slice | int | Sequence[int] | Sequence[slice], optional) – A 1-D array of the indices of delays over which the images are to be averaged. The array can be a list, numpy array or a Tuple consisting of slice objects and integers. For ex.,
np.s_[1:10, 15, -1]
would be a valid input. Defaults to None.tqdm_enable_nested (bool, optional) – Option to enable a nested progress bar. Defaults to False.
- Raises:
ValueError – Raised if both iterations and delays is provided.
IndexError – Raised if no valid dimension for averaging is found.
- Returns:
A list of 2-D numpy arrays of raw data
- Return type:
list[np.ndarray]
- specsscan.helpers.get_raw2d(scan_list, raw_array)
Converts a 1-D array of raw scan names into 2-D based on the number of iterations
- Parameters:
scan_list (list[str]) – A list of AVG scan names.
raw_list (np.ndarray) – 1-D array of RAW scan names.
- Returns:
2-D numpy array of size for ex., (total_iterations, delays) for a delay scan.
- Return type:
np.ndarray
- specsscan.helpers.parse_lut_to_df(scan_path)
Loads the contents of LUT.txt file into a pandas data frame to be used as metadata.
- Parameters:
scan_path (Path) – Path object for the scan path
- Returns:
A pandas DataFrame
- Return type:
pd.DataFrame
- specsscan.helpers.get_coords(scan_path, scan_type, scan_info, df_lut=None)
Reads the contents of scanvector.txt file into a numpy array.
- Parameters:
scan_path (Path) – Path object for the scan path
scan_type (str) – Type of scan (delay, mirror etc.)
scan_info (dict[Any, Any]) – scan_info class dict
df_lut (pd.DataFrame, optional) – Pandas dataframe containing the contents of LUT.txt as obtained from parse_lut_to_df(). Defaults to None.
- Raises:
FileNotFoundError – Raised in neither scanvector.txt nor LUT.txt are found.
- Returns:
coords: 1-D numpy array containing coordinates of the scanned axis.
dim: string containing the name of the coordinate
- Return type:
tuple[np.ndarray, str]
- specsscan.helpers.compare_coords(axis_data)
Identifies the most changing column in a given 2-D numpy array.
- Parameters:
axis_data (np.ndarray) – 2-D numpy array containing LUT data
- Returns:
coords: Maximum changing column as a coordinate
index: Index of the coords in the axis_data array
- Return type:
tuple[np.ndarray, int]
- specsscan.helpers.parse_info_to_dict(path)
Parses the contents of info.txt file into a dictionary
- Parameters:
path (Path) – Path object pointing to the scan folder
- Returns:
Parsed info_dict dictionary
- Return type:
dict
- specsscan.helpers.handle_meta(df_lut, scan_info, config, fast_axes, slow_axes, projection, metadata=None, collect_metadata=False)
Helper function for the handling metadata from different files
- Parameters:
df_lut (pd.DataFrame) – Pandas dataframe containing the contents of LUT.txt as obtained from
parse_lut_to_df()
scan_info (dict) – scan_info class dict containing containing the contents of info.txt file
config (dict) – config dictionary containing the contents of config.yaml file
fast_axes (list[str]) – The fast-axis dimensions of the scan
slow_axes (list[str]) – The slow-axis dimensions of the scan
metadata (dict, optional) – Metadata dictionary with additional metadata for the scan. Defaults to empty dictionary.
collect_metadata (bool, optional) – Option to collect further metadata e.g. from EPICS archiver needed for NeXus conversion. Defaults to False.
- Returns:
metadata dictionary containing additional metadata from the EPICS archive.
- Return type:
dict
- specsscan.helpers.get_archiver_data(archiver_url, archiver_channel, ts_from, ts_to)
Extract time stamps and corresponding data from and EPICS archiver instance
- Parameters:
archiver_url (str) – URL of the archiver data extraction interface
archiver_channel (str) – EPICS channel to extract data for
ts_from (float) – starting time stamp of the range of interest
ts_to (float) – ending time stamp of the range of interest
- Returns:
The extracted time stamps and corresponding data
- Return type:
tuple[List, List]
- specsscan.helpers.find_scan(path, scan)
Search function to locate the scan folder
- Parameters:
path (Path) – Path object for data from the default config file
scan (int) – Scan number of the scan of interest
- Returns:
scan_path: Path object pointing to the scan folder
- Return type:
List[Path]
- specsscan.helpers.find_scan_type(path, scan_type)
Rudimentary function to print scan paths given the scan_type
- Parameters:
path (Path) – Path object pointing to the year, for ex., Path(“//nap32/topfloor/trARPES/PESData/2020”)
scan_type (str) – string containing the scan_type from the list [“delay”,”temperature”,”manipulator”,”mirror”,”single”]