Profile class

class IMTreatment.core.profile.Profile(x=[], y=[], mask=False, unit_x='', unit_y='', name='')[source]

Bases: object

Class representing a profile. You can use ‘make_unit’ to provide unities.

Parameters:
  • y (x,) – Profile values.
  • unit_y (unit_x,) – Values unities.
  • name (string, optionnal) – A name for the profile.
add_point(x, y)[source]

Add the given point to the profile.

add_points(prof)[source]

Add points from another profile.

augment_resolution(fact=2, interp='linear', inplace=True)[source]

Augment the temporal resolution of the profile.

Parameters:
  • fact (integer) – Resolution augmentation needed (default is ‘2’, for a result profile with twice more points)
  • interp (string in ['linear', 'nearest', slinear', 'quadratic, 'cubic']) – Specifies the kind of interpolation as a string (Default is ‘linear’). slinear’, ‘quadratic’ and ‘cubic’ refer to a spline interpolation of first, second or third order.
  • bool (inplace) –

    .

Note

If masked values are present, they are interpolated as well, using the surrounding values.

change_unit(axe, new_unit)[source]

Change the unit of an axe.

Parameters:
  • axe (string) – ‘y’ for changing the profile values unit ‘x’ for changing the profile axe unit
  • new_unit (Unum.unit object or string) – The new unit.
copy()[source]

Return a copy of the Profile object.

crop(intervx=None, intervy=None, ind=False, inplace=False)[source]

Crop the profile along ‘x’.

Parameters:
  • intervx (array of two numbers) – Bound values of x.
  • intervy (array of two numbers) – Bound values of y.
  • ind (Boolean, optionnal) – If ‘False’ (Default), ‘intervx’ and ‘intervy’ are values along x axis, if ‘True’, ‘intervx’ and ‘intervy’ are indices of values along x.
  • inplace (boolean, optional) –

    .

crop_masked_border(inplace=False)[source]

Remove the masked values at the border of the profile in place or not.

display(kind='plot', reverse=False, **plotargs)[source]

Display the profile.

Parameters:
  • reverse (Boolean, optionnal) – If ‘False’, x is put in the abscissa and y in the ordinate. If ‘True’, the inverse.
  • kind (string) – Kind of display to plot (‘plot’, ‘semilogx’, ‘semilogy’, ‘loglog’)
  • **plotargs (dict, optionnale) – Additional argument for the ‘plot’ command.
Returns:

fig – Reference to the displayed plot.

Return type:

Plot reference

evenly_space(kind_interpolation='linear', dx=None, inplace=False)[source]

Return a profile with evenly spaced x values. Use interpolation to get missing values.

Parameters:kind_interpolation (string or int, optional) – Specifies the kind of interpolation as a string (‘value’, ‘linear’, ‘nearest’, ‘zero’, ‘slinear’, ‘quadratic, ‘cubic’ where ‘slinear’, ‘quadratic’ and ‘cubic’ refer to a spline interpolation of first, second or third order) or as an integer specifying the order of the spline interpolator to use. Default is ‘linear’.
fill(kind='slinear', fill_value=0.0, inplace=False, crop=False)[source]

Return a filled profile (no more masked values).

Warning : If ‘crop’ is False, border masked values can’t be interpolated and are filled with ‘fill_value’ or the nearest value.

Parameters:
  • kind (string or int, optional) – Specifies the kind of interpolation as a string (‘value’, ‘linear’, ‘nearest’, ‘zero’, ‘slinear’, ‘quadratic, ‘cubic’ where ‘slinear’, ‘quadratic’ and ‘cubic’ refer to a spline interpolation of first, second or third order) or as an integer specifying the order of the spline interpolator to use. Default is ‘linear’.
  • fill_value (number, optional) – For kind = ‘value’, filling value.
  • inplace (boolean, optional) –

    .

  • crop (boolean, optional) –

    .

Returns:

prof – Filled profile

Return type:

Profile object

get_auto_correlation(window_len, raw=False)[source]

Return the auto-correlation profile.

