Skip to content

Commit

Permalink
Doc: Fix label
Browse files Browse the repository at this point in the history
Closes #122
  • Loading branch information
jschueller committed Nov 26, 2024
1 parent 88f9503 commit 57bbba6
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .ci_support/run_docker_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ aurman -S python-sphinx-renku-theme python-sphinx_rtd_theme --noconfirm --noedit

cp -r /io/* /tmp
cd /tmp
pip install . --user --break-system-packages
pip install . --user --break-system-packages --no-deps
~/.local/bin/mo2fmu -h
~/.local/bin/mo2fmu ./otfmi/example/file/deviation.mo ./otfmi/example/file/fmu/linux-x86_64/deviation.fmu
pythonfmu build --file ./otfmi/example/file/DeviationSlave.py --dest ./otfmi/example/file/fmu/linux-x86_64
Expand Down
11 changes: 7 additions & 4 deletions doc/application/plot_cantilever_beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import openturns as ot
import otfmi
import otfmi.example.utility
from openturns.viewer import View
import openturns.viewer as otv

path_fmu = otfmi.example.utility.get_path_fmu("deviation")

Expand All @@ -41,7 +41,7 @@
# We test the function wrapping the deviation model on a point:
point = ot.Point([3e7, 2e4, 255, 350])
model_evaluation = model_fmu(point)
print("Running the FMU: deviation = {}".format(model_evaluation))
print(f"Running the FMU: deviation = {model_evaluation}")


# %%
Expand Down Expand Up @@ -112,15 +112,18 @@
# Draw the distribution of threshold excedance probability:
monte_carlo_result = algo.getResult()
probabilityDistribution = monte_carlo_result.getProbabilityDistribution()
graph = View(probabilityDistribution.drawPDF())
graph = otv.View(probabilityDistribution.drawPDF())

# %%
# Get the probability with which the beam deviation exceeds 30 cm:

probability = monte_carlo_result.getProbabilityEstimate()
print("Threshold excedance probability: {}".format(probability))
print(f"Threshold excedance probability: {probability}")

# %%
# Given the uncertainties on the load applied and the beam mechanical
# parameters, the beam bending has a probability of 0.01 to exceed 30 cm.
# Is this probability low or not ? It depends on your context 🙂

# %%
otv.View.ShowAll()
23 changes: 12 additions & 11 deletions doc/application/plot_metamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

import otfmi.example.utility
import openturns as ot
import openturns.viewer as viewer
import openturns.viewer as otv

path_fmu = otfmi.example.utility.get_path_fmu("epid")
mesh = ot.RegularGrid(0.0, 0.05, 20)
Expand Down Expand Up @@ -75,12 +75,11 @@
graph.setTitle("FMU simulations")
graph.setXTitle("Time")
graph.setYTitle("Number of infected")
graph.setLegends(["{:.3f}".format(line[0]) for line in inputSample])
view = viewer.View(graph, legend_kw={"title": "infection rate", "loc": "upper left"})
view.ShowAll()
graph.setLegends([f"{line[0]:.3f}" for line in inputSample[:15]] + ["_"] * 15)
view = otv.View(graph, legend_kw={"title": "infection rate", "loc": "upper left"})

# %%
# We define a function to visualize the upcoming Karhunen-Loevem modes.
# We define a function to visualize the upcoming Karhunen-Loeve modes.


def drawKL(scaledKL, KLev, mesh, title="Scaled KL modes"):
Expand Down Expand Up @@ -121,15 +120,14 @@ def drawKL(scaledKL, KLev, mesh, title="Scaled KL modes"):
phi_Y = resultKL.getScaledModesAsProcessSample()
lambda_Y = resultKL.getEigenvalues()
graph_modes_Y, graph_ev_Y = drawKL(phi_Y, lambda_Y, mesh, "Y")
view = viewer.View(graph_modes_Y)
view.ShowAll()
view = otv.View(graph_modes_Y)

# %%
# Now that Karhunen-Loeve algorithm is trained, we can project them
# in the smaller-dimension space:
projectionSample = resultKL.project(outputFMUSample)
n_mode = projectionSample.getDimension()
print("Karhunen-Loeve projection is dimension {}".format(n_mode))
print(f"Karhunen-Loeve projection in dimension {n_mode}")

# %%
# We keep on following our road map, by metamodeling the projection
Expand Down Expand Up @@ -186,20 +184,20 @@ def globalMetamodel(sample):
for graph in [graph1, graph2]:
graph.setXTitle("Time")
graph.setYTitle("Number of infected")
graph.setLegends(["{:.3f}".format(line[0]) for line in inputSample])
graph.setLegends([f"{line[0]:.3f}" for line in inputSample[:10]])

gridLayout.setGraph(0, 0, graph1)
gridLayout.setGraph(0, 1, graph2)
view = viewer.View(
view = otv.View(
gridLayout, legend_kw={"title": "infection rate", "loc": "upper left"}
)
view.ShowAll()

# %%
# We validate the pertinence of Karhunen-Loeve decomposition:

validationKL = ot.KarhunenLoeveValidation(outputFMUTestSample, resultKL)
graph = validationKL.computeResidualMean().draw()
graph.setYTitle("infected residual mean")
ot.Show(graph)

# %%
Expand Down Expand Up @@ -237,3 +235,6 @@ def globalMetamodel(sample):
# - `estimate a failure probability <openturns.github.io/openturns/latest/auto_reliability_sensitivity/index.html#reliability>`_,
#
# etc.

# %%
otv.View.ShowAll()
2 changes: 1 addition & 1 deletion doc/example/dynamic/plot_dyn_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@
graph.setTitle("")
graph.setXTitle("FMU simulation time (s)")
graph.setYTitle("Number of infected")
graph.setLegends(["{:.4f}".format(line[0]) for line in inputSample])
graph.setLegends([f"{line[0]:.4f}" for line in inputSample])
view = viewer.View(graph, legend_kw={"title": "infection rate", "loc": "upper left"})
view.ShowAll()
4 changes: 2 additions & 2 deletions doc/example/low_level/plot_explore.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@

for name in list_name:
causality = otfmi.fmi.get_causality_str(model, name)
print("{}: {}".format(name, causality))
print(f"{name}: {causality}")

# %%
# | Yet the variables type is not known: real, integer, boolean, string?
# | Let check using `PyFMI's method <http://shorturl.at/dJ157>`_:

for name in list_name:
typ = model.get_variable_data_type(name)
print("{}: {}".format(name, typ))
print(f"{name}: {typ}")

# %%
# | The type `0` corresponds to `Real` (aka "float") variables.
Expand Down
2 changes: 1 addition & 1 deletion doc/example/static/plot_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# Simulate the FMU on a point:
inputPoint = ot.Point([3.0e7, 30000, 200, 400])
outputPoint = function(inputPoint)
print("y = {}".format(outputPoint))
print(f"y = {outputPoint}")

# %%
# Simulate the FMU on a sample:
Expand Down

0 comments on commit 57bbba6

Please sign in to comment.