.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples_gallery/output/trajectory_io.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_examples_gallery_output_trajectory_io.py: Writing and reading trajectory data =================================== This example illustrates how to store intermediate data to a file for later post-processing. The storage frequency is an argument to the tracker. .. GENERATED FROM PYTHON SOURCE LINES 8-29 .. image-sg:: /examples_gallery/output/images/sphx_glr_trajectory_io_001.png :alt: trajectory io :srcset: /examples_gallery/output/images/sphx_glr_trajectory_io_001.png :class: sphx-glr-single-img .. code-block:: Python from tempfile import NamedTemporaryFile import pde # define grid, state and pde grid = pde.UnitGrid([32]) state = pde.FieldCollection( [pde.ScalarField.random_uniform(grid), pde.VectorField.random_uniform(grid)] ) eq = pde.PDE({"s": "-0.1 * s", "v": "-v"}) # get a temporary file to write data to with NamedTemporaryFile(suffix=".hdf5") as path: # run a simulation and write the results writer = pde.FileStorage(path.name, write_mode="truncate") eq.solve(state, t_range=32, dt=0.01, tracker=writer.tracker(1)) # read the simulation back in again reader = pde.FileStorage(path.name, write_mode="read_only") pde.plot_kymographs(reader) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 5.075 seconds) .. _sphx_glr_download_examples_gallery_output_trajectory_io.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: trajectory_io.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: trajectory_io.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: trajectory_io.zip `