This algorithm make auto-correlation for all the possible values, and an average of the resulting profile. Profile are normalized, so the central value of the returned profile should be 1.

Parameters:
  • window_len (integer) – Window length for sweep correlation.
  • raw (bool, optional) – If ‘True’, return an array If ‘False’ (default), return a profile
get_convolution(other_prof, mode='full')[source]

Return the convolution with the give profile.

Parameters:
  • other_prof (Profile object) –

    .

  • mode ({‘full’, ‘valid’, ‘same’}, optional) –
    ‘full’:
    By default, mode is ‘full’. This returns the convolution at each point of overlap, with an output shape of (N+M-1,). At the end-points of the convolution, the signals do not overlap completely, and boundary effects may be seen.
    ‘same’:
    Mode same returns output of length max(M, N). Boundary effects are still visible.
    ‘valid’:
    Mode valid returns output of length max(M, N) - min(M, N) + 1. The convolution product is only given for points where the signals overlap completely. Values outside the signal boundary have no effect.
Returns:

conv_prof – Result of the convolution

Return type:

Profile object

Notes

Use the numpy function ‘convolve’.

get_convolution_of_difference(other_profile, normalized=True)[source]

Return a convolution that use difference instead of multiplication.

Note

Difference is not normaized, but averaged on the available points.

get_dephasage(other_profile, conv='difference')[source]

Return the dephasage between the two profiles using convolution

Parameters:conv (string in ['classic', 'difference']) – The convection type to use
Returns:dep – Dephasage, in profiles unit
Return type:number
get_distribution(output_format='normalized', resolution=100, bw_method='scott')[source]

Return he distribution of y values by using gaussian kernel estimator.

Parameters:
  • output_format (string, optional) –

    ‘normalized’ (default) : give position probability (integral egal 1). ‘ponderated’ : give position probability ponderated by the number

    or points (integral egal number of points).

    ’concentration’ : give local concentration (in point per length).

  • resolution (integer) – Resolution of the resulting profile (number of values in it).
  • bw_method (str or scalar, optional) – The method used to calculate the estimator bandwidth. Can be ‘scott’, ‘silverman’ or a number to set manually the gaussians std (it should aproximately be the size of the density node you want to see). (see ‘scipy.stats.gaussian_kde’ documentation for more details)
Returns:

distrib – The y values distribution.

Return type:

Profile object

get_extrema_position(smoothing=None, ind=False, debug=False)[source]

Return the local extrema of the profile.

Parameters:
  • smoothing (number, optional) – Size of the gaussian smoothing to apply before extrema detection.
  • ind (bool, optional) – If ‘True’, return indice position, else, return position along x axis (default is ‘False’).
Returns:

min_pos, max_pos – .

Return type:

arrays of numbers

get_fitting(func, p0=None, output_param=False)[source]

Use non-linear least squares to fit a function, f, to the profile.

Parameters:
  • func (callable) – The model function, f(x, …). It must take the independent variable as the first argument and the parameters to fit as separate remaining arguments.
  • p0 (None, scalar, or M-length sequence) – Initial guess for the parameters. If None, then the initial values will all be 1 (if the number of parameters for the function can be determined using introspection, otherwise a ValueError is raised).
  • output_param (boolean, optional) – If ‘False’ (default), return only a Profile with fitted values If ‘True’, return also the parameters values.
Returns:

  • fit_prof (Profile obect) – The Fitted profile.
  • params (tuple, optional) – Fitting parameters.

get_gradient(position=None, wanted_dx=None)[source]

Return the profile gradient. If ‘position’ is renseigned, interpolations or finite differences are used to get the gradient at x = position. Else, a profile with gradient at profile points is returned. Warning : only work with evenly spaced x

Parameters:
  • position (number, optional) – Wanted point position
  • wanted_dx (number, optional) – interval on which compute gradient when position is renseigned (default is dx similar to axis).
get_integral()[source]

Return the profile integral, and is unit. Use the trapezoidal aproximation.

get_interpolated_values(x=None, y=None, ind=False)[source]

