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

filepath: str

File path of interest.

form: str

File format of interest.

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

Resize an nD array by binning.

Parameters

arr: nD array

N-dimensional array for binning.

bins: list/tuple of int

Bins/Size shrinkage along every axis.

method: str

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

Return

arrbinned: numpy array

Array after resizing.

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

Normalize parameters by the bounds of the given values.

Parameters

pval: array/numeric

A single value/collection of values to normalize.

pmax, pmin: numeric, 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.

Parameters

start, end, steps: numeric, numeric, numeric

Start, end positions and the steps.

ret: str | ‘midpoints’

Specification of positions.

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

D: dict

Main dictionary.

others: list/tuple/dict

Other dictionary or composite dictionarized elements.

Return

D: dict

Merged dictionary.

mpes.utils.find_nearest(val, narray)

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

Parameters

val: float

Value of interest.

narray: 1D numeric array

The array to look for the nearest value.

Return

ind: int

Array index of the value nearest to the given one.

mpes.utils.intify(*nums)

Safely convert to integer (avoiding None).

Parameter

nums: list/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

arr: 1D array

Array for thresholding.

lbs, ubs: list/tuple/array, list/tuple/array

Paired lower and upper bounds for each thresholding level.

ths: list/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

*specs: list/2D array

Collection of 1D signals.

smooth: bool | False

Option to smooth the signals before normalization.

span, order: int, int | 13, 1

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

Return

normalized_specs: 2D 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

seq: 1D numeric array

The numeric array to be converted.

form: str | ‘int’

The format to convert into.

Return

numseq: converted 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

entry: numeric/str

Repeated item in nested list.

row: int

Number of rows in nested list.

column: int

Number of columns in nested list.

Return

Nested list.

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

Reverse an ndarray along certain axis.

Parameters

arr: nD numeric array

array to invert

axis: int | -1

the axis along which to invert

Return

revarr: nD numeric array

axis-inverted nD array

mpes.utils.riffle(*arr)

Interleave multiple arrays of the same number of elements.

Parameter

*arr: array

A number of arrays.

Return

riffarr: 1D 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

arr: ndarray

Array to be shuffled.

axes: tuple of int

Dimensions to be shuffled.

direction: str | ‘front’

Direction of shuffling (‘front’ or ‘end’).

Return

sharr: ndarray

Dimension-shuffled array.

mpes.utils.to_odd(num)

Convert a single number to its nearest odd number.

Parameters

num: float/int

Number to convert.

Return

oddnum: int

The nearest odd number.

mpes.utils.tqdmenv(env)

Choose tqdm progress bar executing environment.

Parameter

env: str

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