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

InputValueError: Given ds is invalid. #127

Open
1 of 3 tasks
gutabeshu opened this issue Oct 25, 2024 · 2 comments
Open
1 of 3 tasks

InputValueError: Given ds is invalid. #127

gutabeshu opened this issue Oct 25, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@gutabeshu
Copy link

gutabeshu commented Oct 25, 2024

What happened?

pygeohydro fails when trying to calculate cover statistics.

What did you expect to happen?

Stats(classes={'Open Water': 3.218275304968691, 'Developed, Open Space': 1.6128251635756874, 'Developed, Low Intensity': 0.5524352553716665, 'Developed, Medium Intensity': 0.2678054930087095, 'Developed, High Intensity': 0.038027458129463905, 'Barren Land (Rock/Sand/Clay)': 0.0977190439205618, 'Deciduous Forest': 41.72741457073914, 'Evergreen Forest': 29.33253744552278, 'Mixed Forest': 14.194382537791228, 'Shrub-Forest': 0.692330207399452, 'Herbaceous-Forest': 0.33994242873308644, 'Shrub/Scrub': 0.05001186917632526, 'Grassland/Herbaceous': 0.18022710458933802, 'Pasture/Hay': 0.4438841476202877, 'Cultivated Crops': 0.008296899955519398, 'Woody Wetlands': 6.641437944950068, 'Emergent Herbaceous Wetlands': 0.6024471245479918}, categories={'Water': 3.218275304968691, 'Developed': 2.471093370085527, 'Barren': 0.0977190439205618, 'Forest': 86.28660719018569, 'Shrubland': 0.05001186917632526, 'Herbaceous': 0.18022710458933802, 'Planted/Cultivated': 0.4521810475758071, 'Wetlands': 7.24388506949806})

Minimal Complete Verifiable Example

from pynhd import NLDI
import pygeohydro as gh
basins = NLDI().get_basins(["01031450", "01318500", "01031510"])
lulc = gh.nlcd_bygeom(basins, 100, years={"cover": [2016, 2019]})
stats = gh.cover_statistics(lulc['USGS-01031450'].cover_2016)

MVCE confirmation

  • Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue.
  • Complete example — the example is self-contained, including all data and the text of any traceback.
  • New issue — a search of GitHub Issues suggests this is not a duplicate.

Relevant log output

InputValueError                           Traceback (most recent call last)
Cell In[17], line 5
      3 basins = NLDI().get_basins([\"01031450\", \"01318500\", \"01031510\"])
      4 lulc = gh.nlcd_bygeom(basins, 100, years={\"cover\": [2016, 2019]})
----> 5 stats = gh.cover_statistics(lulc['USGS-01031450'].cover_2016)

File ~/micromamba/envs/HydroUrban/lib/python3.12/site-packages/pygeohydro/nlcd.py:334, in cover_statistics(cover_da)
    331 total_count = freq.sum()
    333 if any(c not in nlcd_meta[\"classes\"] for c in freq_dict):
--> 334     raise InputValueError(\"ds\", list(nlcd_meta[\"classes\"]))
    336 class_percentage = {
    337     nlcd_meta[\"classes\"][k].split(\" -\")[0].strip(): v / total_count * 100.0
    338     for k, v in freq_dict.items()
    339 }
    340 category_percentage = {
    341     k: sum(freq_dict[c] for c in v if c in freq_dict) / total_count * 100.0
    342     for k, v in nlcd_meta[\"categories\"].items()
    343     if k != \"Background\"
    344 }

InputValueError: Given ds is invalid. Valid options are:
11
12
21
22
23
24
31
41
42
43
45
46
51
52
71
72
73
74
81
82
90
95
127

Anything else we need to know?

This is smaller issue, but would be nice if the examples related to this are updated, because for data returned by lulc = gh.nlcd_bygeom(basins, 100, years={"cover": [2016, 2019]}), the keys are now 'USGS-01031450', instead of just '01031450'

Environment

SYS INFO

commit: None
python: 3.12.3 | packaged by conda-forge | (main, Apr 15 2024, 18:35:20) [Clang 16.0.6 ]
python-bits: 64
OS: Darwin
OS-release: 23.6.0
machine: arm64
processor: arm
byteorder: little
LC_ALL: None
LANG: None
LOCALE: (None, 'UTF-8')

PACKAGE VERSION

async-retriever 0.16.1
pygeoogc 0.16.3
pygeoutils 0.16.3
py3dep 0.16.3
pynhd 0.16.3
pygridmet 0.16.0
pydaymet 0.16.3
hydrosignatures 0.16.0
pynldas2 N/A
pygeohydro 0.16.5
aiohttp 3.9.5
aiohttp-client-cache 0.11.0
aiosqlite 0.20.0
cytoolz 0.12.3
ujson 5.10.0
defusedxml 0.7.1
joblib 1.4.2
multidict 6.0.5
owslib 0.31.0
pyproj 3.6.1
requests 2.32.2
requests-cache 1.2.0
shapely 2.0.4
url-normalize 1.4.3
urllib3 2.2.1
yarl 1.9.4
geopandas 0.14.4
netcdf4 1.6.5
numpy 1.26.4
rasterio 1.3.10
rioxarray 0.15.5
scipy 1.13.1
xarray 2024.5.0
click 8.1.7
pyflwdir N/A
networkx 3.3
pyarrow 16.1.0
folium 0.16.0
h5netcdf 1.3.0
matplotlib 3.5.3
pandas 2.2.2
numba 0.59.1
bottleneck N/A
py7zr N/A
pyogrio 0.8.0

@gutabeshu gutabeshu added the bug Something isn't working label Oct 25, 2024
@cheginit
Copy link
Collaborator

MRLC recently made some changes to their web services so previous versions of HyRiver, which you have installed, won't work anymore for getting NLCD. So, you need to update HRiver packages to the latest version (0.18) and it should work.

@cheginit
Copy link
Collaborator

Regarding the keys, it's based on the index of your input gdf. So, you can change the index of the gdf to whatever you want before passing it to the nlcd function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants