Skip to content

Commit

Permalink
Fix xDEM with a new GeoUtils release (#336)
Browse files Browse the repository at this point in the history
* Pull the latest geoutils

* Fix isort install

* Fix blockwise function call with new Coreg syntax

* Linting

* Fix saving test file on Windows

* Try windows save fix adding .tif extension

* Linting

* Update environment files with latest geoutils release

* Try to fix png writing as well

* Try without suffix

* Fix Windows writing of temporary file with mode option

* Try without context manager for Windows

* Try to fix on Windows with delete tag
  • Loading branch information
rhugonnet authored Feb 2, 2023
1 parent 2b68111 commit e663904
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ repos:

# Sort imports using isort
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black"]
Expand Down
3 changes: 2 additions & 1 deletion dev-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ dependencies:
- richdem

- pip:
- geoutils==0.0.9
# - git+https://github.com/GlacioHack/GeoUtils.git
- geoutils==0.0.10
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ scipy
rasterio
pyproj
tqdm
git+https://github.com/GlacioHack/geoutils.git
geoutils
scikit-gstat
flake8
opencv-contrib-python
Expand Down
3 changes: 2 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ dependencies:
- pip

- pip:
- geoutils==0.0.9
# - git+https://github.com/GlacioHack/GeoUtils.git
- geoutils==0.0.10
4 changes: 3 additions & 1 deletion examples/advanced/plot_blockwise_coreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@
# This shows the estimated shifts that would be applied in elevation; additional horizontal shifts will also be applied if the method supports it.
# The :func:`xdem.coreg.BlockwiseCoreg.stats` method can be used to annotate each block with its associated Z shift.

z_correction = blockwise.apply(np.zeros_like(dem_to_be_aligned.data), transform=dem_to_be_aligned.transform)
z_correction = blockwise.apply(
np.zeros_like(dem_to_be_aligned.data), transform=dem_to_be_aligned.transform, crs=dem_to_be_aligned.crs
)[0]
plt.title("Vertical correction")
plt.imshow(z_correction, cmap="coolwarm_r", vmin=-10, vmax=10, extent=plt_extent)
for _, row in blockwise.stats().iterrows():
Expand Down
10 changes: 5 additions & 5 deletions tests/test_coreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1236,9 +1236,9 @@ def test_dem_coregistration() -> None:
dem_coreg2, _, _, _ = xdem.coreg.dem_coregistration(tba_dem.filename, ref_dem.filename)
assert dem_coreg2 == dem_coreg

# Test saving to file
outfile = tempfile.NamedTemporaryFile()
_, _, _, _ = xdem.coreg.dem_coregistration(tba_dem, ref_dem, out_dem_path=outfile.name)
# Test saving to file (mode = "w" is necessary to work on Windows)
outfile = tempfile.NamedTemporaryFile(suffix=".tif", mode="w", delete=False)
xdem.coreg.dem_coregistration(tba_dem, ref_dem, out_dem_path=outfile.name)
dem_coreg2 = xdem.DEM(outfile.name)
assert dem_coreg2 == dem_coreg
outfile.close()
Expand All @@ -1257,9 +1257,9 @@ def test_dem_coregistration() -> None:
assert np.all(~inlier_mask[gl_mask])

# Testing with plot
out_fig = tempfile.NamedTemporaryFile(suffix=".png")
out_fig = tempfile.NamedTemporaryFile(suffix=".png", mode="w", delete=False)
assert os.path.getsize(out_fig.name) == 0
_, _, _, _ = xdem.coreg.dem_coregistration(tba_dem, ref_dem, plot=True, out_fig=out_fig.name)
xdem.coreg.dem_coregistration(tba_dem, ref_dem, plot=True, out_fig=out_fig.name)
assert os.path.getsize(out_fig.name) > 0
out_fig.close()

Expand Down

0 comments on commit e663904

Please sign in to comment.