xdem
xdem copied to clipboard
Write specific functions to collapse/rebuild input/outputs as `Raster`, `np.ma.masked_array` or `np.ndarray` consistently
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.
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.
@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?
Yes, the 10 lines in Coreg.apply()
for "reconstructing" for example: https://github.com/GlacioHack/xdem/blob/main/xdem/coreg/base.py#L1160
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