Utility functions (mpes.utils)

Utility functions for the mpes package

@author: R. Patrick Xian

mpes.utils.appendformat(filepath, form)

Append a format string to the end of a file path

Parameters
filepathstr

File path of interest

formstr

File format of interest

mpes.utils.arraybin(arr, bins, method='mean')

Resize an nD array by binning.

Parameters
arrnD array

N-dimensional array for binning.

binslist/tuple of int

Bins/Size shrinkage along every axis.

methodstr

Method for binning, ‘mean’ or ‘sum’.

Return

arrbinned : nD array

mpes.utils.bnorm(pval, pmax, pmin)

Normalize parameters by the bounds of the given values.

Parameters
pvalarray/numeric

A single value/collection of values to normalize.

pmax, pminnumeric, numeric

The maximum and the minimum of the values.

Return

Normalized values (with the same dimensions as pval).

mpes.utils.calcax(start, end, steps, ret='midpoint')

Calculate the positions of the axes values.

mpes.utils.concat(*arrays)

Concatenate a sequence of (up to 2D) array-like objects along a given axis.

mpes.utils.dictmerge(D, others)

Merge a dictionary with other dictionaries

Parameters
Ddict

Main dictionary.

otherslist/tuple/dict

Other dictionary or composite dictionarized elements.

Return
Ddict

Merged dictionary.

mpes.utils.find_nearest(val, narray)

Find the value closest to a given one in a 1D array.

Parameters
valfloat

Value of interest.

narray1D numeric array

The array to look for the nearest value.

Return
indint

Array index of the value nearest to the given one.

mpes.utils.intify(*nums)

Safely convert to integer (avoiding None).

Parameter
numslist/tuple/1D array

Numeric array to convert to integer.

Return
intnumslist

Converted list of numerics.

mpes.utils.multithresh(arr, lbs, ubs, ths)

Multilevel thresholding of a 1D array. Somewhat similar to bit depth reduction.

Parameters
arr1D array

Array for thresholding.

lbs, ubslist/tuple/array, list/tuple/array

Paired lower and upper bounds for each thresholding level.

thslist/tuple/array

Thresholds for the values within the paired lower and upper bounds.

mpes.utils.normspec(*specs, smooth=False, span=13, order=1)

Normalize a series of 1D signals.

Parameters
*specslist/2D array

Collection of 1D signals.

smoothbool | False

Option to smooth the signals before normalization.

span, orderint, int | 13, 1

Smoothing parameters of the LOESS method (see scipy.signal.savgol_filter()).

Return
normalized_specs2D array

The matrix assembled from a list of maximum-normalized signals.

mpes.utils.numFormatConversion(seq, form='int', **kwds)

When length keyword is not specified as an argument, the function returns a format-converted sequence of numbers. The function returns nothing when the conversion fails due to errors.

Parameters
seq1D numeric array

The numeric array to be converted.

formstr | ‘int’

The format to convert into.

Return
numseqconverted numeric type

The format-converted array.

mpes.utils.replist(entry, row, column)

Generator of nested lists with identical entries. Generated values are independent of one another.

Parameters
entrynumeric/str

repeated item in nested list

rowint

number of rows in nested list

columnint

number of columns in nested list

Return

Nested list

mpes.utils.revaxis(arr, axis=- 1)

Reverse an ndarray along certain axis.

Parameters
arrnD numeric array

array to invert

axisint | -1

the axis along which to invert

Return
revarrnD numeric array

axis-inverted nD array

mpes.utils.riffle(*arr)

Interleave multiple arrays of the same number of elements.

Parameter
*arrarray

A number of arrays

Return
riffarr1D array

An array with interleaving elements from each input array.

mpes.utils.shuffleaxis(arr, axes, direction='front')

Move multiple axes of a multidimensional array simultaneously to the front or end of its axis order

Parameters
arrndarray

array to be shuffled

axestuple of int

dimensions to be shuffled

directionstr | ‘front’

direction of shuffling (‘front’ or ‘end’)

Return
sharrndarray

dimension-shuffled array

mpes.utils.to_odd(num)

Convert a single number to its nearest odd number.

Parameters
numfloat/int

Number to convert.

Return
oddnumint

The nearest odd number.

mpes.utils.tqdmenv(env)

Choose tqdm progress bar executing environment.

Parameter
envstr

Name of the environment, ‘classic’ for ordinary environment, ‘notebook’ for Jupyter notebook.