ScalarField class¶
-
class
PyFields.core.scalarfield.
ScalarField
(axis_x, axis_y, values, mask=None, unit_x='', unit_y='', unit_values='')[source]¶ Bases:
PyFields.core.field.Field
Class representing a scalar field (2D field, with one component on each point).
-
change_unit
(axis, new_unit)[source]¶ Change the unit of an axis.
Parameters: - axis (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.
-
crop
(intervx=None, intervy=None, ind=False, inplace=False)[source]¶ Crop the scalar field.
Parameters: - intervx (array, optional) – Wanted interval along x.
- intervy (array, optional) – Wanted interval 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, else (default), a copy is returned.
-
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='values', kind='imshow', annotate=True, **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).
- annotate (boolean) – If True (default) add label and legedn to the graph.
- **plotargs (dict) – Arguments passed to the plotting function.
Returns: fig – Reference to the displayed figure.
Return type: figure reference
-
dtype
¶
-
extend
(nmb_left=0, nmb_right=0, nmb_up=0, nmb_down=0, value=None, inplace=False, ind=True)[source]¶ Add columns and/or lines of masked values to the field.
Parameters: - nmb_right, nmb_up, nmb_down (nmb_left,) – Number of lines/columns to add in each direction.
- inplace (bool) – If ‘True’, extend the field in place, else (default), return an extended copy of the field.
Returns: Extended_field – Extended field.
Return type: Field object
Note
If the axis values are not equally spaced, a linear extrapolation is used to obtain the new axis values.
-
fill
(kind='linear', value=0.0, inplace=False, reduce_tri=True, crop=False)[source]¶ Fill the masked parts of the scalar field.
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
(bins=200, cum=False, normalized=False)[source]¶ Return the scalarfield values histogram.
Parameters: - cum (boolean) – If True, get a cumulative histogram.
- normalized (boolean) – If True, normalize the histogram.
- bins (integer) – Number of bins (default to 200).
Returns: hist – Histogram.
Return type: Profile object.
-
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’. Example
>>> interp = SF.get_interpolator(interp='linear') >>> print(interp(4, 5.3)) ... [34.3] >>> print(interp([3, 4, 5], 5.3)) ... [23, 34.3, 54]
-
get_profile
(x=None, y=None, ind=False, interp='linear')[source]¶ Return a profile of the scalar field, at the given position. If position is an interval, the fonction return an average profile in this interval.
Parameters: - y (x,) – Position of the wanted profile.
- 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_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 axis (interpolated if necessary).
-
integrate
()[source]¶ Return the integral of the field. If you want the integral on a subset of the field, use ‘crop’ before.
Returns: - integral (float) – Result of the integrale computation.
- unit (Unit object) – The unit of the integrale result.
Note
Discretized integral is computed with a very rustic algorithm which just sum the value on the surface.
-
make_evenly_spaced
(interp='linear', res=1, inplace=False)[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. A value of 2 means half this resolution.
- inplace (boolean) – If True, modify the scalar field in place, else, return a modified version of it.
-
mask
¶
-
mask_as_sf
¶
-
max
¶
-
mean
¶
-
min
¶
-
reduce_resolution
(fact, inplace=False)[source]¶ Reduce the spatial resolution of the scalar 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 (signe in trigonometric convention). In order to preserve the orthogonal grid, only multiples of 90° are accepted.
- inplace (boolean, optional) – If True, the field is rotated in place, else (default), a rotated copy is returned.
Returns: rotated_field – Rotated field.
Return type: Field object
-
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.
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)
-
std
¶
-
unit_values
¶
-
values
¶
-