Skip to content

Commit

Permalink
Creating a (temporary) mode UQ
Browse files Browse the repository at this point in the history
  • Loading branch information
aaschwanden committed Nov 27, 2024
1 parent c68a59c commit 16d6c38
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
33 changes: 22 additions & 11 deletions analysis/analyze_scalar.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from typing import Any, Callable, Dict, Hashable, List, Mapping, Union

import dask
import matplotlib
import numpy as np
import pandas as pd
import pylab as plt
Expand All @@ -53,7 +54,7 @@

logger = get_logger("pism_ragis")


matplotlib.use("Agg")
xr.set_options(keep_attrs=True)
plt.style.use("tableau-colorblind10")

Expand Down Expand Up @@ -334,7 +335,6 @@ def run_delta_analysis(
print("Calculating Sensitivity Indices")
print("===============================")

ds = ds.load()
client = Client()
print(f"Open client in browser: {client.dashboard_link}")
all_delta_indices_list = []
Expand All @@ -353,7 +353,7 @@ def run_delta_analysis(
f" ...sensitivity indices for basin {gdim} filtered by {filter_var} ",
)

responses = ds.sel({"basin": gdim})[filter_var]
responses = ds.sel({"basin": gdim})[filter_var].load()
responses_scattered = client.scatter(
[
responses.isel({"time": k}).to_numpy()
Expand Down Expand Up @@ -1095,12 +1095,12 @@ def plot_obs_sims_3(
sim_posterior = simulated_mankoff_basins_filtered_ds
sim_posterior["Ensemble"] = "Posterior"

start_time = time.time()
with tqdm(
desc="Plotting basins",
total=len(observed_mankoff_basins_resampled_ds.basin),
) as progress_bar:
# for basin in observed_mankoff_basins_resampled_ds.basin:
for basin in ["GIS"]:
for basin in observed_mankoff_basins_resampled_ds.basin:
plot_obs_sims(
observed_mankoff_basins_resampled_ds.sel(basin=basin),
sim_prior.sel(basin=basin),
Expand All @@ -1112,6 +1112,7 @@ def plot_obs_sims_3(
obs_alpha=obs_alpha,
sim_alpha=sim_alpha,
)
progress_bar.update()

# with ThreadPoolExecutor(max_workers=options.n_jobs) as executor:
# futures = []
Expand All @@ -1130,12 +1131,18 @@ def plot_obs_sims_3(
# sim_alpha=sim_alpha,
# )
# )
# for future in as_completed(futures):
# for future in tqdm(
# as_completed(futures), total=len(futures), desc="Processing basins"
# ):
# try:
# future.result()
# except Exception as e:
# print(f"An error occurred: {e}")

end_time = time.time()
elapsed_time = end_time - start_time
print(f"...took {elapsed_time:.2f}s")

prior_posterior = pd.concat(prior_posterior_list).reset_index()
prior_posterior = prior_posterior.apply(prp.convert_column_to_numeric)
# Define a mapping of columns to their corresponding functions
Expand Down Expand Up @@ -1262,7 +1269,6 @@ def plot_obs_sims_3(
)

plt.rcParams["font.size"] = 6

for indices_var, conf_var in zip(indices_vars, indices_conf):
for basin in aggregated_indices.basin.values:
for filter_var in aggregated_indices.filtered_by.values:
Expand All @@ -1274,14 +1280,19 @@ def plot_obs_sims_3(
conf_da = aggregated_conf.sel(
filtered_by=filter_var, basin=basin, sensitivity_indices_group=g
)[conf_var]
# indices_da.plot(
# hue="sensitivity_indices_group", ax=ax, lw=0.25, label=g.values
# )
rolling_conf_da = conf_da.rolling({"time": 13}).mean()
rolling_indices_da = indices_da.rolling({"time": 13}).mean()
ax.fill_between(
indices_da.time,
(indices_da - conf_da),
(indices_da + conf_da),
(rolling_indices_da - rolling_conf_da),
(rolling_indices_da + rolling_conf_da),
alpha=0.25,
)
indices_da.plot(
hue="sensitivity_indices_group", ax=ax, lw=1, label=g.values
rolling_indices_da.plot(
hue="sensitivity_indices_group", ax=ax, lw=0.75, label=g.values
)
ax.legend()
ax.set_title(f"S1 for {basin} filtered by {filter_var}")
Expand Down
2 changes: 0 additions & 2 deletions pism_ragis/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,6 @@ def load_ensemble(
return ds


@timeit
def normalize_cumulative_variables(
ds: xr.Dataset, variables, reference_date: str = "1992-01-01"
) -> xr.Dataset:
Expand Down Expand Up @@ -648,7 +647,6 @@ def normalize_cumulative_variables(
return ds


@timeit
def standardize_variable_names(
ds: xr.Dataset, name_dict: Union[Mapping[Any, Hashable], None]
) -> xr.Dataset:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SALib
SALib<1.5
bokeh
cartopy
cf-xarray
Expand Down
2 changes: 2 additions & 0 deletions uq/ensemble_gris_ragis_mode.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
,id,calving.vonmises_calving.sigma_max,calving.rate_scaling.file,ocean.th.gamma_T,ocean_file,climate_file,frontal_melt.routing.parameter_a,frontal_melt.routing.parameter_b,frontal_melt.routing.power_alpha,frontal_melt.routing.power_beta,prescribed_retreat_file,stress_balance.sia.enhancement_factor,stress_balance.ssa.Glen_exponent,basal_resistance.pseudo_plastic.q,basal_yield_stress.mohr_coulomb.till_effective_fraction_overburden,basal_yield_stress.mohr_coulomb.topg_to_phi.phi_min,basal_yield_stress.mohr_coulomb.topg_to_phi.phi_max,basal_yield_stress.mohr_coulomb.topg_to_phi.topg_min,basal_yield_stress.mohr_coulomb.topg_to_phi.topg_max,calving.thickness_calving.threshold,climate,fractures,frontal_melt,hydrology,ocean.models,sliding_law
MODE,0,479308.8423088193,seasonal_calving_id_5_1900_2025.nc,0.0001354809575015,MAR3.9_ACCESS1-3_rcp85_ocean_1960-2100_v4.nc,HIRHAM5-monthly-ERA5_1975_2021.nc,0.000340785359703,1.4884430943988265,0.6321793430484832,1.6643602719530464,pism_g450m_frontretreat_calfin_1972_2019.nc,1.9018396,3.299505,0.73261654,0.012281087,5.4509544,43.309277,-590.17255,195.7463,50,given_smb,False,routing,routing,th,pseudo_plastic

0 comments on commit 16d6c38

Please sign in to comment.