ScalarField class

class IMTreatment.core.scalarfield.ScalarField[source]

Bases: IMTreatment.core.field.Field

Class representing a scalar field (2D field, with one component on each point).

change_dtype(new_type)[source]

Change the values dtype.

change_unit(axe, new_unit)[source]

Change the unit of an axe.

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

Return a copy of the scalarfield.

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

Crop the area in respect with given intervals.

Parameters:
  • intervx (array, optional) – interval wanted along x
  • intervy (array, optional) – interval wanted along y
  • ind (boolean, optional) – If ‘True’, intervals are understood as indices along axis. If ‘False’ (default), intervals are understood in axis units.
  • inplace (boolean, optional) – If ‘True’, the field is croped in place.
crop_masked_border(hard=False, inplace=False)[source]

Crop the masked border of the field in place or not.

Parameters:hard (boolean, optional) – If ‘True’, partially masked border are croped as well.
display(component=None, kind=None, **plotargs)[source]

Display the scalar field.

Parameters:
  • component (string, optional) – Component to display, can be ‘values’ or ‘mask’
  • kind (string, optinnal) – If ‘imshow’: (default) each datas are plotted (imshow), if ‘contour’: contours are ploted (contour), if ‘contourf’: filled contours are ploted (contourf).
  • **plotargs (dict) – Arguments passed to the ‘contourf’ function used to display the scalar field.
Returns:

fig – Reference to the displayed figure.

Return type:

figure reference

export_to_scatter(mask=None)[source]

Return the scalar field under the form of a pts.Points object.

Parameters:mask (array of boolean, optional) – Mask to choose values to extract (values are taken where mask is False).
Returns:Pts – Contening the ScalarField points.
Return type:pts.Points object
extend(nmb_left=0, nmb_right=0, nmb_up=0, nmb_down=0, value=None, inplace=False, ind=True)[source]

Add columns or lines of masked values at the scalarfield.

Parameters:
  • nmb_**** (integers) – Number of lines/columns to add in each direction.
  • value (None or number) – Value used to fill the new columns and lines. If ‘value’ is not given, new columns and lines are masked.
  • inplace (bool) – If ‘False’, return a new extended field, if ‘True’, modify the field inplace.
Returns:

Extended_field – Extended field.

Return type:

Field object, optional

fill(kind='linear', value=0.0, inplace=False, reduce_tri=True, crop=False)[source]

Fill the masked part of the array.

Parameters:
  • kind (string, optional) – Type of algorithm used to fill. ‘value’ : fill with the given value ‘nearest’ : fill with the nearest value ‘linear’ (default): fill using linear interpolation (Delaunay triangulation) ‘cubic’ : fill using cubic interpolation (Delaunay triangulation)
  • value (number) – Value used to fill (for kind=’value’).
  • inplace (boolean, optional) – If ‘True’, fill the ScalarField in place. If ‘False’ (default), return a filled version of the field.
  • reduce_tri (boolean, optional) – If ‘True’, treatment is used to reduce the triangulation effort (faster when a lot of masked values) If ‘False’, no treatment (faster when few masked values)
  • crop (boolean, optional) – If ‘True’, SF borders are croped before filling.
get_histogram(cum=False, normalized=False, bins=None, range=None)[source]

Return the image histogram.

Parameters:cum (boolean) – If True, get a cumulative histogram.
Returns:hist – Histogram.
Return type:array of numbers
get_interpolator(interp='linear')[source]

Return the field interpolator.

Parameters:kind ({‘linear’, ‘cubic’, ‘quintic’}, optional) – The kind of spline interpolation to use. Default is ‘linear’.
get_nearest_extrema(pts, extrema='max', ind=False)[source]

For a given set of points, return the positions of the nearest local extrema (minimum or maximum).

Parameters:pts (Nx2 array) – Set of pts.Points position.
Returns:extremum_pos
Return type:Nx2 array
get_norm(norm=2, normalized='perpoint')[source]

Return the field norm

get_profile(direction, position, ind=False, interp='linear')[source]

Return a profile of the scalar field, at the given position (or at least at the nearest possible position). If position is an interval, the fonction return an average profile in this interval.

Parameters:
  • direction (string in ['x', 'y']) – Direction along which we choose a position.
  • position (float, interval of float or string) – Position, interval in which we want a profile or ‘all’
  • ind (boolean) – If ‘True’, position has to be given in indices If ‘False’ (default), position has to be given in axis unit.
  • interp (string in ['nearest', 'linear']) – if ‘nearest’, get the profile at the nearest position on the grid, if ‘linear’, use linear interpolation to get the profile at the exact position
Returns:

profile – Wanted profile

Return type:

prof.Profile object

get_props()[source]

Print the ScalarField main properties

get_spatial_autocorrelation(direction, window_len=None)[source]

Return the spatial auto-correlation along the wanted direction.

Take the middle point for reference for correlation computation.

Parameters:
  • direction (string) – ‘x’ or ‘y’
  • window_len (integer, optional) – Window length for sweep correlation. if ‘None’ (default), all the signal is used, and boundary effect can be seen.
Returns:

profile – Spatial correlation

Return type:

prof.Profile object

get_spatial_spectrum(direction, intervx=None, intervy=None, welch_seglen=None, scaling='base', fill='linear')[source]

Return a spatial spectrum.

Parameters:
  • direction (string) – ‘x’ or ‘y’.
  • and intervy (intervx) – To chose the zone where to calculate the spectrum. If not specified, the biggest possible interval is choosen.
  • 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_axe))
  • fill (string or float) – Specifies the way to treat missing values. A value for value filling. A string (‘linear’, ‘nearest’ or ‘cubic’) for interpolation.
Returns:

spec – Magnitude spectrum.

Return type:

prof.Profile object

Notes

