Skip to content

Commit

Permalink
Merge branch '280-bug-ci-matplotlib-fonction' into 'master'
Browse files Browse the repository at this point in the history
Resolve "Bug CI : matplotlib fonction"

Closes #280

See merge request 3d/demcompare!209
  • Loading branch information
duboise-cnes committed Jan 7, 2025
2 parents e2514f0 + 79c72a8 commit 7867641
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 36 deletions.
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,43 @@ 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$

- 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

Expand All @@ -49,4 +49,4 @@ repos:
language: system
files: ^(docs/.*|demcompare/.*)$
pass_filenames: False
stages: [push]
stages: [pre-push]
52 changes: 27 additions & 25 deletions demcompare/coregistration/nuth_kaab_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -698,42 +698,44 @@ 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,
".",
color="silver",
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):
"""
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions tests/coregistration/test_coregistration_gironde.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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,
},
}
Expand All @@ -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"][
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 7867641

Please sign in to comment.