Skip to content

Commit

Permalink
removing rc_params setting in plotutils (#561)
Browse files Browse the repository at this point in the history
  • Loading branch information
briochh authored Dec 11, 2024
1 parent 65c273f commit af1f3c3
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 157 deletions.
265 changes: 117 additions & 148 deletions autotest/plot_tests.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import os
import shutil

# import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import pyemu
from pathlib import Path


def plot_summary_test(tmp_path):
Expand Down Expand Up @@ -56,54 +53,48 @@ def pst_plot_test(tmp_path):
os.path.join(tmp_path, "freyberg_gr.pst"))
shutil.copy(os.path.join("pst", "freyberg_gr.rei"),
os.path.join(tmp_path, "freyberg_gr.rei"))
bd = Path.cwd()
os.chdir(tmp_path)
try:
pst = pyemu.Pst("pest.pst")
pst.plot()
pst.parameter_data.loc[:, "partrans"] = "none"
pst.plot()

ax = pst.plot(kind="phi_pie")
pst.observation_data.loc[pst.nnz_obs_names[::2],"obgnme"] = "test"
print(pst.phi_components)
pst.plot(kind="phi_pie")
pst.plot(kind="prior")
#plt.show()
#return

pst = pyemu.Pst("pest.pst")
pst.plot(kind="phi_progress")

pst = pyemu.Pst("freyberg_gr.pst")
par = pst.parameter_data
par.loc[pst.par_names[:3],"pargp"] = "test"
par.loc[pst.par_names[1:],"partrans"] = "fixed"
#pst.plot()
pst.parameter_data.loc[:,"partrans"] = "none"
pst.plot(kind="prior", unique_only=False)
pst.plot(kind="prior",unique_only=True)
pst.plot(kind="prior", unique_only=True, fig_title="priors")
pst.plot(kind="prior", unique_only=True, fig_title="priors",
filename=os.path.join(tmp_path,"test.pdf"))

#
pst.plot(kind="1to1")
pst.plot(kind="1to1",include_zero=True)
pst.plot(kind="1to1", include_zero=True,fig_title="1to1")
fig = pst.plot(kind="1to1", include_zero=True, fig_title="1to1")
pst.plot(kind="1to1", include_zero=True, fig_title="1to1",histogram=True)
#
#
#
ax = pst.plot(kind="phi_pie")
ax = plt.subplot(111,aspect="equal")
pst.plot(kind="phi_pie",ax=ax)
# plt.show()
except Exception as e:
os.chdir(bd)
raise e
os.chdir(bd)
pst = pyemu.Pst("pest.pst")
pst.plot()
pst.parameter_data.loc[:, "partrans"] = "none"
pst.plot()

ax = pst.plot(kind="phi_pie")
pst.observation_data.loc[pst.nnz_obs_names[::2],"obgnme"] = "test"
print(pst.phi_components)
pst.plot(kind="phi_pie")
pst.plot(kind="prior")
#plt.show()
#return

pst = pyemu.Pst("pest.pst")
pst.plot(kind="phi_progress")

pst = pyemu.Pst("freyberg_gr.pst")
par = pst.parameter_data
par.loc[pst.par_names[:3],"pargp"] = "test"
par.loc[pst.par_names[1:],"partrans"] = "fixed"
#pst.plot()
pst.parameter_data.loc[:,"partrans"] = "none"
pst.plot(kind="prior", unique_only=False)
pst.plot(kind="prior",unique_only=True)
pst.plot(kind="prior", unique_only=True, fig_title="priors")
pst.plot(kind="prior", unique_only=True, fig_title="priors",
filename=os.path.join(tmp_path,"test.pdf"))

#
pst.plot(kind="1to1")
pst.plot(kind="1to1",include_zero=True)
pst.plot(kind="1to1", include_zero=True,fig_title="1to1")
fig = pst.plot(kind="1to1", include_zero=True, fig_title="1to1")
pst.plot(kind="1to1", include_zero=True, fig_title="1to1",histogram=True)
#
#
#
ax = pst.plot(kind="phi_pie")
ax = plt.subplot(111,aspect="equal")
pst.plot(kind="phi_pie",ax=ax)
# plt.show()