Get the interpolated (or not) value for given ‘x’ or ‘y’ values.

If several possibilities are possible, an array with all the results is returned.

Parameters:
  • x (number or array of number) – Value(s) of x, for which we want the y value.
  • y (number or array of number) – Value(s) of y, for which we want the x value.
  • ind (boolean) – If ‘True’, ‘x’ and ‘y’ are treated as indices, else, they are treated as position alog axis.
Returns:

i_values – Interpolated value(s).

Return type:

number or array

get_interpolator(kind='linear', bounds_error=True, fill_value=nan)[source]

Return an interpolator of the profile

Parameters:
  • kind (str or int, optional) – Specifies the kind of interpolation as a string (‘linear’, ‘nearest’, ‘zero’, ‘slinear’, ‘quadratic, ‘cubic’ where ‘slinear’, ‘quadratic’ and ‘cubic’ refer to a spline interpolation of first, second or third order) or as an integer specifying the order of the spline interpolator to use. Default is ‘linear’.
  • bounds_error (bool, optional) – If True, a ValueError is raised any time interpolation is attempted on a value outside of the range of x (where extrapolation is necessary). If False, out of bounds values are assigned fill_value. By default, an error is raised unless fill_value=”extrapolate”.
  • fill_value (array-like or (array-like, array_like) or "extrapolate") –
    • if a ndarray (or float), this value will be used to fill in for

    requested points outside of the data range. If not provided, then the default is NaN. The array-like must broadcast properly to the dimensions of the non-interpolation axes. - If a two-element tuple, then the first element is used as a fill value for x_new < x[0] and the second element is used for x_new > x[-1]. Anything that is not a 2-element tuple (e.g., list or ndarray, regardless of shape) is taken to be a single array-like argument meant to be used for both bounds as below, above = fill_value, fill_value. - If “extrapolate”, then points outside the data range will be extrapolated.

Returns:

interpolator – Take a single value ‘x’ and return the interpolated value of ‘y’.

Return type:

function

Note

Use scipy.interpolate module

get_pdf(bw_method='scott', resolution=1000, raw=False)[source]

Return the probability density function.

Parameters:
  • bw_method (str, scalar or callable, optional) – The method used to calculate the estimator bandwidth. This can be ‘scott’, ‘silverman’, a scalar constant or a callable. If a scalar, this will be used directly as kde.factor. If a callable, it should take a gaussian_kde instance as only parameter and return a scalar. If None (default), ‘scott’ is used. See ‘scipy.stats.kde’ for more details.
  • resolution (integer, optional) – Resolution of the returned pdf.
  • raw (boolean, optional) – If ‘True’, return an array, else, return a Profile object.
get_props()[source]

Print the Profile main properties

get_spectrum(wanted_x=None, welch_seglen=None, scaling='base', fill='linear', mask_error=True, detrend='constant')[source]

Return a Profile object, with the frequential spectrum of ‘component’, on the point ‘pt’.

Parameters:
  • wanted_x (2x1 array, optional) – Time interval in which compute spectrum (default is all).
  • welch_seglen (integer, optional) – If specified, welch’s method is used (dividing signal into overlapping segments, and averaging periodogram) with the given segments length (in number of points).
  • scaling (string, optional) – If ‘base’ (default), result are in component unit. If ‘spectrum’, the power spectrum is returned (in unit^2). If ‘density’, the power spectral density is returned (in unit^2/(1/unit_x))
  • fill (string or float) – Specifies the way to treat missing values. A value for value filling. A string (‘linear’, ‘nearest’, ‘zero’, ‘slinear’, ‘quadratic’, ‘cubic’ where ‘slinear’, ‘quadratic’ and ‘cubic’ refer to a spline interpolation of first, second or third order) for interpolation.
  • mask_error (boolean) – If ‘False’, instead of raising an error when masked value appear on time profile, ‘(None, None)’ is returned.
  • detrend (string, optional) – Method used to detrend the profile. Can be ‘none’, ‘constant’ (default) or ‘linear’.
Returns:

magn_prof – Magnitude spectrum.

