.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_calibration/least_squares_and_gaussian_calibration/plot_generate_flooding.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_calibration_least_squares_and_gaussian_calibration_plot_generate_flooding.py: Generate flooding model observations ==================================== In this example we are interested in the calibration of the :ref:`flooding model `. We show how to produce the observations that we use in the calibration model of :doc:`Calibration of the flooding model `. In practice, we generally use a data set which has been obtained from measurements. In this example, we generate the data using noisy observations of the physical model. In the next part, we will calibrate the parameters using the calibration algorithms. .. GENERATED FROM PYTHON SOURCE LINES 19-64 Parameters to calibrate ----------------------- The variables to calibrate are :math:`(K_s,Z_v,Z_m)` and are set to the following values: .. math:: K_s = 30, \qquad Z_v = 50, \qquad Z_m = 55. This is the set of *true* values that we wish to estimate with the calibration methods. In practical studies, these values are unknown. In this study, we will simulate noisy observations of the output of the model and estimate the parameters using calibration methods. Observations ------------ In this section, we describe the statistical model associated with the :math:`n` observations. The errors of the water heights are associated with a normal distribution with a zero mean and a standard variation equal to: .. math:: \sigma=0.1. Therefore, the observed water heights are: .. math:: H_i = G(Q_i,K_s,Z_v,Z_m) + \epsilon_i for :math:`i=1,...,n` where .. math:: \epsilon \sim \mathcal{N}(0,\sigma^2) and we make the hypothesis that the observation errors are independent. We consider a sample size equal to: .. math:: n = 10. The observations are the couples :math:`\{(Q_i,H_i)\}_{i=1,...,n}`, i.e. each observation is a couple made of the flowrate and the corresponding river height. .. GENERATED FROM PYTHON SOURCE LINES 64-70 .. code-block:: Python import openturns as ot import openturns.viewer as otv import numpy as np from openturns.usecases import flood_model .. GENERATED FROM PYTHON SOURCE LINES 71-72 Create the flooding model. .. GENERATED FROM PYTHON SOURCE LINES 72-88 .. code-block:: Python def functionFlooding(X): L = 5.0e3 B = 300.0 Q, K_s, Z_v, Z_m = X alpha = (Z_m - Z_v) / L H = (Q / (K_s * B * np.sqrt(alpha))) ** (3.0 / 5.0) return [H] g = ot.PythonFunction(4, 1, functionFlooding) g = ot.MemoizeFunction(g) g.setInputDescription(["Q (m3/s)", "Ks (m^(1/3)/s)", "Zv (m)", "Zm (m)"]) g.setOutputDescription(["H (m)"]) .. GENERATED FROM PYTHON SOURCE LINES 89-90 Print the true values of the parameters. .. GENERATED FROM PYTHON SOURCE LINES 92-98 .. code-block:: Python fm = flood_model.FloodModel() print("Parameters") print(" Ks = ", fm.trueKs) print(" Zv = ", fm.trueZv) print(" Zm = ", fm.trueZm) .. rst-class:: sphx-glr-script-out .. code-block:: none Parameters Ks = 30.0 Zv = 50.0 Zm = 55.0 .. GENERATED FROM PYTHON SOURCE LINES 99-100 Create the parametric function. .. GENERATED FROM PYTHON SOURCE LINES 102-106 .. code-block:: Python calibratedIndices = [1, 2, 3] thetaTrue = [fm.trueKs, fm.trueZv, fm.trueZm] mycf = ot.ParametricFunction(g, calibratedIndices, thetaTrue) .. GENERATED FROM PYTHON SOURCE LINES 107-108 Create a regular grid of the flowrates and evaluate the corresponding outputs. .. GENERATED FROM PYTHON SOURCE LINES 110-118 .. code-block:: Python nbobs = 10 minQ = 100.0 maxQ = 4000.0 step = (maxQ - minQ) / (nbobs - 1) rg = ot.RegularGrid(minQ, step, nbobs) Qobs = rg.getVertices() outputH = mycf(Qobs) .. GENERATED FROM PYTHON SOURCE LINES 119-120 Generate the observation noise and add it to the output of the model. .. GENERATED FROM PYTHON SOURCE LINES 122-127 .. code-block:: Python sigmaObservationNoiseH = 0.1 # (m) noiseH = ot.Normal(0.0, sigmaObservationNoiseH) sampleNoiseH = noiseH.getSample(nbobs) Hobs = outputH + sampleNoiseH .. GENERATED FROM PYTHON SOURCE LINES 128-129 Gather the data into a sample. .. GENERATED FROM PYTHON SOURCE LINES 131-137 .. code-block:: Python data = ot.Sample(nbobs, 2) data[:, 0] = Qobs data[:, 1] = Hobs data.setDescription(["Q (m3/s)", "H (m)"]) data .. raw:: html
Q (m3/s)H (m)
01000.53376
1533.33331.626459
2966.66672.239076
314002.684735
41833.3333.070806
52266.6673.57745
627003.788794
73133.3334.139232
83566.6674.543917
940004.770165


.. GENERATED FROM PYTHON SOURCE LINES 138-139 Plot the Y observations versus the X observations. .. GENERATED FROM PYTHON SOURCE LINES 141-159 .. code-block:: Python graph = ot.Graph("Observations", "Q (m3/s)", "H (m)", True) # Plot the model before calibration curve = mycf.draw(100.0, 4000.0).getDrawable(0) curve.setLegend("True model") curve.setLineStyle(ot.ResourceMap.GetAsString("CalibrationResult-ObservationLineStyle")) graph.add(curve) # Plot the noisy observations cloud = ot.Cloud(Qobs, Hobs) cloud.setLegend("Observations") cloud.setPointStyle( ot.ResourceMap.GetAsString("CalibrationResult-ObservationPointStyle") ) graph.add(cloud) # graph.setColors(ot.Drawable.BuildDefaultPalette(2)) graph.setLegendPosition("topleft") view = otv.View(graph) .. image-sg:: /auto_calibration/least_squares_and_gaussian_calibration/images/sphx_glr_plot_generate_flooding_001.png :alt: Observations :srcset: /auto_calibration/least_squares_and_gaussian_calibration/images/sphx_glr_plot_generate_flooding_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 160-163 The data which are actually used in :doc:`Calibration of the flooding model ` are simplified so that the minimum number of significant digits is printed. .. GENERATED FROM PYTHON SOURCE LINES 163-165 .. code-block:: Python otv.View.ShowAll() .. _sphx_glr_download_auto_calibration_least_squares_and_gaussian_calibration_plot_generate_flooding.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_generate_flooding.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_generate_flooding.py `