def ensemble_plot_test(tmp_path):
Expand All @@ -114,69 +105,63 @@ def ensemble_plot_test(tmp_path):
pstfile = os.path.join("pst", "pest.pst")
shutil.copy(pstfile,
os.path.join(tmp_path, "pest.pst"))
bd = Path.cwd()
os.chdir(tmp_path)
try:
pst = pyemu.Pst("pest.pst")
cov = pyemu.Cov.from_parameter_data(pst)
num_reals = 100
pe = pyemu.ParameterEnsemble.from_gaussian_draw(pst,cov,num_reals=num_reals,fill=True)
csv_file = "pe.csv"
pst = pyemu.Pst("pest.pst")
cov = pyemu.Cov.from_parameter_data(pst)
num_reals = 100
pe = pyemu.ParameterEnsemble.from_gaussian_draw(pst,cov,num_reals=num_reals,fill=True)
csv_file = "pe.csv"

pe.plot(filename=csv_file + ".pdf",plot_cols=pst.par_names[:10])
pe.plot(filename=csv_file + ".pdf",plot_cols=pst.par_names[:10])

pd = pst.parameter_data.groupby("pargp").groups
pd = pst.parameter_data.groupby("pargp").groups

pyemu.plot_utils.ensemble_helper(
pe,plot_cols=pd,
filename=csv_file+".pdf",alpha=0.1
)
pyemu.plot_utils.ensemble_helper(
pe,plot_cols=pd,
filename=csv_file+".pdf",alpha=0.1
)

pe.to_csv(csv_file)
pyemu.plot_utils.ensemble_helper(pe, filename=csv_file + ".pdf",
plot_cols=pst.par_names[:10])
pyemu.plot_utils.ensemble_helper(csv_file, filename=csv_file + ".pdf",
plot_cols=pst.par_names[:10])
pe.to_csv(csv_file)
pyemu.plot_utils.ensemble_helper(pe, filename=csv_file + ".pdf",
plot_cols=pst.par_names[:10])
pyemu.plot_utils.ensemble_helper(csv_file, filename=csv_file + ".pdf",
plot_cols=pst.par_names[:10])


pst.parameter_data.loc[:,"partrans"] = "none"
cov = pyemu.Cov.from_parameter_data(pst)
pe = pyemu.ParameterEnsemble.from_gaussian_draw(pst, cov, num_reals=num_reals)
pst.parameter_data.loc[:,"partrans"] = "none"
cov = pyemu.Cov.from_parameter_data(pst)
pe = pyemu.ParameterEnsemble.from_gaussian_draw(pst, cov, num_reals=num_reals)


pyemu.plot_utils.ensemble_helper([pe,csv_file],filename=csv_file+".pdf",
plot_cols=pst.par_names[:10])
pyemu.plot_utils.ensemble_helper([pe,csv_file],filename=csv_file+".pdf",
plot_cols=pst.par_names[:10])

pyemu.plot_utils.ensemble_helper([pe, csv_file], filename=csv_file + ".pdf",
plot_cols=pst.par_names[:10],sync_bins=False)
pyemu.plot_utils.ensemble_helper([pe, csv_file], filename=csv_file + ".pdf",
plot_cols=pst.par_names[:10],sync_bins=False)

pyemu.plot_utils.ensemble_helper({"b":pe,"y":csv_file}, filename=csv_file + ".pdf",
plot_cols=pst.par_names[:10])
pyemu.plot_utils.ensemble_helper({"b":pe,"y":csv_file}, filename=csv_file + ".pdf",
plot_cols=pst.par_names[:10])

pyemu.plot_utils.ensemble_helper({"b":pe,"y":csv_file}, filename=csv_file + ".pdf",
plot_cols=pst.par_names[:10], sync_bins=False)
pyemu.plot_utils.ensemble_helper({"b":pe,"y":csv_file}, filename=csv_file + ".pdf",
plot_cols=pst.par_names[:10], sync_bins=False)

