-
Notifications
You must be signed in to change notification settings - Fork 215
Description
I am trying to run a hand model for a DEM tile downloaded from Planetary Computer Copernicus GLO-30
api_url = "https://planetarycomputer.microsoft.com/api/stac/v1"
catalog = Client.open( "https://planetarycomputer.microsoft.com/api/stac/v1", modifier=planetary_computer.sign_inplace,)
# Perform a STAC API query against the finer resolution cop-dem-glo-30 collection for our point of interest.
Dempo = [103.121, -4.016]
search = catalog.search( collections=["cop-dem-glo-30"], intersects={"type": "Point", "coordinates": Dempo}, )
items = list(search.get_items())
print(f"Returned {len(items)} items")
The tif file has the following array:
rio.open('./DEM_Tiles/Lamongan.tif').read(1)
Output:
array([[ 92.36827 , 94.1264 , 99.902954, ..., 20.657282, 19.701372, 17.761093], [ 91.486374, 93.41677 , 95.88835 , ..., 19.304647, 19.374046, 19.823298], [ 89.797035, 92.18075 , 94.348694, ..., 19.362255, 19.694624, 19.14562 ], ..., [1632.02 , 1639.4564 , 1645.035 , ..., 832.11505 , 827.7317 , 827.1184 ], [1629.2458 , 1627.0072 , 1626.1676 , ..., 829.8382 , 829.8398 , 828.7866 ], [1647.5671 , 1635.4843 , 1620.6329 , ..., 831.7441 , 831.67694 , 830.6433 ]], shape=(3600, 3600), dtype=float32)
When I run the code grid = Grid.from_raster('./DEM_Tiles/Lamongan.tif')
I get the following errors:
TypeError Traceback (most recent call last)
File c:\Users\jiayu\anaconda3\envs\geospatial\Lib\site-packages\pysheds\sview.py:85, in Raster.new(cls, input_array, viewfinder, metadata)
84 try:
---> 85 assert np.can_cast(viewfinder.nodata, obj.dtype, casting='safe')
86 except:
TypeError: can_cast() does not support Python ints, floats, and complex because the result used to depend on the value.
This change was part of adopting NEP 50, we may explicitly allow them again in the future.
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
Cell In[9], line 1
----> 1 grid = Grid.from_raster('./DEM_Tiles/Lamongan.tif')
2 dem = grid.read_raster('./DEM_Tiles/Lamongan.tif')
File c:\Users\jiayu\anaconda3\envs\geospatial\Lib\site-packages\pysheds\sgrid.py:421, in sGrid.from_raster(cls, data, **kwargs)
419 return newinstance
420 elif isinstance(data, str):
--> 421 data = newinstance.read_raster(data, **kwargs)
422 newinstance.viewfinder = data.viewfinder
423 return newinstance
File c:\Users\jiayu\anaconda3\envs\geospatial\Lib\site-packages\pysheds\sgrid.py:258, in sGrid.read_raster(self, data, band, window, window_crs, metadata, mask_geometry, **kwargs)
226 def read_raster(self, data, band=1, window=None, window_crs=None,
227 metadata={}, mask_geometry=False, **kwargs):
228 """
229 Reads data from a raster file and returns a Raster object.
230
(...) 256 Raster object containing loaded data.
257 """
--> 258 return pysheds.io.read_raster(data=data, band=band, window=window,
259 window_crs=window_crs, metadata=metadata,
260 mask_geometry=mask_geometry, **kwargs)
File c:\Users\jiayu\anaconda3\envs\geospatial\Lib\site-packages\pysheds\io.py:140, in read_raster(data, band, window, window_crs, mask_geometry, nodata, metadata, **kwargs)
138 nodata = data.dtype.type(nodata)
139 viewfinder = ViewFinder(affine=affine, shape=shape, mask=mask, nodata=nodata, crs=crs)
--> 140 out = Raster(data, viewfinder, metadata=metadata)
141 return out
File c:\Users\jiayu\anaconda3\envs\geospatial\Lib\site-packages\pysheds\sview.py:87, in Raster.new(cls, input_array, viewfinder, metadata)
85 assert np.can_cast(viewfinder.nodata, obj.dtype, casting='safe')
86 except:
---> 87 raise TypeError('nodata
value not representable in dtype of array.')
88 # Don't allow original viewfinder and metadata to be modified
89 viewfinder = viewfinder.copy()
TypeError: nodata
value not representable in dtype of array.