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

Xarray interface #12

Open
guillaumeeb opened this issue Jun 19, 2024 · 3 comments
Open

Xarray interface #12

guillaumeeb opened this issue Jun 19, 2024 · 3 comments

Comments

@guillaumeeb
Copy link
Member

The goal would be to replace the current approach using multiprocessing and internal mechanisms by an Xarray interface. This would enable the possibility to use Dask, stream the processing, but also keep results in memory.

@queyruto
Copy link
Collaborator

I began this work a while ago. Be careful: it won't be possible to use xarray to compute zonalstats. You will then have to allow two ways to open the product: as a classical numpy array using rasterio, or as an xarray using rioxarray.

In rasterproc.py, just add something like:

    def open_xarray(self,
                    bands: Union[str, List[str]] = "all",
                    masks: Union[str, List[str]] = "all",
                    roi: Union[Path, str] = None,
                    chunks: Union[int, Dict[str, int], Tuple[int]] = None):
        """Proxy method to xarray.open_rasterio(rasterproduct.get_raster(...))"""
        raster = self.get_raster(bands=bands, masks=masks, roi=roi, create_maskband=True)
        xa = rioxarray.open_rasterio(raster, masked=True, chunks=chunks)
        ds = xa.to_dataset(dim="band")
        ds = ds.rename({b + 1: self.rastertype.get_band_id(self.channels[b])
                        for b in range(len(self.channels))})
        return ds

@cadauxe
Copy link

cadauxe commented Nov 28, 2024

I am working on this issue, you can review my changes on the branch:
https://github.com/cadauxe/rastertools/tree/xarray_interf
Let me know if you have any feedback.

@guillaumeeb
Copy link
Member Author

@cadauxe, could you open a Pull Request, even if in draft, in order to comment the changes there?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants