smashbox 1.0__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- smashbox/.spyproject/config/backups/codestyle.ini.bak +8 -0
- smashbox/.spyproject/config/backups/encoding.ini.bak +6 -0
- smashbox/.spyproject/config/backups/vcs.ini.bak +7 -0
- smashbox/.spyproject/config/backups/workspace.ini.bak +12 -0
- smashbox/.spyproject/config/codestyle.ini +8 -0
- smashbox/.spyproject/config/defaults/defaults-codestyle-0.2.0.ini +5 -0
- smashbox/.spyproject/config/defaults/defaults-encoding-0.2.0.ini +3 -0
- smashbox/.spyproject/config/defaults/defaults-vcs-0.2.0.ini +4 -0
- smashbox/.spyproject/config/defaults/defaults-workspace-0.2.0.ini +6 -0
- smashbox/.spyproject/config/encoding.ini +6 -0
- smashbox/.spyproject/config/vcs.ini +7 -0
- smashbox/.spyproject/config/workspace.ini +12 -0
- smashbox/__init__.py +8 -0
- smashbox/asset/flwdir/flowdir_fr_1000m.tif +0 -0
- smashbox/asset/outlets/.Rhistory +0 -0
- smashbox/asset/outlets/db_bnbv_fr.csv +142704 -0
- smashbox/asset/outlets/db_bnbv_light.csv +42084 -0
- smashbox/asset/outlets/db_sites.csv +8700 -0
- smashbox/asset/outlets/db_stations.csv +2916 -0
- smashbox/asset/outlets/db_stations_example.csv +19 -0
- smashbox/asset/outlets/edit_database.py +185 -0
- smashbox/asset/outlets/readme.txt +5 -0
- smashbox/asset/params/ci.tif +0 -0
- smashbox/asset/params/cp.tif +0 -0
- smashbox/asset/params/ct.tif +0 -0
- smashbox/asset/params/kexc.tif +0 -0
- smashbox/asset/params/kmlt.tif +0 -0
- smashbox/asset/params/llr.tif +0 -0
- smashbox/asset/setup/setup_rhax_gr4_dt3600.yaml +15 -0
- smashbox/asset/setup/setup_rhax_gr4_dt900.yaml +15 -0
- smashbox/asset/setup/setup_rhax_gr5_dt3600.yaml +15 -0
- smashbox/asset/setup/setup_rhax_gr5_dt900.yaml +15 -0
- smashbox/init/README.md +3 -0
- smashbox/init/__init__.py +3 -0
- smashbox/init/multimodel_statistics.py +405 -0
- smashbox/init/param.py +799 -0
- smashbox/init/smashbox.py +186 -0
- smashbox/model/__init__.py +1 -0
- smashbox/model/atmos_data_connector.py +518 -0
- smashbox/model/mesh.py +185 -0
- smashbox/model/model.py +829 -0
- smashbox/model/setup.py +109 -0
- smashbox/plot/__init__.py +1 -0
- smashbox/plot/myplot.py +1133 -0
- smashbox/plot/plot.py +1662 -0
- smashbox/read_inputdata/__init__.py +1 -0
- smashbox/read_inputdata/read_data.py +1229 -0
- smashbox/read_inputdata/smashmodel.py +395 -0
- smashbox/stats/__init__.py +1 -0
- smashbox/stats/mystats.py +1632 -0
- smashbox/stats/stats.py +2022 -0
- smashbox/test.py +532 -0
- smashbox/test_average_stats.py +122 -0
- smashbox/test_mesh.r +8 -0
- smashbox/test_mesh_from_graffas.py +69 -0
- smashbox/tools/__init__.py +1 -0
- smashbox/tools/geo_toolbox.py +1028 -0
- smashbox/tools/tools.py +461 -0
- smashbox/tutorial_R.r +182 -0
- smashbox/tutorial_R_graffas.r +88 -0
- smashbox/tutorial_R_graffas_local.r +33 -0
- smashbox/tutorial_python.py +102 -0
- smashbox/tutorial_readme.py +261 -0
- smashbox/tutorial_report.py +58 -0
- smashbox/tutorials/Python_tutorial.md +124 -0
- smashbox/tutorials/R_Graffas_tutorial.md +153 -0
- smashbox/tutorials/R_tutorial.md +121 -0
- smashbox/tutorials/__init__.py +6 -0
- smashbox/tutorials/generate_doc.md +7 -0
- smashbox-1.0.dist-info/METADATA +998 -0
- smashbox-1.0.dist-info/RECORD +73 -0
- smashbox-1.0.dist-info/WHEEL +5 -0
- smashbox-1.0.dist-info/licenses/LICENSE +100 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
Schypre-Graffas-SmashBox coupling and discharges quantile compuation
|
|
2
|
+
---------------------------------------------------------------------
|
|
3
|
+
|
|
4
|
+
This section contains a R tutorials to connect a Schypre/Graffas simulation with Smash using SmashBox environment. In this tutorial, we are going to use a long chronicle of rainfall data stored in a matrix with Smash, simulate the discharges at every pixel of the domain and compute the discharges quantiles.
|
|
5
|
+
|
|
6
|
+
To use smashbox with R, you must load the module with the Reticulate package.
|
|
7
|
+
|
|
8
|
+
First of all, launch the R console, load the Reticulate package and load your Python environment where SmashBox and Smash are installed (change the path according your installation).
|
|
9
|
+
|
|
10
|
+
```R
|
|
11
|
+
library(reticulate)
|
|
12
|
+
use_virtualenv("path/to/pythonenv/smashbox_env") #use a specific python environnement
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Then load the package EsaySmash
|
|
16
|
+
|
|
17
|
+
```R
|
|
18
|
+
smashbox <- import("smashbox")
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Now we are going to load results from a Schypre/Graffas simulation. This simulation has been done on the Gapeau catchment (France) and is stored in a Rdata file.
|
|
22
|
+
|
|
23
|
+
```R
|
|
24
|
+
path_to_graffas_rainfall="/nas/RHAX/UTILISATEURS/kevin.tartour/2025_Graffas/SPATIAL/Gapeau/DataOutput/simul/RRsim_Gapeau_calage_reso_1000_res_1000_twin1_SMASH.Rdata"
|
|
25
|
+
GraffasRainfall=load(path_to_graffas_rainfall)
|
|
26
|
+
```
|
|
27
|
+
This Rdata file contains 3 elements:
|
|
28
|
+
* `info_simu_smash`: information about the mesh
|
|
29
|
+
* `RRsim_3D`: the 3 dimensional matrix of the rainfall (x,y,nb_time_step)
|
|
30
|
+
* `Calendar` : the list of the date of the rainfall
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
First we need to define the bounding box for Smash from `info_simu_smash`. The bounding box of the Schypre/Graffas model is defined on the center of the cells. The bounding box of Smash is defined from the border of each cell. Thus we need to extend the original domain about the half of the resolution :
|
|
34
|
+
|
|
35
|
+
```R
|
|
36
|
+
bbox=smashbox$tools$tools$infograffas_bbox_extractor(info_simu_smash)
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Then we configure the smashbox module. We set the bounding box, select the outlet database and select the outlet shapefile with catchment boundaries.
|
|
41
|
+
|
|
42
|
+
```R
|
|
43
|
+
es <- smashbox$SmashBox()
|
|
44
|
+
es$myparam$set_param("bbox", bbox)
|
|
45
|
+
```
|
|
46
|
+
We are ready to create a container for your Smash simulation:
|
|
47
|
+
|
|
48
|
+
```R
|
|
49
|
+
es$newmodel("gapeau")
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
No need to adjust the setup. By default the setup `setup_rhax_gr4_dt3600` is automatically loaded.
|
|
53
|
+
|
|
54
|
+
Then we can build the mesh and add any outlets found in the database:
|
|
55
|
+
|
|
56
|
+
```R
|
|
57
|
+
es$gapeau$generate_mesh()
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Again, few plot can help to validate our mesh:
|
|
61
|
+
|
|
62
|
+
```R
|
|
63
|
+
es$gapeau$myplot$plot_mesh(fig_settings=list("figname"= "output/mesh.png"))
|
|
64
|
+
es$gapeau$myplot$plot_catchment_surface_error(fig_settings=list("figname"= "output/mesh_surface_error.png"))
|
|
65
|
+
es$gapeau$myplot$plot_catchment_surface_consistency(
|
|
66
|
+
fig_settings=list("figname"= "output/mesh_surface_consistency.png")
|
|
67
|
+
)
|
|
68
|
+
```
|
|
69
|
+
Let's warm the model, i.e we create a valid initial states. The warmup period is set in days (365) and is prior the `start_time` defined in the setup (default is an arbitrary date: `2014-01-01 00:00`). Precipitation data are read on the disk.
|
|
70
|
+
|
|
71
|
+
```R
|
|
72
|
+
es$gapeau$model_warmup(warmup=365)
|
|
73
|
+
```
|
|
74
|
+
Initial states are created and stored in the Smash container. These initial states will be loaded automatically when doing a forward_run.
|
|
75
|
+
|
|
76
|
+
The next steps aims to create a Smash model, simulate the discharges and compute the maximal discharges values every year. Two cases may append, a small domain with a rather "short" data series which will consume a reasonable amount of RAM or a large domain with long data series which consume to much RAM.
|
|
77
|
+
|
|
78
|
+
### For short periods
|
|
79
|
+
|
|
80
|
+
For "short" period and/or small domain and if the RAM usage if not a constraint we can perform the simulation and the quantile compuation directly:
|
|
81
|
+
|
|
82
|
+
```R
|
|
83
|
+
es$gapeau$atmos_data_connector(input_prcp=RRsim_3D)
|
|
84
|
+
es$gapeau$model()
|
|
85
|
+
es$gapeau$forward_run(return_options=list("q_domain"= TRUE))
|
|
86
|
+
es$gapeau$mystats$fquantile_stats(
|
|
87
|
+
chunk_size=365, estimate_method="MLE", ncpu=6, fit="gumbel", compute_uncertainties=FALSE,
|
|
88
|
+
)
|
|
89
|
+
```
|
|
90
|
+
Some explanations: we connect to SmashBox the precipitation matrix (the ten first year). Then we create the model using the `model()` function. Then we run the model and we compute the quantile on the whole period once.
|
|
91
|
+
|
|
92
|
+
### For long periods
|
|
93
|
+
|
|
94
|
+
Because the matrix contains to many time-steps, we split the calculation in three chunks:
|
|
95
|
+
|
|
96
|
+
```R
|
|
97
|
+
chunk_size=as.integer(dim(RRsim_3D)[3]/3)
|
|
98
|
+
for (i in 0:2){
|
|
99
|
+
#send the rainfall data (Graffas) to smash
|
|
100
|
+
es$gapeau$atmos_data_connector(input_prcp=RRsim_3D[,,(i*chunk_size):((i+1)*chunk_size)])
|
|
101
|
+
#generate the smash model
|
|
102
|
+
es$gapeau$model()
|
|
103
|
+
#run the model with option invert_states=True : we use the final states as initial states except for the 1st chunk
|
|
104
|
+
es$gapeau$forward_run(invert_states=TRUE,return_options=list("q_domain"= TRUE))
|
|
105
|
+
#compute the annual maxima over each chunk: use option cumulated_maxima=True to store and accumulate these maxima
|
|
106
|
+
es$gapeau$mystats$fmaxima_stats(
|
|
107
|
+
chunk_size=365, cumulated_maxima=TRUE,
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Some explanations: For each chunk we send the rainfall data to Smash using the `atmos_data_connector` function. Then we generate a new model with the function `model()`. Then we run the forward model using two options: `invert_state=TRUE` in order to use the final states of the previous simulated chunk as the initial states of the current one (if not possible, current initial states will be preserved, i.e the warmup). Finally we compute the maximal discharges values for each pixel every 365 days. At the last step we use the option `cumulated_maxima=TRUE` to accumulate these maxima after each call of `fmaxima_stats` functions.
|
|
113
|
+
|
|
114
|
+
The last step stands for the discharge quantile computation. Just call the function `fquantile_stats` and use option `compute_uncertainties=TRUE` to compute the uncertainties using the bootstrap method.
|
|
115
|
+
|
|
116
|
+
```R
|
|
117
|
+
es$gapeau$mystats$fquantile_stats(
|
|
118
|
+
chunk_size=365, compute_uncertainties=TRUE
|
|
119
|
+
)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Several figures can be plotted:
|
|
123
|
+
|
|
124
|
+
First, we can plot the quantile discharge of 1h at any pixel of the domain:
|
|
125
|
+
|
|
126
|
+
```R
|
|
127
|
+
es$gapeau$myplot$plot_xy_quantile(
|
|
128
|
+
duration=1,
|
|
129
|
+
X=as.integer(15),
|
|
130
|
+
Y=as.integer(25),
|
|
131
|
+
fig_settings=list("figname"= "output/quantile_XY_1h.png", "font_ratio"= 2),
|
|
132
|
+
ax_settings=list("legend_fontsize"= 20),
|
|
133
|
+
)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Then we can plot the discharges quantile of 1h at every outlets:
|
|
137
|
+
|
|
138
|
+
```R
|
|
139
|
+
es$gapeau$myplot$plot_outlets_quantile(duration=1,fig_settings=list("figname"= "output/quantile_outlets.png", "font_ratio"= 2))
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Spatial quantile discharges of duration 1h and for the return period 2 years can be plotted as follow:
|
|
143
|
+
|
|
144
|
+
```R
|
|
145
|
+
es$gapeau$myplot$plot_spatial_quantile(duration=1, T=2, fig_settings=list("figname"= "/nas/RHAX/UTILISATEURS/maxime.jay-allemand/smashbox/output/quantile_spatial_1hT2.png", "font_ratio"= 2))
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
A multiplot of the spatial discharges quantile for all return period can be achieved by:
|
|
149
|
+
|
|
150
|
+
```R
|
|
151
|
+
es$gapeau$myplot$multiplot_spatial_quantile(duration=1, fig_settings=list("figname"= "output/quantile_spatial_multiplot.png", "font_ratio"= 1))
|
|
152
|
+
|
|
153
|
+
```
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# R tutorial
|
|
2
|
+
|
|
3
|
+
This section contains a R tutorials to achieve common task with SmashBox.
|
|
4
|
+
|
|
5
|
+
To use Smashbox with R, you must load the module with the Reticulate package.
|
|
6
|
+
|
|
7
|
+
Performing a REX
|
|
8
|
+
----------------
|
|
9
|
+
|
|
10
|
+
First of all, launch the R console load the Reticulate package and load your Python environment where SmashBox and Smash are installed (change the path according your installation).
|
|
11
|
+
|
|
12
|
+
```R
|
|
13
|
+
library(reticulate)
|
|
14
|
+
use_virtualenv("path/to/pythonenv/smashbox_env") #use a specific python environnement
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Then load the package EsaySmash
|
|
18
|
+
|
|
19
|
+
```R
|
|
20
|
+
smashbox <- import("smashbox")
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Assume you need to perform a REX on a defined area. This area is defined by a bounding box
|
|
24
|
+
|
|
25
|
+
```R
|
|
26
|
+
bbox={'left': 875000.0,
|
|
27
|
+
'bottom': 6228000.0,
|
|
28
|
+
'right': 1001000.0,
|
|
29
|
+
'top': 6320000.0}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Configure the smashbox module: Set the bounding box, select the outlet database and configure the database fields.
|
|
33
|
+
|
|
34
|
+
```R
|
|
35
|
+
es <- smashbox$SmashBox()
|
|
36
|
+
es$myparam$set_param("bbox", bbox)
|
|
37
|
+
```
|
|
38
|
+
We are ready to create a container for your Smash simulation:
|
|
39
|
+
|
|
40
|
+
```R
|
|
41
|
+
es.newmodel("rex")
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Then we need to adjust the setup. By default the setup `setup_rhax_gr4_dt3600` is automatically loaded. If needed, you can select an other one (see function `es.rex.mysetup.list_available_setup()`), and change some properties of the setup. On the rhax server, only the date must be configured. Path to data are already set, we use comephore 60M for the precipitation, the 2025 extraction of the dicharges at every sites and the daily potential evapotranspiration.
|
|
45
|
+
|
|
46
|
+
```R
|
|
47
|
+
es$rex$mysetup$update_setup(
|
|
48
|
+
list(
|
|
49
|
+
"start_time"= "2014-01-01 00:00",
|
|
50
|
+
"end_time"= "2014-02-01 00:00"
|
|
51
|
+
)
|
|
52
|
+
)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Then we can build the mesh and add outlets with surface greater then 20 km², and automatically exclude outlets if the modeled surface error :math:`(Ssim - Sobs)/Sobs>0.2` (`area_error_th` option).
|
|
56
|
+
|
|
57
|
+
```R
|
|
58
|
+
es.rex.generate_mesh(query="(SURF>20) & (INFLUENCE=='Influence nulle ou faible')", area_error_th=0.2)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Few plot can help to validate our mesh with functions `smashbox.plot.myplot.myplot.plot_mesh` and `smashbox.plot.myplot.myplot.plot_catchment_surface_error` and `smashbox.plot.myplot.plot_catchment_surface_consistency`:
|
|
62
|
+
|
|
63
|
+
```R
|
|
64
|
+
es$rex$myplot$plot_mesh(fig_settings=list("figname"= "output/mesh.png"))
|
|
65
|
+
es$rex$myplot$plot_catchment_surface_error(fig_settings=list("figname"= "output/mesh_surface_error.png"))
|
|
66
|
+
es$rex$myplot$plot_catchment_surface_consistency(
|
|
67
|
+
fig_settings=list("figname"= "output/mesh_surface_consistency.png")
|
|
68
|
+
)
|
|
69
|
+
```
|
|
70
|
+
remark: if figname is not defined, the plot will be sent to the matplotlib interactive UI or to your web browser as html (the fig_settings `xsize` and `ysize` will control the size of the html plot). However, this feature is not working for remote server (perhaps try to ssh -X firefox).
|
|
71
|
+
|
|
72
|
+
Let's now run a forward run (the model will be automatically build), automatically perform a warmup period of 100 days and return the discharge on the grid.
|
|
73
|
+
|
|
74
|
+
```R
|
|
75
|
+
es$rex$forward_run(return_options=list("q_domain"= TRUE), warmup=100)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Statistics can be computed. `smashbox.stats.mystats.mystats.foutlets_stats` method compute basic discharges statistics at every outlets; `smashbox.stats.mystats.mystats.fspatial_stats` method compute basic spatial discharges statistics at every pixel; `smashbox.stats.mystats.mystats.fmisfit_stats` compute many misfits criteria at outlets.
|
|
79
|
+
|
|
80
|
+
```R
|
|
81
|
+
es$rex$mystats$foutlets_stats()
|
|
82
|
+
es$rex$mystats$fspatial_stats()
|
|
83
|
+
es$rex$mystats$fmisfit_stats()
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Several figures can be plotted:
|
|
87
|
+
|
|
88
|
+
First, we can plot the parameters First, we can plot the parameters with functions `smashbox.plot.myplot.myplot.plot_parameters` and `smashbox.plot.myplot.myplot.multiplot_parameters`:
|
|
89
|
+
```R
|
|
90
|
+
es$rex$myplot$multiplot_parameters(
|
|
91
|
+
fig_settings=list("figname"= "output/muliplot_parameters.png")
|
|
92
|
+
)
|
|
93
|
+
es$rex$myplot$plot_parameters(fig_settings=list("figname"= "output/cp_parameters.png"))
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Then we can plot basic statistics with functions `smashbox.plot.myplot.myplot.plot_outlet_stats` and `smashbox.plot.myplot.myplot.plot_spatial_stats` :
|
|
97
|
+
```R
|
|
98
|
+
es$rex$myplot$plot_outlet_stats(
|
|
99
|
+
fig_settings=list("figname"= "output/outlets_max_discharges.png")
|
|
100
|
+
)
|
|
101
|
+
es$rex$myplot$plot_spatial_stats(
|
|
102
|
+
fig_settings=list("figname"= "output/spatial_max_discharges.png")
|
|
103
|
+
)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Let's plot an hydrogram (by default the first outlet is used) with functions `smashbox.plot.myplot.myplot.plot_hydrograph`:
|
|
107
|
+
```R
|
|
108
|
+
es$rex$myplot$plot_hydrograph(fig_settings=list("figname"= "output/discharges_hydrogram.png"))
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Finally, plot the misfit criteria with functions `smashbox.plot.myplot.myplot.multiplot_misfit` and `smashbox.plot.myplot.myplot.plot_misfit` and `smashbox.plot.myplot.plot_misfit_map` :
|
|
112
|
+
```R
|
|
113
|
+
|
|
114
|
+
es$rex$myplot$multiplot_misfit(
|
|
115
|
+
fig_settings=list("figname"= "output/multiplot_nse_misfit.png", "xsize"= 15, "ysize"= 15)
|
|
116
|
+
)
|
|
117
|
+
es$rex$myplot$plot_misfit(
|
|
118
|
+
misfit="nnse", fig_settings=list("figname"= "output/nnse_misfit.png")
|
|
119
|
+
)
|
|
120
|
+
es$rex$myplot$plot_misfit_map(fig_settings=list("figname"= "output/map_nse_misfit.png"))
|
|
121
|
+
```
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Generate the documentation
|
|
2
|
+
|
|
3
|
+
The documentation is auto-generated using pdoc (https://pdoc.dev/). To generate the documentation, go to the base level of the SmashBox module and launch the following command (ensure your SmashBox Python environment is active):
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pdoc smashbox/ --math -o ./html
|
|
7
|
+
```
|