If there is missing values on the field, ‘fill’ is used to linearly interpolate the missing values (can impact the spectrum).

get_value(x, y, ind=False, unit=False)[source]

Return the scalar field value on the point (x, y). If ind is true, x and y are indices, else, x and y are value on axes (interpolated if necessary).

get_zones_centers(bornes=[0.75, 1], rel=True, kind='ponderated')[source]

Return a pts.Points object contening centers of the zones lying in the given bornes.

Parameters:
  • bornes (2x1 array, optionnal) – Trigger values determining the zones. ‘[inferior borne, superior borne]’
  • rel (Boolean) – If ‘rel’ is ‘True’ (default), values of ‘bornes’ are relative to the extremum values of the field. If ‘rel’ is ‘False’, values of bornes are treated like absolute values.
  • kind (string, optional) – if ‘kind’ is ‘center’, given points are geometrical centers, if ‘kind’ is ‘extremum’, given points are extrema (min or max) on zones if ‘kind’ is ‘ponderated’(default, given points are centers of mass, ponderated by the scaler field.
Returns:

pts – Contening the centers coordinates

Return type:

pts.Points object

import_from_arrays(axe_x, axe_y, values, mask=None, unit_x='', unit_y='', unit_values='', dtype=<class 'float'>, dontchecknans=False, dontcheckunits=False)[source]

Set the field from a set of arrays.

Parameters:
  • axe_x (array) – Discretized axis value along x
  • axe_y (array) – Discretized axis value along y
  • values (array or masked array) – Values of the field at the discritized points
  • unit_x (String unit, optionnal) – Unit for the values of axe_x
  • unit_y (String unit, optionnal) – Unit for the values of axe_y
  • unit_values (String unit, optionnal) – Unit for the scalar field
  • dontchecknans (boolean) – Don’t check for nans values (faster)
  • dontcheckunits (boolean) – Don’t check for unit consistency (faster)
  • dtype (Numerical type) – Numerical type to store the data to. Should be a type supported by numpy arrays. Default to ‘float’.
integrate_over_line(direction, interval)[source]

Return the integral on an interval and along a direction (‘x’ or ‘y’). Discretized integral is computed with a trapezoidal algorithm.

Parameters:
  • direction (string in ['x', 'y']) – Direction along which we choose a position.
  • interval (interval of numbers) – Interval on which we want to calculate the integral.
Returns:

  • integral (float) – Result of the integrale calcul
  • unit (Unit object) – Unit of the result

integrate_over_surface(intervx=None, intervy=None)[source]

Return the integral on a surface. Discretized integral is computed with a very rustic algorithm which just sum the value on the surface. if ‘intervx’ and ‘intervy’ are given, return the integral over the delimited surface. WARNING : Only works (and badly) with regular axes.

Parameters:
  • intervx (interval of numbers, optional) – Interval along x on which we want to compute the integrale.
  • intervy (interval of numbers, optional) – Interval along y on which we want to compute the integrale.
Returns:

  • integral (float) – Result of the integrale computation.
  • unit (Unit object) – The unit of the integrale result.

make_evenly_spaced(interp='linear', res=1)[source]

Use interpolation to make the field evenly spaced

Parameters:
  • interp ({‘linear’, ‘cubic’, ‘quintic’}, optional) – The kind of spline interpolation to use. Default is ‘linear’.
  • res (number) – Resolution of the resulting field. A value of 1 meaning a spatial resolution equal to the smallest space along the two axis for the initial field.
mask
mask_as_sf
max
mean
median
min
mirroring(direction, position, inds_to_mirror='all', mir_coef=1, interp=None, value=0, inplace=False)[source]

Return a field with additional mirrored values.

Parameters:
  • direction (string in ['x', 'y']) – Axe on which place the symetry plane
  • position (number) – Position of the symetry plane alogn the given axe
  • inds_to_mirror (integer) – Number of vector rows to symetrize (default is all)
  • mir_coef (number, optional) – Optional coefficient applied only to the mirrored values.
  • inplace (boolean, optional) –

    .

  • interp (string, optional) – If specified, method used to fill the gap near the symetry plane by interpoaltion. ‘value’ : fill with the given value, ‘nearest’ : fill with the nearest value, ‘linear’ (default): fill using linear interpolation (Delaunay triangulation), ‘cubic’ : fill using cubic interpolation (Delaunay triangulation)
  • value (array, optional) – Value at the symetry plane, in case of interpolation
reduce_spatial_resolution(fact, inplace=False)[source]

Reduce the spatial resolution of the field by a factor ‘fact’

Parameters:
  • fact (int) – Reducing factor.
  • inplace (boolean, optional) –

    .

rotate(angle, inplace=False)[source]

Rotate the scalar field.

Parameters:
  • angle (integer) – Angle in degrees (positive for trigonometric direction). In order to preserve the orthogonal grid, only multiples of 90° are accepted (can be negative multiples).
  • inplace (boolean, optional) – If ‘True’, scalar field is rotated in place, else, the function return a rotated field.
Returns:

rotated_field – Rotated scalar field.

Return type:

ScalarField object, optional

scale(scalex=None, scaley=None, scalev=None, inplace=False)[source]

Scale the ScalarField.

Parameters:
  • scaley, scalev (scalex,) – Scale for the axis and the values
  • inplace (boolean) –

    .

smooth(tos='uniform', size=None, inplace=False, **kw)[source]

Smooth the scalarfield in place. Warning : fill up the field (should be used carefully with masked field borders)

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’) in indice number. Default is 3 for ‘uniform’ and 1 for ‘gaussian’.
  • inplace (boolean, optional) – If True, Field is smoothed in place, else, the smoothed field is returned.
  • kw (dic) – Additional parameters for ndimage methods (See ndimage documentation)
unit_values
values