Skip to content

Commit

Permalink
Incremental commit on warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rhugonnet committed Mar 16, 2024
1 parent fb899fc commit e2056ae
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 23 deletions.
1 change: 0 additions & 1 deletion tests/test_coreg/test_affine.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ def test_gradientdescending(self, subsample: int = 10000, inlier_mask: bool = Tr
self.tba,
inlier_mask=inlier_mask,
verbose=verbose,
subsample=subsample,
z_name="b1",
)
assert gds._meta["offset_east_px"] == pytest.approx(-0.496000, rel=1e-1, abs=0.1)
Expand Down
3 changes: 3 additions & 0 deletions tests/test_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def test_robust_norder_polynomial_fit(self, pkg_estimator: str) -> None:

def test_robust_norder_polynomial_fit_noise_and_outliers(self) -> None:

# Ignore sklearn convergence warnings
warnings.filterwarnings("ignore", category=UserWarning, message="lbfgs failed to converge")

np.random.seed(42)

# Define x vector
Expand Down
6 changes: 3 additions & 3 deletions tests/test_spatialstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,9 @@ def test_get_perbin_nd_binning(self) -> None:
# Get the value at the random point for elevation, slope, aspect
x = xrand[i]
y = yrand[i]
h = self.ref.data[x, y]
slp = self.slope.data[x, y]
asp = self.aspect.data[x, y]
h = self.ref.data.filled(np.nan)[x, y]
slp = self.slope.data.filled(np.nan)[x, y]
asp = self.aspect.data.filled(np.nan)[x, y]

if np.logical_or.reduce((np.isnan(h), np.isnan(slp), np.isnan(asp))):
continue
Expand Down
15 changes: 10 additions & 5 deletions tests/test_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_bin_ddem(self) -> None:
assert ddem_stds["value"].mean() < 50
assert np.abs(np.mean(ddem_bins["value"] - ddem_bins_masked["value"])) < 0.01

def test_interpolate_ddem_bins(self) -> pd.Series:
def test_interpolate_ddem_bins(self) -> None:
"""Test dDEM bin interpolation."""
ddem = self.dem_2009 - self.dem_1990

Expand All @@ -61,13 +61,18 @@ def test_interpolate_ddem_bins(self) -> pd.Series:
# Check that no nans exist.
assert not np.any(np.isnan(interpolated_bins))

# Return the value so that they can be used in other tests.
return interpolated_bins

def test_area_calculation(self) -> None:
"""Test the area calculation function."""
ddem_bins = self.test_interpolate_ddem_bins()

ddem = self.dem_2009 - self.dem_1990

ddem_bins = xdem.volume.hypsometric_binning(ddem[self.mask], self.dem_2009[self.mask])

# Simulate a missing bin
ddem_bins.iloc[3, 0] = np.nan

# Interpolate the bins and exclude bins with low pixel counts from the interpolation.
interpolated_bins = xdem.volume.interpolate_hypsometric_bins(ddem_bins, count_threshold=200)
# Test the area calculation with normal parameters.
bin_area = xdem.volume.calculate_hypsometry_area(
ddem_bins, self.dem_2009[self.mask], pixel_size=self.dem_2009.res[0]
Expand Down
2 changes: 2 additions & 0 deletions xdem/coreg/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1784,6 +1784,8 @@ def fit(
" individual steps of the pipeline. To silence this warning: only define 'subsample' in "
"either fit(subsample=...) or instantiation e.g., VerticalShift(subsample=...)."
)
# Filter warnings of individual pipelines now that the one above was raised
warnings.filterwarnings("ignore", message="Subsample argument passed to*", category=UserWarning)

# Pre-process the inputs, by reprojecting and subsampling, without any subsampling (done in each step)
ref_dem, tba_dem, inlier_mask, transform, crs = _preprocess_coreg_fit(
Expand Down
6 changes: 3 additions & 3 deletions xdem/coreg/biascorr.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ def _fit_rst_rst( # type: ignore
print("Estimating rotated coordinates.")

x, _ = gu.raster.get_xy_rotated(
raster=gu.Raster.from_array(data=ref_elev, crs=crs, transform=transform),
raster=gu.Raster.from_array(data=ref_elev, crs=crs, transform=transform, nodata=-9999),
along_track_angle=self._meta["angle"],
)

Expand Down Expand Up @@ -807,7 +807,7 @@ def _fit_rst_pts( # type: ignore
print("Estimating rotated coordinates.")

x, _ = gu.raster.get_xy_rotated(
raster=gu.Raster.from_array(data=rast_elev, crs=crs, transform=transform),
raster=gu.Raster.from_array(data=rast_elev, crs=crs, transform=transform, nodata=-9999),
along_track_angle=self._meta["angle"],
)

Expand Down Expand Up @@ -841,7 +841,7 @@ def _apply_rst(

# Define the coordinates for applying the correction
x, _ = gu.raster.get_xy_rotated(
raster=gu.Raster.from_array(data=elev, crs=crs, transform=transform),
raster=gu.Raster.from_array(data=elev, crs=crs, transform=transform, nodata=-9999),
along_track_angle=self._meta["angle"],
)

Expand Down
2 changes: 1 addition & 1 deletion xdem/dem.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def estimate_uncertainty(
"""

# Elevation change
dh = other_dem.reproject(self) - self
dh = other_dem.reproject(self, silent=True) - self

# If the precision of the other DEM is the same, divide the dh values by sqrt(2)
# See Equation 7 and 8 of Hugonnet et al. (2022)
Expand Down
21 changes: 11 additions & 10 deletions xdem/spatialstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -1191,16 +1191,17 @@ def _get_cdist_empirical_variogram(
"""

if subsample_method == "cdist_equidistant" and "runs" not in kwargs.keys() and "samples" not in kwargs.keys():

# We define subparameters for the equidistant technique to match the number of pairwise comparison
# that would have a classic "subsample" with pdist, except if those parameters are already user-defined
runs, samples, ratio_subsample = _choose_cdist_equidistant_sampling_parameters(**kwargs)

kwargs["runs"] = runs
# The "samples" argument is used by skgstat Metric subclasses (and not "subsample")
kwargs["samples"] = samples
kwargs["ratio_subsample"] = ratio_subsample
if subsample_method == "cdist_equidistant":

if "runs" not in kwargs.keys() and "samples" not in kwargs.keys():
# We define subparameters for the equidistant technique to match the number of pairwise comparison
# that would have a classic "subsample" with pdist, except if those parameters are already user-defined
runs, samples, ratio_subsample = _choose_cdist_equidistant_sampling_parameters(**kwargs)
kwargs["ratio_subsample"] = ratio_subsample
kwargs["runs"] = runs
# The "samples" argument is used by skgstat Metric subclasses (and not "subsample")
kwargs["samples"] = samples

kwargs.pop("subsample")

elif subsample_method == "cdist_point":
Expand Down

0 comments on commit e2056ae

Please sign in to comment.