EcoExtreML / zampy

Tool for downloading Land Surface Model input data
https://zampy.readthedocs.io/
Apache License 2.0
1 stars 0 forks source link

Implement the Prism DEM datasets, add tests. #28

Closed BSchilperoort closed 1 year ago

BSchilperoort commented 1 year ago

A demo notebook is included in demo/prism_dem_demo.ipynb

review-notebook-app[bot] commented 1 year ago

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

geek-yang commented 1 year ago

The API works nicely. But when I tried with the recipe, an error occur:

~/EcoExtreML/temp via 🐍 v3.10.12 (ecoextreml) took 2s
❯ zampy prism90_dem_recipe.yml
Executing recipe: prism90_dem_recipe.yml
Copernicus_DSM_30_N50_00_E003_00.tar: 8.97MB [00:01, 5.29MB/s]
elevation renamed to elevation.
Conversion of dataset 'prism-dem-90' following ALMA convention is complete!
Traceback (most recent call last):
  File "/home/yangliu/venv/ecoextreml/lib/python3.10/site-packages/xarray/core/dataset.py", line 1382, in _construct_dataarray
    variable = self._variables[name]
KeyError: 'time'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/yangliu/venv/ecoextreml/bin/zampy", line 8, in <module>
    sys.exit(run_recipe())
  File "/home/yangliu/venv/ecoextreml/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/yangliu/venv/ecoextreml/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/yangliu/venv/ecoextreml/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/yangliu/venv/ecoextreml/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/yangliu/EcoExtreML/zampy/src/zampy/cli.py", line 13, in run_recipe
    rm.run()
  File "/home/yangliu/EcoExtreML/zampy/src/zampy/recipe.py", line 121, in run
    ds = ds.resample(time=self.frequency).mean()
  File "/home/yangliu/venv/ecoextreml/lib/python3.10/site-packages/xarray/core/dataset.py", line 9322, in resample
    return self._resample(
  File "/home/yangliu/venv/ecoextreml/lib/python3.10/site-packages/xarray/core/common.py", line 982, in _resample
    dim_coord = self[dim]
  File "/home/yangliu/venv/ecoextreml/lib/python3.10/site-packages/xarray/core/dataset.py", line 1473, in __getitem__
    return self._construct_dataarray(key)
  File "/home/yangliu/venv/ecoextreml/lib/python3.10/site-packages/xarray/core/dataset.py", line 1384, in _construct_dataarray
    _, name, variable = _get_virtual_variable(self._variables, name, self.dims)
  File "/home/yangliu/venv/ecoextreml/lib/python3.10/site-packages/xarray/core/dataset.py", line 196, in _get_virtual_variable
    raise KeyError(key)
KeyError: 'time'

Clearly it is due to the missing time axis, which is required in the recipe for saving the output after conversion. But it is easy to fix, just add a time coord, similar to canopy dataset.

BSchilperoort commented 1 year ago

@geek-yang thanks for the review! I had fixed the missing time dim issue, but seem to have forgotten to commit it :man_facepalming:. Instead of adding a time coordinate, I modify recipe.py to allow for variables without a time dim.

sonarcloud[bot] commented 1 year ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

90.1% 90.1% Coverage
0.0% 0.0% Duplication