find¶
- find(x, y, /, axis=- 1, axis_track=None, track=True, diff=None, which='both', centered=True, **kwargs)[source]¶
Find the location of zero values or extrema for a given data array.
- Parameters
x (array-like) – The coordinates.
y (array-like) – The data for which we find zeros.
axis (int, optional) – Axis along which zeros are found and (optionally) derivatives are taken.
axis_track (int, optional) – Axis along which zeros taken along
axis
are “tracked”. Default is the last position not occupied byaxis
.track (bool, optional) – Whether to track zeros. If
False
they are added in the order they appeared.diff (int, optional) – How many times to differentiate along the axis.
which ({‘negpos’, ‘posneg’, ‘both’}, optional) – Whether to find values that go from negative to positive, positive to negative, or both.
centered (bool, optional) – If False, use half-level differentiation rather than centered differentiation. Gives more accurate locations but less accurate values.
**kwargs – Passed to
linetrack
and used to group the locations into coherent tracks.
- Returns
x0s (array-like) – The zero locations.
y0s (array-like) – The zero values. If
diff == 0
these should all be equal to zero up to floating point precision. Otherwise these are the minima and maxima corresponding to the zero derivative locations.
Examples
>>> import numpy as np >>> import xarray as xr >>> import climopy as climo >>> state = np.random.RandomState(51423) >>> ureg = climo.ureg >>> x = np.arange(100) >>> y = np.sort(state.rand(50, 10) - 0.5, axis=0) >>> y = np.concatenate((y, y[::-1, :]), axis=0) >>> xarr = xr.DataArray( ... x * ureg.s, ... dims=('x',), attrs={'long_name': 'x coordinate'} ... ) >>> yarr = xr.DataArray( ... y * ureg.m, name='variable', ... dims=('x', 'y'), coords={'x': xarr.climo.dequantify()} ... ) >>> x0s, y0s = climo.find(xarr, yarr, axis=0, ntrack=2) >>> x0s <xarray.DataArray 'x' (track: 2, y: 10)> <Quantity([[25.56712412 17.1468964 25.94590963 24.43748793 25.96456694 23.50805224 24.26007638 25.76728476 26.30359681 22.41433647] [73.43287588 81.8531036 73.05409037 74.56251207 73.03543306 75.49194776 74.73992362 73.23271524 72.69640319 76.58566353]], 'second')> Dimensions without coordinates: track, y Attributes: long_name: x coordinate