Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ccdc fit method failed #8

Closed
kenoz opened this issue Mar 4, 2024 · 3 comments
Closed

ccdc fit method failed #8

kenoz opened this issue Mar 4, 2024 · 3 comments

Comments

@kenoz
Copy link

kenoz commented Mar 4, 2024

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
Copy link
Collaborator

loicdtx commented Mar 5, 2024

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

@kenoz
Copy link
Author

kenoz commented Mar 5, 2024

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

@loicdtx
Copy link
Collaborator

loicdtx commented Mar 5, 2024

@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)

@loicdtx loicdtx closed this as completed in 5fb7ea3 Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants