WrightTools.data package

Data class and associated.

class WrightTools.data.Data(axes, channels, constants=[], name='', source=None, **kwargs)[source]

Bases: object

Central multidimensional data class.

__init__(axes, channels, constants=[], name='', source=None, **kwargs)[source]

Create a Data object.

Parameters:
  • channels (list) – A list of Channel objects. Channels are also inherited as attributes using the channel name: data.ai0, for example.
  • axes (list) – A list of Axis objects. Axes are also inherited as attributes using the axis name: data.w1, for example.
  • constants (list) – A list of Axis objects, each with exactly one point.
  • **kwargs – Additional keyword arguments are added to the attrs dictionary and to the natural namespace of the object (if possible).
bring_to_front(channel)[source]

Bring a specific channel to the zero-indexed position in channels.

All other channels get pushed back but remain in order.

Parameters:channel (int or str) – Channel index or name.
chop(*args, **kwargs)[source]

Divide the dataset into its lower-dimensionality components.

Parameters:
  • axis (str or int (args)) – Axes of the returned data objects. Strings refer to the names of axes in this object, integers refer to their index. Provide multiple axes to return multidimensional data objects.
  • at (dict (kwarg)) – Choice of position along an axis. Keys are axis names, values are lists [position, input units]. If exact position does not exist, the closest valid position is used.
  • verbose (bool, optional (kwarg)) – Toggle talkback. Default is True.
Returns:

List of chopped data objects.

Return type:

list of WrightTools.data.Data

Examples

>>> data.axis_names
['d2', 'w1', 'w2']

Get all w1 wigners.

>>> datas = data.chop('d2', 'w1')
>>> len(datas)
51

Get 2D frequency at d2=0 fs.

>>> datas = data.chop('w1', 'w2', at={'d2': [0, 'fs']})
>>> len(datas)
0
>>> datas[0].axis_names
['w1', 'w2']
>>> datas[0].d2.points
0.

See also

collapse()
Collapse the dataset along one axis.
split()
Split the dataset while maintaining its dimensionality.
clip(channel=0, *args, **kwargs)[source]

Call Channel.clip.

Wrapper method for Channel.clip.

Parameters:channel (int or str) – The channel to call clip on.
collapse(axis, method='integrate')[source]

Collapse the dataset along one axis.

Parameters:
  • axis (int or str) – The axis to collapse along.
  • method ({'integrate', 'average', 'sum', 'max', 'min'} (optional)) – The method of collapsing the given axis. Method may also be list of methods corresponding to the channels of the object. Default is integrate. All methods but integrate disregard NANs.

See also

chop()
Divide the dataset into its lower-dimensionality components.
split()
Split the dataset while maintaining its dimensionality.
convert(destination_units, verbose=True)[source]

Convert all compatable constants and axes to given units.

Parameters:
  • destination_units (str) – Destination units.
  • verbose (bool (optional)) – Toggle talkback. Default is True.

See also

Axis.convert()
Convert a single axis object to compatable units. Call on an axis object in data.axes or data.constants.
copy()[source]

Copy the object.

Returns:A deep copy of the data object.
Return type:data
dOD(signal_channel, reference_channel, method='digital')[source]

For transient absorption, convert zi signal from dI to dOD.

Parameters:
  • signal_channel (int or str) – Index or name of signal (dI) channel.
  • reference_channel (int or str) – Index or name of reference (I) channel.
  • method ({'digital', 'boxcar'} (optional)) – Shots processing method. Default is digital.

Notes

dOD is calculated as

\[-\log_{10}\left(\frac{I+dI}{I}\right)\]

where I is the reference channel and dI is the signal channel.

dimensionality

Get dimensionality of Data object.

divide(divisor, channel=0, divisor_channel=0)[source]

Divide a given channel by another data object.

Divisor may be self. All axes in divisor must be contained in self.

Parameters:
  • divisor (data) – The denominator in the division.
  • channel (int or str) – The channel to divide into. The result will be written into this channel.
  • divisor_channel (int or str) – The channel in the divisor object to use.
flip(axis)[source]

Flip direction of arrays along an axis.

Changes the index of elements without changing their correspondance to axis positions.

Parameters:axis (int or str) – The axis to flip.
get_nadir(channel=0)[source]

Get the coordinates in units of the minimum in a channel.

Parameters:channel (int or str (optional)) – Channel. Default is 0.
Returns:Coordinates in units for each axis.
Return type:list of numbers
get_zenith(channel=0)[source]

Get the coordinates in units of the maximum in a channel.

