Skip to content

Commit 748faad

Browse files
committed
Update inplace for shift, update vcrs syntax to be similar than rest
1 parent 5bddabf commit 748faad

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

examples/basic/plot_icp_coregistration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
dem = xdem.DEM(xdem.examples.get_path("longyearbyen_ref_dem"))
2323

2424
subset_extent = [523000, 8660000, 529000, 8665000]
25-
dem.crop(subset_extent)
25+
dem = dem.crop(subset_extent)
2626

2727
# %%
2828
# Let's plot a hillshade of the mountain for context.

tests/test_coreg/test_affine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def test_coreg_example_shift(self, shift_px, coreg_class, points_or_raster, verb
182182

183183
# shift DEM by shift_px
184184
shifted_ref = self.ref.copy()
185-
shifted_ref.shift(shift_px[0] * res, shift_px[1] * res)
185+
shifted_ref.shift(shift_px[0] * res, shift_px[1] * res, inplace=True)
186186

187187
shifted_ref_points = shifted_ref.to_points(as_array=False, sample=subsample, pixel_offset="center").ds
188188
shifted_ref_points["E"] = shifted_ref_points.geometry.x

tests/test_dem.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def test_copy(self) -> None:
186186
assert isinstance(r2, xdem.dem.DEM)
187187

188188
# Check all immutable attributes are equal
189-
# raster_attrs = ['bounds', 'count', 'crs', 'dtypes', 'height', 'indexes', 'nodata',
189+
# raster_attrs = ['bounds', 'count', 'crs', 'dtypes', 'height', 'bands', 'nodata',
190190
# 'res', 'shape', 'transform', 'width']
191191
# satimg_attrs = ['satellite', 'sensor', 'product', 'version', 'tile_name', 'datetime']
192192
# dem_attrs = ['vcrs', 'vcrs_grid', 'vcrs_name', 'ccrs']
@@ -271,7 +271,7 @@ def test_to_vcrs(self) -> None:
271271
ccrs_init = dem.ccrs
272272
median_before = np.nanmean(dem)
273273
# Transform to EGM96 geoid
274-
dem.to_vcrs(dst_vcrs="EGM96")
274+
dem.to_vcrs(vcrs="EGM96")
275275
median_after = np.nanmean(dem)
276276

277277
# About 32 meters of difference in Svalbard between EGM96 geoid and ellipsoid

xdem/dem.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ def __init__(
9999
warnings.filterwarnings("ignore", message="Parse metadata from file not implemented")
100100
super().__init__(filename_or_dataset, silent=silent, **kwargs)
101101

102-
# Ensure DEM has only one band: self.indexes can be None when data is not loaded through the Raster class
103-
if self.indexes is not None and len(self.indexes) > 1:
102+
# Ensure DEM has only one band: self.bands can be None when data is not loaded through the Raster class
103+
if self.bands is not None and len(self.bands) > 1:
104104
raise ValueError("DEM rasters should be composed of one band only")
105105

106106
# If the CRS in the raster metadata has a 3rd dimension, could set it as a vertical reference
@@ -233,39 +233,39 @@ def ccrs(self) -> CompoundCRS | CRS | None:
233233

234234
def to_vcrs(
235235
self,
236-
dst_vcrs: Literal["Ellipsoid", "EGM08", "EGM96"] | str | pathlib.Path | VerticalCRS | int,
237-
src_vcrs: Literal["Ellipsoid", "EGM08", "EGM96"] | str | pathlib.Path | VerticalCRS | int | None = None,
236+
vcrs: Literal["Ellipsoid", "EGM08", "EGM96"] | str | pathlib.Path | VerticalCRS | int,
237+
force_source_vcrs: Literal["Ellipsoid", "EGM08", "EGM96"] | str | pathlib.Path | VerticalCRS | int | None = None,
238238
) -> None:
239239
"""
240240
Convert the DEM to another vertical coordinate reference system.
241241
242-
:param dst_vcrs: Destination vertical CRS. Either as a name ("WGS84", "EGM08", "EGM96"),
242+
:param vcrs: Destination vertical CRS. Either as a name ("WGS84", "EGM08", "EGM96"),
243243
an EPSG code or pyproj.crs.VerticalCRS, or a path to a PROJ grid file (https://github.com/OSGeo/PROJ-data)
244-
:param src_vcrs: Force a source vertical CRS (uses metadata by default). Same formats as for `dst_vcrs`.
244+
:param force_source_vcrs: Force a source vertical CRS (uses metadata by default). Same formats as for `dst_vcrs`.
245245
246246
:return:
247247
"""
248248

249-
if self.vcrs is None and src_vcrs is None:
249+
if self.vcrs is None and force_source_vcrs is None:
250250
raise ValueError(
251251
"The current DEM has no vertical reference, define one with .set_vref() "
252252
"or by passing `src_vcrs` to perform a conversion."
253253
)
254254

255255
# Initial Compound CRS (only exists if vertical CRS is not None, as checked above)
256-
if src_vcrs is not None:
256+
if force_source_vcrs is not None:
257257
# Warn if a vertical CRS already existed for that DEM
258258
if self.vcrs is not None:
259259
warnings.warn(
260260
category=UserWarning,
261261
message="Overriding the vertical CRS of the DEM with the one provided in `src_vcrs`.",
262262
)
263-
src_ccrs = _build_ccrs_from_crs_and_vcrs(self.crs, vcrs=src_vcrs)
263+
src_ccrs = _build_ccrs_from_crs_and_vcrs(self.crs, vcrs=force_source_vcrs)
264264
else:
265265
src_ccrs = self.ccrs
266266

267267
# New destination Compound CRS
268-
dst_ccrs = _build_ccrs_from_crs_and_vcrs(self.crs, vcrs=_vcrs_from_user_input(vcrs_input=dst_vcrs))
268+
dst_ccrs = _build_ccrs_from_crs_and_vcrs(self.crs, vcrs=_vcrs_from_user_input(vcrs_input=vcrs))
269269

270270
# If both compound CCRS are equal, do not run any transform
271271
if src_ccrs.equals(dst_ccrs):
@@ -284,4 +284,4 @@ def to_vcrs(
284284
self._data = zz_trans.astype(self.dtypes[0]) # type: ignore
285285

286286
# Update vcrs (which will update ccrs if called)
287-
self.set_vcrs(new_vcrs=dst_vcrs)
287+
self.set_vcrs(new_vcrs=vcrs)

0 commit comments

Comments
 (0)