VectorField class

class IMTreatment.core.vectorfield.VectorField[source]

Bases: IMTreatment.core.field.Field

Class representing a vector field (2D field, with two components on each point).

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.
check_consistency()[source]

Raise errors if the vectorfield show some incoherences.

comp_x
comp_x_as_sf
comp_y
comp_y_as_sf
copy()[source]

Return a copy of the vectorfield.

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.

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

Display something from the vector field. If component is not given, a quiver is displayed. If component is an integer, the coresponding component of the field is displayed.

Parameters:
  • component (string, optional) – Component to display, can be ‘V’, ‘x’, ‘y’, ‘mask’
  • kind (string, optinnal) – Scalar plots : if ‘None’: each datas are plotted (imshow), if ‘contour’: contours are ploted (contour), if ‘contourf’: filled contours are ploted (contourf). Vector plots : if ‘quiver’: quiver plot, if ‘stream’: streamlines.
  • plotargs (dict) – Arguments passed to the function used to display the vector field.
Returns:

fig – Reference to the displayed figure

Return type:

figure reference

extend(nmb_left=0, nmb_right=0, nmb_up=0, nmb_down=0, inplace=False)[source]

Add columns or lines of masked values at the vectorfield.

Parameters:
  • nmb_**** (integers) – Number of lines/columns to add in each direction.
  • 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, 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 (2x1 array of numbers) – Values used to fill (for kind=’value’).
  • inplace (boolean, optional) – If ‘True’, fill the sf.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’, TVF borders are croped before filling.
get_norm(norm=2, normalized='perpoint')[source]

Return the field norm

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

Return a profile of the vector field component, 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:
  • component (string in ['vx', 'vy']) – component to treat.
  • direction (string in ['x', 'y']) – Direction along which we choose a position.
  • position (float or interval of float) – Position or interval in which we want a profile.
  • ind (boolean, optional) – If ‘True’, position is taken as an indice Else (default), position is in the field units.
  • 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 (Profile object) – Asked profile.
  • cutposition (array or number) – Final position or interval in which the profile has been taken.

get_props()[source]

Print the VectorField main properties

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

Return the vector field components 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).

import_from_arrays(axe_x, axe_y, comp_x, comp_y, mask=False, unit_x='', unit_y='', unit_values='')[source]

Set the vector field from a set of arrays.

Parameters:
  • axe_x (array) – Discretized axis value along x
  • axe_y (array) – Discretized axis value along y
  • comp_x (array or masked array) – Values of the x component at the discritized points
  • comp_y (array or masked array) – Values of the y component at the discritized points
  • mask (array of boolean, optional) – Mask on comp_x and comp_y
  • unit_x (string, optionnal) – Unit for the values of axe_x
  • unit_y (string, optionnal) – Unit for the values of axe_y
  • unit_values (string, optionnal) – Unit for the field components.
magnitude

Return a scalar field with the velocity field magnitude.

magnitude_as_sf

Return a scalarfield with the velocity field magnitude.

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
min
mirroring(direction, position, inds_to_mirror='all', mir_coef=1.0, inplace=False, interp=None, value=[0, 0])[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 along the given axe
  • inds_to_mirror (integer) – Number of vector rows to symetrize (default is all)
  • mir_coef (number or 2x1 array, optional) – Optional coefficient(s) applied only to the mirrored values. If ana array first value is for ‘comp_x’ and second one to ‘comp_y’
  • 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 vector 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’, vector field is rotated in place, else, the function return a rotated field.
Returns:

rotated_field – Rotated vector field.

Return type:

VectorField object, optional

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

Scale the VectorField.

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

    .

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

Smooth the vectorfield 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’). Default is 3 for ‘uniform’ and 1 for ‘gaussian’.
  • inplace (boolean, optional) –

    .

  • kw (dic) – Additional parameters for ndimage methods (See ndimage documentation)
theta

Return a scalar field with the vector angle (in reference of the unit_y vector [1, 0]).

Parameters:low_velocity_filter (number) – If not zero, points where V < Vmax*low_velocity_filter are masked.
Returns:theta_sf – Contening theta field.
Return type:sf.ScalarField object
theta_as_sf

Return a scalarfield with the velocity field angles.

unit_values