Skip to content

Commit 42ae7da

Browse files
committed
Fix tests with new geoutils
1 parent 36ce632 commit 42ae7da

File tree

5 files changed

+24
-16
lines changed

5 files changed

+24
-16
lines changed

tests/test_coreg/test_base.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,6 @@ def test_error_method(self) -> None:
9898
dem3 = dem1.copy() + np.random.random(size=dem1.size).reshape(dem1.shape)
9999
assert abs(vshiftcorr.error(dem1, dem3, transform=affine, crs=crs, error_type="std") - np.std(dem3)) < 1e-6
100100

101-
def test_ij_xy(self, i: int = 10, j: int = 20) -> None:
102-
"""
103-
Test the reversibility of ij2xy and xy2ij, which is important for point co-registration.
104-
"""
105-
x, y = self.ref.ij2xy(i, j, offset="ul")
106-
i, j = self.ref.xy2ij(x, y, shift_area_or_point=False)
107-
assert i == pytest.approx(10)
108-
assert j == pytest.approx(20)
109-
110101
@pytest.mark.parametrize("subsample", [10, 10000, 0.5, 1]) # type: ignore
111102
def test_get_subsample_on_valid_mask(self, subsample: float | int) -> None:
112103
"""Test the subsampling function called by all subclasses"""

tests/test_dem.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ def test_set_vcrs(self) -> None:
236236
assert dem.vcrs_grid == "us_nga_egm08_25.tif"
237237

238238
# -- Test 2: we check with grids --
239+
# Most grids aren't going to be downloaded, so this warning can be raised
240+
warnings.filterwarnings("ignore", category=UserWarning, message="Grid not found in *")
241+
239242
dem.set_vcrs(new_vcrs="us_nga_egm96_15.tif")
240243
assert dem.vcrs_name == "unknown using geoidgrids=us_nga_egm96_15.tif"
241244
assert dem.vcrs_grid == "us_nga_egm96_15.tif"
@@ -312,13 +315,16 @@ def test_to_vcrs__equal_warning(self) -> None:
312315
# Compare to manually-extracted shifts at specific coordinates for the geoid grids
313316
egm96_chile = {"grid": "us_nga_egm96_15.tif", "lon": -68, "lat": -20, "shift": 42}
314317
egm08_chile = {"grid": "us_nga_egm08_25.tif", "lon": -68, "lat": -20, "shift": 42}
315-
geoid96_alaska = {"grid": "us_noaa_geoid06_ak.tif", "lon": -145, "lat": 62, "shift": 17}
318+
geoid96_alaska = {"grid": "us_noaa_geoid06_ak.tif", "lon": -145, "lat": 62, "shift": 15}
316319
isn93_iceland = {"grid": "is_lmi_Icegeoid_ISN93.tif", "lon": -18, "lat": 65, "shift": 68}
317320

318321
@pytest.mark.parametrize("grid_shifts", [egm08_chile, egm08_chile, geoid96_alaska, isn93_iceland]) # type: ignore
319322
def test_to_vcrs__grids(self, grid_shifts: dict[str, Any]) -> None:
320323
"""Tests grids to convert vertical CRS."""
321324