Parameters:channel (int or str (optional)) – Channel. Default is 0.
Returns:Coordinates in units for each axis.
Return type:list of numbers
heal(channel=0, method='linear', fill_value=nan, verbose=True)[source]

Remove nans from channel using interpolation.

Parameters:
  • channel (int or str (optional)) – Channel to heal. Default is 0.
  • method ({'linear', 'nearest', 'cubic'} (optional)) – The interpolation method. Note that cubic interpolation is only possible for 1D and 2D data. See griddata for more information. Default is linear.
  • fill_value (number-like (optional)) – The value written to pixels that cannot be filled by interpolation. Default is nan.
  • verbose (bool (optional)) – Toggle talkback. Default is True.

Note

Healing may take several minutes for large datasets. Interpolation time goes as nearest, linear, then cubic.

info

Retrieve info dictionary about a Data object.

level(channel, axis, npts, verbose=True)[source]

For a channel, subtract the average value of several points at the edge of a given axis.

Parameters:
  • channel (int or str) – Channel to level.
  • axis (int or str) – Axis to level along.
  • npts (int) – Number of points to average for each slice. Positive numbers take leading points and negative numbers take trailing points.
  • verbose (bool (optional)) – Toggle talkback. Default is True.
m(abs_data, channel=0, this_exp='TG', indices=None, m=None, bounds_error=True, verbose=True)[source]

Perform m-factor corrections.

Assumes all absorption functions are independent, so we can normalize each axis individually.

Parameters:
  • abs_data (wt.data.Data object) – Absorption data to normalize by
  • channel (int or string (optional)) – Channel to correct (default is zero)
  • this_exp ({'TG', 'TA'} (optional)) – Experimental configuration. Default is TG. Note that TG data should be processed on the intensity level.
  • indices (list of integers (optional)) – axis indices. If None, indices are guessed from label_seed. Default is None.
  • m (function (optional)) – m-factor function. Should take arguments a1 and a2.
  • bounds_error (boolean (optional)) – Toggle bounds_error. Default is True.
  • verbose (boolean (optional)) – Toggle talkback. Default is True.

Notes

m-factors originally derived by Carlson and Wright. [1]

References

[1]Absorption and Coherent Interference Effects in Multiply Resonant Four-Wave Mixing Spectroscopy Roger J. Carlson, and John C. Wright Applied Spectroscopy 1989 43, 1195–1208 doi:10.1366/0003702894203408
map_axis(axis, points, input_units='same', verbose=True)[source]

Map points of an axis to new points using linear interpolation.

Out-of-bounds points are written nan.

Parameters:
  • axis (int or str) – The axis to map onto.
  • points (1D array-like) – The new points.
  • input_units (str (optional)) – The units of the new points. Default is same, which assumes the new points have the same units as the axis.
  • verbose (bool (optional)) – Toggle talkback. Default is True.
normalize(channel=0, axis=None)[source]

Normalize data in given channel so that null=0 and max=1.

Parameters:
  • channel (str or int (optional)) – Channel to normalize. Default is 0.
  • axis (str, int, or 1D list-like of str and int or None) – Axis/axes to normalize against. If None, normalizes by the entire dataset. Default is None.
offset(points, offsets, along, offset_axis, units='same', offset_units='same', mode='valid', method='linear', verbose=True)[source]

Offset one axis based on another axis’ values.

Useful for correcting instrumental artifacts such as zerotune.

Parameters:
  • points (1D array-like) – Points.
  • offsets (1D array-like) – Offsets.
  • along (str or int) – Axis that points array lies along.
  • offset_axis (str or int) – Axis to offset using offsets.
  • units (str (optional)) – Units of points array.
  • offset_units (str (optional)) – Units of offsets aray.
  • mode ({'valid', 'full', 'old'} (optional)) – Define how far the new axis will extend. Points outside of valid interpolation range will be written nan.
  • method ({'linear', 'nearest', 'cubic'} (optional)) – The interpolation method. Note that cubic interpolation is only possible for 1D and 2D data. See griddata for more information. Default is linear.
  • verbose (bool (optional)) – Toggle talkback. Default is True.
>>> points  # an array of w1 points
>>> offsets  # an array of d1 corrections
>>> data.offset(points, offsets, 'w1', 'd1')
remove_channel(channel)[source]

Remove channel from data.

Parameters:channel (int (index) or str (name)) – Channel to remove.
rename_attrs(**kwargs)[source]

Rename a set of attributes.

Keyword Arguments:
 
  • argument should have the key of a current axis or channel, (Each) – and a value which is a string of its new name.
  • name will be set to str(val), and its natural naming identifier (The) –
  • be wt.kit.string2identifier(str(val)) (will) –
save(filepath=None, verbose=True)[source]

