ec-jrc/nrt

ccdc fit method failed

Closed this issue · 3 comments

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)

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

Thanks @loicdtx!
Do you confirm that green and swir arguments are required?
If yes, default values (None) would be useless.

@kenoz , no I do not confirm. green and swir arguments are only required when method or screen_outliers are 'CCDC*'

You could for instance do:

ccdcMonitor = CCDC(trend=False, mask=mask)
ccdcMonitor.fit(dataarray=cube_history.ndvi,
                method='OLS', screen_outliers=None)