ccdc fit method failed
Closed this issue · 3 comments
kenoz commented
Running CCDC method with default parameters results in the following error:
ValueError: green and swir xarray.Dataarray(s) need to be provided using green and swir arguments respectively
The code that failed:
from nrt.monitor.ccdc import CCDC
from nrt import data
mask = (data.romania_forest_cover_percentage() > 30).astype('int')
s2_cube = data.romania_20m()
s2_cube['ndvi'] = (s2_cube.B8A - s2_cube.B4) / (s2_cube.B8A + s2_cube.B4)
s2_cube = s2_cube.where(s2_cube.SCL.isin([4,5,7]))
ndvi_history = s2_cube.ndvi.sel(time=slice('2015-01-01', '2018-12-31'))
ndvi_monitoring = s2_cube.ndvi.sel(time=slice('2019-01-01', '2021-12-31'))
ccdcMonitor = CCDC(trend=False, mask=mask)
ccdcMonitor.fit(dataarray=ndvi_history)
loicdtx commented
Thanks @kenoz; the following code works
from nrt.monitor.ccdc import CCDC
from nrt import data
mask = (data.romania_forest_cover_percentage() > 30).astype('int')
s2_cube = data.romania_20m()
s2_cube['ndvi'] = (s2_cube.B8A - s2_cube.B4) / (s2_cube.B8A + s2_cube.B4)
s2_cube = s2_cube.where(s2_cube.SCL.isin([4,5,7]))
cube_history = s2_cube.sel(time=slice('2015-01-01', '2018-12-31'))
cube_monitoring = s2_cube.sel(time=slice('2019-01-01', '2021-12-31'))
ccdcMonitor = CCDC(trend=True, mask=mask)
ccdcMonitor.fit(dataarray=cube_history.ndvi,
green=cube_history.B3,
swir=cube_history.B11,
scaling_factor=10000)
I agree the scaling_factor
part is a bit under-documented (only briefly explained here). Let me know if you think something else is missing from the documentation