Losing data when add a raster to a dataset
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
As I mentioned here, when I add a raster inside a geocube are produced a lot of nodata.
After a test @snowman2 has indicates that this is a possible bug of xarray libraries.
I was able to reproduce the issue you demonstrated. I think it has to do with decimal precision of the coordinates when adding the DataArray to the Dataset. That being said, I checked that the
xcoordinate andycoordinates were the exact same forraster_inandout_grid. This is likely an issue withxarrayand notgeocube.For a workaround, this got it working without the gaps for me:
import geopandas import rioxarray from geocube.api.core import make_geocube vector_in = geopandas.read_file("vector_data.shp") raster_in = rioxarray.open_rasterio("raster_data.tif", masked=True).sel(band=1).drop("band") out_grid = make_geocube( vector_data=vector_in, measurements=["id"], like=raster_in, ) out_grid["process_value"] = (raster_in.dims, raster_in.values, raster_in.attrs, raster_in.encoding)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Begin with the linked geocube issue #62 and the reproduced example using geopandas, rioxarray, make_geocube, and raster_in/out_grid. Investigate the coordinate-precision behavior when adding raster_in to out_grid; done means the assignment no longer introduces nodata gaps without relying on the shown workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100