Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
rhugonnet committed Nov 21, 2024
1 parent 4e03d3d commit 3f0b397
Show file tree
Hide file tree
Showing 48 changed files with 157 additions and 196 deletions.
2 changes: 1 addition & 1 deletion doc/source/background.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,4 @@ And finally:
- **Reproducibility:** all code should be version-controlled and release-based, to ensure consistency of dependent
packages and works;

- **Open-source:** all code should be accessible and re-usable to anyone in the community, for transparency and open governance.
- **Open-source:** all code should be accessible and reusable to anyone in the community, for transparency and open governance.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Plot an example of local hypsometric interpolation at Scott Turnerbreen, Svalbard."""

import geoutils as gu
import matplotlib.pyplot as plt
import numpy as np
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Plot an example of regional hypsometric interpolation in central Svalbard."""

import geoutils as gu
import matplotlib.pyplot as plt
import numpy as np
Expand Down
1 change: 1 addition & 0 deletions doc/source/code/comparison_plot_spatial_interpolation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Plot an example of spatial interpolation of randomly generated errors."""

import geoutils as gu
import matplotlib.pyplot as plt
import numpy as np
Expand Down
1 change: 1 addition & 0 deletions doc/source/code/intricacies_datatypes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Plot example of elevation data types for guide page."""

import matplotlib
import matplotlib.pyplot as plt
import numpy as np
Expand Down
1 change: 1 addition & 0 deletions doc/source/code/robust_mean_std.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Plot example of NMAD/median as robust estimators for guide page."""

import matplotlib.pyplot as plt
import numpy as np

Expand Down
1 change: 1 addition & 0 deletions doc/source/code/robust_vario.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Plot example of Dowd variogram as robust estimator for guide page."""

import matplotlib.pyplot as plt
import numpy as np
from skgstat import OrdinaryKriging, Variogram
Expand Down
1 change: 1 addition & 0 deletions doc/source/code/spatialstats_heterosc_slope.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Code example for spatial statistics"""

import geoutils as gu
import numpy as np

Expand Down
1 change: 1 addition & 0 deletions doc/source/code/spatialstats_standardizing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Documentation plot illustrating standardization of a distribution"""

import matplotlib.pyplot as plt
import numpy as np

Expand Down
1 change: 1 addition & 0 deletions doc/source/code/spatialstats_stationarity_assumption.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Documentation plot illustrating stationarity of mean and variance"""

import matplotlib.pyplot as plt
import numpy as np

Expand Down
1 change: 1 addition & 0 deletions doc/source/code/spatialstats_variogram_covariance.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Documentation plot illustrating the link between variogram and covariance"""

import matplotlib.pyplot as plt
import numpy as np
from skgstat.models import exponential
Expand Down
2 changes: 2 additions & 0 deletions doc/source/sphinxext.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Functions for documentation configuration only, importable by sphinx"""


# To reset resolution setting for each sphinx-gallery example
def reset_mpl(gallery_conf, fname):
# To get a good resolution for displayed figures
Expand Down
1 change: 1 addition & 0 deletions examples/advanced/plot_blockwise_coreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
5. Warp the DEM to apply the X/Y/Z shifts.
"""

import geoutils as gu

# sphinx_gallery_thumbnail_number = 2
Expand Down
1 change: 1 addition & 0 deletions examples/advanced/plot_deramp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
See also the :ref:`deramp` section in feature pages.
"""

import geoutils as gu
import numpy as np

Expand Down
1 change: 1 addition & 0 deletions examples/advanced/plot_heterosc_estimation_modelling.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
**Reference:** `Hugonnet et al. (2022) <https://doi.org/10.1109/jstars.2022.3188922>`_.
"""

import geoutils as gu

# sphinx_gallery_thumbnail_number = 8
Expand Down
1 change: 1 addition & 0 deletions examples/advanced/plot_norm_regional_hypso.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
The consequence is a much more accurate interpolation approach that can be used in a multitude of glacierized settings.
"""

import geoutils as gu

# sphinx_gallery_thumbnail_number = 2
Expand Down
1 change: 1 addition & 0 deletions examples/advanced/plot_slope_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
**References:** `Horn (1981) <https://ieeexplore.ieee.org/document/1456186>`_, `Zevenbergen and Thorne (1987) <http://dx.doi.org/10.1002/esp.3290120107>`_.
"""

import matplotlib.pyplot as plt
import numpy as np

Expand Down
1 change: 1 addition & 0 deletions examples/advanced/plot_standardization.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
**Reference**: `Hugonnet et al. (2022) <https://doi.org/10.1109/jstars.2022.3188922>`_.
"""

import geoutils as gu

# sphinx_gallery_thumbnail_number = 4
Expand Down
1 change: 1 addition & 0 deletions examples/advanced/plot_variogram_estimation_modelling.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
**References:** `Rolstad et al. (2009) <http://dx.doi.org/10.3189/002214309789470950>`_, `Hugonnet et al. (2022) <https://doi.org/10.1109/jstars.2022.3188922>`_.
"""

