GlacioHack / xdem

Analysis of digital elevation models (DEMs)
https://xdem.readthedocs.io/
MIT License
142 stars 41 forks source link

X dimension of Z error when Coregistering ArcticDEM strips #330

Closed jaha2600 closed 1 year ago

jaha2600 commented 1 year ago

Hi there, I am trying to use xdem to coregister DEMs using the Nuth and Kaab Method. I am coregistering an ArcticDEM strip (EPSG:3413) to an ArcticDEM tile that has been masked to bedrock and is also in the same projection.

When I try and execute the fit section (nuth_kaab.fit(reference_dem.data, dem_to_be_aligned.data, transform=reference_dem.transform) I get the following error (this has also appeared when clipping the ref DEM to equal extents, and trying a different ref dem):

Traceback (most recent call last): File "/home/jhansen/JasmineShare/petermann/xdem_coreg.py", line 27, in nuth_kaab.fit(reference_dem.data, dem_to_be_aligned.data, transform=reference_dem.transform) File "/home/jhansen/miniconda3/envs/gdal/lib/python3.9/site-packages/xdem/coreg.py", line 506, in fit self._fit_func(ref_dem=ref_dem, tba_dem=tba_dem, transform=transform, weights=weights, verbose=verbose) File "/home/jhansen/miniconda3/envs/gdal/lib/python3.9/site-packages/xdem/coreg.py", line 1215, in _fit_func elevation_function = scipy.interpolate.RectBivariateSpline(

File "/home/jhansen/miniconda3/envs/gdal/lib/python3.9/site-packages/scipy/interpolate/fitpack2.py", line 1333, in init raise ValueError('x dimension of z must have same number of ' ValueError: x dimension of z must have same number of elements as x

xdem_coreg.txt Do you happen to have any ideas as to why this may be occurring? I attach the script in text form that I am using to execute the coregistration and I am using the following xdem version: xdem 0.0.7 pyhd8ed1ab_0 conda-forge

thanks!

rhugonnet commented 1 year ago

Hi @jaha2600,

Thanks for reporting this issue! Using the following syntax might solve your issue (not using the .data but directly the Raster objects):

nuth_kaab.fit(reference_dem, dem_to_be_aligned, inlier_mask=inlier_mask)

The Coreg module is one of our oldest and we are currently in the process of re-organizing and simplifying it (#329), and we are then going to adjust the documentation in the next months (aiming for a first stable release sometime next year :wink:).

We also need to update the README for which some examples are outdated. If you want to use the package's features, it is better to use the syntax demonstrated in the documentation example, for example for Nuth & Kääb: https://xdem.readthedocs.io/en/latest/basic_examples/plot_nuth_kaab.html#sphx-glr-basic-examples-plot-nuth-kaab-py

jaha2600 commented 1 year ago

Hi Romain, Thanks for the reply I shall try that new syntax today, looking forward to the upcoming stable release! I just wanted to check a few things:

  1. Would pipelining multiple methods based on the Nuth Kaab example you suggested result in the below syntax needing to be used?
    methods = xdem.coreg.NuthKaab() + xdem.coreg.Deramp(degree=1)
    methods.fit(reference_dem, dem_to_be_aligned, inlier_mask=inlier_mask)
  2. I have already masked my reference DEM to the stable surfaces I require (bedrock only etc.). In that instance would it be fine to exclude the inlier mask option or would you suggest also including a vector mask alongside the reference DEM ?

thanks,

rhugonnet commented 1 year ago

Hi @jaha2600,

  1. Yes.
  2. Should be fine!
rhugonnet commented 1 year ago

@jaha2600 I assume this is solved, closing!