325+
# Most grids aren't going to be downloaded, so this warning can be raised
326+
warnings.filterwarnings("ignore", category=UserWarning, message="Grid not found in *")
327+
322328
# Using an arbitrary elevation of 100 m (no influence on the transformation)
323329
dem = DEM.from_array(
324330
data=np.array([[100, 100]]),

tests/test_vcrs.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import pathlib
55
import re
6+
import warnings
67
from typing import Any
78

89
import numpy as np
@@ -12,8 +13,8 @@
1213
import xdem
1314
import xdem.vcrs
1415

15-
1616
class TestVCRS:
17+
1718
def test_parse_vcrs_name_from_product(self) -> None:
1819
"""Test parsing of vertical CRS name from DEM product name."""
1920

@@ -66,6 +67,9 @@ def test_vcrs_from_crs(self, input_output: tuple[CRS, CRS]) -> None:
6667
def test_vcrs_from_user_input(self, vcrs_input: str | pathlib.Path | int | CRS) -> None:
6768
"""Tests the function _vcrs_from_user_input for varying user inputs, for which it will return a CRS."""
6869

70+
# Most grids aren't going to be downloaded, so this warning can be raised
71+
warnings.filterwarnings("ignore", category=UserWarning, message="Grid not found in *")
72+
6973
# Get user input
7074
vcrs = xdem.dem._vcrs_from_user_input(vcrs_input)
7175

@@ -116,6 +120,9 @@ def test_vcrs_from_user_input__errors(self) -> None:
116120
def test_build_vcrs_from_grid(self, grid: str) -> None:
117121
"""Test that vertical CRS are correctly built from grid"""
118122

123+
# Most grids aren't going to be downloaded, so this warning can be raised
124+
warnings.filterwarnings("ignore", category=UserWarning, message="Grid not found in *")
125+
119126
# Build vertical CRS
120127
vcrs = xdem.vcrs._build_vcrs_from_grid(grid=grid)
121128
assert vcrs.is_vertical
@@ -132,6 +139,9 @@ def test_build_vcrs_from_grid(self, grid: str) -> None:
132139
def test_build_ccrs_from_crs_and_vcrs(self, crs: CRS, vcrs_input: CRS | str) -> None:
133140
"""Test the function build_ccrs_from_crs_and_vcrs."""
134141

142+
# Most grids aren't going to be downloaded, so this warning can be raised
143+
warnings.filterwarnings("ignore", category=UserWarning, message="Grid not found in *")
144+
135145
# Get the vertical CRS from user input
136146
vcrs = xdem.vcrs._vcrs_from_user_input(vcrs_input=vcrs_input)
137147

@@ -180,6 +190,9 @@ def test_build_ccrs_from_crs_and_vcrs__errors(self) -> None:
180190
def test_transform_zz(self, grid_shifts: dict[str, Any]) -> None:
181191
"""Tests grids to convert vertical CRS."""
182192

193+
# Most grids aren't going to be downloaded, so this warning can be raised
194+
warnings.filterwarnings("ignore", category=UserWarning, message="Grid not found in *")
195+
183196
# Using an arbitrary elevation of 100 m (no influence on the transformation)
184197
zz = 100
185198
xx = grid_shifts["lon"]

xdem/coreg/base.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ def _residuals_df(
133133
arr_ = dem.data.astype(np.float32)
134134

135135
# get residual error at the point on DEM.
136-
i, j = dem.xy2ij(
137-
df_shifted["E"].values, df_shifted["N"].values, op=np.float32, shift_area_or_point=("AREA_OR_POINT" in dem.tags)
138-
)
136+
i, j = dem.xy2ij(df_shifted["E"].values, df_shifted["N"].values)
139137

140138
# ndimage return
141139
dem_h = scipy.ndimage.map_coordinates(arr_, [i, j], order=1, mode="nearest", **kwargs)
@@ -177,7 +175,7 @@ def _df_sampling_from_dem(
177175
mask = dem.data.mask
178176

179177
# Get value
180-
x, y = dem.ij2xy(i[~mask[i, j]], j[~mask[i, j]], offset=offset)
178+
x, y = dem.ij2xy(i[~mask[i, j]], j[~mask[i, j]])
181179
z = scipy.ndimage.map_coordinates(
182180
dem.data.astype(np.float32), [i[~mask[i, j]], j[~mask[i, j]]], order=order, mode="nearest"
183181
)

xdem/dem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def to_vcrs(
296296

297297
# Transform elevation with new vertical CRS
298298
zz = self.data
299-
xx, yy = self.coords(offset="center")
299+
xx, yy = self.coords()
300300
zz_trans = _transform_zz(crs_from=src_ccrs, crs_to=dst_ccrs, xx=xx, yy=yy, zz=zz)
301301

302302
# Update DEM

0 commit comments

Comments
 (0)