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

Quickstart example doesn't work #11

Closed
alexgleith opened this issue Jun 24, 2024 · 6 comments
Closed

Quickstart example doesn't work #11

alexgleith opened this issue Jun 24, 2024 · 6 comments

Comments

@alexgleith
Copy link

I tried the quickstart example, here: https://nrt.readthedocs.io/en/latest/quickstart.html

Code looks like this:

from nrt.monitor.ewma import EWMA
from nrt import data

# load example mask
mask = (data.romania_forest_cover_percentage() > 20).astype('int')

# Instantiate
nrt_class = EWMA(
    mask=mask,
    trend=True,
    harmonic_order=3,
    sensitivity=2
)

# load example xarray
s2_cube = data.romania_20m()
history = s2_cube.B3.sel(slice(None, '2019-01-01'))
monitor = s2_cube.B3.sel(slice('2019-01-01', None))

# Fitting
nrt_class.fit(dataarray=history)

# Dump model
nrt_class.to_netcdf('model.nc')

This crashes on the line history = s2_cube.B3.sel(slice(None, '2019-01-01')) with the error:

[1642](https://untitled+.vscode-resource.vscode-cdn.net/opt/homebrew/lib/python3.11/site-packages/xarray/core/dataarray.py:1642)     Dimensions without coordinates: points
   [1643](https://untitled+.vscode-resource.vscode-cdn.net/opt/homebrew/lib/python3.11/site-packages/xarray/core/dataarray.py:1643)     """
-> [1644](https://untitled+.vscode-resource.vscode-cdn.net/opt/homebrew/lib/python3.11/site-packages/xarray/core/dataarray.py:1644)     ds = self._to_temp_dataset().sel(
   [1645](https://untitled+.vscode-resource.vscode-cdn.net/opt/homebrew/lib/python3.11/site-packages/xarray/core/dataarray.py:1645)         indexers=indexers,
   [1646](https://untitled+.vscode-resource.vscode-cdn.net/opt/homebrew/lib/python3.11/site-packages/xarray/core/dataarray.py:1646)         drop=drop,
...
    [195](https://untitled+.vscode-resource.vscode-cdn.net/opt/homebrew/lib/python3.11/site-packages/xarray/namedarray/utils.py:195)     raise ValueError(
    [196](https://untitled+.vscode-resource.vscode-cdn.net/opt/homebrew/lib/python3.11/site-packages/xarray/namedarray/utils.py:196)         f"cannot specify both keyword and positional arguments to .{func_name}"
    [197](https://untitled+.vscode-resource.vscode-cdn.net/opt/homebrew/lib/python3.11/site-packages/xarray/namedarray/utils.py:197)     )

ValueError: the first argument to .sel must be a dictionary

I'm running using xarray version 2024.6.0, but also tested with an older version. Both crashed with the same error.

@loicdtx
Copy link
Collaborator

loicdtx commented Jun 24, 2024

Thanks for reporting this @alexgleith

Did you install nrt from pypi of from a local copy?

The reason I'm asking is because large binary files are tracked with git lfs in the repo. When the repository is cloned without lfs, these files are silently ignored (or git only downloads a pointer instead of the actual file).

@alexgleith
Copy link
Author

Ah, from PyPI.

Are the files very large?

@alexgleith
Copy link
Author

Also, this crash doesn't look like it's caused by missing data...

@loicdtx
Copy link
Collaborator

loicdtx commented Jun 24, 2024

Okay, I was able to reproduce and identify the issue.

history = s2_cube.B3.sel(time=slice(None, '2019-01-01'))
monitor = s2_cube.B3.sel(time=slice('2019-01-01', None))

must be used instead of:

history = s2_cube.B3.sel(slice(None, '2019-01-01'))
monitor = s2_cube.B3.sel(slice('2019-01-01', None))

@alexgleith
Copy link
Author

Of course, yep! Sorry, I should habe been able to figure that out too! haha

@alexgleith
Copy link
Author

Ok, now it works, but crashes on nrt_class.fit(dataarray=history), which may be a Python 3.11 issue. I reported this in #10

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