import geoutils as gu

# sphinx_gallery_thumbnail_number = 6
Expand Down
1 change: 1 addition & 0 deletions examples/basic/plot_dem_subtraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Before DEMs can be compared, they need to be reprojected to the same grid and have the same 3D CRSs. The :func:`~xdem.DEM.reproject` and :func:`~xdem.DEM.to_vcrs` methods are used for this.
"""

import geoutils as gu

import xdem
Expand Down
1 change: 1 addition & 0 deletions examples/basic/plot_icp_coregistration.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
**References**: `Besl and McKay (1992) <https://doi.org/10.1117/12.57955>`_.
"""

# sphinx_gallery_thumbnail_number = 2
import matplotlib.pyplot as plt
import numpy as np
Expand Down
1 change: 1 addition & 0 deletions examples/basic/plot_infer_heterosc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
**Reference:** `Hugonnet et al. (2022) <https://doi.org/10.1109/jstars.2022.3188922>`_.
"""

import geoutils as gu

# sphinx_gallery_thumbnail_number = 1
Expand Down
1 change: 1 addition & 0 deletions examples/basic/plot_infer_spatial_correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
**References:** `Rolstad et al. (2009) <http://dx.doi.org/10.3189/002214309789470950>`_, `Hugonnet et al. (2022) <https://doi.org/10.1109/jstars.2022.3188922>`_.
"""

import geoutils as gu

# sphinx_gallery_thumbnail_number = 1
Expand Down
1 change: 1 addition & 0 deletions examples/basic/plot_nuth_kaab.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
**Reference:** `Nuth and Kääb (2011) <https:https://doi.org/10.5194/tc-5-271-2011>`_.
"""

import geoutils as gu
import numpy as np

Expand Down
1 change: 1 addition & 0 deletions examples/basic/plot_spatial_error_propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
**References:** `Rolstad et al. (2009) <http://dx.doi.org/10.3189/002214309789470950>`_, `Hugonnet et al. (2022) <https://doi.org/10.1109/jstars.2022.3188922>`_.
"""

import geoutils as gu
import matplotlib.pyplot as plt

Expand Down
1 change: 1 addition & 0 deletions examples/basic/plot_terrain_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
`Riley et al. (1999) <http://download.osgeo.org/qgis/doc/reference-docs/Terrain_Ruggedness_Index.pdf>`_ (terrain
ruggedness index), `Jenness (2004) <https://doi.org/10.2193/0091-7648(2004)032%5B0829:CLSAFD%5D2.0.CO;2>`_ (rugosity).
"""

# sphinx_gallery_thumbnail_number = 1
import matplotlib.pyplot as plt

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This file now only serves for backward-compatibility for routines explicitly calling python setup.py"""

from setuptools import setup

