GEUS-SICE / pySICE

Python and Fortran scripts behind the SICE toolchain for albedo retrieval.
GNU General Public License v2.0
5 stars 1 forks source link

Stacked multiindex #12

Closed BaptisteVandecrux closed 2 years ago

BaptisteVandecrux commented 2 years ago

With xarray and rasterio, reading tiff is very easy. But the coordinates are not stacked

import xarray as xr
import rioxarray
a = rioxarray.open_rasterio(InputFolder+'OZA.tif')
new = some_function(a)
new .rio.to_raster('new.tif')

I can see that you chose to stack the xy coordinates:

a_stacked = rioxarray.open_rasterio(InputFolder+'OZA.tif').stack(xy=("x", "y")).compute()

but

a_stacked .rio.to_raster('new.tif')

does not work anymore.

So what is the benefit of stacking the coordinates?

If we are fine with leaving them unstacked, then we need to change: https://github.com/GEUS-SICE/pySICE/blob/448a886b8533ad6fa8c3d37f830376ba13611b1c/misc/sice_lib_optim.py#L851-L856

to

def prepare_coef_new(tau, g, p, cos_sza, cos_vza, inv_cos_za):  # , gaer, taumol, tauaer):
    args = tau, g, p, cos_sza, cos_vza, inv_cos_za  # , gaer, taumol, tauaer

    dims = [a.dims for a in args]
    dims = [('band', 'y', 'x', )] * 3 + [('y','x', )] * 3
    t1, t2, ratm, r = xr.apply_ufunc(prepare_coef_numpy, *args, input_core_dims=dims, output_core_dims=[('band', 'y','x')]*4)
BaptisteVandecrux commented 2 years ago

stacked multi-index don't seem that bad after all. Keeping them