Skip to content

Commit

Permalink
Change of resolution for figures in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
thouska committed Sep 25, 2020
1 parent 1fc2110 commit b1bc7e0
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 25 deletions.
1 change: 1 addition & 0 deletions docs/Advanced_hints.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>

# Advanced settings

This chapter will show you, how to get the full power out of SPOTPY:
Expand Down
8 changes: 4 additions & 4 deletions docs/Bayesian_uncertainty_analysis_with_DREAM.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ If you want to see the remaining posterior model uncertainty:
ax.legend()
fig.savefig('python_hymod.png',dpi=300)

![Posterior model uncertainty](../img/python_hymod_simulation.png)
![Posterior simulation uncertainty](../img/DREAM_simulation_uncertainty_Hymod.png)
*Figure 1: Posterior model uncertainty of HYMOD.*

## Plot convergence diagnostic
If you want to check the convergence of the DREAM algorithm:

spotpy.analyser.plot_gelman_rubin(results, r_hat, fig_name='python_hymod_convergence.png')

![Convergence diagnostic](../img/python_hymod_convergence.png)
![Convergence diagnostic](../img/DREAM_r_hat.png)

*Figure 2: Gelman-Rubin onvergence diagnostic of DREAM results.*

Expand All @@ -121,8 +121,8 @@ Or if you want to check the posterior parameter distribution:
plt.show()
fig.savefig('hymod_parameters.png',dpi=300)

![Parameter distribution](../img/python_hymod_parameters.png)
![DREAM_parameter_uncertainty_Hymod](../img/DREAM_parameter_uncertainty_Hymod.png)

*Figure 3: Posterior parameter distribution of HYMOD.*
*Figure 3: Posterior parameter distribution of HYMOD. Plotting the last 100 repetitions of the algorithm as a histogram.*

