rioxarray
rioxarray copied to clipboard
RuntimeWarning is triggered when clipping data in uint8 format
Code Sample, a copy-pastable example if possible
import rioxarray
import geopandas as gpd
roi_shapefile = "C:/Datasets/Geo/HB/HB.shp"
rgb_file = "C:/Datasets/RS/Landsat9-OLI-SP-30M/rgb.wgs84.tif"
shp_obj = gpd.read_file(roi_shapefile)
rio_geometry = shp_obj.geometry.values
rgb_xds = rioxarray.open_rasterio(rgb_file)
clipped_rgb = rgb_xds.rio.clip(rio_geometry, shp_obj.crs, drop=True, invert=False)
Below is information about rgb_xds output using Ipython
rgb_xds
Out[27]:
<xarray.DataArray (band: 3, y: 7101, x: 8607)>
[183354921 values with dtype=uint8]
Coordinates:
* band (band) int32 1 2 3
* x (x) float64 112.5 112.5 112.5 112.5 ... 115.1 115.1 115.1 115.1
* y (y) float64 37.1 37.1 37.1 37.1 ... 34.97 34.97 34.97 34.97
spatial_ref int32 0
Attributes:
AREA_OR_POINT: Area
scale_factor: 1.0
add_offset: 0.0
Problem description
C:\Users\xueke\AppData\Local\Programs\Python\Python310\lib\site-packages\xarray\core\duck_array_ops.py:188:
RuntimeWarning: invalid value encountered in cast
return data.astype(dtype, **kwargs)
This RuntimeWarning only appears when clipping uint8 data, not when I try to clip a DEM data (dtpye=int16).
Even though this warning exists, I don't see anything unusual about the clipped data, and I'm more curious about why this warning exists.
Expected Output
Environment Information
rioxarray (0.15.0) deps:
rasterio: 1.3.8
xarray: 2023.8.0
GDAL: 3.6.4
GEOS: 3.11.1
PROJ: 9.0.1
PROJ DATA: C:\OnlineWorkspace\SoilMoisture\.venv\lib\site-packages\rasterio\proj_data
GDAL DATA: C:\OnlineWorkspace\SoilMoisture\.venv\lib\site-packages\rasterio\gdal_data
Other python deps:
scipy: 1.11.2
pyproj: 3.6.0
System:
python: 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
executable: C:\OnlineWorkspace\SoilMoisture\.venv\Scripts\python.exe
machine: Windows-10-10.0.19045-SP0
Installation method
pypi