Save using the pickle module.

Parameters:
  • filepath (str (optional)) – The savepath. ‘.p’ extension must be included. If not defined, the pickle will be saved in the current working directory with a timestamp.
  • verbose (bool (optional)) – Toggle talkback. Default is True.
Returns:

The filepath of the saved pickle.

Return type:

str

See also

from_pickle()
Generate a data object from a saved pickle.
scale(channel=0, kind='amplitude', verbose=True)[source]

Scale a channel.

Parameters:
  • channel (int or str (optional)) – The channel to scale. Default is 0.
  • kind ({'amplitude', 'log', 'invert'} (optional)) – The scaling operation to perform.
  • verbose (bool (optional)) – Toggle talkback. Default is True.
share_nans()[source]

Share not-a-numbers between all channels.

If any channel is nan at a given index, all channels will be nan at that index after this operation.

Uses the share_nans method found in wt.kit.

smooth(factors, channel=None, verbose=True)[source]

Smooth a channel using an n-dimenional kaiser window.

Parameters:
  • factors (int or list of int) – The smoothing factor. You may provide a list of smoothing factors for each axis.
  • channel (int or str or None (optional)) – The channel to smooth. If None, all channels will be smoothed. Default is None.
  • verbose (bool (optional)) – Toggle talkback. Default is True.
split(axis, positions, units='same', direction='below', verbose=True)[source]

Split the data object along a given axis, in units.

Parameters:
  • axis (int or str) – The axis to split along.
  • positions (number-type or 1D array-type) – The position(s) to split at, in units. If a non-exact position is given, the closest valid axis position will be used.
  • units (str (optional)) – The units of the given positions. Default is same, which assumes input units are identical to axis units.
  • direction ({'below', 'above'} (optional)) – Choose which group of data the points at positions remains with. Consider points [0, 1, 2, 3, 4, 5] and positions [3]. If direction is above the returned objects are [0, 1, 2] and [3, 4, 5]. If direction is below the returned objects are [0, 1, 2, 3] and [4, 5]. Default is below.
  • verbose (bool (optional)) – Toggle talkback. Default is True.
Returns:

A list of data objects.

Return type:

list

See also

chop()
Divide the dataset into its lower-dimensionality components.
collapse()
Collapse the dataset along one axis.
subtract(subtrahend, channel=0, subtrahend_channel=0)[source]

Subtract a given channel by another data object.

Subtrahend may be self. All axes in subtrahend must be contained in self.

Parameters:
  • subtrahend (data) – The data being subtracted by. Can be self.
  • channel (int or str) – The channel to subtract into. The result will be written into this channel.
  • subtrahend_channel (int or str) – The channel in the subtrahend object to use.
transform(transform=None)[source]

Transform the dataset using arbitrary coordinates, then regrids the data.

Parameters:transform (str) – The tranformation to perform. Str must use axis names. Only handles two axes at a time.
transpose(axes=None, verbose=True)[source]

Transpose the dataset.

Parameters:
  • axes (None or list of int (optional)) – The permutation to perform. If None axes are simply reversed. Default is None.
  • verbose (bool (optional)) – Toggle talkback. Default is True.
trim(channel, **kwargs)[source]

Call Channel.trim.

Wrapper method for Channel.trim.

Parameters:channel (int or str) – The channel index (or name) to trim.
zoom(factor, order=1, verbose=True)[source]

Zoom the data array using spline interpolation of the requested order.

The number of points along each axis is increased by factor. See scipy ndimage for more info.

Parameters:
  • factor (float) – The number of points along each axis will increase by this factor.
  • order (int (optional)) – The order of the spline used to interpolate onto new points.
  • verbose (bool (optional)) – Toggle talkback. Default is True.
WrightTools.data.join(datas, method='first', verbose=True, **kwargs)[source]

Join a list of data objects together.

For now datas must have identical dimensionalities (order and identity).

Parameters:
  • datas (list of data) – The list of data objects to join together.
  • method ({'first', 'sum', 'max', 'min', 'mean'} (optional)) – The method for how overlapping points get treated. Default is first, meaning that the data object that appears first in datas will take precedence.
  • verbose (bool (optional)) – Toggle talkback. Default is True.
Keyword Arguments:
 

objects (axis) – The axes of the new data object. If not supplied, the points of the new axis will be guessed from the given datas.

Returns:

A Data instance.

Return type:

data

class WrightTools.data.Axis(points, units, name, symbol_type=None, label_seed=[''], **kwargs)[source]

Bases: object

Axis class.

__init__(points, units, name, symbol_type=None, label_seed=[''], **kwargs)[source]

Create an Axis object.

