Base classes (mpes.base)
¶
Information about the base classes, the building blocks of data processing classes.
@author: R. Patrick Xian
-
class
mpes.base.
FileCollection
(files=[], file_sorting=True, folder='')¶ File collecting and sorting class.
-
static
_sort_terms
(terms, parameter)¶ Sort terms according to parameter value.
Parameters
- terms: list
List of terms (e.g. strings).
- parameter: bool
Decision parameter for sorting.
Return
Sorted or unsorted terms.
-
property
fileID
¶ The sequence IDs of the files.
-
filter
(wexpr=None, woexpr=None, str_start=None, str_end=None)¶ Filter filenames by keywords.
Parameters
- wexpr: str | None
Expression in a name to leave in the filename list (w = with).
- woexpr: str | None
Expression in a name to leave out of the filename list (wo = without).
- str_start, str_end: int, int | None, None
Starting and ending indices of the filename string.
Return
- filteredFiles: list
List of filtered filenames.
-
gather
(folder='', identifier='/*.h5', f_start=None, f_end=None, f_step=1, file_sorting=True)¶ Gather files from a folder (specified at instantiation).
Parameters
- identifier: str | r’/*.h5’
File identifier used for glob.glob().
- f_start, f_end, f_step: int, int, int | None, None, 1
Starting, ending file id and the step. Used to construct a file selector.
- file_sorting: bool | True
Option to sort the files by their names.
-
property
nallfiles
¶ Total number of files with the same attributes. # of allfiles >= # of files (equal when no selection criterion is applied).
-
property
nfiles
¶ Total number of files for a specific workflow.
-
select
(ids=[], update='', ret=False)¶ Select gathered files by the filename ids.
Parameters
- ids: list/1D array | []
File IDs for selection.
- update: str | ‘’
File address list update condition, ‘remove’ = remove the selected files. ‘keep’ = keep the selected files and remove the rest. others strings or no action = do nothing. ‘’ = nothing happens (can be used in combination with ret=True to retrieve filtered file names).
- ret: str | ‘selected’
Return option, :’selected’: Return of the selected files. :’rest’: Return the rest of the files (not selected). :False: No action (return).
-
static
-
class
mpes.base.
MapParser
(files=[], file_sorting=True, folder=None, **kwds)¶ Parser of recorded parameters and turn into functional maps.
-
property
EMap
¶ The ToF to energy coordinate transform function.
Parameter
- parse_key: str | ‘coeffs’
Parsing key for extracting parameters.
-
property
Efile
¶ File containing the energy calibration information.
-
property
bfile
¶ File containing the binning parameters.
-
property
kMap
¶ The (row, column) to momentum coordinate transform function.
-
property
kfile
¶ File containing the momentum correction and calibration information.
-
static
listfind
(namelist, name, itemlist)¶ Find item in the itemlist according to the name index in the namelist.
-
static
mapConstruct
(mapfunc, **kwds)¶ Construct mapping function (partial function) by filling in certain known parameters.
-
static
parse
(parse_map, **mapkeys)¶ Parse map parameters stored in files.
Parameter
- parse_map: function
Run parse_map function to populate the class namespace.
Return
- flag: int (0 or 1)
Returns 1 if successful, 0 if not.
-
parse_Emap
(key='coeffs')¶ Retrieve the parameters to construct the energy conversion function.
-
parse_bfile
()¶ Retrieve the binning parameters.
-
parse_kmap
(key='coeffs')¶ Retrieve the parameters to construct the momentum conversion function.
-
parse_wmap
(key='warping')¶ Retrieve the parameters to construct the distortion correction function
-
property
wMap
¶ The distortion correction transform function.
-
property
-
mpes.base.
correctnd
(data, warping, func=<built-in function warpPerspective>, **kwds)¶ Apply a 2D transform to 2D in n-dimensional data.
-
mpes.base.
detrc2krc
(rdet, cdet, rstart, cstart, r0, c0, fr, fc, rstep, cstep)¶ Conversion from detector coordinates (rdet, cdet) to momentum coordinates (kr, kc).
-
mpes.base.
detxy2kxy
(xdet, ydet, xstart, ystart, x0, y0, fx, fy, xstep, ystep)¶ Conversion from detector coordinates (xd, yd) to momentum coordinates (kx, ky).
Parameters
- xdet, ydet: numeric, numeric
Pixel coordinates in the detector coordinate system.
- xstart, ystart: numeric, numeric
The starting pixel number in the detector coordinate system along the x and y axes used in the binning.
- x0, y0: numeric, numeric
The center pixel position in binned image used in calibration.
- fx, fy: numeric, numeric
Scaling factor along the x and y axes (in binned image).
- xstep, ystep: numeric, numeric
Binning step size along x and y directions.
-
mpes.base.
dfieldapply
(edf, dfield, X='X', Y='Y', newX='Xm', newY='Ym')¶ Application of the inverse displacement-field to the dataframe coordinates
-
mpes.base.
generateDfield
(rdeform_field, cdeform_field)¶ Generate inverse deformation field using inperpolation with griddata. Assuming the binning range of the input
rdeform_field
andcdeform_field
covers the whole detector.Parameters
- rdeform_field, cdeform_field: 2d array, 2d array
Row-wise and column-wise deformation fields.
-
mpes.base.
imrc2krc
(r, c, r0, c0, fr, fc)¶ Conversion from image coordinate (row, column) to momentum coordinates (kr, kc).
-
mpes.base.
imxy2kxy
(x, y, x0, y0, fx, fy)¶ Conversion from Cartesian coordinate in binned image (x, y) to momentum coordinates (kx, ky).
Parameters
- x, y: numeric, numeric
Components of the Cartesian coordinates.
- x0, y0: numeric, numeric
Origins of the Cartesian coordinates.
- fx, fy: numeric numeric
Numerical scaling in the conversion.
-
mpes.base.
loadClassAttributes
(form, load_addr)¶ Load class from saved attributes.
Parameters
- form: dump
Format to load from (only works for ‘dump’ right now).
- load_addr: str
The address to load the attributes from.
Return
Returns the loaded class
-
mpes.base.
mapping
(data, f, **kwds)¶ Mapping a generic function to multidimensional data with the possibility to supply keyword arguments.
Parameter
- data: numpy.ndarray
Data to map the function to.
- f: function
Function to map to data.
- **kwds: keyword arguments
Keyword arguments of the function map.
-
mpes.base.
perspectiveTransform
(x, y, M)¶ Implementation of the perspective transform (homography) in 2D.
Parameters
- x, y: numeric, numeric
Pixel coordinates of the original point.
- M: 2d array
Perspective transform matrix.
Return
- xtrans, ytrans: numeric, numeric
Pixel coordinates after projective/perspective transform.
-
mpes.base.
reshape2d
(data, apply_axis)¶ Reshape matrix to apply 2D function to.
Parameters
- data: numpy.ndarray
N-dimensional numerical array.
- apply_axis: tuple/list of int
The index of the axes to apply the transform to.
Return
- data: numpy.ndarray
Reshaped n-dimensional array.
-
mpes.base.
saveClassAttributes
(clss, form, save_addr)¶ Save class attributes.
Parameters
- clss: instance
Handle of the instance to be saved.
- form: str
Format to save in (‘h5’/’hdf5’, ‘mat’, or ‘dmp’/’dump’).
- save_addr: str
The address to save the attributes in.
-
mpes.base.
tof2evpoly
(a, E0, t)¶ Polynomial approximation of the time-of-flight to electron volt conversion formula.
Parameters
- a: 1D array
Polynomial coefficients.
- E0: float
Energy offset.
- t: numeric array
Drift time of electron.
Return
- E: numeric array
Converted energy