Processor Utilities
Utility functions for the CRD file processor CRDFileProcessor
.
Many of the mathematically heavy routines
are outsourced here for JITing with
numba.
create_packages()
- rimseval.processor_utils.create_packages(shots: int, tofs_mapper: ndarray, all_tofs: ndarray) Tuple[ndarray, ndarray]
Create packages from data.
- Parameters:
shots – Number of shots per package
tofs_mapper – mapper for ions_per_shot to tofs
all_tofs – all arrival times / bins of ions
- Returns:
Data array where each row is a full spectrum, each line a package and a shot array on how many shots are there per pkg
dead_time_correction()
- rimseval.processor_utils.dead_time_correction(data: ndarray, nof_shots: ndarray, dbins: int) ndarray
Calculate dead time for a given spectrum.
- Parameters:
data – Data array, histogram in bins. 2D array (even for 1D data!)
nof_shots – Number of shots, 1D array of data
dbins – Number of dead bins after original bin (total - 1).
- Returns:
Dead time corrected data array.
gaussian_fit_get_max()
- rimseval.processor_utils.gaussian_fit_get_max(xdata: ndarray, ydata: ndarray) float
Fit a Gaussian to xdata and ydata and return the xvalue of the peak.
- Parameters:
xdata – X-axis data
ydata – Y-axis data
- Returns:
Maximum mof the peak on the x-axis
integrals_bg_corr()
- rimseval.processor_utils.integrals_bg_corr(integrals: ndarray, int_names: ndarray, int_ch: ndarray, bgs: ndarray, bgs_names: ndarray, bgs_ch: ndarray, int_pkg: ndarray = None, bgs_pkg: ndarray = None) Tuple[ndarray, ndarray]
Calculate background correction for integrals with given backgrounds.
This takes the integrals that already exist and updates them by subtracting the backgrounds. Multiple backgrounds per integral can be defined. Important is that the names of the backgrounds are equal to the names of the integrals that they need to be subtracted from and that the names of the integrals are unique. The latter point is tested when defining the integrals.
Note
This routine currently cannot be jitted since we are using an
np.where
statement. If required for speed, we can go an replace that statement. Most likely, this is plenty fast enough though.- Parameters:
integrals – Integrals and uncertianties for all defined peaks.
int_names – Name of the individual peaks. Must be unique values!
int_ch – Number of channels for the whole peak width.
bgs – Backgrounds and their uncertianties for all defined backgrounds.
bgs_names – Peaks each backgrounds go with, can be multiple.
bgs_ch – Number of channels for background width.
int_pkg – Packaged integrals, if exist: otherwise provide
None
bgs_pkg – Packaged backgrounds, if exist: otherwise provide
None
- Returns:
Corrected data and data_packages.
integrals_summing()
- rimseval.processor_utils.integrals_summing(data: ndarray, windows: Tuple[ndarray], data_pkg: ndarray = None) Tuple[ndarray, ndarray]
Sum up the integrals within the defined windows and return them.
- Parameters:
data – Data to be summed over.
windows – The windows to be investigated (using numpy views)
data_pkg – Package data (optional), if present.
- Returns:
integrals for data, integrals for data_pkg
mask_filter_max_ions_per_time()
- rimseval.processor_utils.mask_filter_max_ions_per_time(ions_per_shot: array, tofs: array, max_ions: int, time_chan: int) array
Return indices where more than wanted shots are in a time window.
- Parameters:
ions_per_shot – How many ions are there per shot? Also defines the shape of the return array.
tofs – All ToFs. Must be of length ions_per_shot.sum().
max_ions – Maximum number of ions that are allowed in channel window.
time_chan – Width of the window in channels (bins).
- Returns:
Boolean array of shape like ions_per_shot if more are in or not.
mask_filter_max_ions_per_tof_window()
- rimseval.processor_utils.mask_filter_max_ions_per_tof_window(ions_per_shot: array, tofs: array, max_ions: int, tof_window: array) array
Return indices where more than wanted shots are in a given ToF window.
- Parameters:
ions_per_shot – How many ions are there per shot? Also defines the shape of the return array.
tofs – All ToFs. Must be of length ions_per_shot.sum().
max_ions – Maximum number of ions that are allowed in channel window.
tof_window – Start and stop time of the ToF window in channel numbers.
- Returns:
Boolean array of shape like ions_per_shot if more are in or not.
mass_calibration()
- rimseval.processor_utils.mass_calibration(params: array, tof: array, return_params: bool = False) array | Tuple[array]
Perform the mass calibration.
- Parameters:
params – Parameters for mass calibration.
tof – Array with all the ToFs that need a mass equivalent.
return_params – Return parameters as well? Defaults to False
- Returns:
Mass for given ToF.
mass_to_tof()
- rimseval.processor_utils.mass_to_tof(m: ndarray | float, tm0: float, const: float) ndarray | float
Functional prescription to turn mass into ToF.
Returns the ToF with the defined functional description for a mass calibration. Two parameters are required. The equation, with parameters defined as below, is as following:
\[t = \sqrt{m} \cdot \mathrm{const} + t_{0}\]- Parameters:
m – mass
tm0 – parameter 1
const – parameter 2
- Returns:
time
multi_range_indexes()
- rimseval.processor_utils.multi_range_indexes(rng: array) array
Create multi range indexes.
If a range is given as (from, to), the from will be included, while the to will be excluded.
- Parameters:
rng – Range, given as a numpy array of two entries each.
- Returns:
A 1D array with all the indexes spelled out. This allows for viewing numpy arrays for multiple windows.
remove_shots_from_filtered_packages_ind()
- rimseval.processor_utils.remove_shots_from_filtered_packages_ind(shots_rejected: array, len_indexes: int, filtered_pkg_ind: array, pkg_size: int) Tuple[array, array]
Remove packages that were already filtered pkg from ion filter indexes.
This routine is used to filter indexes in case a package filter has been applied, and now an ion / shot based filter needs to be applied.
- Parameters:
shots_rejected – Array of indexes with rejected shots.
len_indexes – length of the indexes that the rejected shots are from.
pkg_size – Size of the packages that were created.
filtered_pkg_ind – Array with indexes of packages that have been filtered.
- Returns:
List of two Arrays with shots_indexes and shots_rejected, but filtered.
remove_shots_from_packages()
- rimseval.processor_utils.remove_shots_from_packages(pkg_size: int, shots_rejected: array, ions_to_tof_map: array, all_tofs: array, data_pkg: array, nof_shots_pkg: array, pkg_filtered_ind: array = None) Tuple[array, array]
Remove shots from packages.
This routine can take a list of individual ions and remove them from fully packaged data. In addition, it can also take a list of packages that, with respect to the raw data, have previously been removed. This is useful in order to filter individual shots from packages after packages themselves have been filtered.
- Parameters:
pkg_size – How many shots were grouped into a package originally?
shots_rejected – Index array of the rejected shots.
ions_to_tof_map – Mapping array where ions are in all_tof array.
all_tofs – Array containing all the ToFs.
data_pkg – Original data_pkg before filtering.
nof_shots_pkg – Original nof_shots_pkg before filtering.
pkg_filtered_ind – Indexes where the filtered packages are.
- Returns:
Filtered data_pkg and nof_shots_pkg arrays.
sort_data_into_spectrum()
- rimseval.processor_utils.sort_data_into_spectrum(ions: ndarray, bin_start: int, bin_end: int) ndarray
Sort ion data in 1D array into an overall array and sum them up.
- Parameters:
ions – Arrival time of the ions - number of time bin
bin_start – First bin of spectrum
bin_end – Last bin of spectrum
- Returns:
arrival bins summed up
tof_to_mass()
- rimseval.processor_utils.tof_to_mass(tm: ndarray | float, tm0: float, const: float) ndarray | float
Functional prescription to turn ToF into mass.
Returns the mass with the defined functional description for a mass calibration. Two parameters are required. The equation, with parameters defined as below, is as following:
\[m = \left(\frac{tm - tm_{0}}{\mathrm{const}}\right)^{2}\]- Parameters:
tm – time or channel
tm0 – parameter 1
const – parameter 2
- Returns:
mass m