hyriver / py3dep

A part of HyRiver software stack for getting topography data within the US through 3D Elevation Program (3DEP)
https://docs.hyriver.io
Other
42 stars 7 forks source link

Unable to fetch data with "not recognized as a supported file format" error from Rasterio #55

Closed onnyyonn closed 2 years ago

onnyyonn commented 2 years ago

What happened: While fetching data, the following error is thrown not recognized as a supported file format.

Minimal Complete Verifiable Example:

import pygeohydro, py3dep
wbd = pygeohydro.WBD("huc8")
geom = wbd.byids("huc8", "07120003").geometry[0]
dem = py3dep.get_map("DEM", geom, resolution=30, geo_crs="epsg:4326", crs="epsg:4326")

This throws the following error

---------------------------------------------------------------------------
CPLE_OpenFailedError                      Traceback (most recent call last)
File rasterio/_base.pyx:261, in rasterio._base.DatasetBase.__init__()

File rasterio/_shim.pyx:78, in rasterio._shim.open_dataset()

File rasterio/_err.pyx:216, in rasterio._err.exc_wrap_pointer()

CPLE_OpenFailedError: '/vsimem/2b58107f-8a05-4142-892f-bdd7137d218d/2b58107f-8a05-4142-892f-bdd7137d218d.tif' not recognized as a supported file format.

During handling of the above exception, another exception occurred:

RasterioIOError                           Traceback (most recent call last)
/home/oni/Projects/hyriver/input_data_prepare.ipynb Cell 5' in <cell line: 4>()
      [2](vscode-notebook-cell:/home/oni/Projects/hyriver/input_data_prepare.ipynb#ch0000011?line=1) wbd = pygeohydro.WBD("huc8")
      [3](vscode-notebook-cell:/home/oni/Projects/hyriver/input_data_prepare.ipynb#ch0000011?line=2) geom = wbd.byids("huc8", "07120003").geometry[0]
----> [4](vscode-notebook-cell:/home/oni/Projects/hyriver/input_data_prepare.ipynb#ch0000011?line=3) dem = py3dep.get_map("DEM", geom, resolution=30, geo_crs="epsg:4326", crs="epsg:4326")

File ~/miniconda3/envs/scicomp/lib/python3.9/site-packages/py3dep/py3dep.py:121, in get_map(layers, geometry, resolution, geo_crs, crs)
    119 r_dict = wms.getmap_bybox(_geometry.bounds, resolution, box_crs=crs)
    120 if isinstance(geometry, (Polygon, MultiPolygon)):
--> 121     ds = geoutils.gtiff2xarray(r_dict, _geometry, crs)
    122 else:
    123     ds = geoutils.gtiff2xarray(r_dict)
...
    133     writer = get_writer_for_driver(driver)

File rasterio/_base.pyx:263, in rasterio._base.DatasetBase.__init__()

RasterioIOError: '/vsimem/2b58107f-8a05-4142-892f-bdd7137d218d/2b58107f-8a05-4142-892f-bdd7137d218d.tif' not recognized as a supported file format.

Anything else we need to know?:

Environment:

Output of py3dep.show_versions() ``` INSTALLED VERSIONS ------------------ commit: None python: 3.9.12 | packaged by conda-forge | (main, Mar 24 2022, 23:25:59) [GCC 10.3.0] python-bits: 64 OS: Linux OS-release: 5.18.5-1-MANJARO machine: x86_64 processor: byteorder: little LC_ALL: None LANG: en_IN.UTF-8 LOCALE: en_IN.UTF-8 libhdf5: 1.12.1 libnetcdf: 4.8.1 aiodns: 3.0.0 aiohttp: 3.8.1 aiohttp-client-cache: 0.7.1 aiosqlite: 0.17.0 async-retriever: 0.3.3 bottleneck: 1.3.4 brotli: 1.0.9 cchardet: 2.1.7 click: 8.0.1 cytoolz: 0.11.2 dask: 2022.6.1 defusedxml: 0.7.1 folium: 0.12.1.post1 geopandas: 0.11.0 lxml: 4.8.0 matplotlib: 3.5.2 netCDF4: 1.6.0 networkx: 2.8.4 numpy: 1.22.4 owslib: 0.25.0 pandas: 1.4.3 py3dep: 0.0 pyarrow: 6.0.1 pydantic: 1.9.1 pydaymet: 0.13.2 pygeohydro: 0.13.0 pygeoogc: 0.13.2 pygeos: 0.12.0 pygeoutils: 0.13.2 pynhd: 0.13.2 pyproj: 3.3.1 pytest: 6.2.4 pytest-cov: None rasterio: 1.2.10 requests: 2.28.0 requests-cache: 0.9.4 richdem: 2.3.0 rioxarray: 0.11.1 scipy: 1.8.1 shapely: 1.8.2 tables: 3.7.0 ujson: 5.3.0 urllib3: 1.26.5 xarray: 2022.3.0 xdist: None yaml: 5.4.1 ```
cheginit commented 2 years ago

This exception means that the 3DEP service is down temporarily. I will catch this exception in the next version as a ServiceError to make sure users know this is service related. You can check the service status from here. At the time of writing this comment, it's operational and I was able to run your code:

image
onnyyonn commented 2 years ago

Thanks. I can confirm that it is working as expected now.