Skip to content

Commit 3b3e59c

Browse files
authored
Update to Raster.dtype refactorisation and cast_nodata logic from GeoUtils (#498)
1 parent 663a702 commit 3b3e59c

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

dev-environment.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ dependencies:
99
- matplotlib=3.*
1010
- pyproj>=3.4,<4
1111
- rasterio>=1.3,<2
12-
- scipy=1.*
12+
- scipy>=1.0,<1.13
1313
- tqdm
1414
- scikit-image=0.*
1515
- scikit-gstat>=1.0
16-
- geoutils>=0.1.2
16+
- geoutils>=0.1.4,<0.2
1717

1818
# Development-specific, to mirror manually in setup.cfg [options.extras_require].
1919
- pip

environment.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ dependencies:
99
- matplotlib=3.*
1010
- pyproj>=3.4,<4
1111
- rasterio>=1.3,<2
12-
- scipy=1.*
12+
- scipy>=1.0,<1.13
1313
- tqdm
1414
- scikit-image=0.*
1515
- scikit-gstat>=1.0
16-
- geoutils>=0.1.2
16+
- geoutils>=0.1.4,<0.2
1717
- pip
1818

1919
# To run CI against latest GeoUtils

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ numpy==1.*
77
matplotlib==3.*
88
pyproj>=3.4,<4
99
rasterio>=1.3,<2
10-
scipy==1.*
10+
scipy>=1.0,<1.13
1111
tqdm
1212
scikit-image==0.*
1313
scikit-gstat>=1.0
14-
geoutils>=0.1.2
14+
geoutils>=0.1.4,<0.2
1515
pip

tests/test_coreg/test_biascorr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,10 +560,10 @@ def test_deramp__synthetic(self, fit_args, order: int) -> None:
560560
deramp = biascorr.Deramp(poly_order=order)
561561
elev_fit_args = fit_args.copy()
562562
if isinstance(elev_fit_args["to_be_aligned_elev"], gpd.GeoDataFrame):
563-
bias_elev = bias_dem.to_pointcloud(data_column_name="z", subsample=20000).ds
563+
bias_elev = bias_dem.to_pointcloud(data_column_name="z", subsample=30000).ds
564564
else:
565565
bias_elev = bias_dem
566-
deramp.fit(elev_fit_args["reference_elev"], to_be_aligned_elev=bias_elev, subsample=10000, random_state=42)
566+
deramp.fit(elev_fit_args["reference_elev"], to_be_aligned_elev=bias_elev, subsample=20000, random_state=42)
567567

568568
# Check high-order fit parameters are the same within 10%
569569
fit_params = deramp._meta["fit_params"]

xdem/dem.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ def from_array(
162162
nodata: int | float | None = None,
163163
area_or_point: Literal["Area", "Point"] | None = None,
164164
tags: dict[str, Any] = None,
165+
cast_nodata: bool = True,
165166
vcrs: Literal["Ellipsoid"]
166167
| Literal["EGM08"]
167168
| Literal["EGM96"]
@@ -180,13 +181,21 @@ def from_array(
180181
:param nodata: Nodata value.
181182
:param area_or_point: Pixel interpretation of the raster, will be stored in AREA_OR_POINT metadata.
182183
:param tags: Metadata stored in a dictionary.
184+
:param cast_nodata: Automatically cast nodata value to the default nodata for the new array type if not
185+
compatible. If False, will raise an error when incompatible.
183186
:param vcrs: Vertical coordinate reference system.
184187
185188
:returns: DEM created from the provided array and georeferencing.
186189
"""
187190
# We first apply the from_array of the parent class
188191
rast = SatelliteImage.from_array(
189-
data=data, transform=transform, crs=crs, nodata=nodata, area_or_point=area_or_point, tags=tags
192+
data=data,
193+
transform=transform,
194+
crs=crs,
195+
nodata=nodata,
196+
area_or_point=area_or_point,
197+
tags=tags,
198+
cast_nodata=cast_nodata,
190199
)
191200
# Then add the vcrs to the class call (that builds on top of the parent class)
192201
return cls(filename_or_dataset=rast, vcrs=vcrs)
@@ -300,7 +309,7 @@ def to_vcrs(
300309
zz_trans = _transform_zz(crs_from=src_ccrs, crs_to=dst_ccrs, xx=xx, yy=yy, zz=zz)
301310

302311
# Update DEM
303-
self._data = zz_trans.astype(self.dtypes[0]) # type: ignore
312+
self._data = zz_trans.astype(self.dtype) # type: ignore
304313

305314
# Update vcrs (which will update ccrs if called)
306315
self.set_vcrs(new_vcrs=vcrs)

0 commit comments

Comments
 (0)