Return type:

Profile object

get_value_position(value, ind=False)[source]

Return the interpolated position(s) of the wanted value.

Parameters:
  • value (number) –

    .

  • ind (boolean) – If ‘True’, return the value indices, else, return the ‘y’ position. (Default is ‘False’)
get_wavelet_transform(widths=None, fill='linear', raw=False, verbose=False)[source]

Return the wavelet transformation of the profile.

Parameters:
  • widths (array of number, optional) – Widths of the wavelet to use (by default use 100 homogeneously distributed wavelets)
  • fill (string or float) – Specifies the way to treat missing values. A value for value filling. A string (‘linear’, ‘nearest’, ‘zero’, ‘slinear’, ‘quadratic, ‘cubic’ where ‘slinear’, ‘quadratic’ and ‘cubic’ refer to a spline interpolation of first, second or third order) for interpolation.
  • raw (bool) – if ‘True’, return an array, else (default), return a ScalarField object.
  • verbose (boolean) – If ‘True’, display message on the computing advancement.

Warning

Only work with uniformely spaced data.

mask
max

Return the maxima along an axe.

Parameters:axe (integer, optionnal) – Axe along which we want the maxima.
Returns:max – Maxima along ‘axe’.
Return type:number
mean

Return the minima along an axe.

Parameters:axe (integer, optionnal) – Axe along which we want the minima.
Returns:max – Minima along ‘axe’.
Return type:number
min

Return the minima along an axe.

Parameters:axe (integer, optionnal) – Axe along which we want the minima.
Returns:max – Minima along ‘axe’.
Return type:number
remove_doublons(method='average', inplace=False, eps_rel=1e-06)[source]

Replace values associated to the same ‘x’ by their average.

Parameters:method (string in {'average', 'max', 'min'}) – Method used to remove the doublons.
remove_local_marginal_values(fact=5, neighb=20, inplace=False)[source]

Remove (mask) the local marginal values.

Parameters:
  • fact (positive number) – Number of standard deviation in the ‘acceptable’ value range. (default to 5)
  • neighb (positive number) – Size of the neighbourhood to consider to check if a value if marginal or not.
remove_marginal_values(fact=5, inplace=False)[source]

Remove (mask) the marginal values.

Parameters:fact (positive number) – Number of standard deviation in the ‘acceptable’ value range. (default to 5)
remove_nans(inplace=False)[source]

Remove the NaNs points from the profile.

remove_point(ind)[source]

Remove a point from the profile

Parameters:ind (integer) – Idice of the point to remove
rotate(angle, inplace=False)[source]

Rotate the profile.

Parameters:angle (number) – Rotation angle in radian.
scale(scalex=1.0, scaley=1.0, inplace=False)[source]

Change the scale of the axis.

Parameters:
  • scaley (scalex,) – scales along x and y
  • inplace (boolean, optional) – If ‘True’, scaling is done in place, else, a new instance is returned.
smooth(tos='uniform', size=None, direction='y', inplace=False, **kw)[source]

Return a smoothed profile. Warning : fill up the field

Parameters:
  • tos (string, optional) – Type of smoothing, can be ‘uniform’ (default) or ‘gaussian’ (See ndimage module documentation for more details)
  • size (number, optional) – Size of the smoothing (is radius for ‘uniform’ and sigma for ‘gaussian’). Default is 3 for ‘uniform’ and 1 for ‘gaussian’.
  • dir (string, optional) – In which direction smoothing (can be ‘x’, ‘y’ or ‘xy’).
  • inplace (boolean) – If ‘False’, return a smoothed profile else, smooth in place.
  • kw (dic) – Additional parameters for ndimage methods (See ndimage documentation)
spectral_filtering(fmin=None, fmax=None, order=2)[source]

Perform a spectral filtering (highpass, lowpass, bandpass).

Parameters:
  • fmax (fmin,) – Minimal and maximal frequencies
  • order (integer, optional) – Butterworth filter order
Returns:

filt_prof – Filtered profile

Return type:

Profile object

unit_x
unit_y
x
y