Points class

class IMTreatment.core.points.Points(xy=array([], shape=(0, 2), dtype=float64), v=[], unit_x='', unit_y='', unit_v='', name='')[source]

Bases: object

add(pt, v=None)[source]

Add a new point.

Parameters:
  • pt (2x1 array of numbers) – Point to add.
  • v (number, optional) – Value of the point (needed if other points have values).
augment_resolution(fact=2, interp='linear', inplace=False)[source]

Augment the temporal resolution of the points. Only have sense if points are sorted to set some kind of trajectory.

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 y axis unit ‘x’ for changing the profile x axis unit ‘v’ for changing the profile values unit
  • new_unit (Unum.unit object or string) – The new unit.
copy()[source]

Return a copy of the Points object.

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

Crop the points cloud.

Parameters:
  • intervx (2x1 tuple) – Interval on x axis
  • intervy (2x1 tuple) – Interval on y axis
  • intervv (2x1 tuple) – Interval on v values
Returns:

tmp_pts – croped version of the point cloud.

Return type:

Points object

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

Return a point cloud where the given area has been removed.

Parameters:
  • intervx (2x1 tuple) – Interval on x axis
  • intervy (2x1 tuple) – Interval on y axis
Returns:

tmp_pts – Cutted version of the point cloud.

Return type:

Points object

decompose()[source]

return a tuple of Points object, with only one point per object.

display(kind=None, axe_x=None, axe_y=None, axe_color=None, **plotargs)[source]

Display the set of points.

Parameters:
  • kind (string, optional) – Can be ‘plot’ (default if points have not values). or ‘scatter’ (default if points have values). or ‘colored_plot’.
  • axe_y, axe_color (axe_x,) – To determine wich value has to be plotted along which axis, and whith value is used to color the scattered points. Default plot ‘y’ to ‘x’ with colors from ‘v’.
  • **plotargs (dic) – Additionnal arguments sent to ‘plot’ or ‘scatter’
display3D(kind='plot', xlabel='', ylabel='', zlabel='', title='', **plotargs)[source]

Display the points on a 3D graph.

Parameters:
  • kind (string, optional) – Kind of graph to use, can be ‘plot’ or ‘surf’.
  • ylabel, zlabel (xlabel,) – Label fo each axis (respectively ‘x’, ‘y’, and ‘v’)
  • title (strin, optional) – Title
  • **plotargs – Additional parameters feeded to matplotlib
export_to_profile(axe_x='x', axe_y='y')[source]

Export the unsorted point object to a sorted Profile object.

Parameters:axe_y (axe_x,) – Which value used to construct the profile
fit(kind='polynomial', order=2, simplify=False)[source]

Return the parametric coefficients of the fitting curve on the points.

Parameters:
  • kind (string, optional) – The kind of fitting used. Can be ‘polynomial’ or ‘ellipse’.
  • order (integer) – Approximation order for the fitting.
  • Simplify (boolean or string, optional) – Can be False (default), ‘x’ or ‘y’. Perform a simplification (see Points.Siplify()) before the fitting.
Returns:

  • p (array, only for polynomial fitting) – Polynomial coefficients, highest power first
  • radii (array, only for ellipse fitting) – Ellipse demi-axes radii.
  • center (array, only for ellipse fitting) – Ellipse center coordinates.
  • alpha (number) – Angle between the x axis and the major axis.

get_clusters(eps, min_samples=5)[source]

Perform DBSCAN clustering from vector array or distance matrix. (see sklearn.cluster.DBSCAN)

Notes

DBSCAN - Density-Based Spatial Clustering of Applications with Noise. Finds core samples of high density and expands clusters from them. Good for data which contains clusters of similar density.

get_envelope(alpha=None)[source]

Return the convex or concave hull (if alpha specified) for the set of points.

Parameters:alpha (number) – maximum distance between two points of the hull.

Notes

