From 207f69639cb8eb35ed346a6843c95efa2ef2e8ba Mon Sep 17 00:00:00 2001 From: Amelie Date: Tue, 4 Jun 2024 16:45:08 +0200 Subject: [PATCH] fix: precommit --- xdem/coreg/base.py | 15 ++++++++++----- xdem/coreg/biascorr.py | 6 +++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/xdem/coreg/base.py b/xdem/coreg/base.py index 212a3d20..fea745d5 100644 --- a/xdem/coreg/base.py +++ b/xdem/coreg/base.py @@ -644,7 +644,7 @@ def _preprocess_coreg_fit( return ref_elev, tba_elev, inlier_mask, transform, crs -def mask_array(arr: NDArrayf, nodata: int | float): +def mask_array(arr: NDArrayf, nodata: int | float) -> NDArrayf: """Convert invalid data to nan.""" return np.where(np.logical_or(~da.isfinite(arr), arr == nodata), np.nan, arr) @@ -717,7 +717,9 @@ def _postprocess_coreg_apply_pts( return applied_elev -def _postprocess_coreg_apply_xarray_xarray(applied_elev: da.Array, out_transform: affine.Affine): +def _postprocess_coreg_apply_xarray_xarray( + applied_elev: da.Array, out_transform: affine.Affine +) -> tuple[da.Array, affine.Affine]: """Post-processing and checks of apply for dask inputs.""" # TODO mimic what is happening in the postprocess_coreg_apply_rst. @@ -1321,9 +1323,12 @@ def _get_subsample_on_valid_mask(self, valid_mask: NDArrayb, verbose: bool = Fal def _get_subsample_indices_dask(self, data: NDArrayb) -> tuple[NDArrayf, NDArrayf]: """Get subsampled indices from a dask array.""" - # subsample value is handled in delyyed_subsample + # subsample value is handled in delayed_subsample indices = delayed_subsample( - darr=data, subsample=self._meta["subsample"], return_indices=True, silence_max_subsample=True + darr=data, + subsample=self._meta["subsample"], + return_indices=True, + silence_max_subsample=True, ) # Write final subsample to class @@ -1761,7 +1766,7 @@ def _apply_func(self, **kwargs: Any) -> tuple[NDArrayf | gpd.GeoDataFrame, affin """Distribute to _apply_rst and _apply_pts based on input and method availability.""" # If input is a raster - if isinstance(kwargs["elev"], np.ndarray): + if isinstance(kwargs["elev"], (np.ndarray, da.Array)): # See if a _apply_rst exists try: diff --git a/xdem/coreg/biascorr.py b/xdem/coreg/biascorr.py index 9c8c0fec..421b33ec 100644 --- a/xdem/coreg/biascorr.py +++ b/xdem/coreg/biascorr.py @@ -1050,7 +1050,11 @@ def _apply_rst( # TODO move this function somewhere sensible -def meshgrid(_, axis="x", block_info=None): +def meshgrid( + _: NDArrayf | NDArrayb, + block_info: dict[Any, Any], + axis: Literal["x", "y"] = "x", +) -> NDArrayf: """A bit of a hack to create a meshgrid for a dask array.""" loc = block_info[0]["array-location"] mesh = np.meshgrid(np.arange(*loc[1]), np.arange(*loc[0]))