Skip to content

Commit 2c312c0

Browse files
committed
fixed exercise 4 plotting of their own calibration thanks to Luuk, also some typos etc
1 parent b72d611 commit 2c312c0

File tree

1 file changed

+29
-28
lines changed

1 file changed

+29
-28
lines changed

book/2_modelling_advanced_ewatercycle/exercise4_calibrate_HBV_eWaterCycle.ipynb

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -229,24 +229,23 @@
229229
]
230230
},
231231
{
232-
"cell_type": "code",
233-
"execution_count": null,
234232
"metadata": {},
233+
"cell_type": "code",
235234
"outputs": [],
235+
"execution_count": null,
236236
"source": [
237237
"def calibrationObjective(modelOutput, observation, start_calibration, end_calibration):\n",
238-
" # A function that takes in two dataFrames, interpolates the model output to the\n",
239-
" # observations and calculates the average absolute difference between the two.\n",
238+
" '''A function that takes in two dataFrames, interpolates the model output to the\n",
239+
" observations and calculates the average absolute difference between the two. '''\n",
240240
"\n",
241-
" #combine the two in one dataFrame\n",
241+
" # Combine the two in one dataFrame\n",
242242
" hydro_data = pd.concat([modelOutput.reindex(observation.index, method = 'ffill'), observation], axis=1)\n",
243243
"\n",
244-
" #only select the calibration period\n",
244+
" # Only select the calibration period\n",
245245
" hydro_data = hydro_data[hydro_data.index > pd.to_datetime(pd.Timestamp(start_calibration).date())]\n",
246246
" hydro_data = hydro_data[hydro_data.index < pd.to_datetime(pd.Timestamp(end_calibration).date())]\n",
247247
"\n",
248-
" #calculate mean absolute difference\n",
249-
"\n",
248+
" # Calculate mean absolute difference\n",
250249
" diff = hydro_data['Observations from GRDC'] - hydro_data['model output']\n",
251250
" absDiff = np.abs(diff)\n",
252251
" meanAbsDiff = np.mean(absDiff)\n",
@@ -308,12 +307,12 @@
308307
]
309308
},
310309
{
311-
"cell_type": "code",
312-
"execution_count": null,
313310
"metadata": {},
311+
"cell_type": "code",
314312
"outputs": [],
313+
"execution_count": null,
315314
"source": [
316-
"# Finaly, just like before, we remove the models themselves to save up space and memory.\n",
315+
"# Finally, just like before, we remove the models themselves to save up space and memory.\n",
317316
"for ensembleMember in ensemble:\n",
318317
" ensembleMember.finalize()"
319318
]
@@ -434,10 +433,10 @@
434433
]
435434
},
436435
{
437-
"cell_type": "code",
438-
"execution_count": null,
439436
"metadata": {},
437+
"cell_type": "code",
440438
"outputs": [],
439+
"execution_count": null,
441440
"source": [
442441
"# An object to show a progress bar, since this can take a while:\n",
443442
"f = IntProgress(min=0, max=N) # instantiate the bar\n",
@@ -464,19 +463,19 @@
464463
" # It is good practice to remove any variable you don't need anymore to save memory.\n",
465464
" del Q_m, time, discharge_dataframe, objective_this_model\n",
466465
"\n",
467-
" #update progress bar\n",
466+
" # Update progress bar\n",
468467
" f.value += 1\n",
469468
"\n",
470-
"# Finaly, just like before, we remove the models themselves to save up space and memory.\n",
469+
"# Finally, just like before, we remove the models themselves to save up space and memory.\n",
471470
"for ensembleMember in ensemble:\n",
472471
" ensembleMember.finalize()"
473472
]
474473
},
475474
{
476-
"cell_type": "code",
477-
"execution_count": null,
478475
"metadata": {},
476+
"cell_type": "code",
479477
"outputs": [],
478+
"execution_count": null,
480479
"source": [
481480
"xFigNr = 2\n",
482481
"yFigNr = 4\n",
@@ -488,17 +487,19 @@
488487
" for yFig in range(yFigNr):\n",
489488
" paramCounter = xFig*yFigNr + yFig\n",
490489
" # Extract NSE and log NSE for all runs\n",
491-
" nse_values = objectives[:, 0]\n",
492-
" log_nse_values = objectives[:, 1]\n",
493-
" \n",
494-
" axs[xFig_nse,yFig_nse].plot(parameters[paramCounter,:],nse_values,'.', label='NSE')\n",
495-
" axs[xFig_nse,yFig_nse].set_title(p_names[paramCounter])\n",
496-
" \n",
497-
" axs[xFig_nselog,yFig_nselog].plot(parameters[paramCounter,:],log_nse_values,'.', label='log NSE')\n",
498-
" axs[xFig_nselog,yFig_nselog].set_title(p_names[paramCounter])\n",
499-
"\n",
500-
" axs[xFig_nse,yFig_nse].legend()\n",
501-
" axs[xFig_nselog,yFig_nselog].legend()\n"
490+
" # nse_values = objectives[:, 0] #objectives is a list of tuples, so this goes wrong\n",
491+
" # log_nse_values = objectives[:, 1]\n",
492+
" nse_values = [i[0] for i in objectives]\n",
493+
" log_nse_values = [i[1] for i in objectives]\n",
494+
"\n",
495+
" axs_nse[xFig,yFig].plot(parameters[paramCounter,:],nse_values,'.', label='NSE')\n",
496+
" axs_nse[xFig,yFig].set_title(p_names[paramCounter])\n",
497+
"\n",
498+
" axs_nselog[xFig,yFig].plot(parameters[paramCounter,:],log_nse_values,'.', label='log NSE')\n",
499+
" axs_nselog[xFig,yFig].set_title(p_names[paramCounter])\n",
500+
"\n",
501+
" axs_nse[xFig,yFig].legend()\n",
502+
" axs_nselog[xFig,yFig].legend()\n"
502503
]
503504
},
504505
{

0 commit comments

Comments
 (0)