diff --git a/tests/test_coreg/test_affine.py b/tests/test_coreg/test_affine.py index 28c86c71..dc19d31e 100644 --- a/tests/test_coreg/test_affine.py +++ b/tests/test_coreg/test_affine.py @@ -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) diff --git a/tests/test_fit.py b/tests/test_fit.py index d10c8840..fbef0726 100644 --- a/tests/test_fit.py +++ b/tests/test_fit.py @@ -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 diff --git a/tests/test_spatialstats.py b/tests/test_spatialstats.py index 815e17df..b067faa9 100644 --- a/tests/test_spatialstats.py +++ b/tests/test_spatialstats.py @@ -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 diff --git a/tests/test_volume.py b/tests/test_volume.py index 2bb2e226..96090000 100644 --- a/tests/test_volume.py +++ b/tests/test_volume.py @@ -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 @@ -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] diff --git a/xdem/coreg/base.py b/xdem/coreg/base.py index 1fe7e6f4..42ea5881 100644 --- a/xdem/coreg/base.py +++ b/xdem/coreg/base.py @@ -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( diff --git a/xdem/coreg/biascorr.py b/xdem/coreg/biascorr.py index effc163d..42c030ce 100644 --- a/xdem/coreg/biascorr.py +++ b/xdem/coreg/biascorr.py @@ -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"], ) @@ -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"], ) @@ -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"], ) diff --git a/xdem/dem.py b/xdem/dem.py index 3fbc858a..64f6d3dc 100644 --- a/xdem/dem.py +++ b/xdem/dem.py @@ -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) diff --git a/xdem/spatialstats.py b/xdem/spatialstats.py index 94a729b8..f15602ee 100644 --- a/xdem/spatialstats.py +++ b/xdem/spatialstats.py @@ -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":