-
Notifications
You must be signed in to change notification settings - Fork 45
Description
There is no test in fit_and_apply
to check that the DEM to coregister and the inlier_mask have the same shape. if that happens, this leads to an error downstream that is difficult to understand.
Here is a MWE (an opportunity for me to test the new icrop
😄) :
import geoutils as gu
import numpy as np
import xdem
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"))
# We create a stable ground mask (not glacierized) to mark "inlier data".
inlier_mask = ~glacier_outlines.create_mask(reference_dem)
# crop the mask by a few pixels on each side
nrows, ncols = inlier_mask.shape
inlier_mask2 = inlier_mask.icrop((0, 0, ncols-2, nrows-2))
print(inlier_mask2.shape)
print(inlier_mask.shape)
# Try running coregistration
nuth_kaab = xdem.coreg.NuthKaab()
aligned_dem = nuth_kaab.fit_and_apply(reference_dem, dem_to_be_aligned, inlier_mask2)
returns the following error:
File /usr/local/Caskroom/miniconda/base/envs/xdem/lib/python3.12/site-packages/xdem/coreg/base.py:268, in _preprocess_coreg_fit_raster_raster(reference_dem, dem_to_be_aligned, inlier_mask, transform, crs, area_or_point)
265 raise ValueError("'dem_to_be_aligned' had only NaNs")
267 # Isolate all invalid values
--> 268 invalid_mask = np.logical_or.reduce((~inlier_mask, ref_mask, tba_mask))
270 if np.all(invalid_mask):
271 raise ValueError("All values of the inlier mask are NaNs in either 'reference_dem' or 'dem_to_be_aligned'.")ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (3,) + inhomogeneous part.