Skip to content

Commit

Permalink
Update geoutils' function call following API change
Browse files Browse the repository at this point in the history
  • Loading branch information
adehecq committed Jan 25, 2024
1 parent f2431d1 commit 8a2067f
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion tests/test_coreg/test_affine.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def test_coreg_example_shift(self, shift_px, coreg_class, points_or_raster, verb
shifted_ref = self.ref.copy()
shifted_ref.shift(shift_px[0] * res, shift_px[1] * res)

shifted_ref_points = shifted_ref.to_points(as_array=False, subset=subsample, pixel_offset="center").ds
shifted_ref_points = shifted_ref.to_points(as_array=False, sample=subsample, pixel_offset="center").ds
shifted_ref_points["E"] = shifted_ref_points.geometry.x
shifted_ref_points["N"] = shifted_ref_points.geometry.y
shifted_ref_points.rename(columns={"b1": "z"}, inplace=True)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_coreg/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def test_coreg_raster_and_ndarray_args(self) -> None:
dem1.data[1, 1] = 100

# Translate the DEM 1 "meter" right and add a vertical shift
dem2 = dem1.reproject(dst_bounds=rio.coords.BoundingBox(1, 0, 6, 5), silent=True)
dem2 = dem1.reproject(bounds=rio.coords.BoundingBox(1, 0, 6, 5), silent=True)
dem2 += 1

# Create a vertical shift correction for Rasters ("_r") and for arrays ("_a")
Expand Down Expand Up @@ -783,8 +783,8 @@ def test_blockwise_coreg(self, pipeline: Coreg, subdivision: int) -> None:
def test_blockwise_coreg_large_gaps(self) -> None:
"""Test BlockwiseCoreg when large gaps are encountered, e.g. around the frame of a rotated DEM."""
warnings.simplefilter("error")
reference_dem = self.ref.reproject(dst_crs="EPSG:3413", dst_res=self.ref.res, resampling="bilinear")
dem_to_be_aligned = self.tba.reproject(dst_ref=reference_dem, resampling="bilinear")
reference_dem = self.ref.reproject(crs="EPSG:3413", res=self.ref.res, resampling="bilinear")
dem_to_be_aligned = self.tba.reproject(ref=reference_dem, resampling="bilinear")

blockwise = xdem.coreg.BlockwiseCoreg(xdem.coreg.NuthKaab(), 64, warn_failures=False)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_dem.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_init__vcrs(self) -> None:
# Tests 2: instantiation with a file that has a 3D CRS
# Create such a file
dem = DEM(fn_img)
dem_reproj = dem.reproject(dst_crs=4979)
dem_reproj = dem.reproject(crs=4979)

# Save to temporary folder
temp_dir = tempfile.TemporaryDirectory()
Expand Down Expand Up @@ -263,7 +263,7 @@ def test_to_vcrs(self) -> None:
dem = DEM(fn_dem)

# Reproject in WGS84 2D
dem = dem.reproject(dst_crs=4326)
dem = dem.reproject(crs=4326)
dem_before_trans = dem.copy()

# Set ellipsoid as vertical reference
Expand Down
4 changes: 2 additions & 2 deletions tests/test_spatialstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def test_nd_binning(self) -> None:
"""Check that the nd_binning function works adequately and save dataframes to files for later tests"""

# Subsampler
indices = gu.raster.subsample_array(
self.diff.data.flatten(), subsample=10000, return_indices=True, random_state=42
indices = gu.raster.sample_array(
self.diff.data.flatten(), sample=10000, return_indices=True, random_state=42
)

# 1D binning, by default will create 10 bins
Expand Down
12 changes: 6 additions & 6 deletions xdem/coreg/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
get_array_and_mask,
raster,
subdivide_array,
subsample_array,
sample_array,
)
from tqdm import tqdm

Expand Down Expand Up @@ -450,7 +450,7 @@ def residuals(coefs: NDArrayf, x_coords: NDArrayf, y_coords: NDArrayf, targets:
print("Estimating deramp function...")

# reduce number of elements for speed
rand_indices = subsample_array(x_coords, subsample=subsample, return_indices=True)
rand_indices = sample_array(x_coords, sample=subsample, return_indices=True)
x_coords = x_coords[rand_indices]
y_coords = y_coords[rand_indices]
ddem = ddem[rand_indices]
Expand Down Expand Up @@ -748,9 +748,9 @@ def _get_subsample_on_valid_mask(self, valid_mask: NDArrayb, verbose: bool = Fal
# Build a low memory masked array with invalid values masked to pass to subsampling
ma_valid = np.ma.masked_array(data=np.ones(np.shape(valid_mask), dtype=bool), mask=~valid_mask)
# Take a subsample within the valid values
indices = gu.raster.subsample_array(
indices = gu.raster.sample_array(
ma_valid,
subsample=self._meta["subsample"],
sample=self._meta["subsample"],
return_indices=True,
random_state=self._meta["random_state"],
)
Expand Down Expand Up @@ -1041,8 +1041,8 @@ def fit_pts(
if subsample != 1.0:

# Randomly pick N inliers in the full_mask where N=subsample
random_valids = subsample_array(
ref_dem[z_name].values, subsample=subsample, return_indices=True, random_state=random_state
random_valids = sample_array(
ref_dem[z_name].values, sample=subsample, return_indices=True, random_state=random_state
)

# Subset to the N random inliers
Expand Down
4 changes: 2 additions & 2 deletions xdem/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import numpy as np
import scipy
from geoutils.raster import subsample_array
from geoutils.raster import sample_array
from numpy.polynomial.polynomial import polyval, polyval2d

from xdem._typing import NDArrayf
Expand Down Expand Up @@ -376,7 +376,7 @@ def robust_norder_polynomial_fit(

# Subsample data
if subsample != 1:
subsamp = subsample_array(x, subsample=subsample, return_indices=True, random_state=random_state)
subsamp = sample_array(x, subsample=subsample, return_indices=True, random_state=random_state)
x = x[subsamp]
y = y[subsamp]

Expand Down
6 changes: 3 additions & 3 deletions xdem/spatialstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
Raster,
RasterType,
get_array_and_mask,
subsample_array,
sample_array,
)
from geoutils.vector import Vector, VectorType
from numpy.typing import ArrayLike
Expand Down Expand Up @@ -974,7 +974,7 @@ def _subsample_wrapper(
values_sp = values
coords_sp = coords

index = subsample_array(values_sp, subsample=subsample, return_indices=True, random_state=rnd)
index = sample_array(values_sp, sample=subsample, return_indices=True, random_state=rnd)
values_sub = values_sp[index[0]]
coords_sub = coords_sp[index[0], :]

Expand Down Expand Up @@ -2402,7 +2402,7 @@ def number_effective_samples(
elif isinstance(rasterize_resolution, Raster):

# With a Raster we can get the coordinates directly
mask = V.create_mask(rst=rasterize_resolution, as_array=True).squeeze()
mask = V.create_mask(raster=rasterize_resolution, as_array=True).squeeze()
coords = np.array(rasterize_resolution.coords())
coords_on_mask = coords[:, mask].T

Expand Down

0 comments on commit 8a2067f

Please sign in to comment.