xdem icon indicating copy to clipboard operation
xdem copied to clipboard

Write specific functions to collapse/rebuild input/outputs as `Raster`, `np.ma.masked_array` or `np.ndarray` consistently

Open rhugonnet opened this issue 1 year ago • 4 comments

We have tons of "wrapper" functions that can take either Raster, np.ma.masked_array or np.ndarray as input, but then only work on the np.ndarray (and possibly some metadata), and for output rebuild a Raster, np.ma.masked_array or np.ndarray to match the input. Right now this is done semi-manually everywhere, we need to have consistent input/output functions for those conversions. Might be triggering issues in #291 due to https://github.com/GlacioHack/GeoUtils/pull/265.

rhugonnet avatar Aug 26 '22 13:08 rhugonnet

That's a good idea. A small problem right now (or an unintended feature) is that all metadata are lost after raster recreation. Only the CRS and transform are identical to the input.

erikmannerfelt avatar Aug 16 '23 10:08 erikmannerfelt

@rhugonnet, could you add here the few lines of code that are repeated each time? Is it more than just 1-2 lines of code?

adehecq avatar Sep 06 '23 14:09 adehecq

Yes, the 10 lines in Coreg.apply() for "reconstructing" for example: https://github.com/GlacioHack/xdem/blob/main/xdem/coreg/base.py#L1160

rhugonnet avatar Sep 06 '23 21:09 rhugonnet

We could do the same to construct masks from a Vector, a Mask, an array, etc... It is used everywhere! Something like this: https://github.com/GlacioHack/xdem/blob/main/xdem/spatialstats.py#L593

rhugonnet avatar Sep 25 '23 22:09 rhugonnet