zerofind¶
-
zerofind(x, y, axis=0, diff=None, centered=True, which='both', **kwargs)[source]¶ Find the location of the zero value for a given data array.
- Parameters
x (array-like) – The coordinates.
y (array-like) – The data for which we find zeros.
axis (int, optional) – The axis along which zeros are found and (optionally) derivatives are taken. These will be connected along the other axis with
linetrack.diff (int, optional) – How many times to differentiate along the axis.
centered (bool, optional) – Whether to use centered finite differencing or half level differencing.
which ({‘negpos’, ‘posneg’, ‘both’}, optional) – Whether to find values that go from negative to positive, positive to negative, or both (the
'min'and'max'keys really only apply to whendiffis1).**kwargs – Passed to
linetrackand used to group the locations into coherent tracks.
- Returns
zx (array-like) – The zero locations.
zy (array-like) – The zero values. If
diff == 0these should all be equal to zero up to floating point precision. Otherwise these are the minima and maxima corresponding to the zero derivative locations.
Example
>>> import xarray as xr ... import climopy as climo ... ureg = climo.ureg ... x = np.arange(100) ... y = np.sort(np.random.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'} ... ) ... with climo.internals.warnings._unit_stripped_ignore(): ... yarr = xr.DataArray( ... y * ureg.m, name='variable', ... dims=('x', 'y'), coords={'x': xarr} ... ) ... zx, zy = climo.zerofind(xarr, yarr, ntrack=2)