Parameters:
  • points (1D array-like) – Axis points.
  • units (string) – Axis units.
  • name (string) – Axis name. Must be unique.
  • symbol_type (string (optional)) – Axis symbol type. If None, symbol_type is automatically generated. Default is None.
  • label_seed (list of strings) – Axis label subscripts. Default is [‘’].
  • **kwargs – Additional keyword arguments are added to the attrs dictionary and to the natural namespace of the object (if possible).
convert(destination_units)[source]

Convert axis to destination units.

Parameters:destination_units (string) – Destination units.
get_label(show_units=True, points=False, decimals=2)[source]

Get a LaTeX formatted label.

Parameters:
  • show_units (boolean (optional)) – Toggle showing units. Default is True.
  • points (boolean (optional)) – Toggle showing points. Default is False.
  • decimals (integer (optional)) – Number of decimals to show for numbers. Default is 2.
info

Axis info dictionary.

is_constant()[source]

Axis constant flag.

label

LaTeX formatted label.

max()[source]

Axis max, ignoring nans.

min()[source]

Axis min, ignoring nans.

class WrightTools.data.Channel(values, name, units=None, null=None, signed=None, label=None, label_seed=None, **kwargs)[source]

Bases: object

Channel.

__init__(values, name, units=None, null=None, signed=None, label=None, label_seed=None, **kwargs)[source]

Construct a channel object.

Parameters:
  • values (array-like) – Values.
  • name (string) – Channel name.
  • units (string (optional)) – Channel units. Default is None.
  • null (number (optional)) – Channel null. Default is None (0).
  • signed (booelan (optional)) – Channel signed flag. Default is None (guess).
  • label (string.) – Label. Default is None.
  • label_seed (list of strings) – Label seed. Default is None.
  • **kwargs – Additional keyword arguments are added to the attrs dictionary and to the natural namespace of the object (if possible).
clip(min=None, max=None, replace='nan')[source]

Clip (limit) the values in a channel.

Parameters:
  • min (number (optional)) – New channel minimum. Default is None.
  • max (number (optional)) – New channel maximum. Default is None.
  • replace ({'val', 'nan', 'mask'} (optional)) – Replace behavior. Default is nan.
give_values(values, null=None, signed=None)[source]

Give values.

Parameters:
  • values (array-like) – Values.
  • null (number (optional)) – Null. Default is None (0).
  • signed (boolean (optional)) – Signed flag. Default is None (guess).
info

Return Channel info dictionary.

invert()[source]

Invert channel values.

mag()[source]

Channel magnitude (maximum deviation from null).

major_extent

Maximum deviation from null.

max()[source]

Maximum, ignorning nans.

min()[source]

Minimum, ignoring nans.

minor_extent

Minimum deviation from null.

normalize(axis=None)[source]

Normalize a Channel, set null to 0 and the max to 1.

null()[source]

Null value.

trim(neighborhood, method='ztest', factor=3, replace='nan', verbose=True)[source]

Remove outliers from the dataset.

Identifies outliers by comparing each point to its neighbors using a statistical test.

Parameters:
  • neighborhood (list of integers) – Size of the neighborhood in each dimension. Length of the list must be equal to the dimensionality of the channel.
  • method ({'ztest'} (optional)) –

    Statistical test used to detect outliers. Default is ztest.

    ztest
    Compare point deviation from neighborhood mean to neighborhood standard deviation.
  • factor (number (optional)) – Tolerance factor. Default is 3.
  • replace ({'nan', 'mean', 'mask', number} (optional)) –

    Behavior of outlier replacement. Default is nan.

    nan
    Outliers are replaced by numpy nans.
    mean
    Outliers are replaced by the mean of its neighborhood.
    mask
    Array is masked at outliers.
    number
    Array becomes given number.
Returns:

Indicies of trimmed outliers.

Return type:

list of tuples

See also

clip()
Remove pixels outside of a certain range.
zmag

Channel magnitude.

zmax

Channel maximum.

zmin

Channel minimum.

znull

Channel null.

WrightTools.data.from_BrunoldrRaman(filepath, name=None, verbose=True)[source]

Create a data object from the Brunold rRaman instrument.

Expects one energy (in wavenumbers) and one counts value.

Parameters:
  • filepath (string, list of strings, or array of strings) – Path to .txt file.
  • name (string (optional)) – Name to give to the created data object. If None, filename is used. Default is None.
  • verbose (boolean (optional)) – Toggle talkback. Default is True.
Returns:

New data object(s).

Return type:

data

WrightTools.data.from_Cary50(filepath, verbose=True)[source]

Create a data object from a Cary 50 UV VIS absorbance file.

