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

RuntimeWarning is triggered when clipping data in uint8 format #694

Open
xueke114 opened this issue Sep 5, 2023 · 0 comments
Open

RuntimeWarning is triggered when clipping data in uint8 format #694

xueke114 opened this issue Sep 5, 2023 · 0 comments
Labels
question Further information is requested

Comments

@xueke114
Copy link

xueke114 commented Sep 5, 2023

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

@xueke114 xueke114 added the bug Something isn't working label Sep 5, 2023
@snowman2 snowman2 added question Further information is requested and removed bug Something isn't working labels Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants