corteva / rioxarray

geospatial xarray extension powered by rasterio
https://corteva.github.io/rioxarray
Other
511 stars 81 forks source link

Issues with xarray and raster computation #566

Closed sehHeiden closed 1 year ago

sehHeiden commented 2 years ago

Code Sample, a copy-pastable example if possible

I tried to use the matimatical methods of xarrays which than interferes with the capacity of the xarray to behave as a raster.

raster = raster.sum(dim='band', keepdim=True)

This keeps the dim band, but removes it from the indexes.

raster3 = xarray.where(raster1 != raster.rio.nodata, raster2, raster2.rio.nodata)

the new raster3, doesn't have neither crs nor nodata.

    save_layers: list[DataArray] = []
    for month in range(1, 13):
        month_raster1 = raster1.sel(band=[mth])  # radiation of the month

        mirrored_mth = mirror_month(mth)
        mth_raster2 = raster2.sel(band=[mirrored_mth])  # raster2 has only 6 bands, so I use band 7 as band 6, 8 as 5, and so on.

        save_layer = (mth_raster2 == 0) * month_raster1 
        save_layers.append(save_layer)
    save_layers = concat(save_layers, dim='band')

Doesn't work as expected. (mth_raster2 == 0) and month_raster1 both always have band = [1], but (mth_raster2 == 0) * month_raster1 has band=[1] for the first 6 month and band=[0] for the later six. concat uses only 6 bands!

Perhaps you don't conider some as bugs and others to be fixes over on xarray. But still, I think, these are good to know.

Environment Information

rioxarray (0.12.0) deps: rasterio: 1.2.1 xarray: 2022.3.0 GDAL: 3.1.4 GEOS: None PROJ: None PROJ DATA: None GDAL DATA: None Other python deps: scipy: 1.8.1 pyproj: 3.0.1 System: python: 3.9.13 | packaged by conda-forge | (main, May 27 2022, 16:50:36) [MSC v.1929 64 bit (AMD64)] executable: C:\Users\remote\anaconda3\envs\OBAL\python.exe machine: Windows-10-10.0.19043-SP0

Installation method

Conda environment information (if you installed with conda):

Environment : gdal 3.1.4 py39haafd053_15 conda-forge libgdal 3.1.4 h966def8_15 conda-forge rasterio 1.2.1 py39hfec4536_0 conda-forge rioxarray 0.12.0 pyhd8ed1ab_0 conda-forge xarray 2022.3.0 pyhd8ed1ab_0 conda-forge

snowman2 commented 2 years ago

I recommend reading the Getting Started documentation . The information loss section should be helpful for you.