xdem
xdem copied to clipboard
Re-organization of `coreg.py`
Several ideas here in relation to the one-liner coregistration: https://github.com/GlacioHack/xdem/pull/267#pullrequestreview-1145346346
More generically:
- The core functionalities of
Coreg
methods should live outside ofCoreg
classes for readability and flexibility (e.g., functions to estimate the horizontal shift, to deramp, etc). In other words allCoreg
methods should only be wrappers of already existing functions; - Optimization functions should call the methods of
fit.py
instead of directly callingscipy.optimize
, so that their tolerance and outputs are consistently tested, and that any type of optimization method can be used; - While all class method should retain flexibility to work with
np.ndarray
, they should still be optimized to function withRaster
objects (e.g., modifying the geotransform instead of resampling in case of a horizontal shift). To have a similar default behaviour fornp.ndarray
objects, we could potentially introduce a return of atransform
object as output ofapply()
.
Maybe @adehecq has more specific things to add!
Yes, I agree with those points. Below I outlined the main steps to be done, hopefully in logical order:
- Step 2 requires that the data is convertible to a DEM instance -> Change coreg apply and fit functions so that they accept either an xdem.DEM instance, or a numpy array, transform and CRS.
- Replace all Coreg core functionalities with either standalone function or xdem/geoutils functions
- Replace calculate_slope_and_aspect with xdem.terrain attributes
- Replace subsampling with geoutils’ subsampling
- Remove duplicates of deramping
- Add function to calculate standard stats before/after coregistration (mean, median, NMAD, std, others?). Call this function in apply.
- Add plotting step in all
apply
methods, and in somefit
methods, like N&K. - Update Coreg so that coregistration params are more easily output than currently with _meta
- Add function to create inlier mask (load vectors, remove slopes, outliers…)
- Save input/output DEM during fit and apply functions to avoid redoing calc?
- Remove unused/redundant functions (
filter_by_range
,filtered_slope
,apply_xy_shift
,apply_z_shift
,mask_as_array
,dilate_mask
option,Coreg.residuals
anderror
)
Adding some points after closing #158:
9. Move apply_matrix
from base.py
to affine.py
by overridding apply()
in AffineCoreg
(as done in BiasCorr
), and related functions,
10. Add a run
or fit_and_apply
class method for Coreg
,
11. Add a is_rigid
property for AffineCoreg
and subclasses,
12. Improve tests of apply_matrix
or add a geo-ref based one? This joins #110.
13. Refine documentation pages to differentiate affine/non-affine (bias corrections) and explain the generic inputs/ouputs.
Since #436, relevant for the re-org: Make subsampling consistent in AffineCoreg
classes once the inside of _fit_func
are consistently defined as functions working on 1D vector inputs (as in BiasCorr
)