Skip to content

Commit

Permalink
Edit bands into indexes of DEM class (#340)
Browse files Browse the repository at this point in the history
* bands_into_indexes

* Add test to check error is properly raised when loading from multi-band rasters

* Linting

* Correct typo in NuthKaab verbose

---------

Co-authored-by: Romain Hugonnet <[email protected]>
  • Loading branch information
liuh886 and rhugonnet authored Mar 2, 2023
1 parent dc57c44 commit f40e897
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions tests/test_dem.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import numpy as np
import pyproj
import pytest
import rasterio as rio
from geoutils.georaster.raster import _default_rio_attrs

import xdem
Expand Down Expand Up @@ -65,6 +66,15 @@ def test_init(self) -> None:
)
)

# Check that an error is raised when more than one band is provided
with pytest.raises(ValueError, match="DEM rasters should be composed of one band only"):
xdem.DEM.from_array(
data=np.zeros(shape=(2, 5, 5)),
transform=rio.transform.from_bounds(0, 0, 1, 1, 5, 5),
crs=None,
nodata=None,
)

def test_copy(self) -> None:
"""
Test that the copy method works as expected for DEM. In particular
Expand Down
2 changes: 1 addition & 1 deletion xdem/coreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1401,7 +1401,7 @@ def _fit_func(

# Iteratively run the analysis until the maximum iterations or until the error gets low enough
if verbose:
print(" Iteratively estimating horizontal shit:")
print(" Iteratively estimating horizontal shift:")

# If verbose is True, will use progressbar and print additional statements
pbar = trange(self.max_iterations, disable=not verbose, desc=" Progress")
Expand Down
4 changes: 2 additions & 2 deletions xdem/dem.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ def __init__(
warnings.filterwarnings("ignore", message="Parse metadata from file not implemented")
super().__init__(filename_or_dataset, silent=silent, **kwargs)

# self.nbands can be None when data is not loaded through the Raster class
if self.nbands is not None and self.nbands > 1:
# self.indexes can be None when data is not loaded through the Raster class
if self.indexes is not None and len(self.indexes) > 1:
raise ValueError("DEM rasters should be composed of one band only")

# user input
Expand Down

0 comments on commit f40e897

Please sign in to comment.