devctrl.data.transforms#

Apply mathematical transforms to data in a standardized way.

Transforms#

The functions in this module are designed to make it easy to apply mathematical operations on 2D data, where each column represents a different data type. The order of these data types is given by a “column-array”. For example columns = ['E', 'wl', 'dR/R', 'dT/T'] corresponds to the columns of the data array being energy, wavelength, reflectance change and transmittance change. If you now want to normalize your y-data, you can just apply the normalize transform on your array by also giving it the “columns” list: normalize(data, columns, {"docols": ["dR/R", "dT/T"]}), where the dictionary contains the keywords describing on which columns the transform should be applied. The real power of this system comes when the apply-keywords are already given: If you import the same transforms from spectrum.transforms, the apply-keywords are already preconfigured to ignore “E” and “wl”, since you usually do not want to transformations to your x-data. The normalization thus becomes just normalize(data, columns).

Registering transforms#

Transforms can be registered using the decorator @_register_transform. Registered transforms can then be redefined with different default parameters, for example to allow specialized transform modules to set default columns to skip.

Functions

apply_to_columns

Apply a transform to all selected columns.

derivative

Calculate the n-th derivative of column(s) <key> numerically. :param n: The derivative to calculate :param pre_func: A function taking and returning a 1d numpy array. If given, it is applied before every derivative. This may, for example, be useful if the data should be smoothened before taking the derivatives.

downsample_log

export_functions

Create new versions of all registered functions with new default arguments override_kwargs

get_data_normalize_scale

Return the scale factor that data must be multiplied with to be entirely within the interval [-1, 1]

integrate

Numerically integrate the data of column(s) <key> n times

normalize

Normalize all columns except skipcols so that the largest absolute value becomes either 1 or -1.

normalize_data

Return data scaled to be within [-1, 1]

normalize_to

Normalize the data so that for each column, the value at x or the mean value of the range x-dx,x+dx is set to (-)1.

notch

Notch filter at frequency w0 with quality factor Q.

remove_nans

Delete all rows where any number is nan

scale

Multiply data by factor

shift

Add shift to data

shift_to_zero

Shift data so that either the min or max value is zero

smoothen