PEOPLE-ER/spectral-recovery

Unexpected Y2R values

Closed this issue · 1 comments

In some cases, RestorationArea.yr2() is producing unexpected results. e.g saying 1 year for recovery when it should be 0. This behavior is not consistent for all inputs, and the current set of units tests are all passing, so something weird is going on. A more detailed description with examples of the behaviour will be added soon.

Looks like Y2R is failing when the first recovered year, X, is followed by years with values that are recovered (geq threshold) but smaller than X's value. For example:

>>> from spectral_recovery.metrics import y2r
>>> 
>>> target = xr.DataArray([100], dims=["band"]).rio.write_crs("4326") 
>>> failing_timeseries = [[[[70]], [[90]], [[85]], [[80]]]]
>>> failing = xr.DataArray(failing_timeseries, dims=["band", "time", "y", "x"], coords=[0, 1, 2, 3],).rio.write_crs("4326")
>>> y2r(failing, recovery_target=target, rest_start="0")
# Incorrect!
<xarray.DataArray (band: 1, y: 1, x: 1)>
array([[[3.]]])
Coordinates:
    spatial_ref  int32 0
Dimensions without coordinates: band, y, x
# Expected is 1.0 because 90 is the first value to reach recovery (80% of 100)