libpyhat.transform package

Subpackages

Submodules

libpyhat.transform.cal_tran module

class libpyhat.transform.cal_tran.admm_ds(rho=1, beta=0.2, epsilon=1e-05, max_iter=100, verbose=True, reg='lasso')[source]

Bases: object

L2_norm(data)[source]
apply_transform(C)[source]
derive_transform(A, B)[source]
undo_L2_norm(data_normed, w)[source]
class libpyhat.transform.cal_tran.cal_tran(params)[source]

Bases: object

apply_transform(C)[source]
derive_transform(A, B)[source]
save_transform(outfile, wvls)[source]
libpyhat.transform.cal_tran.call_cal_tran(A, B, C, dataAmatchcol, dataBmatchcol, params, spect_label='wvl', dataAname='A', dataBname='B', dataCname='C')[source]
class libpyhat.transform.cal_tran.cca(n_components=1, ccatype=None)[source]

Bases: object

apply_transform(C)[source]
derive_transform(A, B)[source]
class libpyhat.transform.cal_tran.ds(fit_intercept=False)[source]

Bases: object

apply_transform(C)[source]
derive_transform(A, B)[source]
get_working_data(data)[source]
class libpyhat.transform.cal_tran.forward_backward_ds(t=0.001, svt=1, l1=1, epsilon=1e-05, max_iter=20, verbose=True)[source]

Bases: object

apply_transform(C)[source]
derive_transform(A, B)[source]
class libpyhat.transform.cal_tran.ipd_ds(t=0.0002, svt=10, l1=10, epsilon=1e-05, max_iter=50, verbose=True)[source]

Bases: object

apply_transform(C)[source]
derive_transform(A, B)[source]
class libpyhat.transform.cal_tran.no_transform[source]

Bases: object

apply_transform(C)[source]
derive_transform(A, B)[source]
class libpyhat.transform.cal_tran.piecewise_ds(win_size=5, pls=False, nc=5)[source]

Bases: object

apply_transform(C)[source]
derive_transform(A, B)[source]
class libpyhat.transform.cal_tran.ratio[source]

Bases: object

apply_transform(C)[source]
derive_transform(A, B)[source]

libpyhat.transform.cal_tran_cv module

libpyhat.transform.cal_tran_cv.cal_tran_cv(A, B, paramgrid, data_A_col, data_B_col, spect_label='wvl', meta_label='meta')[source]
libpyhat.transform.cal_tran_cv.call_cal_tran_cv(A, B, dataAmatchcol, dataBmatchcol, paramgrid, spect_label='wvl', dataAname='A', dataBname='B')[source]

libpyhat.transform.caltran_utils module

libpyhat.transform.caltran_utils.check_data(data1, data2, label1, label2, spect_label='wvl')[source]
libpyhat.transform.caltran_utils.multi_dot(arrays)[source]
libpyhat.transform.caltran_utils.prepare_data(A, B, metaColNameA='Target', metaColNameB='Target', averageRepeats=True, colvar='wvl', meta_label='meta')[source]
libpyhat.transform.caltran_utils.soft_thresh(X, thresh)[source]

Solves argmin_X 1/2 ||X-Y||_F^2 + thresh ||X||_1 proximal operator for l1-norm (sparsifier) See: http://www.simonlucey.com/soft-thresholding/

libpyhat.transform.caltran_utils.svt_thresh(X, thresh)[source]

Solves argmin_X 1/2 ||X-Y||_F^2 + thresh ||X||_* proximal operator for spectral norm (rank reducer) See: http://www-stat.stanford.edu/~candes/papers/SVT.pdf

libpyhat.transform.continuum module

libpyhat.transform.continuum.continuum_correction(data, fit_wvls, method='linear', poly_order=2, divide=True, verbose=True)[source]
libpyhat.transform.continuum.linear(data, fit_wvls)[source]

Compute a continuum using a line between two points

Parameters

data : PyHAT spectral data object

fit_wvls: [x1,x2] x1: lower wavelength to use as line starting point x2: higher wavelength to use as line end point

Returns: y: Array of y values at all wavelengths in the data object (not just those used in the fit)

libpyhat.transform.continuum.polynomial(data, fit_wvls, order=2)[source]

Compute a continuum using a polynomial fit.

Parameters

data : PyHAT spectral data object

fit_wvls: The wavelengths over which to perform the fit

Returns: y: Array of y values at all wavelengths in the data object (not just those used in the fit)

libpyhat.transform.continuum.regression(data, fit_wvls)[source]

Compute a continuum using a standard linear regression.

Parameters

data : PyHAT spectral data object

fit_wvls: The wavelengths over which to perform the fit

Returns: y: Array of y values at all wavelengths in the data object (not just those used in the fit)

libpyhat.transform.deriv module

libpyhat.transform.deriv.deriv(df, spect_label='wvl')[source]

libpyhat.transform.dim_red module