The corresponding code is available for download [here](https://github.com/thouska/spotpy/blob/master/spotpy/examples/tutorial_dream_hymod.py).
5 changes: 3 additions & 2 deletions docs/Calibration_with_SCE-UA.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ Herein we show a example how the objective function was minimized during samplin
*Figure 1: Root Mean Squared Error of Hymod model results during the optimization with SCE-UA algorithm.*


## Plot parameter uncertainty
## Plot best model run
Or if you want to check the best model run, we first need to find the run_id with the minimal objective function value

bestindex,bestobjf = spotpy.analyser.get_minlikeindex(results)

Than we select the best model run:

best_model_run = results[bestindex]

And filter results for simulation results only:

fields=[word for word in best_model_run.dtype.names if word.startswith('sim')]
Expand Down
3 changes: 2 additions & 1 deletion docs/Sensitivity_analysis_with_FAST.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>

# Sensitivity analysis of HYMOD with FAST

SPOTPY gives you the opportunity to start a sensitivity analysis of your model. In this case, we included a global sensitivity analysis called "FAST" based on
Expand All @@ -8,7 +9,7 @@ The algorithm will tell you, how sensitive your parameters are based on whatever
iterations you need to get an reliable information about your parameter. The number of iteration can be calculate after [Henkel et al. GLOBAL SENSITIVITY ANALYSIS OF NONLINEAR MATHEMATICAL MODELS - AN
IMPLEMENTATION OF TWO COMPLEMENTING VARIANCE-BASED ALGORITHMS, 2012] (https://www.informs-sim.org/wsc12papers/includes/files/con308.pdf):

$$N = (1+4M^2(1+(k-2)d))k$$
$$N = (1+4M^2(1+(k-2)d))k$$

with N = needed parameter iterations, M= inference factor (SPOTPY default M=4) and d= frequency step (SPOTPY default d=2) and k as the number of parameters of your model.

Expand Down
Binary file modified docs/img/FAST_sensitivity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/SCEUA_best_modelrun.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/img/SCEUA_objectivefunctiontrace.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 7 additions & 7 deletions spotpy/analyser.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,13 @@ def plot_parameter_trace(ax, results, parameter):
#THis function plots the parameter setting for each run
for i in range(int(max(results['chain']))):
index=np.where(results['chain']==i)
ax.plot(results['par'+parameter['name']][index],'.')
ax.plot(results['par'+parameter['name']][index],'.', markersize=2)
ax.set_ylabel(parameter['name'])
ax.set_ylim(parameter['minbound'], parameter['maxbound'])

def plot_posterior_parameter_histogram(ax, results, parameter):
#This functing is plotting the last 10% of the results
ax.hist(results['par'+parameter['name']][int(len(results)*0.9):],
#This functing is the last 100 runs
ax.hist(results['par'+parameter['name']][-100:],
bins =np.linspace(parameter['minbound'],parameter['maxbound'],20))
ax.set_ylabel('Density')
ax.set_xlim(parameter['minbound'], parameter['maxbound'])
Expand Down Expand Up @@ -468,7 +468,7 @@ def plot_fast_sensitivity(results,like_index=1,number_of_sensitiv_pars=10,fig_na
import matplotlib.pyplot as plt

parnames=get_parameternames(results)
fig=plt.figure(figsize=(16,6))
fig=plt.figure(figsize=(9,6))

ax = plt.subplot(1,1,1)
Si = get_sensitivity_of_fast(results, like_index=like_index)
Expand Down Expand Up @@ -530,7 +530,7 @@ def plot_fast_sensitivity(results,like_index=1,number_of_sensitiv_pars=10,fig_na
ax.plot(np.arange(-1,len(parnames)+1,1),[threshold]*(len(parnames)+2),'r--')
ax.set_xlim(-0.5,len(parnames)-0.5)
plt.tight_layout()
fig.savefig(fig_name,dpi=300)
fig.savefig(fig_name,dpi=150)


def plot_heatmap_griewank(results,algorithms, fig_name='heatmap_griewank.png'):
Expand Down Expand Up @@ -989,7 +989,7 @@ def plot_gelman_rubin(results, r_hat_values,fig_name='gelman_rub.png'):
Output: Plot as seen for e.g. in (Sadegh and Vrugt 2014)'''
import matplotlib.pyplot as plt

fig= plt.figure(figsize=(12,16))
fig= plt.figure(figsize=(9,6))
ax1 = plt.subplot(2,1,1)
for i in range(int(max(results['chain']))+1):
index=np.where(results['chain']==i)
Expand All @@ -1008,7 +1008,7 @@ def plot_gelman_rubin(results, r_hat_values,fig_name='gelman_rub.png'):
ax2.set_ylabel('R$^d$ - convergence diagnostic')
ax2.set_xlabel('Number of chainruns')
ax2.legend()
fig.savefig(fig_name,dpi=300)
fig.savefig(fig_name,dpi=150)

def gelman_rubin(x):
'''NOT USED YET'''
Expand Down
17 changes: 10 additions & 7 deletions spotpy/examples/tutorial_dream_hymod.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
acceptance_test_option = 6

sampler=spotpy.algorithms.dream(spot_setup, dbname='DREAM_hymod', dbformat='csv')
r_hat = sampler.sample(rep, nChains, nCr, eps, convergence_limit,
runs_after_convergence,acceptance_test_option)
#r_hat = sampler.sample(rep, nChains, nCr, eps, convergence_limit,
# runs_after_convergence,acceptance_test_option)



Expand All @@ -53,7 +53,7 @@


# Example plot to show remaining parameter uncertainty #
fig= plt.figure(figsize=(16,9))
fig= plt.figure(figsize=(9,6))
ax = plt.subplot(1,1,1)
q5,q25,q75,q95=[],[],[],[]
for field in fields:
Expand All @@ -63,16 +63,16 @@
ax.plot(q95,color='dimgrey',linestyle='solid')
ax.fill_between(np.arange(0,len(q5),1),list(q5),list(q95),facecolor='dimgrey',zorder=0,
linewidth=0,label='parameter uncertainty')
ax.plot(spot_setup.evaluation(),'r.',label='data')
ax.plot(spot_setup.evaluation(),color='red', markersize=2,label='data')
ax.set_ylim(-50,450)
ax.set_xlim(0,729)
ax.legend()
fig.savefig('python_hymod.png',dpi=300)
fig.savefig('DREAM_simulation_uncertainty_Hymod.png',dpi=150)
#########################################################


# Example plot to show the convergence #################
spotpy.analyser.plot_gelman_rubin(results, r_hat)
spotpy.analyser.plot_gelman_rubin(results, r_hat, fig_name='DREAM_r_hat.png')
########################################################


Expand All @@ -82,6 +82,8 @@
parameters = spotpy.parameter.get_parameters_array(spot_setup)

fig, ax = plt.subplots(nrows=5, ncols=2)
fig.set_figheight(9)
fig.set_figwidth(9)
for par_id in range(len(parameters)):
plot_parameter_trace(ax[par_id][0], results, parameters[par_id])
plot_posterior_parameter_histogram(ax[par_id][1], results, parameters[par_id])
Expand All @@ -90,5 +92,6 @@
ax[-1][1].set_xlabel('Parameter range')

plt.show()
fig.savefig('hymod_parameters.png',dpi=300)
fig.tight_layout()
fig.savefig('DREAM_parameter_uncertainty_Hymod.png',dpi=300)
#######################################################
8 changes: 4 additions & 4 deletions spotpy/examples/tutorial_sceua_hymod.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@


#Plot how the objective function was minimized during sampling
fig= plt.figure(1,figsize=(9,5))
fig= plt.figure(1,figsize=(9,6))
plt.plot(results['like1'])
plt.show()
plt.ylabel('RMSE')
plt.xlabel('Iteration')
fig.savefig('SCEUA_objectivefunctiontrace.png',dpi=300)
fig.savefig('SCEUA_objectivefunctiontrace.png',dpi=150)

# Plot the best model run
#Find the run_id with the minimal objective function value
Expand All @@ -53,12 +53,12 @@
fields=[word for word in best_model_run.dtype.names if word.startswith('sim')]
best_simulation = list(best_model_run[fields])

fig= plt.figure(figsize=(16,9))
fig= plt.figure(figsize=(9,6))
ax = plt.subplot(1,1,1)
ax.plot(best_simulation,color='black',linestyle='solid', label='Best objf.='+str(bestobjf))
ax.plot(spot_setup.evaluation(),'r.',markersize=3, label='Observation data')
plt.xlabel('Number of Observation Points')
plt.ylabel ('Discharge [l s-1]')
plt.legend(loc='upper right')
fig.savefig('SCEUA_best_modelrun.png',dpi=300)
fig.savefig('SCEUA_best_modelrun.png',dpi=150)

0 comments on commit b1bc7e0

Please sign in to comment.