Credit to mlaloux (https://github.com/mlaloux/Python–alpha-shape_concave_hull)

get_evolution_on_sf(SF, axe_x=None)[source]

Return the evolution of the value represented by a scalar field, on the path of the trajectory.

Parameters:
  • SF (ScalarField object) –
  • axe_x (string, optional) – What put in the x axis (can be ‘x’, ‘y’, ‘v’). default is ‘v’ when available and ‘x’ else.
Returns:

evol

Return type:

Profile object

get_evolution_on_tsf(TSF, axe_x=None)[source]

Return the evolution of the value represented by scalar fields, on the path of the trajectory. Timse of the TSF must be consistent with the times of the Points.

Parameters:
  • TSF (tsf.TemporalScalarField object) –
  • axe_x (string, optional) – What put in the x axis (can be ‘x’, ‘y’, ‘v’). default is ‘v’ (associated with time)
Returns:

evol

Return type:

Profile object

get_points_density(bw_method=None, resolution=100, output_format='normalized', raw=False)[source]

Return a ScalarField with points density.

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 as percent of the data std. If a callable, it should take a gaussian_kde instance as only parameter and return a scalar. If None (default), ‘scott’ is used.
  • resolution (integer, optional) – Resolution for the resulting field.
  • 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 surface).

  • raw (boolean, optional) – If ‘False’ (default), return a ScalarField object, if ‘True’, return numpy array.
Returns:

density – Return ‘None’ if there is not enough points in the cloud.

Return type:

array, ScalarField object or None

get_points_density2(res, subres=None, raw=False, ponderated=False)[source]

Return a ScalarField with points density.

Parameters:
  • res (number or 2x1 array of numbers) – fdensity field number of subdivision. Can be the same number for both axis, or one number per axis (need to give a tuple).
  • raw (boolean, optional) – If ‘False’ (default), return a ScalarField object, if ‘True’, return numpy array.
  • ponderated (boolean, optiona) – If ‘True’, values associated to points are used to ponderate the density field. Default is ‘False’.
  • subres (odd integer, optional) – If specified, a subgrid of resolution res*subres is used to make result more accurate.
get_velocity(incr=1, smooth=0, xaxis='time')[source]

Assuming that associated ‘v’ values are times for each points, compute the velocity of the trajectory.

Parameters:
  • incr (integer, optional) – Increment use to get used points (default is 1).
  • smooth (number, optional) – Cut off frequency for the lowpass filter.
  • xaxis (string, optional) – Value to put in the profile x axis, can be ‘time’ (default), ‘x’ or ‘y’.
Returns:

  • Vx (Profile object) – Profile of x velocity versus time.
  • Vy (Profile object) – Profile of y velocity versus time.

name
order_on_line(inplace=False)[source]

Re-order the set of points to try to create a line.

remove(ind)[source]

Remove the point number ‘ind’ of the points cloud. In place.

Parameters:ind (integer or array of integer) –
remove_doublons(method='average', inplace=False, eps_rel=1e-06)[source]

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

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

Remove the points containing nans values.

reverse()[source]

Return a Points object where x and y axis are swaped.

rotate(angle, inplace=False)[source]

Rotate the point set.

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

Change the scale of the axis.

Parameters:
  • scaley, scalev (scalex,) – scales along x, y and v
  • inplace (boolean, optional) – If ‘True’, scaling is done in place, else, a new instance is returned.
set_origin(x=None, y=None)[source]

Set the given point (x, y) as the new referential.

Parameters:
  • x (number) –

    .

  • y (number) –

    .

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

Return a smoothed points field.

Parameters:
  • tos (string, optional) – Type of smoothing, can be ‘uniform’ (default), ‘gaussian’ or ‘lowpass’.
  • size (number, optional) – radius of the smoothing for ‘uniform’, radius of the smoothing for ‘gaussian’, cut off frequency for ‘lowpass’ Default are 3 for ‘uniform’, 1 for ‘gaussian’ and 0.1 for ‘ lowpass’.
  • inplace (boolean) – If ‘False’, return a smoothed points field else, smooth in place.
  • kw (dic) – Additional parameters for ndimage methods (See ndimage documentation)
sort(ref='x', inplace=False)[source]

Sort the points according to the reference.

Parameters:
  • ref (string or array of indice) – can be ‘x’, ‘y’ or ‘v’ to sort according those values or an array of indice
  • ; boolean (inplace) – If ‘True’, sort in place, else, return an new sorted instance.
unit_v
unit_x
unit_y
v
xy