libpyhat.transform.dim_red.check_positive(data)[source]
libpyhat.transform.dim_red.dim_red(df, xcol, method, params, kws, load_fit=None, ycol=None)[source]

libpyhat.transform.interp module

libpyhat.transform.interp.interp(df, xnew, spect_label='wvl')[source]

libpyhat.transform.lra module

Low Rank Alignment algorithm by T. Boucher and C.J. Carey from https://github.com/all-umass/low_rank_alignment This method has been demonstrated to be effective for calibration transfer on LIBS spectra: http://www.aaai.org/ocs/index.php/AAAI/AAAI15/paper/download/9972/9880

libpyhat.transform.lra.demo()[source]

3-D noisy dollar example

libpyhat.transform.lra.dollar_sign(num_s_points, num_bar_points)[source]

returns a tuple of (3d points, 1d labels)

libpyhat.transform.lra.low_rank_align(X, Y, Cxy, d=None, mu=0.8)[source]
Input: data matrices X,Y, correspondence matrix Cxy,

embedding dimension d, and correspondence weight mu

Output: embedded X and embedded Y

libpyhat.transform.lra.low_rank_repr(X, n_dim)[source]
libpyhat.transform.lra.s_curve(n_pts)[source]

libpyhat.transform.mask module

libpyhat.transform.mask.mask(df, maskfile, maskvar='wvl')[source]

libpyhat.transform.meancenter module

Created on Sun Mar 27 13:07:07 2016

@author: [username deleted]

libpyhat.transform.meancenter.meancenter(df, col, previous_mean=None)[source]

libpyhat.transform.multiply_vector module

libpyhat.transform.multiply_vector.multiply_vector(df, vector, spect_label='wvl')[source]

libpyhat.transform.norm module

libpyhat.transform.norm.norm(df, ranges, col_var='wvl')[source]
libpyhat.transform.norm.norm_total(df)[source]

libpyhat.transform.peak_area module

libpyhat.transform.peak_area.peak_area(df, peaks_mins_file=None, spect_label='wvl')[source]

libpyhat.transform.remove_baseline module

libpyhat.transform.remove_baseline.remove_baseline(df, method='ALS', segment=True, params=None, spect_label='wvl')[source]

libpyhat.transform.scale module

libpyhat.transform.scale.do_scale(df_to_scale, df_to_fit=None, spect_label='wvl')[source]

libpyhat.transform.shift_spect module

libpyhat.transform.shift_spect.shift_spect(df, shifts, spect_label='wvl', meta_label='meta')[source]

This function takes a data frame containing spectra and shifts them by a specified amount.

Arguments: df = The data frame. Spectra should be stored in rows, with each column having a multi-indexed column name. The

top level should be the specified ‘spect_label’ string, the second level should be a floating point value indicating the wavelength.

shifts = The amounts by which the spectra should be shifted. spect_label = the string used to label spectral data. Defaults to ‘wvl’

libpyhat.transform.smooth module

libpyhat.transform.smooth.boxcar(y, window_size=3, axis=0, **kwargs)[source]

Smooth the input vector using the mean of the neighboring values, where neighborhood size is defined by the window.

Parameters

yarray

The vector to be smoothed.

window_sizeint

An odd integer describing the window size.

axisint

Ignored in the 1d case. In the 2d case, this is the axis along which to apply the convolution.

Returns

: array

The smoothed array.

libpyhat.transform.smooth.gaussian(y, window_size=3, sigma=2, axis=0, **kwargs)[source]

Apply a gaussian filter to smooth the input vector

Parameters

yarray

The input array

window_sizeint

An odd integer describing the size of the filter.

sigmafloat

The numver of standard deviation

libpyhat.transform.stretch module

libpyhat.transform.stretch.gethist_cdf(array, num_bins=128)[source]

This function calculates the cumulative distribution function of a given array and requires that both the input array and the number of bins be provided.

Parameters

arrayndarray

(n,m,p) array

Returns Returns: ———-

: cdf

A CDF (cumulative distribution function) graph that can be used for plotting.

: bins

The bins of the associated CDF graph

libpyhat.transform.stretch.histequ_stretch(array)[source]

Stretch a given ndarray using a histogram

Parameters

arrayndarray

(n,m,p) array

Returns

: ndarray

the processed ndarray

libpyhat.transform.stretch.inverse_stretch(array)[source]

Stretch a given ndarray using the inverse

Parameters

arrayndarray

(n,m,p) array

Returns

: ndarray

the processed ndarray

libpyhat.transform.stretch.linear_stretch(array, clip=2.0)[source]

Linearly stretch a given ndarray

Parameters

datandarray

(n,m,p) array

clipfloat

the amount that the image should be clipped by

Returns

: ndarray

the processed ndarray

libpyhat.transform.stretch.standard_deviation_stretch(array, sigma=2.0)[source]

Stretch a given ndarray by the standard deviation

Parameters

datandarray

(n,m,p) array

sigma : float

Returns

: ndarray

the processed ndarray

Module contents