setup()
3 changes: 2 additions & 1 deletion tests/test_coreg/test_affine.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions to test the affine coregistrations."""

from __future__ import annotations

import warnings
Expand Down Expand Up @@ -409,7 +410,7 @@ def test_coreg_rigid__synthetic(self, fit_args, shifts_rotations, coreg_method)
matrix[:3, 3] = shifts

# Pass a centroid
centroid = [ref.bounds.left, ref.bounds.bottom, np.nanmean(ref)]
centroid = (ref.bounds.left, ref.bounds.bottom, np.nanmean(ref))
ref_shifted_rotated = coreg.apply_matrix(ref, matrix=matrix, centroid=centroid)

# Convert to point cloud if input was point cloud
Expand Down
14 changes: 8 additions & 6 deletions tests/test_coreg/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def assert_coreg_meta_equal(input1: Any, input2: Any) -> bool:
"""Short test function to check equality of coreg dictionary values."""

# Different equality check based on input: number, callable, array, dataframe
if type(input1) != type(input2):
if not isinstance(input1, type(input2)):
return False
elif isinstance(input1, (str, float, int, np.floating, np.integer, tuple, list)) or callable(input1):
return input1 == input2
Expand Down Expand Up @@ -466,12 +466,16 @@ def test_fit_and_apply__pipeline(self) -> None:
assert aligned_and.raster_equal(aligned_then, warn_failure_reason=True)
assert list(coreg_fit_and_apply.pipeline[0].meta.keys()) == list(coreg_fit_then_apply.pipeline[0].meta.keys())
assert all(
assert_coreg_meta_equal(coreg_fit_and_apply.pipeline[0].meta[k], coreg_fit_then_apply.pipeline[0].meta[k])
assert_coreg_meta_equal(
coreg_fit_and_apply.pipeline[0].meta[k], coreg_fit_then_apply.pipeline[0].meta[k] # type: ignore
)
for k in coreg_fit_and_apply.pipeline[0].meta.keys()
)
assert list(coreg_fit_and_apply.pipeline[1].meta.keys()) == list(coreg_fit_then_apply.pipeline[1].meta.keys())
assert all(
assert_coreg_meta_equal(coreg_fit_and_apply.pipeline[1].meta[k], coreg_fit_then_apply.pipeline[1].meta[k])
assert_coreg_meta_equal(
coreg_fit_and_apply.pipeline[1].meta[k], coreg_fit_then_apply.pipeline[1].meta[k] # type: ignore
)
for k in coreg_fit_and_apply.pipeline[1].meta.keys()
)

Expand Down Expand Up @@ -702,9 +706,7 @@ def test_pipeline_combinations__biasvar(
"""Test pipelines with all combinations of coregistration subclasses with bias variables"""

# Create a pipeline from one affine and one biascorr methods
pipeline = coreg.CoregPipeline([coreg1(), coreg.BiasCorr(**coreg2_init_kwargs)])
print(pipeline.pipeline[0].meta["inputs"]["random"]["subsample"])
print(pipeline.pipeline[1].meta["inputs"]["random"]["subsample"])
pipeline = coreg.CoregPipeline([coreg1(), coreg.BiasCorr(**coreg2_init_kwargs)]) # type: ignore
bias_vars = {"slope": xdem.terrain.slope(self.ref), "aspect": xdem.terrain.aspect(self.ref)}
pipeline.fit(**self.fit_params, bias_vars=bias_vars, subsample=5000, random_state=42)

Expand Down
1 change: 1 addition & 0 deletions tests/test_coreg/test_biascorr.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for the biascorr module (non-rigid coregistrations)."""

from __future__ import annotations

import re
Expand Down
1 change: 1 addition & 0 deletions tests/test_coreg/test_workflows.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions to test the coregistration workflows."""

from __future__ import annotations

import os
Expand Down
1 change: 1 addition & 0 deletions tests/test_dem.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" Functions to test the DEM tools."""

from __future__ import annotations

import os
Expand Down
1 change: 1 addition & 0 deletions tests/test_demcollection.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions to test the DEM collection tools."""

import datetime
import warnings

Expand Down
1 change: 1 addition & 0 deletions tests/test_doc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions to test the documentation."""

import logging
import os
import platform
Expand Down
1 change: 1 addition & 0 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions to test the example data."""

from __future__ import annotations

import geoutils as gu
Expand Down
1 change: 1 addition & 0 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions to test the filtering tools."""

from __future__ import annotations

import geoutils as gu
Expand Down
1 change: 1 addition & 0 deletions tests/test_fit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Functions to test the fitting tools.
"""

import platform
import warnings

Expand Down
1 change: 1 addition & 0 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test the xdem.misc functions."""

from __future__ import annotations

import os
Expand Down
1 change: 1 addition & 0 deletions tests/test_spatialstats.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions to test the spatial statistics."""

from __future__ import annotations

import os
Expand Down
2 changes: 1 addition & 1 deletion tests/test_terrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def test_raster_argument(self) -> None:

assert slope != aspect

assert type(slope) == type(aspect)
assert isinstance(slope, type(aspect))
assert all(isinstance(r, gu.Raster) for r in (aspect, slope, self.dem))

assert slope.transform == self.dem.transform == aspect.transform
Expand Down
1 change: 1 addition & 0 deletions tests/test_vcrs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for vertical CRS transformation tools."""

from __future__ import annotations

import pathlib
Expand Down
4 changes: 2 additions & 2 deletions xdem/coreg/affine.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ def sub_dh_interpolator(shift_x: float, shift_y: float) -> NDArrayf:
else:

# Identify which dataset is point or raster
pts_elev = ref_elev if isinstance(ref_elev, gpd.GeoDataFrame) else tba_elev
rst_elev = ref_elev if not isinstance(ref_elev, gpd.GeoDataFrame) else tba_elev
pts_elev: gpd.GeoDataFrame = ref_elev if isinstance(ref_elev, gpd.GeoDataFrame) else tba_elev
rst_elev: NDArrayf = ref_elev if not isinstance(ref_elev, gpd.GeoDataFrame) else tba_elev
# Check which input is reference, to compute the dh always in the same direction (ref minus tba) further below
ref = "point" if isinstance(ref_elev, gpd.GeoDataFrame) else "raster"

Expand Down
Loading

0 comments on commit 3f0b397

Please sign in to comment.