>>> import WrightTools as wt
>>> from WrightTools import datasets
>>> p = datasets.Cary50.CuPCtS_H2O_vis
>>> data = wt.data.from_Cary50(p)[0]
>>> artist = wt.artists.mpl_1D(data)
>>> artist.plot()

(Source code, png, pdf)

../_images/WrightTools-data-1.png
Parameters:
  • filepath (string) – Path to Cary50 output file (.csv).
  • verbose (boolean (optional)) – Toggle talkback. Default is True.
Returns:

New data object.

Return type:

data

WrightTools.data.from_COLORS(filepaths, null=None, name=None, cols=None, invert_d1=True, color_steps_as='energy', ignore=['num', 'w3', 'wa', 'dref', 'm0', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6'], even=True, verbose=True)[source]

Read a Data object from a COLORS filetype.

color_steps_as one in ‘energy’, ‘wavelength’

WrightTools.data.from_JASCO(filepath, name=None, kind='absorbance', verbose=True)[source]

Create a data object from a JASCO UV-VIS NIR file.

Parameters:
  • filepath (string) – Path to JASCO output file (.txt).
  • name (string (optional)) – Name to give to the created data object. If None, filename is used. Default is None.
  • kind ({'absorbance', 'diffuse reflectance'} (optional)) – Kind of data taken. Default is absorbance.
  • verbose (boolean (optional)) – Toggle talkback. Default is True.
Returns:

New data object.

Return type:

data

WrightTools.data.from_KENT(filepaths, null=None, name=None, ignore=['wm'], use_norm=False, delay_tolerance=0.1, frequency_tolerance=0.5, verbose=True)[source]

Read data object from KENT files.

WrightTools.data.from_PyCMDS(filepath, name=None, shots_processing_module='mean_and_std', verbose=True)[source]

Create a data object from a single PyCMDS output file.

Parameters:
  • filepath (str) – The file to load. Can accept .data, .fit, or .shots files.
  • name (str or None (optional)) – The name to be applied to the new data object. If None, name is read from file.
  • shots_processing_module (str (optional)) – The module used to process .shots files, if provided. Must be the name of a module in the shots_processing directory.
  • verbose (bool (optional)) – Toggle talkback. Default is True.
Returns:

A Data instance.

Return type:

data

WrightTools.data.from_scope(filepath, name=None, verbose=True)[source]

Create a Data object from an Ocean Optics .scope file.

Parameters:
  • filepath (path) – Filepath to .scope file.
  • name (string (optional)) – Name of Data object. Default is None (filename).
  • verbose (boolean (optional)) – Toggle talkback. Default is True.
Returns:

Return type:

WrightTools.data.Data object

WrightTools.data.from_shimadzu(filepath, name=None, verbose=True)[source]

Create a Data object from a Shimadzu txt file.

Parameters:
  • filepath (path) – Path to Shimadzu dataset.
  • name (string (optional)) – Data name. Default is None (filename).
  • verbose (boolean (optional)) – Toggle talkback. Default is True.
Returns:

Return type:

WrightTools.data.Data object

WrightTools.data.from_spcm(filepath, name=None, delimiter=', ', format=None, verbose=True)[source]

Create a data object from Becker & Hickl spcm software.

Parameters:
  • filepath (string) – Path to SPC-130 .asc file.
  • name (string (optional)) – Name to give to the created data object. If None, filename is used. Default is None.
  • delimiter (string (optional)) – The string used to separate values. Default is ‘,’.
  • format ({'ascii'} (optional)) – Force file to be interpreted as a specific format. Default is None (autorecognized).
  • verbose (boolean (optional)) – Toggle talkback. Default is True.
Returns:

Return type:

WrightTools.data.Data object

WrightTools.data.from_Tensor27(filepath, name=None, verbose=True)[source]

Create a data object from a Tensor27 FTIR file.

>>> import WrightTools as wt
>>> import matplotlib
>>> from WrightTools import datasets
>>> p = datasets.Tensor27.CuPCtS_powder_ATR
>>> data = wt.data.from_Tensor27(p)
>>> artist = wt.artists.mpl_1D(data)
>>> artist.plot()
>>> matplotlib.pyplot.xlim(1300,1700)
>>> matplotlib.pyplot.ylim(-0.005,.02)

(Source code, png, pdf)

../_images/WrightTools-data-2.png
Parameters:
  • filepath (string) – Path to Tensor27 output file (.dpt).
  • name (string (optional)) – Name to give to the created data object. If None, filename is used. Default is None.
  • verbose (boolean (optional)) – Toggle talkback. Default is True.
Returns:

New data object.

Return type:

data