-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathplot_deramp.py
More file actions
54 lines (36 loc) · 1.85 KB
/
plot_deramp.py
File metadata and controls
54 lines (36 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""Bias-correction with deramping
==============================
Deramping can help correct rotational or doming errors in elevation data.
In xDEM, this approach is implemented through the :class:`xdem.coreg.Deramp` class.
See also the :ref:`deramp` section in feature pages.
"""
import geoutils as gu
import numpy as np
import xdem
# %%
# We open example files.
reference_dem = xdem.DEM(xdem.examples.get_path("longyearbyen_ref_dem"))
dem_to_be_aligned = xdem.DEM(xdem.examples.get_path("longyearbyen_tba_dem"))
glacier_outlines = gu.Vector(xdem.examples.get_path("longyearbyen_glacier_outlines"))
# Create a stable ground mask (not glacierized) to mark "inlier data"
inlier_mask = ~glacier_outlines.create_mask(reference_dem)
# %%
# We visualize the patterns of error from the elevation differences.
diff_before = reference_dem - dem_to_be_aligned
diff_before.plot(cmap="RdYlBu", vmin=-10, vmax=10, cbar_title="Elevation differences (m)")
# %%
# A 2-D 3rd order polynomial is estimated, and applied to the data:
deramp = xdem.coreg.Deramp(poly_order=2)
corrected_dem = deramp.fit_and_apply(reference_dem, dem_to_be_aligned, inlier_mask=inlier_mask)
# %%
# Then, the new difference can be plotted.
diff_after = reference_dem - corrected_dem
diff_after.plot(cmap="RdYlBu", vmin=-10, vmax=10, cbar_title="Elevation differences (m)")
# %%
# We compare the median and NMAD to validate numerically that there was an improvement (see :ref:`robuststats-meanstd`):
inliers_before = diff_before[inlier_mask]
med_before, nmad_before = np.ma.median(inliers_before), xdem.spatialstats.nmad(inliers_before)
inliers_after = diff_after[inlier_mask]
med_after, nmad_after = np.ma.median(inliers_after), xdem.spatialstats.nmad(inliers_after)
print(f"Error before: median = {med_before:.2f} - NMAD = {nmad_before:.2f} m")
print(f"Error after: median = {med_after:.2f} - NMAD = {nmad_after:.2f} m")