pyemu.plot_utils.ensemble_helper({"b": pe, "y": csv_file}, filename=csv_file + ".pdf",
plot_cols=pst.par_names[:10], sync_bins=False,
func_dict={pst.par_names[0]:np.log10})
pyemu.plot_utils.ensemble_helper({"b": pe, "y": csv_file}, filename=csv_file + ".pdf",
plot_cols=pst.par_names[:10], sync_bins=False,
func_dict={pst.par_names[0]:np.log10})

figs = pyemu.plot_utils.ensemble_helper({"b": pe, "y": csv_file}, filename=None,
plot_cols=pst.par_names[:10], sync_bins=False,
func_dict={pst.par_names[0]:np.log10})
plt.close("all")
deter_vals = pst.parameter_data.parval1.apply(np.log10).to_dict()
pyemu.plot_utils.ensemble_helper({"b": pe, "y": csv_file}, filename=csv_file + ".pdf",
plot_cols=pst.par_names[:10], sync_bins=False,
deter_vals=deter_vals)
figs = pyemu.plot_utils.ensemble_helper({"b": pe, "y": csv_file}, filename=None,
plot_cols=pst.par_names[:10], sync_bins=False,
func_dict={pst.par_names[0]:np.log10})
plt.close("all")
deter_vals = pst.parameter_data.parval1.apply(np.log10).to_dict()
pyemu.plot_utils.ensemble_helper({"b": pe, "y": csv_file}, filename=csv_file + ".pdf",
plot_cols=pst.par_names[:10], sync_bins=False,
deter_vals=deter_vals)


pyemu.plot_utils.ensemble_helper({"b": pe, "y": csv_file}, filename=csv_file + ".pdf",
plot_cols=pst.par_names[:10], sync_bins=False,
deter_vals=deter_vals,deter_range=True)
except Exception as e:
os.chdir(bd)
raise e
os.chdir(bd)
pyemu.plot_utils.ensemble_helper({"b": pe, "y": csv_file}, filename=csv_file + ".pdf",
plot_cols=pst.par_names[:10], sync_bins=False,
deter_vals=deter_vals,deter_range=True)


def ensemble_1to1_test(tmp_path):
Expand All @@ -188,7 +173,6 @@ def ensemble_1to1_test(tmp_path):
os.path.join(tmp_path, "pest.pst"))
shutil.copy(os.path.join("pst","pest.rei"),
os.path.join(tmp_path, "pest.rei"))
bd = Path.cwd()
os.chdir(tmp_path)
#try:
pst = pyemu.Pst("pest.pst")
Expand Down Expand Up @@ -272,10 +256,6 @@ def ensemble_1to1_test(tmp_path):
pst.observation_data.loc[:, 'obgnme'] = pst.observation_data.o_obgnme
pyemu.plot_utils.res_phi_pie(pst=pst,ensemble=oe1)
pyemu.plot_utils.res_1to1(pst=pst, ensemble=oe1)
#except Exception as e:
# os.chdir(bd)
# raise e
os.chdir(bd)


def ensemble_summary_test(tmp_path):
Expand All @@ -288,37 +268,31 @@ def ensemble_summary_test(tmp_path):
os.path.join(tmp_path, "pest.pst"))
shutil.copy(os.path.join("pst", "pest.rei"),
os.path.join(tmp_path, "pest.rei"))
bd = Path.cwd()
os.chdir(tmp_path)
try:
pst = pyemu.Pst("pest.pst")
num_reals = 100

oe1 = pyemu.ObservationEnsemble.from_gaussian_draw(pst,num_reals=num_reals)
pst.observation_data.loc[pst.nnz_obs_names,"weight"] *= 10.0
oe2 = pyemu.ObservationEnsemble.from_gaussian_draw(pst, num_reals=num_reals)
#print(oe1.loc[:,pst.nnz_obs_names].std())
#print(oe2.loc[:,pst.nnz_obs_names].std())

