jhardenberg / smmregrid

A compact regridder using sparse matrix multiplication
Apache License 2.0
8 stars 0 forks source link

Possibility to select levels from the weights file #21

Closed jhardenberg closed 10 months ago

jhardenberg commented 11 months ago

If weights are built for a 3D data source and then later a subset of n levels is selected from that Dataset or Dataarray, regridding will still use the first n levels from the weights (which is wrong). We would need that the Dataset 'remembers' the positions of the original levels. To address this I suggest that if the Dataset contains a special coordinate 'idx_3d' (depending on the vertical dimension) that will be used as a 'memory' of the original levels. To explain better: a Dataset initially could have idx_3d which is simply the range of existing levels (i.e. [0, 1, 2 ... 75]) as a function of the vertical dimension (say 'level'), while maybe level could be [1000 900 800 700 600 500 ...] . Then, if later we select specific levels from that dataset (e.g. with .sel(level=[800, 700, 600]), also idx_3d is subselected and will contain [2, 3, 4] . If later we apply smmregrid to this resulting array, the correct weights of levels [2, 3, 4] will be used. The iplementation would be such that this happens only if idx_3d is among the coordinates of the Dataset/Dataarray.

jhardenberg commented 10 months ago

closing as completed