diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a66128c..71fa430 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,35 +3,35 @@ repos: hooks: - id: isort name: Isort - stages: [commit] + stages: [pre-commit] language: system entry: isort types: [python] - id: black name: Black - stages: [commit] + stages: [pre-commit] language: system entry: black types: [python] - id: flake8 name: Flake8 - stages: [commit] + stages: [pre-commit] language: system entry: flake8 types: [python] - id: pylint name: PyLint - stages: [commit] + stages: [pre-commit] language: system entry: pylint --rcfile=.pylintrc files: \.py$ - id: mypy name: mypy - stages: [ commit ] + stages: [ pre-commit ] language: system entry: mypy files: \.py$ @@ -39,7 +39,7 @@ repos: - id: jupyter-nb-clear-output name: jupyter-nb-clear-output files: \.ipynb$ - stages: [commit] + stages: [pre-commit] language: system entry: jupyter nbconvert --ClearOutputPreprocessor.enabled=True --inplace @@ -49,4 +49,4 @@ repos: language: system files: ^(docs/.*|demcompare/.*)$ pass_filenames: False - stages: [push] + stages: [pre-push] diff --git a/demcompare/coregistration/nuth_kaab_internal.py b/demcompare/coregistration/nuth_kaab_internal.py index 518c981..9bf8035 100644 --- a/demcompare/coregistration/nuth_kaab_internal.py +++ b/demcompare/coregistration/nuth_kaab_internal.py @@ -36,7 +36,7 @@ from typing import Tuple, Union # Third party imports -import matplotlib.pyplot as pl +import matplotlib.pyplot as plt import numpy as np import xarray as xr from json_checker import And @@ -187,18 +187,18 @@ def _coregister_dems_algorithm( # pylint:disable=too-many-locals np.abs(initial_dh[np.isfinite(initial_dh)] - median) ) maxval = 3 * nmad_old - pl.figure(1, figsize=(7.0, 8.0)) - pl.imshow(initial_dh, vmin=-maxval, vmax=maxval) - color_bar = pl.colorbar() + fig1, ax1 = plt.subplots(figsize=(7.0, 8.0)) + image_ax1 = ax1.imshow(initial_dh, vmin=-maxval, vmax=maxval) + color_bar = fig1.colorbar(image_ax1, ax=ax1) color_bar.set_label("Elevation difference (m)") if self.save_optional_outputs: output_dir_ = os.path.join(self.output_dir, "./nuth_kaab_tmp_dir") - pl.savefig( + fig1.savefig( os.path.join(output_dir_, "ElevationDiff_BeforeCoreg.png"), dpi=100, bbox_inches="tight", ) - pl.close() + plt.close(fig1) # Initialize offsets x_offset, y_offset = 0.0, 0.0 logging.debug("Nuth & Kaab iterations: %s", self.iterations) @@ -327,18 +327,18 @@ def _coregister_dems_algorithm( # pylint:disable=too-many-locals np.abs(final_dh[np.isfinite(final_dh)] - median) ) maxval = 3 * nmad_old - pl.figure(1, figsize=(7.0, 8.0)) - pl.imshow(final_dh, vmin=-maxval, vmax=maxval) - color_bar = pl.colorbar() - color_bar.set_label("Elevation difference (m)") + fig2, ax2 = plt.subplots(figsize=(7.0, 8.0)) + image_ax2 = ax2.imshow(final_dh, vmin=-maxval, vmax=maxval) + color_bar2 = fig2.colorbar(image_ax2, ax=ax2) + color_bar2.set_label("Elevation difference (m)") if self.save_optional_outputs: output_dir_ = os.path.join(self.output_dir, "./nuth_kaab_tmp_dir") - pl.savefig( + fig2.savefig( os.path.join(output_dir_, "ElevationDiff_AfterCoreg.png"), dpi=100, bbox_inches="tight", ) - pl.close() + plt.close(fig2) z_offset = float(np.nanmean(final_dh)) transform = Transformation( x_offset=x_offset, @@ -698,8 +698,8 @@ def _save_fit_plots( """ # plotting results - pl.figure(1, figsize=(7.0, 8.0)) - pl.plot( + fig, ax = plt.subplots(figsize=(7.0, 8.0)) + ax.plot( aspect * 180 / np.pi, target, ".", @@ -707,33 +707,35 @@ def _save_fit_plots( markersize=3, label="target", ) - pl.plot( + ax.plot( aspect * 180 / np.pi, target_filt, "c.", markersize=3, label="target filtered", ) - pl.plot( + ax.plot( self.aspect_bounds * 180 / np.pi, slice_filt_median, "k.", label="median", ) - pl.plot( - self.aspect_bounds * 180 / np.pi, yfit, "b-", label="median fit" + ax.plot( + self.aspect_bounds * 180 / np.pi, + yfit, + "b-", + label="median fit", ) - pl.xlabel("Terrain aspect (deg)") - pl.ylabel(r"dh/tan($\alpha$) (meters)") + ax.set_xlabel("Terrain aspect (deg)") + ax.set_ylabel(r"dh/tan($\alpha$) (meters)") # set axes limit on twice the min/max of the median, # or +-2 if the value is below it - axes = pl.gca() ax_min = np.min([np.nanmin(slice_filt_median) * 2, -2]) ax_max = np.max([np.nanmax(slice_filt_median) * 2, 2]) - axes.set_ylim((ax_min, ax_max)) - pl.legend(loc="upper left") - pl.savefig(plot_file, dpi=100, bbox_inches="tight") - pl.close() + ax.set_ylim((ax_min, ax_max)) + ax.legend(loc="upper left") + fig.savefig(plot_file, dpi=100, bbox_inches="tight") + plt.close(fig) def save_results_dict(self): """ diff --git a/pyproject.toml b/pyproject.toml index 7441d7d..b4b4c50 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,6 +36,7 @@ profile = 'black' line_length = 80 [tool.mypy] +explicit_package_bases = true no_implicit_optional = false strict_optional = false allow_redefinition = true diff --git a/tests/coregistration/test_coregistration_gironde.py b/tests/coregistration/test_coregistration_gironde.py index 2f5a9b2..819ee29 100644 --- a/tests/coregistration/test_coregistration_gironde.py +++ b/tests/coregistration/test_coregistration_gironde.py @@ -83,7 +83,7 @@ def test_compute_coregistration_with_gironde_test_data_sampling_dem(): "nuth_offset": -1.43664, "total_offset": -1.43664, "unit_offset": "px", - "total_bias_value": -718.31907, + "total_bias_value": -718.31906, "unit_bias_value": "m", }, "dy": { @@ -94,9 +94,9 @@ def test_compute_coregistration_with_gironde_test_data_sampling_dem(): "unit_bias_value": "m", }, "gdal_translate_bounds": { - "ulx": 599536.68093, + "ulx": 599536.68094, "uly": 5099954.51619, - "lrx": 708536.68093, + "lrx": 708536.68094, "lry": 4990954.51619, }, } @@ -120,6 +120,7 @@ def test_compute_coregistration_with_gironde_test_data_sampling_dem(): gt_plani_results["dx"]["unit_offset"] == coregistration_results["coregistration_results"]["dx"]["unit_offset"] ) + np.testing.assert_equal( gt_plani_results["dx"]["total_bias_value"], coregistration_results["coregistration_results"]["dx"][ diff --git a/tests/data/end_to_end_data/gironde_test_data/ref_output/coregistration/coregistration_results.json b/tests/data/end_to_end_data/gironde_test_data/ref_output/coregistration/coregistration_results.json index ac94b4e..7658770 100644 --- a/tests/data/end_to_end_data/gironde_test_data/ref_output/coregistration/coregistration_results.json +++ b/tests/data/end_to_end_data/gironde_test_data/ref_output/coregistration/coregistration_results.json @@ -24,7 +24,7 @@ "nuth_offset": -1.43664, "total_offset": -1.43664, "unit_offset": "px", - "total_bias_value": -718.31907, + "total_bias_value": -718.31906, "unit_bias_value": "m" }, "dy": {