From 7a02d2a12faba2697c843c05a87bd48294dd8d5b Mon Sep 17 00:00:00 2001 From: Andy Aschwanden Date: Thu, 19 Dec 2024 15:04:53 +0100 Subject: [PATCH] Fixed bug in sensitivity plot --- README.md | 2 +- analysis/analyze_scalar.py | 11 +++++++---- pism_ragis/data/ragis_config.toml | 2 +- pism_ragis/decorators.py | 2 +- pism_ragis/plotting.py | 10 ++++++++-- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 417d56b..3dded52 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ [![DOI](https://zenodo.org/badge/562988605.svg)](https://zenodo.org/badge/latestdoi/562988605) [![License: GPL-3.0](https://img.shields.io:/github/license/pism/pypac)](https://opensource.org/licenses/GPL-3.0) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) -[![flake8](https://img.shields.io/badge/flake8-enabled-green)](https://github.com/PyCQA/flake8) [![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/) +[![linting: pylint](https://img.shields.io/badge/linting-pylint-yellowgreen)](https://github.com/pylint-dev/pylint) # pism-ragis: A Reanalysis for the Greenland Ice Sheet (RAGIS) diff --git a/analysis/analyze_scalar.py b/analysis/analyze_scalar.py index 33db58d..6776296 100644 --- a/analysis/analyze_scalar.py +++ b/analysis/analyze_scalar.py @@ -283,7 +283,7 @@ def run_sampling( return prior_posterior -def filter_config(ds: xr.Dataset, params: List[str]) -> xr.DataArray: +def filter_config(ds: xr.Dataset, params: list[str]) -> xr.DataArray: """ Filter the configuration parameters from the dataset. @@ -927,7 +927,7 @@ def run_sensitivity_analysis( [intersection_grace, intersection_mankoff], [["mass_balance"], ["mass_balance", "grounding_line_flux"]], ): - sobol_response_ds = basin_group.sel(time=slice("1980-01-01", "1990-01-01")) + sobol_response_ds = basin_group sobol_input_df = params_df[params_df["basin"].isin(intersection)] sensitivity_indices_list.append( @@ -969,10 +969,13 @@ def run_sensitivity_analysis( for basin in aggregated_ds.basin.values: for filter_var in aggregated_ds.filtered_by.values: plot_sensitivity_indices( - aggregated_ds.sel(filtered_by=filter_var) + aggregated_ds.sel(basin=basin, filtered_by=filter_var) .rolling({"time": 13}) - .mean(), + .mean() + .sel(time=slice("1980-01-01", "2020-01-01")), indices_var=indices_var, indices_conf_var=indices_conf_var, + basin=basin, + filter_var=filter_var, fig_dir=fig_dir, ) diff --git a/pism_ragis/data/ragis_config.toml b/pism_ragis/data/ragis_config.toml index b9f3925..649e2d0 100644 --- a/pism_ragis/data/ragis_config.toml +++ b/pism_ragis/data/ragis_config.toml @@ -46,7 +46,7 @@ "atmosphere" = "Climate" "ocean" = "Ocean" "calving" = "Frontal Ablation" -"geometry" = "Frontal Ablation" +"geometry" = "Retreat" "frontal_melt" = "Frontal Ablation" "basal_resistance" = "Flow" "basal_yield_stress" = "Flow" diff --git a/pism_ragis/decorators.py b/pism_ragis/decorators.py index 33a7e61..279e013 100644 --- a/pism_ragis/decorators.py +++ b/pism_ragis/decorators.py @@ -28,7 +28,7 @@ from pism_ragis.logger import get_logger -logger: logging.Logger = get_logger(__name__) +logger: logging.Logger = get_logger("pism_ragis") def timeit(func): diff --git a/pism_ragis/plotting.py b/pism_ragis/plotting.py index 9b58c5d..5caaca6 100644 --- a/pism_ragis/plotting.py +++ b/pism_ragis/plotting.py @@ -200,6 +200,8 @@ def plot_sensitivity_indices( ds: xr.Dataset, indices_var: str = "S1", indices_conf_var: str = "S1_conf", + basin: str = "", + filter_var: str = "", fig_dir: Union[str, Path] = "figures", fontsize: float = 6, ): @@ -214,6 +216,10 @@ def plot_sensitivity_indices( The variable name for sensitivity indices in the dataset, by default "S1". indices_conf_var : str, optional The variable name for confidence intervals of sensitivity indices in the dataset, by default "S1_conf". + basin : str, optional + The basin for which the sensitivity indices are plotted, by default None. + filter_var : str, optional + The variable used for filtering, by default "". fig_dir : Union[str, Path], optional The directory where the figures will be saved, by default "figures". fontsize : float, optional @@ -242,8 +248,8 @@ def plot_sensitivity_indices( legend = ax.legend(loc="upper left") legend.get_frame().set_linewidth(0.0) legend.get_frame().set_alpha(0.0) - ax.set_title(f"{indices_var} filtered by sensitivity_indices_group") - fn = pdf_dir / f"{indices_var}_filtered_by_sensitivity_indices_group.pdf" + ax.set_title(f"{indices_var} for basin {basin} for {filter_var}") + fn = pdf_dir / f"basin_{basin}_{indices_var}_for_{filter_var}.pdf" fig.savefig(fn) plt.close()