smashbox.plot.myplot
1import matplotlib.pyplot as plt 2import numpy as np 3import mpld3 # à ajouter dans le build du module 4 5from smashbox.tools import tools 6from smashbox.stats import stats 7from smashbox.plot import plot 8from smashbox.tools import geo_toolbox 9 10 11class myplot: 12 """Class that provide some plotting functions. Plot can be displayed with matplolib UI 13 or as html web page. Every plot can be saved into files.""" 14 15 def __init__(self, parent_class): 16 """ 17 Initialisation. 18 :param parent_class: The parent class src.model.model() to be able to access to 19 the smash model 20 :type parent_class: src.model.model() 21 """ 22 self._parent_class = parent_class 23 """The parent class src.model.model() to be able to access to the smash model""" 24 25 def plot_mesh( 26 self, 27 coef_hydro: float = 99.0, 28 ax_settings: dict = {}, 29 fig_settings: dict = {}, 30 html_show: bool = False, 31 ): 32 """ 33 Plot the map of the mesh of the Smash model with teh outlets and the hydrographic 34 network. 35 :param coef_hydro: couloring cells where the surface is higher than `coef_hydro`% 36 of the total surface catchment, defaults to 99.0 37 :type coef_hydro: float, optional 38 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 39 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 40 :type ax_settings: dict, optional 41 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 42 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 43 :type fig_settings: dict, optional 44 :param html_show: Display the figure in an html page with your navigator, defaults 45 to False 46 :type html_show: bool, optional 47 48 """ 49 default_ax_settings = plot.ax_properties( 50 title="Mesh of the Smash model", 51 xlabel="x_coords", 52 ylabel="y_coords", 53 ) 54 default_ax_settings.update(**ax_settings) 55 56 fig_settings = plot.fig_properties(**fig_settings) 57 58 if not hasattr(self._parent_class.mymesh, "mesh"): 59 raise ValueError("No smash mesh found. Build the mesh first.") 60 61 fig, ax = plot.plot_mesh( 62 self._parent_class.mymesh.mesh, 63 catchment_polygon=self._parent_class.mymesh.catchment_polygon, 64 coef_hydro=coef_hydro, 65 ax_settings=ax_settings, 66 fig_settings=fig_settings, 67 ) 68 69 if fig_settings.figname is None: 70 if tools.with_reticulate() or html_show: 71 mpld3.show(fig, open_browser=True) 72 else: 73 fig.show() 74 75 def plot_catchment_surface_consistency( 76 self, 77 label: bool = True, 78 ax_settings: dict = {}, 79 fig_settings: dict = {}, 80 plot_settings: dict = {}, 81 html_show: bool = False, 82 ): 83 """ 84 Plot the modeled surface vs the observed surface. Check its consistency. 85 :param label, labels the point on the plot with the code of the outlets. 86 :type label: bool, default True 87 :param ax_settings, any properties of plot.ax_properties() class can be defined 88 in this dictionnary, defaults to {} 89 :type ax_settings: dict, optional 90 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 91 plot.fig_properties() class can be defined in this dictionnary, defaults to {} 92 :type fig_settings: dict, optional 93 :param plot_settings, any properties of plot.plot_properties() class can be 94 defined in this dictionnary, defaults to {} 95 :param html_show: Display the figure in an html page with your navigator, defaults 96 to False 97 :type html_show: bool, optional 98 99 """ 100 101 default_ax_settings = plot.ax_properties( 102 title="Modeled and observed surface consistency", 103 xlabel="Observed surface", 104 ylabel="Modeled surface", 105 ) 106 default_ax_settings.update(**ax_settings) 107 108 fig_settings = plot.fig_properties(**fig_settings) 109 110 if not hasattr(self._parent_class.mymesh, "mesh"): 111 raise ValueError("No smash mesh found. Build the mesh first.") 112 113 fig, ax = plot.plot_catchment_surface_consistency( 114 mesh=self._parent_class.mymesh.mesh, 115 label=label, 116 ax_settings=ax_settings, 117 fig_settings=fig_settings, 118 plot_settings=plot_settings, 119 ) 120 121 if fig_settings.figname is None: 122 if tools.with_reticulate() or html_show: 123 mpld3.show(fig, open_browser=True) 124 else: 125 fig.show() 126 127 def plot_catchment_surface_error( 128 self, 129 ax_settings: dict = {}, 130 fig_settings: dict = {}, 131 html_show: bool = False, 132 ): 133 """ 134 Plot the modeled surface vs the observed surface. Check its consistency. 135 :param ax_settings, any properties of plot.ax_properties() class can be defined 136 in this dictionnary, defaults to {} 137 :type ax_settings: dict, optional 138 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 139 plot.fig_properties() class can be defined in this dictionnary, defaults to {} 140 :param html_show: Display the figure in an html page with your navigator, defaults 141 to False 142 :type html_show: bool, optional 143 144 """ 145 146 default_ax_settings = plot.ax_properties( 147 title="Catchment surface error", 148 xlabel="Catchments", 149 ylabel="(Ssim - Sobs)/Sobs", 150 ) 151 default_ax_settings.update(**ax_settings) 152 153 fig_settings = plot.fig_properties(**fig_settings) 154 155 if not hasattr(self._parent_class.mymesh, "mesh"): 156 raise ValueError("No smash mesh found. Build the mesh first.") 157 158 fig, ax = plot.plot_catchment_surface_error( 159 mesh=self._parent_class.mymesh.mesh, 160 ax_settings=ax_settings, 161 fig_settings=fig_settings, 162 ) 163 164 if fig_settings.figname is None: 165 if tools.with_reticulate() or html_show: 166 mpld3.show(fig, open_browser=True) 167 else: 168 fig.show() 169 170 @tools.autocast_args 171 def plot_xy_quantile( 172 self, 173 duration: int = 1, 174 X: int = 0, 175 Y: int = 0, 176 ax_settings: dict = {}, 177 fig_settings: dict = {}, 178 plot_settings: dict = {}, 179 html_show: bool = False, 180 ): 181 """ 182 183 :param duration: Duration of the quantile, defaults to 1 184 :type duration: int, optional 185 :param X: X coordinate of the targeted cell (matrix coordinate system), defaults 186 to 0 187 :type X: int, optional 188 :param Y: Y coordinate of the targeted cell (matrix coordinate system), defaults 189 to 0 190 :type Y: int, optional 191 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 192 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 193 :type ax_settings: dict, optional 194 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 195 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 196 :type fig_settings: dict, optional 197 :param html_show: Display the figure in an html page with your navigator, 198 defaults to False 199 :type html_show: bool, optional 200 201 """ 202 203 if not hasattr( 204 self._parent_class.mystats.quantile_stats, f"Quantile_{duration}h" 205 ): 206 raise ValueError(f"No statistical results found for duration {duration}h") 207 208 results_quantile = getattr( 209 self._parent_class.mystats.quantile_stats, 210 f"Quantile_{duration}h", 211 ) 212 213 if self._parent_class.mymesh.mesh["active_cell"][X, Y] == 0: 214 raise ValueError( 215 f"`{X},{Y}` coordinates does not correspond to an active cell." 216 ) 217 218 default_ax_settings = plot.ax_properties( 219 title=f"Maximal discharges frequency curve on {results_quantile.chunk_size}" 220 " days", 221 xscale="log", 222 xlabel=f"Return period (*{results_quantile.chunk_size} days)", 223 ylabel="Discharges (m³/s)", 224 grid=True, 225 legend=True, 226 ) 227 default_ax_settings.update(**ax_settings) 228 229 fig_settings = plot.fig_properties(**fig_settings) 230 231 fig, ax = plot.plot_xy_quantile( 232 results_quantile.__dict__, 233 X, 234 Y, 235 ax_settings=default_ax_settings, 236 fig_settings=fig_settings, 237 plot_settings=plot_settings, 238 ) 239 240 if fig_settings.figname is None: 241 if tools.with_reticulate() or html_show: 242 mpld3.show(fig, open_browser=True) 243 else: 244 fig.show() 245 # return fig, ax 246 247 @tools.autocast_args 248 def plot_outlets_quantile( 249 self, 250 duration: int = 1, 251 quantile_obs=True, 252 gauge: list | None = None, 253 ax_settings: dict = {}, 254 fig_settings: dict = {}, 255 plot_settings: dict = {}, 256 html_show: bool = False, 257 ): 258 """ 259 Plot the quantiles prediction for different return period for every outlets. 260 :param duration: Duration of the quantile, defaults to 1 261 :type duration: int, optional 262 :param quantile_obs: Compute and display the observed quantile in th graphics. 263 Observed quantile are computed again the whole observed discharge chronicle 264 from 1900 until today. 265 :type quantile_obs: Bool, default is True 266 :param gauge: List of gauge code to plot. Default is None. If None all gague 267 are plotted 268 :type gauge: list | None, default None. 269 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 270 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 271 :type ax_settings: dict, optional 272 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 273 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 274 :type fig_settings: dict, optional 275 :param plot_settings: Parameters of the matplotlib figure 'fig'. Any properties of 276 plot.plot_settings() class ca be defined in this dictionnary, defaults to {} 277 :type plot_settings: dict, optional 278 :param html_show: Display the figure in an html page with your navigator, defaults 279 to False 280 :type html_show: bool, optional 281 282 """ 283 284 # fig_settings = plot.fig_properties(**fig_settings) 285 286 if not hasattr( 287 self._parent_class.mystats.quantile_stats, f"Quantile_{duration}h" 288 ): 289 raise ValueError(f"No statistical results found for duration {duration}h") 290 291 gauge_pos = list(self._parent_class.mymesh.mesh["gauge_pos"]) 292 gauge_code = list(self._parent_class.mymesh.mesh["code"]) 293 294 if gauge is not None: 295 list_ind_gauge = [] 296 for i, g in enumerate(gauge_code): 297 if g in gauge: 298 list_ind_gauge.append(i) 299 else: 300 print(f"</> gauge {g} not found in the mesh gauge list {gauge_code}") 301 if len(list_ind_gauge) > 0: 302 gauge_pos = gauge_pos[list_ind_gauge] 303 gauge_code = gauge_code[list_ind_gauge] 304 else: 305 print(f"</> gauge {gauge} not found in the mesh gauge list {gauge_code}") 306 307 yfig = int(np.sqrt(len(gauge_pos))) 308 xfig = int(np.ceil(len(gauge_pos) / yfig)) 309 310 default_fig_settings = plot.fig_properties(ysize=yfig * 5, xsize=xfig * 3) 311 default_fig_settings.update(**fig_settings) 312 313 if quantile_obs: 314 res_quantile_obs = stats.quantil_obs( 315 qobs_directory=self._parent_class.mysetup.setup["qobs_directory"], 316 code=gauge_code, 317 model_time_step=self._parent_class.mysetup.setup["dt"], 318 quantile_duration=duration, 319 ) 320 else: 321 res_quantile_obs = None 322 323 fig, axs = plt.subplots( 324 xfig, 325 yfig, 326 constrained_layout=True, 327 ) 328 329 for ax, coords, code in zip(axs.flat, gauge_pos, gauge_code): 330 331 X, Y = coords 332 results_quantile = getattr( 333 self._parent_class.mystats.quantile_stats, 334 f"Quantile_{duration}h", 335 ) 336 337 # default_ax_settings = plot.ax_properties( 338 # title=f"Discharges quantile at gauge {code}", 339 # legend_fontsize=6, 340 # ) 341 # default_ax_settings.update(**ax_settings) 342 343 default_ax_settings = plot.ax_properties( 344 title=f"Discharges quantile at gauge {code}", 345 xscale="log", 346 xlabel=f"Return period (*{results_quantile.chunk_size} days)", 347 ylabel="Discharges (m³/s)", 348 grid=True, 349 legend=True, 350 legend_fontsize=8, 351 xtics_fontsize=8, 352 ytics_fontsize=8, 353 ) 354 default_ax_settings.update(**ax_settings) 355 356 default_plot_settings = plot.plot_properties( 357 markersize=6, 358 ) 359 default_plot_settings.update(**plot_settings) 360 361 fig, ax = plot.plot_xy_quantile( 362 results_quantile.__dict__, 363 X, 364 Y, 365 res_quantile_obs=res_quantile_obs, 366 gauge_pos=list(gauge_code).index(code), 367 figure=[fig, ax], 368 ax_settings=default_ax_settings, 369 plot_settings=default_plot_settings, 370 ) 371 372 default_fig_settings.change((fig, axs)) 373 374 if default_fig_settings.figname is None: 375 if tools.with_reticulate() or html_show: 376 mpld3.show(fig, open_browser=True) 377 else: 378 fig.show() 379 380 # return fig, axs 381 382 @tools.autocast_args 383 def plot_spatial_quantile( 384 self, 385 duration: int = 1, 386 T: int = 2, 387 vmin: float | None = 0, 388 vmax: float | None = None, 389 ax_settings: dict = {}, 390 fig_settings: dict = {}, 391 html_show=False, 392 ): 393 """ 394 Plot the map of the quantiles for given return period and a given duration. 395 :param duration: Duration of the quantile, defaults to 1 396 :type duration: int, optional 397 :param T: return period, defaults to 2 (default is years, but that depends 398 of the chunk size) 399 :type T: int, optional 400 :param vmin: Minimal bounds value for the colorbar, defaults to 0 401 :type vmin: float, optional 402 :param vmax: Maximal bounds value for the colorbar, defaults to None 403 :type vmax: float, optional 404 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 405 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 406 :type ax_settings: dict, optional 407 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 408 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 409 :type fig_settings: dict, optional 410 :param html_show: Display the figure in an html page with your navigator, defaults to False 411 :type html_show: bool, optional 412 413 """ 414 415 fig_settings = plot.fig_properties(**fig_settings) 416 417 if not hasattr( 418 self._parent_class.mystats.quantile_stats, f"Quantile_{duration}h" 419 ): 420 raise ValueError(f"No statistical results found for duration {duration}h") 421 422 results_quantile = getattr( 423 self._parent_class.mystats.quantile_stats, 424 f"Quantile_{duration}h", 425 ) 426 427 default_ax_settings = plot.ax_properties( 428 title=f"Discharges quantile for duration={duration} h, T={T}", 429 xlabel="Coords X", 430 ylabel="Coords_Y", 431 clabel="Discharge (m^3/s)", 432 cmap="viridis", 433 ) 434 default_ax_settings.update(**ax_settings) 435 436 z = list(results_quantile.T).index(T) 437 438 fig, ax = plot.plot_image( 439 matrice=results_quantile.Q_th[:, :, z], 440 bbox=geo_toolbox.get_bbox_from_smash_mesh(self._parent_class.mymesh.mesh), 441 vmin=vmin, 442 vmax=vmax, 443 mask=self._parent_class.mysmashmodel.mesh.active_cell, 444 catchment_polygon=self._parent_class.mymesh.catchment_polygon, 445 ax_settings=default_ax_settings, 446 fig_settings=fig_settings, 447 ) 448 449 if fig_settings.figname is None: 450 if tools.with_reticulate() or html_show: 451 mpld3.show(fig, open_browser=True) 452 else: 453 fig.show() 454 455 # return fig, ax 456 457 @tools.autocast_args 458 def multiplot_spatial_quantile( 459 self, 460 duration: int = 1, 461 vmin: float | None = 0, 462 vmax: float | None = None, 463 ax_settings={}, 464 fig_settings={}, 465 html_show: bool = False, 466 ): 467 """ 468 Plot the map of the quantiles for every return period for a given duration. 469 :param duration: Duration of the quantile, defaults to 1 470 :type duration: int, optional 471 :param vmin: Minimal bounds value for the colorbar, defaults to 0 472 :type vmin: float, optional 473 :param vmax: Maximal bounds value for the colorbar, defaults to None 474 :type vmax: float, optional 475 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 476 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 477 :type ax_settings: dict, optional 478 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 479 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 480 :type fig_settings: dict, optional 481 :param html_show: Display the figure in an html page with your navigator, defaults 482 to False 483 :type html_show: bool, optional 484 485 """ 486 487 fig_settings = plot.fig_properties(**fig_settings) 488 489 if not hasattr( 490 self._parent_class.mystats.quantile_stats, f"Quantile_{duration}h" 491 ): 492 raise ValueError(f"No statistical results found for duration {duration}h") 493 494 results_quantile = getattr( 495 self._parent_class.mystats.quantile_stats, 496 f"Quantile_{duration}h", 497 ) 498 499 yfig = int(np.sqrt(len(results_quantile.T))) 500 xfig = int(np.ceil(len(results_quantile.T) / yfig)) 501 502 fig, axs = plt.subplots( 503 xfig, 504 yfig, 505 constrained_layout=False, 506 ) 507 plt.subplots_adjust( 508 left=None, bottom=None, right=None, top=None, wspace=0.5, hspace=None 509 ) 510 511 for ax, T in zip(axs.flat, results_quantile.T): 512 513 default_ax_settings = plot.ax_properties( 514 title=f"Discharges quantile for duration={duration} h, T={T}", 515 xlabel="Coords X", 516 ylabel="Coords_Y", 517 clabel="Discharge (m^3/s)", 518 cmap="viridis", 519 title_fontsize=10, 520 label_fontsize=8, 521 xtics_fontsize=6, 522 ytics_fontsize=6, 523 ) 524 default_ax_settings.update(**ax_settings) 525 526 z = list(results_quantile.T).index(T) 527 528 fig, ax = plot.plot_image( 529 matrice=results_quantile.Q_th[:, :, z], 530 bbox=geo_toolbox.get_bbox_from_smash_mesh(self._parent_class.mymesh.mesh), 531 vmin=vmin, 532 vmax=vmax, 533 mask=self._parent_class.mysmashmodel.mesh.active_cell, 534 catchment_polygon=self._parent_class.mymesh.catchment_polygon, 535 ax_settings=default_ax_settings, 536 figure=[fig, ax], 537 ) 538 539 [fig.delaxes(ax) for ax in axs.flatten() if not ax.has_data()] 540 fig_settings.change((fig, axs)) 541 542 if fig_settings.figname is None or html_show: 543 if tools.with_reticulate(): 544 mpld3.show(fig, open_browser=True) 545 else: 546 fig.show() 547 548 # return fig, axs 549 550 def plot_spatial_stats( 551 self, 552 stats: str = "max", 553 vmin: float | None = 0, 554 vmax: float | None = None, 555 ax_settings: dict = {}, 556 fig_settings: dict = {}, 557 html_show: bool = False, 558 ): 559 """ 560 Plot the map of a given spatial statistic. 561 :param stats: The statistic to plot, choice are 562 'max, min, mean, median, q20, q80', defaults to "max" 563 :type stats: str, optional 564 ::param vmin: Minimal bounds value for the colorbar, defaults to 0 565 :type vmin: float, optional 566 :param vmax: Maximal bounds value for the colorbar, defaults to None 567 :type vmax: float, optional 568 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 569 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 570 :type ax_settings: dict, optional 571 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 572 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 573 :type fig_settings: dict, optional 574 :param html_show: Display the figure in an html page with your navigator, defaults 575 to False 576 :type html_show: bool, optional 577 578 """ 579 580 fig_settings = plot.fig_properties(**fig_settings) 581 582 if not hasattr(self._parent_class.mystats.spatial_stats.results, stats): 583 raise ValueError( 584 f"Statistical results `{stats}` not found. Choice are: " 585 "[min, max, mean, median, q20, q80]" 586 ) 587 588 stats_matrix = getattr( 589 self._parent_class.mystats.spatial_stats.results, 590 stats, 591 ) 592 default_ax_settings = plot.ax_properties( 593 title="Maximal Discharges on periode" 594 f" {self._parent_class.mysmashmodel.setup.start_time} -" 595 f" {self._parent_class.mysmashmodel.setup.end_time}", 596 xlabel="Coords X", 597 ylabel="Coords_Y", 598 clabel="Discharge (m^3/s)", 599 cmap="viridis", 600 ) 601 default_ax_settings.update(**ax_settings) 602 603 fig, ax = plot.plot_image( 604 matrice=stats_matrix, 605 bbox=geo_toolbox.get_bbox_from_smash_mesh(self._parent_class.mymesh.mesh), 606 vmin=vmin, 607 vmax=vmax, 608 mask=self._parent_class.mysmashmodel.mesh.active_cell, 609 catchment_polygon=self._parent_class.mymesh.catchment_polygon, 610 ax_settings=default_ax_settings, 611 fig_settings=fig_settings, 612 ) 613 614 if fig_settings.figname is None: 615 if tools.with_reticulate() or html_show: 616 mpld3.show(fig, open_browser=True) 617 else: 618 fig.show() 619 620 # return fig, ax 621 622 def plot_hydrograph( 623 self, 624 columns: list | None = [], 625 outlets_name: list = [], 626 plot_rainfall: bool = True, 627 ax_settings: dict = {}, 628 fig_settings: dict = {}, 629 plot_settings_sim: dict = {}, 630 plot_settings_obs: dict = {}, 631 html_show: bool = False, 632 ): 633 """ 634 Plot the simulated and the observed hydrogram for different outlets. 635 636 :param columns: Columns of the matrix to plot (outlets), defaults to [] 637 :type columns: list | None, optional 638 :param outlets_name: List of the outlets name to plot, defaults to [] 639 :type outlets_name: list, optional 640 :param plot_rainfall: Plot the rainfall on the graphics, defaults to True 641 :type plot_rainfall: bool, optional 642 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 643 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 644 :type ax_settings: dict, optional 645 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 646 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 647 :type fig_settings: dict, optional 648 :param plot_settings_sim: Parameters of the matplotlib curves. Any propoerties of 649 plot.plot_properties() class ca be defined in this dictionnary, defaults to {} 650 :type plot_settings_sim: dict, optional 651 :param plot_settings_obs: DParameters of the matplotlib curves. Any propoerties of 652 plot.plot_properties() class ca be defined in this dictionnary, defaults to {} 653 :type plot_settings_obs: dict, optional 654 :pparam html_show: Display the figure in an html page with your navigator, defaults 655 to False 656 :type html_show: bool, optional 657 658 """ 659 660 fig_settings = plot.fig_properties(**fig_settings) 661 662 if len(outlets_name) > 0: 663 columns = tools.array_isin( 664 self._parent_class.mysmashmodel.mesh.code, 665 np.array(outlets_name), 666 ) 667 elif len(columns) > 0: 668 outlets_name = [self._parent_class.mysmashmodel.mesh.code[i] for i in columns] 669 670 if columns is None: 671 columns = list(range(0, self._parent_class.mysmashmodel.response.q.shape[0])) 672 outlets_name = list(self._parent_class.mysmashmodel.mesh.code) 673 674 if len(columns) == 0: 675 columns = [0] 676 outlets_name = [list(self._parent_class.mysmashmodel.mesh.code)[0]] 677 678 fig, ax = plot.plot_hydrograph( 679 model=self._parent_class.mysmashmodel, 680 columns=columns, 681 outlets_name=outlets_name, 682 plot_rainfall=plot_rainfall, 683 ax_settings=ax_settings, 684 fig_settings=fig_settings, 685 plot_settings_sim=plot_settings_sim, 686 plot_settings_obs=plot_settings_obs, 687 ) 688 689 if fig_settings.figname is None: 690 if tools.with_reticulate() or html_show: 691 mpld3.show(fig, open_browser=True) 692 else: 693 fig.show() 694 695 # return fig, ax 696 697 def plot_misfit( 698 self, 699 columns: list | None = None, 700 outlets_name: list = [], 701 misfit: str = "nse", 702 ax_settings: dict = {}, 703 fig_settings: dict = {}, 704 html_show: bool = False, 705 ): 706 """ 707 Plot a misfit criteria for a given list of outlet. 708 :param columns: Columns of the matrix to plot (outlets), defaults to [] 709 :type columns: list | None, optional 710 :param outlets_name: List of the outlets name to plot, defaults to [] 711 :type outlets_name: list, optional 712 :param misfit: The misfit criteria to plot, choice are 713 "nse, nnse, rmse, nrmse, se, kge", defaults to "nse" 714 :type misfit: str, optional 715 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 716 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 717 :type ax_settings: dict, optional 718 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 719 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 720 :type fig_settings: dict, optional 721 :param html_show: Display the figure in an html page with your navigator, defaults 722 to False 723 :type html_show: bool, optional 724 725 """ 726 727 fig_settings = plot.fig_properties(**fig_settings) 728 729 values = getattr(self._parent_class.mystats.misfit_stats.results, misfit) 730 731 if len(outlets_name) > 0: 732 columns = tools.array_isin( 733 self._parent_class.mysmashmodel.mesh.code, 734 np.array(outlets_name), 735 ) 736 737 if columns is None: 738 columns = list(range(0, self._parent_class.mysmashmodel.response.q.shape[0])) 739 outlets_name = self._parent_class.mysmashmodel.mesh.code 740 741 fig, ax = plot.plot_misfit( 742 values=values[columns], 743 names=outlets_name, 744 columns=None, 745 misfit=misfit, 746 ax_settings=ax_settings, 747 fig_settings=fig_settings, 748 ) 749 750 if fig_settings.figname is None: 751 if tools.with_reticulate() or html_show: 752 mpld3.show(fig, open_browser=True) 753 else: 754 fig.show() 755 756 # return fig, ax 757 758 def plot_outlet_stats( 759 self, 760 columns: list | None = None, 761 outlets_name: list = [], 762 stat: str = "max", 763 ax_settings: dict = {}, 764 fig_settings: dict = {}, 765 html_show: bool = False, 766 ): 767 """ 768 Plot a statistical criteria for a given list of outlet. 769 :param columns: Columns of the matrix to plot (outlets), defaults to [] 770 :type columns: list | None, optional 771 :param outlets_name: List of the outlets name to plot, defaults to [] 772 :type outlets_name: list, optional 773 :param misfit: The misfit criteria to plot, choice are 774 "nse, nnse, rmse, nrmse, se, kge", defaults to "nse" 775 :type misfit: str, optional 776 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 777 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 778 :type ax_settings: dict, optional 779 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 780 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 781 :type fig_settings: dict, optional 782 :param html_show: Display the figure in an html page with your navigator, defaults 783 to False 784 :type html_show: bool, optional 785 786 """ 787 788 fig_settings = plot.fig_properties(**fig_settings) 789 790 values_sim = getattr(self._parent_class.mystats.outlets_stats.results_sim, stat) 791 values_obs = getattr(self._parent_class.mystats.outlets_stats.results_obs, stat) 792 793 if len(outlets_name) > 0: 794 columns = tools.array_isin( 795 self._parent_class.mysmashmodel.mesh.code, 796 np.array(outlets_name), 797 ) 798 799 if columns is None: 800 columns = list(range(0, self._parent_class.mysmashmodel.response.q.shape[0])) 801 outlets_name = list(self._parent_class.mysmashmodel.mesh.code) 802 803 fig, ax = plot.plot_outlet_stats( 804 values_sim=values_sim[columns], 805 values_obs=values_obs[columns], 806 names=outlets_name, 807 columns=None, 808 stat=stat, 809 ax_settings=ax_settings, 810 fig_settings=fig_settings, 811 ) 812 813 if fig_settings.figname is None: 814 if tools.with_reticulate() or html_show: 815 mpld3.show(fig, open_browser=True) 816 else: 817 fig.show() 818 819 # return fig, ax 820 821 def multiplot_misfit( 822 self, 823 columns: list | None = None, 824 outlets_name: list = [], 825 misfit: list = [ 826 "nse", 827 "nnse", 828 "kge", 829 "mse", 830 "rmse", 831 "nrmse", 832 "se", 833 "mae", 834 "mape", 835 "lgrm", 836 ], 837 ax_settings: dict = {}, 838 fig_settings: dict = {}, 839 html_show: bool = False, 840 ): 841 """ 842 Plot misfit criterium for a given list of outlets. 843 844 :param columns: Columns of the matrix to plot (outlets), defaults to [] 845 :type columns: list | None, optional 846 :param outlets_name: List of the outlets name to plot, defaults to [] 847 :type outlets_name: list, optional 848 :param misfit: The misfit criteria to plot, list of criteria among 849 "nse, nnse, mse, rmse, nrmse, se, mae, mape, lgrm, kge", defaults to "nse" 850 :type misfit: str, optional 851 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 852 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 853 :type ax_settings: dict, optional 854 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 855 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 856 :type fig_settings: dict, optional 857 :param html_show: Display the figure in an html page with your navigator, defaults 858 to False 859 :type html_show: bool, optional 860 861 """ 862 863 fig_settings = plot.fig_properties(**fig_settings) 864 865 if len(outlets_name) > 0: 866 columns = tools.array_isin( 867 self._parent_class.mysmashmodel.mesh.code, 868 np.array(outlets_name), 869 ) 870 871 if columns is None: 872 columns = list(range(0, self._parent_class.mysmashmodel.response.q.shape[0])) 873 outlets_name = list(self._parent_class.mysmashmodel.mesh.code) 874 875 yfig = int(np.sqrt(len(misfit))) 876 xfig = int(np.ceil(len(misfit) / yfig)) 877 878 fig, axs = plt.subplots( 879 xfig, 880 yfig, 881 constrained_layout=True, 882 ) 883 884 # for ax in axs: 885 # ax.set_axis_off() 886 887 for ax, crit in zip( 888 axs.flat, 889 misfit, 890 ): 891 892 # ax.set_axis_on() 893 ax_settings["ylabel"] = f"{crit} criteria" 894 ax_settings["title"] = f"{crit} criteria" 895 896 if hasattr(self._parent_class.mystats.misfit_stats.results, crit): 897 values = getattr(self._parent_class.mystats.misfit_stats.results, crit) 898 else: 899 raise ValueError( 900 f"`{crit}` is not a valid statistic. choice are:" 901 "[nse, nnse, mse, rmse, nrmse, se, mae, mape, lgrm, kge]" 902 ) 903 904 fig, ax = plot.plot_misfit( 905 values=values[columns], 906 names=np.array(outlets_name), 907 columns=None, 908 misfit=crit, 909 figure=(fig, ax), 910 ax_settings=ax_settings, 911 ) 912 913 [fig.delaxes(ax) for ax in axs.flatten() if not ax.has_data()] 914 fig_settings.change((fig, ax)) 915 916 if fig_settings.figname is None: 917 if tools.with_reticulate() or html_show: 918 mpld3.show(fig, open_browser=True) 919 else: 920 fig.show() 921 922 # return fig, ax 923 924 def plot_misfit_map( 925 self, 926 misfit: str = "nse", 927 coef_hydro: float = 99.0, 928 ax_settings: dict = {}, 929 fig_settings: dict = {}, 930 plot_settings: dict = {}, 931 html_show: bool = False, 932 ): 933 """ 934 Plot a map of a misfit criteria. 935 936 :param columns: Columns of the matrix to plot (outlets), defaults to [] 937 :type columns: list | None, optional 938 :param outlets_name: List of the outlets name to plot, defaults to [] 939 :type outlets_name: list, optional 940 :param misfit: The misfit criteria to plot, choice are 941 "nse, nnse, mse, rmse, nrmse, se, mae, mape, lgrm, kge", defaults to "nse" 942 :type misfit: str, optional 943 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 944 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 945 :type ax_settings: dict, optional 946 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 947 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 948 :type fig_settings: dict, optional 949 :param html_show: Display the figure in an html page with your navigator, defaults 950 to False 951 :type html_show: bool, optional 952 953 """ 954 955 if hasattr(self._parent_class.mystats.misfit_stats.results, misfit): 956 values = getattr(self._parent_class.mystats.misfit_stats.results, misfit) 957 else: 958 raise ValueError( 959 f"`{misfit}` is not a valid statistic. choice are:" 960 "[nse, nnse, mse, rmse, nrmse, se, mae, mape, lgrm, kge]" 961 ) 962 963 fig_settings = plot.fig_properties(**fig_settings) 964 965 name = self._parent_class.mysmashmodel.mesh.code 966 mesh = self._parent_class.mymesh.mesh 967 968 fig, ax = plot.plot_misfit_map( 969 values=values, 970 names=name, 971 mesh=mesh, 972 misfit=misfit, 973 coef_hydro=coef_hydro, 974 ax_settings=ax_settings, 975 fig_settings=fig_settings, 976 plot_settings=plot_settings, 977 ) 978 979 if fig_settings.figname is None: 980 if tools.with_reticulate() or html_show: 981 mpld3.show(fig, open_browser=True) 982 else: 983 fig.show() 984 985 # return fig, ax 986 987 def multiplot_parameters( 988 self, 989 mask_active_cell=False, 990 ax_settings={}, 991 fig_settings={}, 992 html_show: bool = False, 993 ): 994 """ 995 Multiplot map of every Smash parameters 996 :param mask_active_cell: Use the mask of the active cell to hide the non-active cell, defaults to False 997 :type mask_active_cell: bool, False, optional 998 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 999 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 1000 :type ax_settings: dict, optional 1001 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 1002 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 1003 :type fig_settings: dict, optional 1004 :param html_show: Display the figure in an html page with your navigator, defaults 1005 to False 1006 :type html_show: bool, optional 1007 1008 """ 1009 1010 default_fig_settings = plot.fig_properties(xsize=8, ysize=8) 1011 default_fig_settings.update(**fig_settings) 1012 1013 param = list(self._parent_class.mysmashmodel.rr_parameters.keys) 1014 1015 if mask_active_cell: 1016 mask = self._parent_class.mysmashmodel.mesh.active_cell 1017 else: 1018 mask = None 1019 1020 yfig = int(np.sqrt(len(param))) 1021 xfig = int(np.ceil(len(param) / yfig)) 1022 1023 fig, axs = plt.subplots( 1024 xfig, 1025 yfig, 1026 constrained_layout=False, 1027 ) 1028 plt.subplots_adjust( 1029 left=None, bottom=None, right=None, top=None, wspace=0.5, hspace=0.5 1030 ) 1031 for ax, p in zip(axs.flat, param): 1032 1033 default_ax_settings = plot.ax_properties( 1034 title=f"{p} parameters map", 1035 xlabel="Coords X", 1036 ylabel="Coords_Y", 1037 clabel=f"{p} parameter value", 1038 cmap="viridis", 1039 ) 1040 default_ax_settings.update(**ax_settings) 1041 1042 z = param.index(p) 1043 1044 fig, ax = plot.plot_image( 1045 matrice=self._parent_class.mysmashmodel.rr_parameters.values[:, :, z], 1046 bbox=geo_toolbox.get_bbox_from_smash_mesh(self._parent_class.mymesh.mesh), 1047 mask=mask, 1048 vmin=0.0, 1049 catchment_polygon=self._parent_class.mymesh.catchment_polygon, 1050 ax_settings=default_ax_settings, 1051 figure=[fig, ax], 1052 ) 1053 1054 [fig.delaxes(ax) for ax in axs.flatten() if not ax.has_data()] 1055 default_fig_settings.change((fig, axs)) 1056 1057 if default_fig_settings.figname is None or html_show: 1058 if tools.with_reticulate(): 1059 mpld3.show(fig, open_browser=True) 1060 else: 1061 fig.show() 1062 1063 # return fig, axs 1064 1065 def plot_parameters( 1066 self, 1067 param="cp", 1068 mask_active_cell=False, 1069 vmin=0.0, 1070 vmax=None, 1071 ax_settings={}, 1072 fig_settings={}, 1073 html_show: bool = False, 1074 ): 1075 """ 1076 Plot a map of a Smash parameters 1077 :param param: Name of the parameter to plot, defaults to "cp" 1078 :type param: str, optional 1079 :param mask_active_cell: Use the mask of the active cell to hide the non-active cell, defaults to False 1080 :type mask_active_cell: bool, False, optional 1081 :param vmin: Minimum value of the colorbar, defaults to 0.0 1082 :type vmin: float, optional 1083 :param vmax: Maximum value of the colorbar, defaults to None 1084 :type vmax: float, optional 1085 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 1086 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 1087 :type ax_settings: dict, optional 1088 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 1089 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 1090 :type fig_settings: dict, optional 1091 :param html_show: Display the figure in an html page with your navigator, defaults 1092 to False 1093 :type html_show: bool, optional 1094 """ 1095 1096 fig_settings = plot.fig_properties(**fig_settings) 1097 1098 list_param = list(self._parent_class.mysmashmodel.rr_parameters.keys) 1099 z = list_param.index(param) 1100 1101 if mask_active_cell: 1102 mask = self._parent_class.mysmashmodel.mesh.active_cell 1103 else: 1104 mask = None 1105 1106 fig, axs = plt.subplots() 1107 1108 default_ax_settings = plot.ax_properties( 1109 title=f"{param} parameters map", 1110 xlabel="Coords X", 1111 ylabel="Coords_Y", 1112 clabel=f"{param} parameter value", 1113 cmap="viridis", 1114 ) 1115 default_ax_settings.update(**ax_settings) 1116 1117 fig, ax = plot.plot_image( 1118 matrice=self._parent_class.mysmashmodel.rr_parameters.values[:, :, z], 1119 bbox=geo_toolbox.get_bbox_from_smash_mesh(self._parent_class.mymesh.mesh), 1120 mask=mask, 1121 vmin=vmin, 1122 vmax=vmax, 1123 catchment_polygon=self._parent_class.mymesh.catchment_polygon, 1124 ax_settings=default_ax_settings, 1125 ) 1126 1127 fig_settings.change((fig, axs)) 1128 1129 if fig_settings.figname is None or html_show: 1130 if tools.with_reticulate(): 1131 mpld3.show(fig, open_browser=True) 1132 else: 1133 fig.show() 1134 1135 # return fig, axs
12class myplot: 13 """Class that provide some plotting functions. Plot can be displayed with matplolib UI 14 or as html web page. Every plot can be saved into files.""" 15 16 def __init__(self, parent_class): 17 """ 18 Initialisation. 19 :param parent_class: The parent class src.model.model() to be able to access to 20 the smash model 21 :type parent_class: src.model.model() 22 """ 23 self._parent_class = parent_class 24 """The parent class src.model.model() to be able to access to the smash model""" 25 26 def plot_mesh( 27 self, 28 coef_hydro: float = 99.0, 29 ax_settings: dict = {}, 30 fig_settings: dict = {}, 31 html_show: bool = False, 32 ): 33 """ 34 Plot the map of the mesh of the Smash model with teh outlets and the hydrographic 35 network. 36 :param coef_hydro: couloring cells where the surface is higher than `coef_hydro`% 37 of the total surface catchment, defaults to 99.0 38 :type coef_hydro: float, optional 39 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 40 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 41 :type ax_settings: dict, optional 42 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 43 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 44 :type fig_settings: dict, optional 45 :param html_show: Display the figure in an html page with your navigator, defaults 46 to False 47 :type html_show: bool, optional 48 49 """ 50 default_ax_settings = plot.ax_properties( 51 title="Mesh of the Smash model", 52 xlabel="x_coords", 53 ylabel="y_coords", 54 ) 55 default_ax_settings.update(**ax_settings) 56 57 fig_settings = plot.fig_properties(**fig_settings) 58 59 if not hasattr(self._parent_class.mymesh, "mesh"): 60 raise ValueError("No smash mesh found. Build the mesh first.") 61 62 fig, ax = plot.plot_mesh( 63 self._parent_class.mymesh.mesh, 64 catchment_polygon=self._parent_class.mymesh.catchment_polygon, 65 coef_hydro=coef_hydro, 66 ax_settings=ax_settings, 67 fig_settings=fig_settings, 68 ) 69 70 if fig_settings.figname is None: 71 if tools.with_reticulate() or html_show: 72 mpld3.show(fig, open_browser=True) 73 else: 74 fig.show() 75 76 def plot_catchment_surface_consistency( 77 self, 78 label: bool = True, 79 ax_settings: dict = {}, 80 fig_settings: dict = {}, 81 plot_settings: dict = {}, 82 html_show: bool = False, 83 ): 84 """ 85 Plot the modeled surface vs the observed surface. Check its consistency. 86 :param label, labels the point on the plot with the code of the outlets. 87 :type label: bool, default True 88 :param ax_settings, any properties of plot.ax_properties() class can be defined 89 in this dictionnary, defaults to {} 90 :type ax_settings: dict, optional 91 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 92 plot.fig_properties() class can be defined in this dictionnary, defaults to {} 93 :type fig_settings: dict, optional 94 :param plot_settings, any properties of plot.plot_properties() class can be 95 defined in this dictionnary, defaults to {} 96 :param html_show: Display the figure in an html page with your navigator, defaults 97 to False 98 :type html_show: bool, optional 99 100 """ 101 102 default_ax_settings = plot.ax_properties( 103 title="Modeled and observed surface consistency", 104 xlabel="Observed surface", 105 ylabel="Modeled surface", 106 ) 107 default_ax_settings.update(**ax_settings) 108 109 fig_settings = plot.fig_properties(**fig_settings) 110 111 if not hasattr(self._parent_class.mymesh, "mesh"): 112 raise ValueError("No smash mesh found. Build the mesh first.") 113 114 fig, ax = plot.plot_catchment_surface_consistency( 115 mesh=self._parent_class.mymesh.mesh, 116 label=label, 117 ax_settings=ax_settings, 118 fig_settings=fig_settings, 119 plot_settings=plot_settings, 120 ) 121 122 if fig_settings.figname is None: 123 if tools.with_reticulate() or html_show: 124 mpld3.show(fig, open_browser=True) 125 else: 126 fig.show() 127 128 def plot_catchment_surface_error( 129 self, 130 ax_settings: dict = {}, 131 fig_settings: dict = {}, 132 html_show: bool = False, 133 ): 134 """ 135 Plot the modeled surface vs the observed surface. Check its consistency. 136 :param ax_settings, any properties of plot.ax_properties() class can be defined 137 in this dictionnary, defaults to {} 138 :type ax_settings: dict, optional 139 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 140 plot.fig_properties() class can be defined in this dictionnary, defaults to {} 141 :param html_show: Display the figure in an html page with your navigator, defaults 142 to False 143 :type html_show: bool, optional 144 145 """ 146 147 default_ax_settings = plot.ax_properties( 148 title="Catchment surface error", 149 xlabel="Catchments", 150 ylabel="(Ssim - Sobs)/Sobs", 151 ) 152 default_ax_settings.update(**ax_settings) 153 154 fig_settings = plot.fig_properties(**fig_settings) 155 156 if not hasattr(self._parent_class.mymesh, "mesh"): 157 raise ValueError("No smash mesh found. Build the mesh first.") 158 159 fig, ax = plot.plot_catchment_surface_error( 160 mesh=self._parent_class.mymesh.mesh, 161 ax_settings=ax_settings, 162 fig_settings=fig_settings, 163 ) 164 165 if fig_settings.figname is None: 166 if tools.with_reticulate() or html_show: 167 mpld3.show(fig, open_browser=True) 168 else: 169 fig.show() 170 171 @tools.autocast_args 172 def plot_xy_quantile( 173 self, 174 duration: int = 1, 175 X: int = 0, 176 Y: int = 0, 177 ax_settings: dict = {}, 178 fig_settings: dict = {}, 179 plot_settings: dict = {}, 180 html_show: bool = False, 181 ): 182 """ 183 184 :param duration: Duration of the quantile, defaults to 1 185 :type duration: int, optional 186 :param X: X coordinate of the targeted cell (matrix coordinate system), defaults 187 to 0 188 :type X: int, optional 189 :param Y: Y coordinate of the targeted cell (matrix coordinate system), defaults 190 to 0 191 :type Y: int, optional 192 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 193 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 194 :type ax_settings: dict, optional 195 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 196 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 197 :type fig_settings: dict, optional 198 :param html_show: Display the figure in an html page with your navigator, 199 defaults to False 200 :type html_show: bool, optional 201 202 """ 203 204 if not hasattr( 205 self._parent_class.mystats.quantile_stats, f"Quantile_{duration}h" 206 ): 207 raise ValueError(f"No statistical results found for duration {duration}h") 208 209 results_quantile = getattr( 210 self._parent_class.mystats.quantile_stats, 211 f"Quantile_{duration}h", 212 ) 213 214 if self._parent_class.mymesh.mesh["active_cell"][X, Y] == 0: 215 raise ValueError( 216 f"`{X},{Y}` coordinates does not correspond to an active cell." 217 ) 218 219 default_ax_settings = plot.ax_properties( 220 title=f"Maximal discharges frequency curve on {results_quantile.chunk_size}" 221 " days", 222 xscale="log", 223 xlabel=f"Return period (*{results_quantile.chunk_size} days)", 224 ylabel="Discharges (m³/s)", 225 grid=True, 226 legend=True, 227 ) 228 default_ax_settings.update(**ax_settings) 229 230 fig_settings = plot.fig_properties(**fig_settings) 231 232 fig, ax = plot.plot_xy_quantile( 233 results_quantile.__dict__, 234 X, 235 Y, 236 ax_settings=default_ax_settings, 237 fig_settings=fig_settings, 238 plot_settings=plot_settings, 239 ) 240 241 if fig_settings.figname is None: 242 if tools.with_reticulate() or html_show: 243 mpld3.show(fig, open_browser=True) 244 else: 245 fig.show() 246 # return fig, ax 247 248 @tools.autocast_args 249 def plot_outlets_quantile( 250 self, 251 duration: int = 1, 252 quantile_obs=True, 253 gauge: list | None = None, 254 ax_settings: dict = {}, 255 fig_settings: dict = {}, 256 plot_settings: dict = {}, 257 html_show: bool = False, 258 ): 259 """ 260 Plot the quantiles prediction for different return period for every outlets. 261 :param duration: Duration of the quantile, defaults to 1 262 :type duration: int, optional 263 :param quantile_obs: Compute and display the observed quantile in th graphics. 264 Observed quantile are computed again the whole observed discharge chronicle 265 from 1900 until today. 266 :type quantile_obs: Bool, default is True 267 :param gauge: List of gauge code to plot. Default is None. If None all gague 268 are plotted 269 :type gauge: list | None, default None. 270 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 271 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 272 :type ax_settings: dict, optional 273 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 274 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 275 :type fig_settings: dict, optional 276 :param plot_settings: Parameters of the matplotlib figure 'fig'. Any properties of 277 plot.plot_settings() class ca be defined in this dictionnary, defaults to {} 278 :type plot_settings: dict, optional 279 :param html_show: Display the figure in an html page with your navigator, defaults 280 to False 281 :type html_show: bool, optional 282 283 """ 284 285 # fig_settings = plot.fig_properties(**fig_settings) 286 287 if not hasattr( 288 self._parent_class.mystats.quantile_stats, f"Quantile_{duration}h" 289 ): 290 raise ValueError(f"No statistical results found for duration {duration}h") 291 292 gauge_pos = list(self._parent_class.mymesh.mesh["gauge_pos"]) 293 gauge_code = list(self._parent_class.mymesh.mesh["code"]) 294 295 if gauge is not None: 296 list_ind_gauge = [] 297 for i, g in enumerate(gauge_code): 298 if g in gauge: 299 list_ind_gauge.append(i) 300 else: 301 print(f"</> gauge {g} not found in the mesh gauge list {gauge_code}") 302 if len(list_ind_gauge) > 0: 303 gauge_pos = gauge_pos[list_ind_gauge] 304 gauge_code = gauge_code[list_ind_gauge] 305 else: 306 print(f"</> gauge {gauge} not found in the mesh gauge list {gauge_code}") 307 308 yfig = int(np.sqrt(len(gauge_pos))) 309 xfig = int(np.ceil(len(gauge_pos) / yfig)) 310 311 default_fig_settings = plot.fig_properties(ysize=yfig * 5, xsize=xfig * 3) 312 default_fig_settings.update(**fig_settings) 313 314 if quantile_obs: 315 res_quantile_obs = stats.quantil_obs( 316 qobs_directory=self._parent_class.mysetup.setup["qobs_directory"], 317 code=gauge_code, 318 model_time_step=self._parent_class.mysetup.setup["dt"], 319 quantile_duration=duration, 320 ) 321 else: 322 res_quantile_obs = None 323 324 fig, axs = plt.subplots( 325 xfig, 326 yfig, 327 constrained_layout=True, 328 ) 329 330 for ax, coords, code in zip(axs.flat, gauge_pos, gauge_code): 331 332 X, Y = coords 333 results_quantile = getattr( 334 self._parent_class.mystats.quantile_stats, 335 f"Quantile_{duration}h", 336 ) 337 338 # default_ax_settings = plot.ax_properties( 339 # title=f"Discharges quantile at gauge {code}", 340 # legend_fontsize=6, 341 # ) 342 # default_ax_settings.update(**ax_settings) 343 344 default_ax_settings = plot.ax_properties( 345 title=f"Discharges quantile at gauge {code}", 346 xscale="log", 347 xlabel=f"Return period (*{results_quantile.chunk_size} days)", 348 ylabel="Discharges (m³/s)", 349 grid=True, 350 legend=True, 351 legend_fontsize=8, 352 xtics_fontsize=8, 353 ytics_fontsize=8, 354 ) 355 default_ax_settings.update(**ax_settings) 356 357 default_plot_settings = plot.plot_properties( 358 markersize=6, 359 ) 360 default_plot_settings.update(**plot_settings) 361 362 fig, ax = plot.plot_xy_quantile( 363 results_quantile.__dict__, 364 X, 365 Y, 366 res_quantile_obs=res_quantile_obs, 367 gauge_pos=list(gauge_code).index(code), 368 figure=[fig, ax], 369 ax_settings=default_ax_settings, 370 plot_settings=default_plot_settings, 371 ) 372 373 default_fig_settings.change((fig, axs)) 374 375 if default_fig_settings.figname is None: 376 if tools.with_reticulate() or html_show: 377 mpld3.show(fig, open_browser=True) 378 else: 379 fig.show() 380 381 # return fig, axs 382 383 @tools.autocast_args 384 def plot_spatial_quantile( 385 self, 386 duration: int = 1, 387 T: int = 2, 388 vmin: float | None = 0, 389 vmax: float | None = None, 390 ax_settings: dict = {}, 391 fig_settings: dict = {}, 392 html_show=False, 393 ): 394 """ 395 Plot the map of the quantiles for given return period and a given duration. 396 :param duration: Duration of the quantile, defaults to 1 397 :type duration: int, optional 398 :param T: return period, defaults to 2 (default is years, but that depends 399 of the chunk size) 400 :type T: int, optional 401 :param vmin: Minimal bounds value for the colorbar, defaults to 0 402 :type vmin: float, optional 403 :param vmax: Maximal bounds value for the colorbar, defaults to None 404 :type vmax: float, optional 405 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 406 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 407 :type ax_settings: dict, optional 408 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 409 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 410 :type fig_settings: dict, optional 411 :param html_show: Display the figure in an html page with your navigator, defaults to False 412 :type html_show: bool, optional 413 414 """ 415 416 fig_settings = plot.fig_properties(**fig_settings) 417 418 if not hasattr( 419 self._parent_class.mystats.quantile_stats, f"Quantile_{duration}h" 420 ): 421 raise ValueError(f"No statistical results found for duration {duration}h") 422 423 results_quantile = getattr( 424 self._parent_class.mystats.quantile_stats, 425 f"Quantile_{duration}h", 426 ) 427 428 default_ax_settings = plot.ax_properties( 429 title=f"Discharges quantile for duration={duration} h, T={T}", 430 xlabel="Coords X", 431 ylabel="Coords_Y", 432 clabel="Discharge (m^3/s)", 433 cmap="viridis", 434 ) 435 default_ax_settings.update(**ax_settings) 436 437 z = list(results_quantile.T).index(T) 438 439 fig, ax = plot.plot_image( 440 matrice=results_quantile.Q_th[:, :, z], 441 bbox=geo_toolbox.get_bbox_from_smash_mesh(self._parent_class.mymesh.mesh), 442 vmin=vmin, 443 vmax=vmax, 444 mask=self._parent_class.mysmashmodel.mesh.active_cell, 445 catchment_polygon=self._parent_class.mymesh.catchment_polygon, 446 ax_settings=default_ax_settings, 447 fig_settings=fig_settings, 448 ) 449 450 if fig_settings.figname is None: 451 if tools.with_reticulate() or html_show: 452 mpld3.show(fig, open_browser=True) 453 else: 454 fig.show() 455 456 # return fig, ax 457 458 @tools.autocast_args 459 def multiplot_spatial_quantile( 460 self, 461 duration: int = 1, 462 vmin: float | None = 0, 463 vmax: float | None = None, 464 ax_settings={}, 465 fig_settings={}, 466 html_show: bool = False, 467 ): 468 """ 469 Plot the map of the quantiles for every return period for a given duration. 470 :param duration: Duration of the quantile, defaults to 1 471 :type duration: int, optional 472 :param vmin: Minimal bounds value for the colorbar, defaults to 0 473 :type vmin: float, optional 474 :param vmax: Maximal bounds value for the colorbar, defaults to None 475 :type vmax: float, optional 476 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 477 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 478 :type ax_settings: dict, optional 479 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 480 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 481 :type fig_settings: dict, optional 482 :param html_show: Display the figure in an html page with your navigator, defaults 483 to False 484 :type html_show: bool, optional 485 486 """ 487 488 fig_settings = plot.fig_properties(**fig_settings) 489 490 if not hasattr( 491 self._parent_class.mystats.quantile_stats, f"Quantile_{duration}h" 492 ): 493 raise ValueError(f"No statistical results found for duration {duration}h") 494 495 results_quantile = getattr( 496 self._parent_class.mystats.quantile_stats, 497 f"Quantile_{duration}h", 498 ) 499 500 yfig = int(np.sqrt(len(results_quantile.T))) 501 xfig = int(np.ceil(len(results_quantile.T) / yfig)) 502 503 fig, axs = plt.subplots( 504 xfig, 505 yfig, 506 constrained_layout=False, 507 ) 508 plt.subplots_adjust( 509 left=None, bottom=None, right=None, top=None, wspace=0.5, hspace=None 510 ) 511 512 for ax, T in zip(axs.flat, results_quantile.T): 513 514 default_ax_settings = plot.ax_properties( 515 title=f"Discharges quantile for duration={duration} h, T={T}", 516 xlabel="Coords X", 517 ylabel="Coords_Y", 518 clabel="Discharge (m^3/s)", 519 cmap="viridis", 520 title_fontsize=10, 521 label_fontsize=8, 522 xtics_fontsize=6, 523 ytics_fontsize=6, 524 ) 525 default_ax_settings.update(**ax_settings) 526 527 z = list(results_quantile.T).index(T) 528 529 fig, ax = plot.plot_image( 530 matrice=results_quantile.Q_th[:, :, z], 531 bbox=geo_toolbox.get_bbox_from_smash_mesh(self._parent_class.mymesh.mesh), 532 vmin=vmin, 533 vmax=vmax, 534 mask=self._parent_class.mysmashmodel.mesh.active_cell, 535 catchment_polygon=self._parent_class.mymesh.catchment_polygon, 536 ax_settings=default_ax_settings, 537 figure=[fig, ax], 538 ) 539 540 [fig.delaxes(ax) for ax in axs.flatten() if not ax.has_data()] 541 fig_settings.change((fig, axs)) 542 543 if fig_settings.figname is None or html_show: 544 if tools.with_reticulate(): 545 mpld3.show(fig, open_browser=True) 546 else: 547 fig.show() 548 549 # return fig, axs 550 551 def plot_spatial_stats( 552 self, 553 stats: str = "max", 554 vmin: float | None = 0, 555 vmax: float | None = None, 556 ax_settings: dict = {}, 557 fig_settings: dict = {}, 558 html_show: bool = False, 559 ): 560 """ 561 Plot the map of a given spatial statistic. 562 :param stats: The statistic to plot, choice are 563 'max, min, mean, median, q20, q80', defaults to "max" 564 :type stats: str, optional 565 ::param vmin: Minimal bounds value for the colorbar, defaults to 0 566 :type vmin: float, optional 567 :param vmax: Maximal bounds value for the colorbar, defaults to None 568 :type vmax: float, optional 569 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 570 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 571 :type ax_settings: dict, optional 572 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 573 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 574 :type fig_settings: dict, optional 575 :param html_show: Display the figure in an html page with your navigator, defaults 576 to False 577 :type html_show: bool, optional 578 579 """ 580 581 fig_settings = plot.fig_properties(**fig_settings) 582 583 if not hasattr(self._parent_class.mystats.spatial_stats.results, stats): 584 raise ValueError( 585 f"Statistical results `{stats}` not found. Choice are: " 586 "[min, max, mean, median, q20, q80]" 587 ) 588 589 stats_matrix = getattr( 590 self._parent_class.mystats.spatial_stats.results, 591 stats, 592 ) 593 default_ax_settings = plot.ax_properties( 594 title="Maximal Discharges on periode" 595 f" {self._parent_class.mysmashmodel.setup.start_time} -" 596 f" {self._parent_class.mysmashmodel.setup.end_time}", 597 xlabel="Coords X", 598 ylabel="Coords_Y", 599 clabel="Discharge (m^3/s)", 600 cmap="viridis", 601 ) 602 default_ax_settings.update(**ax_settings) 603 604 fig, ax = plot.plot_image( 605 matrice=stats_matrix, 606 bbox=geo_toolbox.get_bbox_from_smash_mesh(self._parent_class.mymesh.mesh), 607 vmin=vmin, 608 vmax=vmax, 609 mask=self._parent_class.mysmashmodel.mesh.active_cell, 610 catchment_polygon=self._parent_class.mymesh.catchment_polygon, 611 ax_settings=default_ax_settings, 612 fig_settings=fig_settings, 613 ) 614 615 if fig_settings.figname is None: 616 if tools.with_reticulate() or html_show: 617 mpld3.show(fig, open_browser=True) 618 else: 619 fig.show() 620 621 # return fig, ax 622 623 def plot_hydrograph( 624 self, 625 columns: list | None = [], 626 outlets_name: list = [], 627 plot_rainfall: bool = True, 628 ax_settings: dict = {}, 629 fig_settings: dict = {}, 630 plot_settings_sim: dict = {}, 631 plot_settings_obs: dict = {}, 632 html_show: bool = False, 633 ): 634 """ 635 Plot the simulated and the observed hydrogram for different outlets. 636 637 :param columns: Columns of the matrix to plot (outlets), defaults to [] 638 :type columns: list | None, optional 639 :param outlets_name: List of the outlets name to plot, defaults to [] 640 :type outlets_name: list, optional 641 :param plot_rainfall: Plot the rainfall on the graphics, defaults to True 642 :type plot_rainfall: bool, optional 643 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 644 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 645 :type ax_settings: dict, optional 646 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 647 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 648 :type fig_settings: dict, optional 649 :param plot_settings_sim: Parameters of the matplotlib curves. Any propoerties of 650 plot.plot_properties() class ca be defined in this dictionnary, defaults to {} 651 :type plot_settings_sim: dict, optional 652 :param plot_settings_obs: DParameters of the matplotlib curves. Any propoerties of 653 plot.plot_properties() class ca be defined in this dictionnary, defaults to {} 654 :type plot_settings_obs: dict, optional 655 :pparam html_show: Display the figure in an html page with your navigator, defaults 656 to False 657 :type html_show: bool, optional 658 659 """ 660 661 fig_settings = plot.fig_properties(**fig_settings) 662 663 if len(outlets_name) > 0: 664 columns = tools.array_isin( 665 self._parent_class.mysmashmodel.mesh.code, 666 np.array(outlets_name), 667 ) 668 elif len(columns) > 0: 669 outlets_name = [self._parent_class.mysmashmodel.mesh.code[i] for i in columns] 670 671 if columns is None: 672 columns = list(range(0, self._parent_class.mysmashmodel.response.q.shape[0])) 673 outlets_name = list(self._parent_class.mysmashmodel.mesh.code) 674 675 if len(columns) == 0: 676 columns = [0] 677 outlets_name = [list(self._parent_class.mysmashmodel.mesh.code)[0]] 678 679 fig, ax = plot.plot_hydrograph( 680 model=self._parent_class.mysmashmodel, 681 columns=columns, 682 outlets_name=outlets_name, 683 plot_rainfall=plot_rainfall, 684 ax_settings=ax_settings, 685 fig_settings=fig_settings, 686 plot_settings_sim=plot_settings_sim, 687 plot_settings_obs=plot_settings_obs, 688 ) 689 690 if fig_settings.figname is None: 691 if tools.with_reticulate() or html_show: 692 mpld3.show(fig, open_browser=True) 693 else: 694 fig.show() 695 696 # return fig, ax 697 698 def plot_misfit( 699 self, 700 columns: list | None = None, 701 outlets_name: list = [], 702 misfit: str = "nse", 703 ax_settings: dict = {}, 704 fig_settings: dict = {}, 705 html_show: bool = False, 706 ): 707 """ 708 Plot a misfit criteria for a given list of outlet. 709 :param columns: Columns of the matrix to plot (outlets), defaults to [] 710 :type columns: list | None, optional 711 :param outlets_name: List of the outlets name to plot, defaults to [] 712 :type outlets_name: list, optional 713 :param misfit: The misfit criteria to plot, choice are 714 "nse, nnse, rmse, nrmse, se, kge", defaults to "nse" 715 :type misfit: str, optional 716 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 717 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 718 :type ax_settings: dict, optional 719 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 720 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 721 :type fig_settings: dict, optional 722 :param html_show: Display the figure in an html page with your navigator, defaults 723 to False 724 :type html_show: bool, optional 725 726 """ 727 728 fig_settings = plot.fig_properties(**fig_settings) 729 730 values = getattr(self._parent_class.mystats.misfit_stats.results, misfit) 731 732 if len(outlets_name) > 0: 733 columns = tools.array_isin( 734 self._parent_class.mysmashmodel.mesh.code, 735 np.array(outlets_name), 736 ) 737 738 if columns is None: 739 columns = list(range(0, self._parent_class.mysmashmodel.response.q.shape[0])) 740 outlets_name = self._parent_class.mysmashmodel.mesh.code 741 742 fig, ax = plot.plot_misfit( 743 values=values[columns], 744 names=outlets_name, 745 columns=None, 746 misfit=misfit, 747 ax_settings=ax_settings, 748 fig_settings=fig_settings, 749 ) 750 751 if fig_settings.figname is None: 752 if tools.with_reticulate() or html_show: 753 mpld3.show(fig, open_browser=True) 754 else: 755 fig.show() 756 757 # return fig, ax 758 759 def plot_outlet_stats( 760 self, 761 columns: list | None = None, 762 outlets_name: list = [], 763 stat: str = "max", 764 ax_settings: dict = {}, 765 fig_settings: dict = {}, 766 html_show: bool = False, 767 ): 768 """ 769 Plot a statistical criteria for a given list of outlet. 770 :param columns: Columns of the matrix to plot (outlets), defaults to [] 771 :type columns: list | None, optional 772 :param outlets_name: List of the outlets name to plot, defaults to [] 773 :type outlets_name: list, optional 774 :param misfit: The misfit criteria to plot, choice are 775 "nse, nnse, rmse, nrmse, se, kge", defaults to "nse" 776 :type misfit: str, optional 777 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 778 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 779 :type ax_settings: dict, optional 780 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 781 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 782 :type fig_settings: dict, optional 783 :param html_show: Display the figure in an html page with your navigator, defaults 784 to False 785 :type html_show: bool, optional 786 787 """ 788 789 fig_settings = plot.fig_properties(**fig_settings) 790 791 values_sim = getattr(self._parent_class.mystats.outlets_stats.results_sim, stat) 792 values_obs = getattr(self._parent_class.mystats.outlets_stats.results_obs, stat) 793 794 if len(outlets_name) > 0: 795 columns = tools.array_isin( 796 self._parent_class.mysmashmodel.mesh.code, 797 np.array(outlets_name), 798 ) 799 800 if columns is None: 801 columns = list(range(0, self._parent_class.mysmashmodel.response.q.shape[0])) 802 outlets_name = list(self._parent_class.mysmashmodel.mesh.code) 803 804 fig, ax = plot.plot_outlet_stats( 805 values_sim=values_sim[columns], 806 values_obs=values_obs[columns], 807 names=outlets_name, 808 columns=None, 809 stat=stat, 810 ax_settings=ax_settings, 811 fig_settings=fig_settings, 812 ) 813 814 if fig_settings.figname is None: 815 if tools.with_reticulate() or html_show: 816 mpld3.show(fig, open_browser=True) 817 else: 818 fig.show() 819 820 # return fig, ax 821 822 def multiplot_misfit( 823 self, 824 columns: list | None = None, 825 outlets_name: list = [], 826 misfit: list = [ 827 "nse", 828 "nnse", 829 "kge", 830 "mse", 831 "rmse", 832 "nrmse", 833 "se", 834 "mae", 835 "mape", 836 "lgrm", 837 ], 838 ax_settings: dict = {}, 839 fig_settings: dict = {}, 840 html_show: bool = False, 841 ): 842 """ 843 Plot misfit criterium for a given list of outlets. 844 845 :param columns: Columns of the matrix to plot (outlets), defaults to [] 846 :type columns: list | None, optional 847 :param outlets_name: List of the outlets name to plot, defaults to [] 848 :type outlets_name: list, optional 849 :param misfit: The misfit criteria to plot, list of criteria among 850 "nse, nnse, mse, rmse, nrmse, se, mae, mape, lgrm, kge", defaults to "nse" 851 :type misfit: str, optional 852 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 853 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 854 :type ax_settings: dict, optional 855 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 856 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 857 :type fig_settings: dict, optional 858 :param html_show: Display the figure in an html page with your navigator, defaults 859 to False 860 :type html_show: bool, optional 861 862 """ 863 864 fig_settings = plot.fig_properties(**fig_settings) 865 866 if len(outlets_name) > 0: 867 columns = tools.array_isin( 868 self._parent_class.mysmashmodel.mesh.code, 869 np.array(outlets_name), 870 ) 871 872 if columns is None: 873 columns = list(range(0, self._parent_class.mysmashmodel.response.q.shape[0])) 874 outlets_name = list(self._parent_class.mysmashmodel.mesh.code) 875 876 yfig = int(np.sqrt(len(misfit))) 877 xfig = int(np.ceil(len(misfit) / yfig)) 878 879 fig, axs = plt.subplots( 880 xfig, 881 yfig, 882 constrained_layout=True, 883 ) 884 885 # for ax in axs: 886 # ax.set_axis_off() 887 888 for ax, crit in zip( 889 axs.flat, 890 misfit, 891 ): 892 893 # ax.set_axis_on() 894 ax_settings["ylabel"] = f"{crit} criteria" 895 ax_settings["title"] = f"{crit} criteria" 896 897 if hasattr(self._parent_class.mystats.misfit_stats.results, crit): 898 values = getattr(self._parent_class.mystats.misfit_stats.results, crit) 899 else: 900 raise ValueError( 901 f"`{crit}` is not a valid statistic. choice are:" 902 "[nse, nnse, mse, rmse, nrmse, se, mae, mape, lgrm, kge]" 903 ) 904 905 fig, ax = plot.plot_misfit( 906 values=values[columns], 907 names=np.array(outlets_name), 908 columns=None, 909 misfit=crit, 910 figure=(fig, ax), 911 ax_settings=ax_settings, 912 ) 913 914 [fig.delaxes(ax) for ax in axs.flatten() if not ax.has_data()] 915 fig_settings.change((fig, ax)) 916 917 if fig_settings.figname is None: 918 if tools.with_reticulate() or html_show: 919 mpld3.show(fig, open_browser=True) 920 else: 921 fig.show() 922 923 # return fig, ax 924 925 def plot_misfit_map( 926 self, 927 misfit: str = "nse", 928 coef_hydro: float = 99.0, 929 ax_settings: dict = {}, 930 fig_settings: dict = {}, 931 plot_settings: dict = {}, 932 html_show: bool = False, 933 ): 934 """ 935 Plot a map of a misfit criteria. 936 937 :param columns: Columns of the matrix to plot (outlets), defaults to [] 938 :type columns: list | None, optional 939 :param outlets_name: List of the outlets name to plot, defaults to [] 940 :type outlets_name: list, optional 941 :param misfit: The misfit criteria to plot, choice are 942 "nse, nnse, mse, rmse, nrmse, se, mae, mape, lgrm, kge", defaults to "nse" 943 :type misfit: str, optional 944 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 945 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 946 :type ax_settings: dict, optional 947 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 948 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 949 :type fig_settings: dict, optional 950 :param html_show: Display the figure in an html page with your navigator, defaults 951 to False 952 :type html_show: bool, optional 953 954 """ 955 956 if hasattr(self._parent_class.mystats.misfit_stats.results, misfit): 957 values = getattr(self._parent_class.mystats.misfit_stats.results, misfit) 958 else: 959 raise ValueError( 960 f"`{misfit}` is not a valid statistic. choice are:" 961 "[nse, nnse, mse, rmse, nrmse, se, mae, mape, lgrm, kge]" 962 ) 963 964 fig_settings = plot.fig_properties(**fig_settings) 965 966 name = self._parent_class.mysmashmodel.mesh.code 967 mesh = self._parent_class.mymesh.mesh 968 969 fig, ax = plot.plot_misfit_map( 970 values=values, 971 names=name, 972 mesh=mesh, 973 misfit=misfit, 974 coef_hydro=coef_hydro, 975 ax_settings=ax_settings, 976 fig_settings=fig_settings, 977 plot_settings=plot_settings, 978 ) 979 980 if fig_settings.figname is None: 981 if tools.with_reticulate() or html_show: 982 mpld3.show(fig, open_browser=True) 983 else: 984 fig.show() 985 986 # return fig, ax 987 988 def multiplot_parameters( 989 self, 990 mask_active_cell=False, 991 ax_settings={}, 992 fig_settings={}, 993 html_show: bool = False, 994 ): 995 """ 996 Multiplot map of every Smash parameters 997 :param mask_active_cell: Use the mask of the active cell to hide the non-active cell, defaults to False 998 :type mask_active_cell: bool, False, optional 999 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 1000 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 1001 :type ax_settings: dict, optional 1002 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 1003 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 1004 :type fig_settings: dict, optional 1005 :param html_show: Display the figure in an html page with your navigator, defaults 1006 to False 1007 :type html_show: bool, optional 1008 1009 """ 1010 1011 default_fig_settings = plot.fig_properties(xsize=8, ysize=8) 1012 default_fig_settings.update(**fig_settings) 1013 1014 param = list(self._parent_class.mysmashmodel.rr_parameters.keys) 1015 1016 if mask_active_cell: 1017 mask = self._parent_class.mysmashmodel.mesh.active_cell 1018 else: 1019 mask = None 1020 1021 yfig = int(np.sqrt(len(param))) 1022 xfig = int(np.ceil(len(param) / yfig)) 1023 1024 fig, axs = plt.subplots( 1025 xfig, 1026 yfig, 1027 constrained_layout=False, 1028 ) 1029 plt.subplots_adjust( 1030 left=None, bottom=None, right=None, top=None, wspace=0.5, hspace=0.5 1031 ) 1032 for ax, p in zip(axs.flat, param): 1033 1034 default_ax_settings = plot.ax_properties( 1035 title=f"{p} parameters map", 1036 xlabel="Coords X", 1037 ylabel="Coords_Y", 1038 clabel=f"{p} parameter value", 1039 cmap="viridis", 1040 ) 1041 default_ax_settings.update(**ax_settings) 1042 1043 z = param.index(p) 1044 1045 fig, ax = plot.plot_image( 1046 matrice=self._parent_class.mysmashmodel.rr_parameters.values[:, :, z], 1047 bbox=geo_toolbox.get_bbox_from_smash_mesh(self._parent_class.mymesh.mesh), 1048 mask=mask, 1049 vmin=0.0, 1050 catchment_polygon=self._parent_class.mymesh.catchment_polygon, 1051 ax_settings=default_ax_settings, 1052 figure=[fig, ax], 1053 ) 1054 1055 [fig.delaxes(ax) for ax in axs.flatten() if not ax.has_data()] 1056 default_fig_settings.change((fig, axs)) 1057 1058 if default_fig_settings.figname is None or html_show: 1059 if tools.with_reticulate(): 1060 mpld3.show(fig, open_browser=True) 1061 else: 1062 fig.show() 1063 1064 # return fig, axs 1065 1066 def plot_parameters( 1067 self, 1068 param="cp", 1069 mask_active_cell=False, 1070 vmin=0.0, 1071 vmax=None, 1072 ax_settings={}, 1073 fig_settings={}, 1074 html_show: bool = False, 1075 ): 1076 """ 1077 Plot a map of a Smash parameters 1078 :param param: Name of the parameter to plot, defaults to "cp" 1079 :type param: str, optional 1080 :param mask_active_cell: Use the mask of the active cell to hide the non-active cell, defaults to False 1081 :type mask_active_cell: bool, False, optional 1082 :param vmin: Minimum value of the colorbar, defaults to 0.0 1083 :type vmin: float, optional 1084 :param vmax: Maximum value of the colorbar, defaults to None 1085 :type vmax: float, optional 1086 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 1087 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 1088 :type ax_settings: dict, optional 1089 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 1090 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 1091 :type fig_settings: dict, optional 1092 :param html_show: Display the figure in an html page with your navigator, defaults 1093 to False 1094 :type html_show: bool, optional 1095 """ 1096 1097 fig_settings = plot.fig_properties(**fig_settings) 1098 1099 list_param = list(self._parent_class.mysmashmodel.rr_parameters.keys) 1100 z = list_param.index(param) 1101 1102 if mask_active_cell: 1103 mask = self._parent_class.mysmashmodel.mesh.active_cell 1104 else: 1105 mask = None 1106 1107 fig, axs = plt.subplots() 1108 1109 default_ax_settings = plot.ax_properties( 1110 title=f"{param} parameters map", 1111 xlabel="Coords X", 1112 ylabel="Coords_Y", 1113 clabel=f"{param} parameter value", 1114 cmap="viridis", 1115 ) 1116 default_ax_settings.update(**ax_settings) 1117 1118 fig, ax = plot.plot_image( 1119 matrice=self._parent_class.mysmashmodel.rr_parameters.values[:, :, z], 1120 bbox=geo_toolbox.get_bbox_from_smash_mesh(self._parent_class.mymesh.mesh), 1121 mask=mask, 1122 vmin=vmin, 1123 vmax=vmax, 1124 catchment_polygon=self._parent_class.mymesh.catchment_polygon, 1125 ax_settings=default_ax_settings, 1126 ) 1127 1128 fig_settings.change((fig, axs)) 1129 1130 if fig_settings.figname is None or html_show: 1131 if tools.with_reticulate(): 1132 mpld3.show(fig, open_browser=True) 1133 else: 1134 fig.show() 1135 1136 # return fig, axs
Class that provide some plotting functions. Plot can be displayed with matplolib UI or as html web page. Every plot can be saved into files.
16 def __init__(self, parent_class): 17 """ 18 Initialisation. 19 :param parent_class: The parent class src.model.model() to be able to access to 20 the smash model 21 :type parent_class: src.model.model() 22 """ 23 self._parent_class = parent_class 24 """The parent class src.model.model() to be able to access to the smash model"""
Initialisation.
Parameters
- parent_class: The parent class src.model.model() to be able to access to the smash model
26 def plot_mesh( 27 self, 28 coef_hydro: float = 99.0, 29 ax_settings: dict = {}, 30 fig_settings: dict = {}, 31 html_show: bool = False, 32 ): 33 """ 34 Plot the map of the mesh of the Smash model with teh outlets and the hydrographic 35 network. 36 :param coef_hydro: couloring cells where the surface is higher than `coef_hydro`% 37 of the total surface catchment, defaults to 99.0 38 :type coef_hydro: float, optional 39 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 40 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 41 :type ax_settings: dict, optional 42 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 43 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 44 :type fig_settings: dict, optional 45 :param html_show: Display the figure in an html page with your navigator, defaults 46 to False 47 :type html_show: bool, optional 48 49 """ 50 default_ax_settings = plot.ax_properties( 51 title="Mesh of the Smash model", 52 xlabel="x_coords", 53 ylabel="y_coords", 54 ) 55 default_ax_settings.update(**ax_settings) 56 57 fig_settings = plot.fig_properties(**fig_settings) 58 59 if not hasattr(self._parent_class.mymesh, "mesh"): 60 raise ValueError("No smash mesh found. Build the mesh first.") 61 62 fig, ax = plot.plot_mesh( 63 self._parent_class.mymesh.mesh, 64 catchment_polygon=self._parent_class.mymesh.catchment_polygon, 65 coef_hydro=coef_hydro, 66 ax_settings=ax_settings, 67 fig_settings=fig_settings, 68 ) 69 70 if fig_settings.figname is None: 71 if tools.with_reticulate() or html_show: 72 mpld3.show(fig, open_browser=True) 73 else: 74 fig.show()
Plot the map of the mesh of the Smash model with teh outlets and the hydrographic network.
Parameters
- coef_hydro: couloring cells where the surface is higher than
coef_hydro% of the total surface catchment, defaults to 99.0 - ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of plot.ax_properties() class ca be defined in this dictionnary, defaults to {}
- fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of plot.fig_properties() class ca be defined in this dictionnary, defaults to {}
- html_show: Display the figure in an html page with your navigator, defaults to False
76 def plot_catchment_surface_consistency( 77 self, 78 label: bool = True, 79 ax_settings: dict = {}, 80 fig_settings: dict = {}, 81 plot_settings: dict = {}, 82 html_show: bool = False, 83 ): 84 """ 85 Plot the modeled surface vs the observed surface. Check its consistency. 86 :param label, labels the point on the plot with the code of the outlets. 87 :type label: bool, default True 88 :param ax_settings, any properties of plot.ax_properties() class can be defined 89 in this dictionnary, defaults to {} 90 :type ax_settings: dict, optional 91 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 92 plot.fig_properties() class can be defined in this dictionnary, defaults to {} 93 :type fig_settings: dict, optional 94 :param plot_settings, any properties of plot.plot_properties() class can be 95 defined in this dictionnary, defaults to {} 96 :param html_show: Display the figure in an html page with your navigator, defaults 97 to False 98 :type html_show: bool, optional 99 100 """ 101 102 default_ax_settings = plot.ax_properties( 103 title="Modeled and observed surface consistency", 104 xlabel="Observed surface", 105 ylabel="Modeled surface", 106 ) 107 default_ax_settings.update(**ax_settings) 108 109 fig_settings = plot.fig_properties(**fig_settings) 110 111 if not hasattr(self._parent_class.mymesh, "mesh"): 112 raise ValueError("No smash mesh found. Build the mesh first.") 113 114 fig, ax = plot.plot_catchment_surface_consistency( 115 mesh=self._parent_class.mymesh.mesh, 116 label=label, 117 ax_settings=ax_settings, 118 fig_settings=fig_settings, 119 plot_settings=plot_settings, 120 ) 121 122 if fig_settings.figname is None: 123 if tools.with_reticulate() or html_show: 124 mpld3.show(fig, open_browser=True) 125 else: 126 fig.show()
Plot the modeled surface vs the observed surface. Check its consistency. :param label, labels the point on the plot with the code of the outlets. :type label: bool, default True :param ax_settings, any properties of plot.ax_properties() class can be defined in this dictionnary, defaults to {}
Parameters
- fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of plot.fig_properties() class can be defined in this dictionnary, defaults to {} :param plot_settings, any properties of plot.plot_properties() class can be defined in this dictionnary, defaults to {}
- html_show: Display the figure in an html page with your navigator, defaults to False
128 def plot_catchment_surface_error( 129 self, 130 ax_settings: dict = {}, 131 fig_settings: dict = {}, 132 html_show: bool = False, 133 ): 134 """ 135 Plot the modeled surface vs the observed surface. Check its consistency. 136 :param ax_settings, any properties of plot.ax_properties() class can be defined 137 in this dictionnary, defaults to {} 138 :type ax_settings: dict, optional 139 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 140 plot.fig_properties() class can be defined in this dictionnary, defaults to {} 141 :param html_show: Display the figure in an html page with your navigator, defaults 142 to False 143 :type html_show: bool, optional 144 145 """ 146 147 default_ax_settings = plot.ax_properties( 148 title="Catchment surface error", 149 xlabel="Catchments", 150 ylabel="(Ssim - Sobs)/Sobs", 151 ) 152 default_ax_settings.update(**ax_settings) 153 154 fig_settings = plot.fig_properties(**fig_settings) 155 156 if not hasattr(self._parent_class.mymesh, "mesh"): 157 raise ValueError("No smash mesh found. Build the mesh first.") 158 159 fig, ax = plot.plot_catchment_surface_error( 160 mesh=self._parent_class.mymesh.mesh, 161 ax_settings=ax_settings, 162 fig_settings=fig_settings, 163 ) 164 165 if fig_settings.figname is None: 166 if tools.with_reticulate() or html_show: 167 mpld3.show(fig, open_browser=True) 168 else: 169 fig.show()
Plot the modeled surface vs the observed surface. Check its consistency. :param ax_settings, any properties of plot.ax_properties() class can be defined in this dictionnary, defaults to {}
Parameters
- fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of plot.fig_properties() class can be defined in this dictionnary, defaults to {}
- html_show: Display the figure in an html page with your navigator, defaults to False
95 def wrapper(*args, **kwargs): 96 97 bound = sig.bind(*args, **kwargs) 98 bound.apply_defaults() 99 100 for name, value in bound.arguments.items(): 101 if name in annotations: 102 103 target_type = annotations[name] 104 105 args_ = get_args(target_type) 106 107 if target_type is None and len(args_) == 0: 108 args_ = (type(None),) 109 target_type = type(None) 110 111 if not type(value) in args_: 112 113 if len(args_) > 1 and type(None) in args_: 114 115 converted = False 116 for t in args_: 117 118 if t is not type(None): 119 120 if value is not None: 121 try: 122 print( 123 f"</> Warning: Arg '{name}' of type {type(value)} is being" 124 f" converted to {t}" 125 ) 126 bound.arguments[name] = t(value) 127 converted = True 128 except: 129 pass 130 131 if converted: 132 break 133 134 if not converted: 135 raise TypeError( 136 f"</> Error: Arg '{name}' must be a type of " 137 f" {args_}, got {value}" 138 f" ({type(value).__name__})" 139 ) 140 141 else: 142 if not isinstance(value, target_type): 143 try: 144 print( 145 f"</> Warning: Arg '{name}' of type {type(value)} is being" 146 f" converted to {target_type}" 147 ) 148 bound.arguments[name] = target_type(value) 149 except Exception: 150 raise TypeError( 151 f"</> Error: Arg '{name}' must be a type of " 152 f" {target_type.__name__}, got {value}" 153 f" ({type(value).__name__})" 154 ) 155 156 return func(*bound.args, **bound.kwargs)
Parameters
- duration: Duration of the quantile, defaults to 1
- X: X coordinate of the targeted cell (matrix coordinate system), defaults to 0
- Y: Y coordinate of the targeted cell (matrix coordinate system), defaults to 0
- ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of plot.ax_properties() class ca be defined in this dictionnary, defaults to {}
- fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of plot.fig_properties() class ca be defined in this dictionnary, defaults to {}
- html_show: Display the figure in an html page with your navigator, defaults to False
95 def wrapper(*args, **kwargs): 96 97 bound = sig.bind(*args, **kwargs) 98 bound.apply_defaults() 99 100 for name, value in bound.arguments.items(): 101 if name in annotations: 102 103 target_type = annotations[name] 104 105 args_ = get_args(target_type) 106 107 if target_type is None and len(args_) == 0: 108 args_ = (type(None),) 109 target_type = type(None) 110 111 if not type(value) in args_: 112 113 if len(args_) > 1 and type(None) in args_: 114 115 converted = False 116 for t in args_: 117 118 if t is not type(None): 119 120 if value is not None: 121 try: 122 print( 123 f"</> Warning: Arg '{name}' of type {type(value)} is being" 124 f" converted to {t}" 125 ) 126 bound.arguments[name] = t(value) 127 converted = True 128 except: 129 pass 130 131 if converted: 132 break 133 134 if not converted: 135 raise TypeError( 136 f"</> Error: Arg '{name}' must be a type of " 137 f" {args_}, got {value}" 138 f" ({type(value).__name__})" 139 ) 140 141 else: 142 if not isinstance(value, target_type): 143 try: 144 print( 145 f"</> Warning: Arg '{name}' of type {type(value)} is being" 146 f" converted to {target_type}" 147 ) 148 bound.arguments[name] = target_type(value) 149 except Exception: 150 raise TypeError( 151 f"</> Error: Arg '{name}' must be a type of " 152 f" {target_type.__name__}, got {value}" 153 f" ({type(value).__name__})" 154 ) 155 156 return func(*bound.args, **bound.kwargs)
Plot the quantiles prediction for different return period for every outlets.
Parameters
- duration: Duration of the quantile, defaults to 1
- quantile_obs: Compute and display the observed quantile in th graphics. Observed quantile are computed again the whole observed discharge chronicle from 1900 until today.
- gauge: List of gauge code to plot. Default is None. If None all gague are plotted
- ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of plot.ax_properties() class ca be defined in this dictionnary, defaults to {}
- fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of plot.fig_properties() class ca be defined in this dictionnary, defaults to {}
- plot_settings: Parameters of the matplotlib figure 'fig'. Any properties of plot.plot_settings() class ca be defined in this dictionnary, defaults to {}
- html_show: Display the figure in an html page with your navigator, defaults to False
95 def wrapper(*args, **kwargs): 96 97 bound = sig.bind(*args, **kwargs) 98 bound.apply_defaults() 99 100 for name, value in bound.arguments.items(): 101 if name in annotations: 102 103 target_type = annotations[name] 104 105 args_ = get_args(target_type) 106 107 if target_type is None and len(args_) == 0: 108 args_ = (type(None),) 109 target_type = type(None) 110 111 if not type(value) in args_: 112 113 if len(args_) > 1 and type(None) in args_: 114 115 converted = False 116 for t in args_: 117 118 if t is not type(None): 119 120 if value is not None: 121 try: 122 print( 123 f"</> Warning: Arg '{name}' of type {type(value)} is being" 124 f" converted to {t}" 125 ) 126 bound.arguments[name] = t(value) 127 converted = True 128 except: 129 pass 130 131 if converted: 132 break 133 134 if not converted: 135 raise TypeError( 136 f"</> Error: Arg '{name}' must be a type of " 137 f" {args_}, got {value}" 138 f" ({type(value).__name__})" 139 ) 140 141 else: 142 if not isinstance(value, target_type): 143 try: 144 print( 145 f"</> Warning: Arg '{name}' of type {type(value)} is being" 146 f" converted to {target_type}" 147 ) 148 bound.arguments[name] = target_type(value) 149 except Exception: 150 raise TypeError( 151 f"</> Error: Arg '{name}' must be a type of " 152 f" {target_type.__name__}, got {value}" 153 f" ({type(value).__name__})" 154 ) 155 156 return func(*bound.args, **bound.kwargs)
Plot the map of the quantiles for given return period and a given duration.
Parameters
- duration: Duration of the quantile, defaults to 1
- T: return period, defaults to 2 (default is years, but that depends of the chunk size)
- vmin: Minimal bounds value for the colorbar, defaults to 0
- vmax: Maximal bounds value for the colorbar, defaults to None
- ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of plot.ax_properties() class ca be defined in this dictionnary, defaults to {}
- fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of plot.fig_properties() class ca be defined in this dictionnary, defaults to {}
- html_show: Display the figure in an html page with your navigator, defaults to False
95 def wrapper(*args, **kwargs): 96 97 bound = sig.bind(*args, **kwargs) 98 bound.apply_defaults() 99 100 for name, value in bound.arguments.items(): 101 if name in annotations: 102 103 target_type = annotations[name] 104 105 args_ = get_args(target_type) 106 107 if target_type is None and len(args_) == 0: 108 args_ = (type(None),) 109 target_type = type(None) 110 111 if not type(value) in args_: 112 113 if len(args_) > 1 and type(None) in args_: 114 115 converted = False 116 for t in args_: 117 118 if t is not type(None): 119 120 if value is not None: 121 try: 122 print( 123 f"</> Warning: Arg '{name}' of type {type(value)} is being" 124 f" converted to {t}" 125 ) 126 bound.arguments[name] = t(value) 127 converted = True 128 except: 129 pass 130 131 if converted: 132 break 133 134 if not converted: 135 raise TypeError( 136 f"</> Error: Arg '{name}' must be a type of " 137 f" {args_}, got {value}" 138 f" ({type(value).__name__})" 139 ) 140 141 else: 142 if not isinstance(value, target_type): 143 try: 144 print( 145 f"</> Warning: Arg '{name}' of type {type(value)} is being" 146 f" converted to {target_type}" 147 ) 148 bound.arguments[name] = target_type(value) 149 except Exception: 150 raise TypeError( 151 f"</> Error: Arg '{name}' must be a type of " 152 f" {target_type.__name__}, got {value}" 153 f" ({type(value).__name__})" 154 ) 155 156 return func(*bound.args, **bound.kwargs)
Plot the map of the quantiles for every return period for a given duration.
Parameters
- duration: Duration of the quantile, defaults to 1
- vmin: Minimal bounds value for the colorbar, defaults to 0
- vmax: Maximal bounds value for the colorbar, defaults to None
- ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of plot.ax_properties() class ca be defined in this dictionnary, defaults to {}
- fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of plot.fig_properties() class ca be defined in this dictionnary, defaults to {}
- html_show: Display the figure in an html page with your navigator, defaults to False
551 def plot_spatial_stats( 552 self, 553 stats: str = "max", 554 vmin: float | None = 0, 555 vmax: float | None = None, 556 ax_settings: dict = {}, 557 fig_settings: dict = {}, 558 html_show: bool = False, 559 ): 560 """ 561 Plot the map of a given spatial statistic. 562 :param stats: The statistic to plot, choice are 563 'max, min, mean, median, q20, q80', defaults to "max" 564 :type stats: str, optional 565 ::param vmin: Minimal bounds value for the colorbar, defaults to 0 566 :type vmin: float, optional 567 :param vmax: Maximal bounds value for the colorbar, defaults to None 568 :type vmax: float, optional 569 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 570 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 571 :type ax_settings: dict, optional 572 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 573 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 574 :type fig_settings: dict, optional 575 :param html_show: Display the figure in an html page with your navigator, defaults 576 to False 577 :type html_show: bool, optional 578 579 """ 580 581 fig_settings = plot.fig_properties(**fig_settings) 582 583 if not hasattr(self._parent_class.mystats.spatial_stats.results, stats): 584 raise ValueError( 585 f"Statistical results `{stats}` not found. Choice are: " 586 "[min, max, mean, median, q20, q80]" 587 ) 588 589 stats_matrix = getattr( 590 self._parent_class.mystats.spatial_stats.results, 591 stats, 592 ) 593 default_ax_settings = plot.ax_properties( 594 title="Maximal Discharges on periode" 595 f" {self._parent_class.mysmashmodel.setup.start_time} -" 596 f" {self._parent_class.mysmashmodel.setup.end_time}", 597 xlabel="Coords X", 598 ylabel="Coords_Y", 599 clabel="Discharge (m^3/s)", 600 cmap="viridis", 601 ) 602 default_ax_settings.update(**ax_settings) 603 604 fig, ax = plot.plot_image( 605 matrice=stats_matrix, 606 bbox=geo_toolbox.get_bbox_from_smash_mesh(self._parent_class.mymesh.mesh), 607 vmin=vmin, 608 vmax=vmax, 609 mask=self._parent_class.mysmashmodel.mesh.active_cell, 610 catchment_polygon=self._parent_class.mymesh.catchment_polygon, 611 ax_settings=default_ax_settings, 612 fig_settings=fig_settings, 613 ) 614 615 if fig_settings.figname is None: 616 if tools.with_reticulate() or html_show: 617 mpld3.show(fig, open_browser=True) 618 else: 619 fig.show() 620 621 # return fig, ax
Plot the map of a given spatial statistic.
Parameters
- stats: The statistic to plot, choice are 'max, min, mean, median, q20, q80', defaults to "max" ::param vmin: Minimal bounds value for the colorbar, defaults to 0
- vmax: Maximal bounds value for the colorbar, defaults to None
- ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of plot.ax_properties() class ca be defined in this dictionnary, defaults to {}
- fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of plot.fig_properties() class ca be defined in this dictionnary, defaults to {}
- html_show: Display the figure in an html page with your navigator, defaults to False
623 def plot_hydrograph( 624 self, 625 columns: list | None = [], 626 outlets_name: list = [], 627 plot_rainfall: bool = True, 628 ax_settings: dict = {}, 629 fig_settings: dict = {}, 630 plot_settings_sim: dict = {}, 631 plot_settings_obs: dict = {}, 632 html_show: bool = False, 633 ): 634 """ 635 Plot the simulated and the observed hydrogram for different outlets. 636 637 :param columns: Columns of the matrix to plot (outlets), defaults to [] 638 :type columns: list | None, optional 639 :param outlets_name: List of the outlets name to plot, defaults to [] 640 :type outlets_name: list, optional 641 :param plot_rainfall: Plot the rainfall on the graphics, defaults to True 642 :type plot_rainfall: bool, optional 643 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 644 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 645 :type ax_settings: dict, optional 646 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 647 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 648 :type fig_settings: dict, optional 649 :param plot_settings_sim: Parameters of the matplotlib curves. Any propoerties of 650 plot.plot_properties() class ca be defined in this dictionnary, defaults to {} 651 :type plot_settings_sim: dict, optional 652 :param plot_settings_obs: DParameters of the matplotlib curves. Any propoerties of 653 plot.plot_properties() class ca be defined in this dictionnary, defaults to {} 654 :type plot_settings_obs: dict, optional 655 :pparam html_show: Display the figure in an html page with your navigator, defaults 656 to False 657 :type html_show: bool, optional 658 659 """ 660 661 fig_settings = plot.fig_properties(**fig_settings) 662 663 if len(outlets_name) > 0: 664 columns = tools.array_isin( 665 self._parent_class.mysmashmodel.mesh.code, 666 np.array(outlets_name), 667 ) 668 elif len(columns) > 0: 669 outlets_name = [self._parent_class.mysmashmodel.mesh.code[i] for i in columns] 670 671 if columns is None: 672 columns = list(range(0, self._parent_class.mysmashmodel.response.q.shape[0])) 673 outlets_name = list(self._parent_class.mysmashmodel.mesh.code) 674 675 if len(columns) == 0: 676 columns = [0] 677 outlets_name = [list(self._parent_class.mysmashmodel.mesh.code)[0]] 678 679 fig, ax = plot.plot_hydrograph( 680 model=self._parent_class.mysmashmodel, 681 columns=columns, 682 outlets_name=outlets_name, 683 plot_rainfall=plot_rainfall, 684 ax_settings=ax_settings, 685 fig_settings=fig_settings, 686 plot_settings_sim=plot_settings_sim, 687 plot_settings_obs=plot_settings_obs, 688 ) 689 690 if fig_settings.figname is None: 691 if tools.with_reticulate() or html_show: 692 mpld3.show(fig, open_browser=True) 693 else: 694 fig.show() 695 696 # return fig, ax
Plot the simulated and the observed hydrogram for different outlets.
Parameters
- columns: Columns of the matrix to plot (outlets), defaults to []
- outlets_name: List of the outlets name to plot, defaults to []
- plot_rainfall: Plot the rainfall on the graphics, defaults to True
- ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of plot.ax_properties() class ca be defined in this dictionnary, defaults to {}
- fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of plot.fig_properties() class ca be defined in this dictionnary, defaults to {}
- plot_settings_sim: Parameters of the matplotlib curves. Any propoerties of plot.plot_properties() class ca be defined in this dictionnary, defaults to {}
- plot_settings_obs: DParameters of the matplotlib curves. Any propoerties of plot.plot_properties() class ca be defined in this dictionnary, defaults to {} :pparam html_show: Display the figure in an html page with your navigator, defaults to False
698 def plot_misfit( 699 self, 700 columns: list | None = None, 701 outlets_name: list = [], 702 misfit: str = "nse", 703 ax_settings: dict = {}, 704 fig_settings: dict = {}, 705 html_show: bool = False, 706 ): 707 """ 708 Plot a misfit criteria for a given list of outlet. 709 :param columns: Columns of the matrix to plot (outlets), defaults to [] 710 :type columns: list | None, optional 711 :param outlets_name: List of the outlets name to plot, defaults to [] 712 :type outlets_name: list, optional 713 :param misfit: The misfit criteria to plot, choice are 714 "nse, nnse, rmse, nrmse, se, kge", defaults to "nse" 715 :type misfit: str, optional 716 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 717 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 718 :type ax_settings: dict, optional 719 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 720 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 721 :type fig_settings: dict, optional 722 :param html_show: Display the figure in an html page with your navigator, defaults 723 to False 724 :type html_show: bool, optional 725 726 """ 727 728 fig_settings = plot.fig_properties(**fig_settings) 729 730 values = getattr(self._parent_class.mystats.misfit_stats.results, misfit) 731 732 if len(outlets_name) > 0: 733 columns = tools.array_isin( 734 self._parent_class.mysmashmodel.mesh.code, 735 np.array(outlets_name), 736 ) 737 738 if columns is None: 739 columns = list(range(0, self._parent_class.mysmashmodel.response.q.shape[0])) 740 outlets_name = self._parent_class.mysmashmodel.mesh.code 741 742 fig, ax = plot.plot_misfit( 743 values=values[columns], 744 names=outlets_name, 745 columns=None, 746 misfit=misfit, 747 ax_settings=ax_settings, 748 fig_settings=fig_settings, 749 ) 750 751 if fig_settings.figname is None: 752 if tools.with_reticulate() or html_show: 753 mpld3.show(fig, open_browser=True) 754 else: 755 fig.show() 756 757 # return fig, ax
Plot a misfit criteria for a given list of outlet.
Parameters
- columns: Columns of the matrix to plot (outlets), defaults to []
- outlets_name: List of the outlets name to plot, defaults to []
- misfit: The misfit criteria to plot, choice are "nse, nnse, rmse, nrmse, se, kge", defaults to "nse"
- ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of plot.ax_properties() class ca be defined in this dictionnary, defaults to {}
- fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of plot.fig_properties() class ca be defined in this dictionnary, defaults to {}
- html_show: Display the figure in an html page with your navigator, defaults to False
759 def plot_outlet_stats( 760 self, 761 columns: list | None = None, 762 outlets_name: list = [], 763 stat: str = "max", 764 ax_settings: dict = {}, 765 fig_settings: dict = {}, 766 html_show: bool = False, 767 ): 768 """ 769 Plot a statistical criteria for a given list of outlet. 770 :param columns: Columns of the matrix to plot (outlets), defaults to [] 771 :type columns: list | None, optional 772 :param outlets_name: List of the outlets name to plot, defaults to [] 773 :type outlets_name: list, optional 774 :param misfit: The misfit criteria to plot, choice are 775 "nse, nnse, rmse, nrmse, se, kge", defaults to "nse" 776 :type misfit: str, optional 777 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 778 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 779 :type ax_settings: dict, optional 780 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 781 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 782 :type fig_settings: dict, optional 783 :param html_show: Display the figure in an html page with your navigator, defaults 784 to False 785 :type html_show: bool, optional 786 787 """ 788 789 fig_settings = plot.fig_properties(**fig_settings) 790 791 values_sim = getattr(self._parent_class.mystats.outlets_stats.results_sim, stat) 792 values_obs = getattr(self._parent_class.mystats.outlets_stats.results_obs, stat) 793 794 if len(outlets_name) > 0: 795 columns = tools.array_isin( 796 self._parent_class.mysmashmodel.mesh.code, 797 np.array(outlets_name), 798 ) 799 800 if columns is None: 801 columns = list(range(0, self._parent_class.mysmashmodel.response.q.shape[0])) 802 outlets_name = list(self._parent_class.mysmashmodel.mesh.code) 803 804 fig, ax = plot.plot_outlet_stats( 805 values_sim=values_sim[columns], 806 values_obs=values_obs[columns], 807 names=outlets_name, 808 columns=None, 809 stat=stat, 810 ax_settings=ax_settings, 811 fig_settings=fig_settings, 812 ) 813 814 if fig_settings.figname is None: 815 if tools.with_reticulate() or html_show: 816 mpld3.show(fig, open_browser=True) 817 else: 818 fig.show() 819 820 # return fig, ax
Plot a statistical criteria for a given list of outlet.
Parameters
- columns: Columns of the matrix to plot (outlets), defaults to []
- outlets_name: List of the outlets name to plot, defaults to []
- misfit: The misfit criteria to plot, choice are "nse, nnse, rmse, nrmse, se, kge", defaults to "nse"
- ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of plot.ax_properties() class ca be defined in this dictionnary, defaults to {}
- fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of plot.fig_properties() class ca be defined in this dictionnary, defaults to {}
- html_show: Display the figure in an html page with your navigator, defaults to False
822 def multiplot_misfit( 823 self, 824 columns: list | None = None, 825 outlets_name: list = [], 826 misfit: list = [ 827 "nse", 828 "nnse", 829 "kge", 830 "mse", 831 "rmse", 832 "nrmse", 833 "se", 834 "mae", 835 "mape", 836 "lgrm", 837 ], 838 ax_settings: dict = {}, 839 fig_settings: dict = {}, 840 html_show: bool = False, 841 ): 842 """ 843 Plot misfit criterium for a given list of outlets. 844 845 :param columns: Columns of the matrix to plot (outlets), defaults to [] 846 :type columns: list | None, optional 847 :param outlets_name: List of the outlets name to plot, defaults to [] 848 :type outlets_name: list, optional 849 :param misfit: The misfit criteria to plot, list of criteria among 850 "nse, nnse, mse, rmse, nrmse, se, mae, mape, lgrm, kge", defaults to "nse" 851 :type misfit: str, optional 852 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 853 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 854 :type ax_settings: dict, optional 855 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 856 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 857 :type fig_settings: dict, optional 858 :param html_show: Display the figure in an html page with your navigator, defaults 859 to False 860 :type html_show: bool, optional 861 862 """ 863 864 fig_settings = plot.fig_properties(**fig_settings) 865 866 if len(outlets_name) > 0: 867 columns = tools.array_isin( 868 self._parent_class.mysmashmodel.mesh.code, 869 np.array(outlets_name), 870 ) 871 872 if columns is None: 873 columns = list(range(0, self._parent_class.mysmashmodel.response.q.shape[0])) 874 outlets_name = list(self._parent_class.mysmashmodel.mesh.code) 875 876 yfig = int(np.sqrt(len(misfit))) 877 xfig = int(np.ceil(len(misfit) / yfig)) 878 879 fig, axs = plt.subplots( 880 xfig, 881 yfig, 882 constrained_layout=True, 883 ) 884 885 # for ax in axs: 886 # ax.set_axis_off() 887 888 for ax, crit in zip( 889 axs.flat, 890 misfit, 891 ): 892 893 # ax.set_axis_on() 894 ax_settings["ylabel"] = f"{crit} criteria" 895 ax_settings["title"] = f"{crit} criteria" 896 897 if hasattr(self._parent_class.mystats.misfit_stats.results, crit): 898 values = getattr(self._parent_class.mystats.misfit_stats.results, crit) 899 else: 900 raise ValueError( 901 f"`{crit}` is not a valid statistic. choice are:" 902 "[nse, nnse, mse, rmse, nrmse, se, mae, mape, lgrm, kge]" 903 ) 904 905 fig, ax = plot.plot_misfit( 906 values=values[columns], 907 names=np.array(outlets_name), 908 columns=None, 909 misfit=crit, 910 figure=(fig, ax), 911 ax_settings=ax_settings, 912 ) 913 914 [fig.delaxes(ax) for ax in axs.flatten() if not ax.has_data()] 915 fig_settings.change((fig, ax)) 916 917 if fig_settings.figname is None: 918 if tools.with_reticulate() or html_show: 919 mpld3.show(fig, open_browser=True) 920 else: 921 fig.show() 922 923 # return fig, ax
Plot misfit criterium for a given list of outlets.
Parameters
- columns: Columns of the matrix to plot (outlets), defaults to []
- outlets_name: List of the outlets name to plot, defaults to []
- misfit: The misfit criteria to plot, list of criteria among "nse, nnse, mse, rmse, nrmse, se, mae, mape, lgrm, kge", defaults to "nse"
- ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of plot.ax_properties() class ca be defined in this dictionnary, defaults to {}
- fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of plot.fig_properties() class ca be defined in this dictionnary, defaults to {}
- html_show: Display the figure in an html page with your navigator, defaults to False
925 def plot_misfit_map( 926 self, 927 misfit: str = "nse", 928 coef_hydro: float = 99.0, 929 ax_settings: dict = {}, 930 fig_settings: dict = {}, 931 plot_settings: dict = {}, 932 html_show: bool = False, 933 ): 934 """ 935 Plot a map of a misfit criteria. 936 937 :param columns: Columns of the matrix to plot (outlets), defaults to [] 938 :type columns: list | None, optional 939 :param outlets_name: List of the outlets name to plot, defaults to [] 940 :type outlets_name: list, optional 941 :param misfit: The misfit criteria to plot, choice are 942 "nse, nnse, mse, rmse, nrmse, se, mae, mape, lgrm, kge", defaults to "nse" 943 :type misfit: str, optional 944 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 945 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 946 :type ax_settings: dict, optional 947 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 948 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 949 :type fig_settings: dict, optional 950 :param html_show: Display the figure in an html page with your navigator, defaults 951 to False 952 :type html_show: bool, optional 953 954 """ 955 956 if hasattr(self._parent_class.mystats.misfit_stats.results, misfit): 957 values = getattr(self._parent_class.mystats.misfit_stats.results, misfit) 958 else: 959 raise ValueError( 960 f"`{misfit}` is not a valid statistic. choice are:" 961 "[nse, nnse, mse, rmse, nrmse, se, mae, mape, lgrm, kge]" 962 ) 963 964 fig_settings = plot.fig_properties(**fig_settings) 965 966 name = self._parent_class.mysmashmodel.mesh.code 967 mesh = self._parent_class.mymesh.mesh 968 969 fig, ax = plot.plot_misfit_map( 970 values=values, 971 names=name, 972 mesh=mesh, 973 misfit=misfit, 974 coef_hydro=coef_hydro, 975 ax_settings=ax_settings, 976 fig_settings=fig_settings, 977 plot_settings=plot_settings, 978 ) 979 980 if fig_settings.figname is None: 981 if tools.with_reticulate() or html_show: 982 mpld3.show(fig, open_browser=True) 983 else: 984 fig.show() 985 986 # return fig, ax
Plot a map of a misfit criteria.
Parameters
- columns: Columns of the matrix to plot (outlets), defaults to []
- outlets_name: List of the outlets name to plot, defaults to []
- misfit: The misfit criteria to plot, choice are "nse, nnse, mse, rmse, nrmse, se, mae, mape, lgrm, kge", defaults to "nse"
- ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of plot.ax_properties() class ca be defined in this dictionnary, defaults to {}
- fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of plot.fig_properties() class ca be defined in this dictionnary, defaults to {}
- html_show: Display the figure in an html page with your navigator, defaults to False
988 def multiplot_parameters( 989 self, 990 mask_active_cell=False, 991 ax_settings={}, 992 fig_settings={}, 993 html_show: bool = False, 994 ): 995 """ 996 Multiplot map of every Smash parameters 997 :param mask_active_cell: Use the mask of the active cell to hide the non-active cell, defaults to False 998 :type mask_active_cell: bool, False, optional 999 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 1000 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 1001 :type ax_settings: dict, optional 1002 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 1003 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 1004 :type fig_settings: dict, optional 1005 :param html_show: Display the figure in an html page with your navigator, defaults 1006 to False 1007 :type html_show: bool, optional 1008 1009 """ 1010 1011 default_fig_settings = plot.fig_properties(xsize=8, ysize=8) 1012 default_fig_settings.update(**fig_settings) 1013 1014 param = list(self._parent_class.mysmashmodel.rr_parameters.keys) 1015 1016 if mask_active_cell: 1017 mask = self._parent_class.mysmashmodel.mesh.active_cell 1018 else: 1019 mask = None 1020 1021 yfig = int(np.sqrt(len(param))) 1022 xfig = int(np.ceil(len(param) / yfig)) 1023 1024 fig, axs = plt.subplots( 1025 xfig, 1026 yfig, 1027 constrained_layout=False, 1028 ) 1029 plt.subplots_adjust( 1030 left=None, bottom=None, right=None, top=None, wspace=0.5, hspace=0.5 1031 ) 1032 for ax, p in zip(axs.flat, param): 1033 1034 default_ax_settings = plot.ax_properties( 1035 title=f"{p} parameters map", 1036 xlabel="Coords X", 1037 ylabel="Coords_Y", 1038 clabel=f"{p} parameter value", 1039 cmap="viridis", 1040 ) 1041 default_ax_settings.update(**ax_settings) 1042 1043 z = param.index(p) 1044 1045 fig, ax = plot.plot_image( 1046 matrice=self._parent_class.mysmashmodel.rr_parameters.values[:, :, z], 1047 bbox=geo_toolbox.get_bbox_from_smash_mesh(self._parent_class.mymesh.mesh), 1048 mask=mask, 1049 vmin=0.0, 1050 catchment_polygon=self._parent_class.mymesh.catchment_polygon, 1051 ax_settings=default_ax_settings, 1052 figure=[fig, ax], 1053 ) 1054 1055 [fig.delaxes(ax) for ax in axs.flatten() if not ax.has_data()] 1056 default_fig_settings.change((fig, axs)) 1057 1058 if default_fig_settings.figname is None or html_show: 1059 if tools.with_reticulate(): 1060 mpld3.show(fig, open_browser=True) 1061 else: 1062 fig.show() 1063 1064 # return fig, axs
Multiplot map of every Smash parameters
Parameters
- mask_active_cell: Use the mask of the active cell to hide the non-active cell, defaults to False
- ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of plot.ax_properties() class ca be defined in this dictionnary, defaults to {}
- fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of plot.fig_properties() class ca be defined in this dictionnary, defaults to {}
- html_show: Display the figure in an html page with your navigator, defaults to False
1066 def plot_parameters( 1067 self, 1068 param="cp", 1069 mask_active_cell=False, 1070 vmin=0.0, 1071 vmax=None, 1072 ax_settings={}, 1073 fig_settings={}, 1074 html_show: bool = False, 1075 ): 1076 """ 1077 Plot a map of a Smash parameters 1078 :param param: Name of the parameter to plot, defaults to "cp" 1079 :type param: str, optional 1080 :param mask_active_cell: Use the mask of the active cell to hide the non-active cell, defaults to False 1081 :type mask_active_cell: bool, False, optional 1082 :param vmin: Minimum value of the colorbar, defaults to 0.0 1083 :type vmin: float, optional 1084 :param vmax: Maximum value of the colorbar, defaults to None 1085 :type vmax: float, optional 1086 :param ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of 1087 plot.ax_properties() class ca be defined in this dictionnary, defaults to {} 1088 :type ax_settings: dict, optional 1089 :param fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of 1090 plot.fig_properties() class ca be defined in this dictionnary, defaults to {} 1091 :type fig_settings: dict, optional 1092 :param html_show: Display the figure in an html page with your navigator, defaults 1093 to False 1094 :type html_show: bool, optional 1095 """ 1096 1097 fig_settings = plot.fig_properties(**fig_settings) 1098 1099 list_param = list(self._parent_class.mysmashmodel.rr_parameters.keys) 1100 z = list_param.index(param) 1101 1102 if mask_active_cell: 1103 mask = self._parent_class.mysmashmodel.mesh.active_cell 1104 else: 1105 mask = None 1106 1107 fig, axs = plt.subplots() 1108 1109 default_ax_settings = plot.ax_properties( 1110 title=f"{param} parameters map", 1111 xlabel="Coords X", 1112 ylabel="Coords_Y", 1113 clabel=f"{param} parameter value", 1114 cmap="viridis", 1115 ) 1116 default_ax_settings.update(**ax_settings) 1117 1118 fig, ax = plot.plot_image( 1119 matrice=self._parent_class.mysmashmodel.rr_parameters.values[:, :, z], 1120 bbox=geo_toolbox.get_bbox_from_smash_mesh(self._parent_class.mymesh.mesh), 1121 mask=mask, 1122 vmin=vmin, 1123 vmax=vmax, 1124 catchment_polygon=self._parent_class.mymesh.catchment_polygon, 1125 ax_settings=default_ax_settings, 1126 ) 1127 1128 fig_settings.change((fig, axs)) 1129 1130 if fig_settings.figname is None or html_show: 1131 if tools.with_reticulate(): 1132 mpld3.show(fig, open_browser=True) 1133 else: 1134 fig.show() 1135 1136 # return fig, axs
Plot a map of a Smash parameters
Parameters
- param: Name of the parameter to plot, defaults to "cp"
- mask_active_cell: Use the mask of the active cell to hide the non-active cell, defaults to False
- vmin: Minimum value of the colorbar, defaults to 0.0
- vmax: Maximum value of the colorbar, defaults to None
- ax_settings: Parameters of the matplotlib figure 'ax'. Any propoerties of plot.ax_properties() class ca be defined in this dictionnary, defaults to {}
- fig_settings: Parameters of the matplotlib figure 'fig'. Any propoerties of plot.fig_properties() class ca be defined in this dictionnary, defaults to {}
- html_show: Display the figure in an html page with your navigator, defaults to False