pyemu.plot_utils.ensemble_change_summary(
oe1,oe2,pst,
filename="edeltasum.pdf"
)
pst.parameter_data.loc[:,"partrans"] = "none"
cov1 = pyemu.Cov.from_parameter_data(pst,sigma_range=6)
pe1 = pyemu.ParameterEnsemble.from_gaussian_draw(pst,cov1,num_reals=1000)

cov2 = cov1 * 0.001
pe2 = pyemu.ParameterEnsemble.from_gaussian_draw(pst,cov2,num_reals=1000)

pyemu.plot_utils.ensemble_change_summary(
pe1, pe2, pst,
filename="edeltasum.pdf"
)
except Exception as e:
os.chdir(bd)
raise e
os.chdir(bd)
pst = pyemu.Pst("pest.pst")
num_reals = 100

oe1 = pyemu.ObservationEnsemble.from_gaussian_draw(pst,num_reals=num_reals)
pst.observation_data.loc[pst.nnz_obs_names,"weight"] *= 10.0
oe2 = pyemu.ObservationEnsemble.from_gaussian_draw(pst, num_reals=num_reals)
#print(oe1.loc[:,pst.nnz_obs_names].std())
#print(oe2.loc[:,pst.nnz_obs_names].std())

pyemu.plot_utils.ensemble_change_summary(
oe1,oe2,pst,
filename="edeltasum.pdf"
)
pst.parameter_data.loc[:,"partrans"] = "none"
cov1 = pyemu.Cov.from_parameter_data(pst,sigma_range=6)
pe1 = pyemu.ParameterEnsemble.from_gaussian_draw(pst,cov1,num_reals=1000)

cov2 = cov1 * 0.001
pe2 = pyemu.ParameterEnsemble.from_gaussian_draw(pst,cov2,num_reals=1000)

pyemu.plot_utils.ensemble_change_summary(
pe1, pe2, pst,
filename="edeltasum.pdf"
)

# def cov_test():
# try:
Expand Down Expand Up @@ -350,23 +324,18 @@ def ensemble_summary_test(tmp_path):

def ensemble_change_test(tmp_path):
import matplotlib.pyplot as plt
bd = Path.cwd()
os.chdir(tmp_path)
try:
pst = pyemu.Pst.from_par_obs_names(par_names=["p1","p2"])
cov = pyemu.Cov(np.array([[1.0,0.0],[0.0,1.0]]),names=["p1","p2"])
pe1 = pyemu.ParameterEnsemble.from_gaussian_draw(pst=pst,cov=cov,num_reals=5000)
cov *= 0.1
pe2 = pyemu.ParameterEnsemble.from_gaussian_draw(pst=pst,cov=cov,num_reals=5000)
pyemu.plot_utils.ensemble_change_summary(pe1,pe2,pst=pst)
print(pe1.mean(),pe1.std())
print(pe2.mean(),pe2.std())
pyemu.plot_utils.ensemble_change_summary(pe1,pe2,pst)
#plt.show()
except Exception as e:
os.chdir(bd)
raise e
os.chdir(bd)
pst = pyemu.Pst.from_par_obs_names(par_names=["p1","p2"])
cov = pyemu.Cov(np.array([[1.0,0.0],[0.0,1.0]]),names=["p1","p2"])
pe1 = pyemu.ParameterEnsemble.from_gaussian_draw(pst=pst,cov=cov,num_reals=5000)
cov *= 0.1
pe2 = pyemu.ParameterEnsemble.from_gaussian_draw(pst=pst,cov=cov,num_reals=5000)
pyemu.plot_utils.ensemble_change_summary(pe1,pe2,pst=pst)
print(pe1.mean(),pe1.std())
print(pe2.mean(),pe2.std())
pyemu.plot_utils.ensemble_change_summary(pe1,pe2,pst)
#plt.show()


if __name__ == "__main__":
# plot_summary_test('.')
Expand Down
Loading

0 comments on commit af1f3c3

Please sign in to comment.