|
229 | 229 | ] |
230 | 230 | }, |
231 | 231 | { |
232 | | - "cell_type": "code", |
233 | | - "execution_count": null, |
234 | 232 | "metadata": {}, |
| 233 | + "cell_type": "code", |
235 | 234 | "outputs": [], |
| 235 | + "execution_count": null, |
236 | 236 | "source": [ |
237 | 237 | "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", |
240 | 240 | "\n", |
241 | | - " #combine the two in one dataFrame\n", |
| 241 | + " # Combine the two in one dataFrame\n", |
242 | 242 | " hydro_data = pd.concat([modelOutput.reindex(observation.index, method = 'ffill'), observation], axis=1)\n", |
243 | 243 | "\n", |
244 | | - " #only select the calibration period\n", |
| 244 | + " # Only select the calibration period\n", |
245 | 245 | " hydro_data = hydro_data[hydro_data.index > pd.to_datetime(pd.Timestamp(start_calibration).date())]\n", |
246 | 246 | " hydro_data = hydro_data[hydro_data.index < pd.to_datetime(pd.Timestamp(end_calibration).date())]\n", |
247 | 247 | "\n", |
248 | | - " #calculate mean absolute difference\n", |
249 | | - "\n", |
| 248 | + " # Calculate mean absolute difference\n", |
250 | 249 | " diff = hydro_data['Observations from GRDC'] - hydro_data['model output']\n", |
251 | 250 | " absDiff = np.abs(diff)\n", |
252 | 251 | " meanAbsDiff = np.mean(absDiff)\n", |
|
308 | 307 | ] |
309 | 308 | }, |
310 | 309 | { |
311 | | - "cell_type": "code", |
312 | | - "execution_count": null, |
313 | 310 | "metadata": {}, |
| 311 | + "cell_type": "code", |
314 | 312 | "outputs": [], |
| 313 | + "execution_count": null, |
315 | 314 | "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", |
317 | 316 | "for ensembleMember in ensemble:\n", |
318 | 317 | " ensembleMember.finalize()" |
319 | 318 | ] |
|
434 | 433 | ] |
435 | 434 | }, |
436 | 435 | { |
437 | | - "cell_type": "code", |
438 | | - "execution_count": null, |
439 | 436 | "metadata": {}, |
| 437 | + "cell_type": "code", |
440 | 438 | "outputs": [], |
| 439 | + "execution_count": null, |
441 | 440 | "source": [ |
442 | 441 | "# An object to show a progress bar, since this can take a while:\n", |
443 | 442 | "f = IntProgress(min=0, max=N) # instantiate the bar\n", |
|
464 | 463 | " # It is good practice to remove any variable you don't need anymore to save memory.\n", |
465 | 464 | " del Q_m, time, discharge_dataframe, objective_this_model\n", |
466 | 465 | "\n", |
467 | | - " #update progress bar\n", |
| 466 | + " # Update progress bar\n", |
468 | 467 | " f.value += 1\n", |
469 | 468 | "\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", |
471 | 470 | "for ensembleMember in ensemble:\n", |
472 | 471 | " ensembleMember.finalize()" |
473 | 472 | ] |
474 | 473 | }, |
475 | 474 | { |
476 | | - "cell_type": "code", |
477 | | - "execution_count": null, |
478 | 475 | "metadata": {}, |
| 476 | + "cell_type": "code", |
479 | 477 | "outputs": [], |
| 478 | + "execution_count": null, |
480 | 479 | "source": [ |
481 | 480 | "xFigNr = 2\n", |
482 | 481 | "yFigNr = 4\n", |
|
488 | 487 | " for yFig in range(yFigNr):\n", |
489 | 488 | " paramCounter = xFig*yFigNr + yFig\n", |
490 | 489 | " # 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" |
502 | 503 | ] |
503 | 504 | }, |
504 | 505 | { |
|
0 commit comments