diff --git a/src/doc/gallery/index.rst b/src/doc/gallery/index.rst new file mode 100644 index 0000000000000000000000000000000000000000..67f7779ebada2b42250ad6ea6b5ccd1e0f68c381 --- /dev/null +++ b/src/doc/gallery/index.rst @@ -0,0 +1,12 @@ + +PyCaosDB Code Gallery +===================== + +This chapter collects code examples which can be immediately run against an empty CaosDB instance. + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + :hidden: + + simulation diff --git a/src/doc/gallery/simulation.py b/src/doc/gallery/simulation.py new file mode 100644 index 0000000000000000000000000000000000000000..3e588408cede311a835e1df0c2e69633f66c02ca --- /dev/null +++ b/src/doc/gallery/simulation.py @@ -0,0 +1,58 @@ +import caosdb as db +import numpy as np + + +def main(): + # 1. Set up the data model + setup_caosdb() + + # 2.Run simulations + for i in range(200): + run_simulation(run=i, t_max=10) + + +if __name__ == '__main__': + main() + + +def setup_caosdb(): + """Create the data model and insert it into CaosDB + + The data model consists of the following RecordTypes: + + Software + with author and revision. + + SoftwareRun + A specific run of the sofware, with input parameters, a date and a result. + + Parameters + An aggregate of parameters, in this case the x,y,z initial values. + + Result + The x,y,z values at the end of the software run. + + The data model of course also contains the corresponding properties for these RecordTypes. + + """ + + + +def run_simulation(run, t_max): + """ + Integrate the Rössler attractor from random initial values. + """ + + a = 0.2; b = 0.2; c = 5.7 + + def diff(x, dt): + return (dt * (-x[1] - x[2]), + dt * (x[0] + a * x[1]), + dt * (b + x[2] * (x[0] - c))) + + x0 = np.random.uniform(-10, 10, 3) + dt = 0.01 + x = x0 + for t in range(0, t_max, dt): + x += diff(x, dt) + return (x0, x) diff --git a/src/doc/gallery/simulation.rst b/src/doc/gallery/simulation.rst new file mode 100644 index 0000000000000000000000000000000000000000..522aece7d27f5342f2f2990052f3ee433af5f01c --- /dev/null +++ b/src/doc/gallery/simulation.rst @@ -0,0 +1,14 @@ +======================================== +Managing data from numerical simulations +======================================== + +This code example + +1. sets up the data model +2. runs simulations +3. stores the parameters and results into CaosDB +4. retrieves the parameters for interesting results + +:download:`Download code<simulation.py>` + +.. literalinclude:: simulation.py diff --git a/src/doc/index.rst b/src/doc/index.rst index bd29c6c56acf5c173e94ae6471a6aeba56ea4b93..004ae3a9926ed7a9a27720db1f3c28e72f1f3f28 100644 --- a/src/doc/index.rst +++ b/src/doc/index.rst @@ -12,6 +12,7 @@ Welcome to PyCaosDB's documentation! Concepts <concepts> Configuration <configuration> Administration <administration> + Code gallery <gallery/index> API documentation<_apidoc/caosdb> This is the documentation for the Python client library for CaosDB, ``PyCaosDB``.