<!-- DO NOT EDIT. -->
<!-- THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. -->
<!-- TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: -->
<!-- "auto_examples/readers_writers/plot_time_averaged_data_reader.py" -->
<!-- LINE NUMBERS ARE GIVEN BELOW. -->

#### NOTE
[Go to the end](#sphx-glr-download-auto-examples-readers-writers-plot-time-averaged-data-reader-py)
to download the full example code.

<a id="sphx-glr-auto-examples-readers-writers-plot-time-averaged-data-reader-py"></a>

# Time-Averaged Data Reader

Read output from LAMMPS `fix ave/time` commands.

Relevant documentation: [`read_averages_file()`](../../pylimer_tools.io.html.md#pylimer_tools.io.read_lammps_output_file.read_averages_file)
and [`read_sectioned_averages_file()`](../../pylimer_tools.io.html.md#pylimer_tools.io.read_lammps_output_file.read_sectioned_averages_file)

**Supported averaging formats:**

- Scalar quantities (single values per output timestep)
- Vector quantities (multiple values per output timestep)
- Multi-section files with varying column structures

<!-- GENERATED FROM PYTHON SOURCE LINES 17-59 -->
```none
Timestep 100: 3 data points
Timestep 200: 3 data points
Timestep 300: 3 data points
```

<br/>
```Python
import os
from pathlib import Path

from pylimer_tools.io.read_lammps_output_file import read_averages_file


def _find_fixtures_dir() -> Path:
    for cur in (
        [Path(__file__).resolve().parent] if "__file__" in globals() else []
    ) + [Path.cwd()]:
        for p in [cur] + list(cur.parents):
            candidate = p / "tests" / "pylimer_tools" / "fixtures"
            if candidate.is_dir():
                return candidate
    return Path("tests/pylimer_tools/fixtures").resolve()


_fixtures_dir = _find_fixtures_dir()
averages_file = str(_fixtures_dir / "example_avg_file.out.avg.txt")

# Read simple averages file
averages = read_averages_file(averages_file)

# Plot "TimeStep" vs "something"
averages.plot(
    x="TimeStep",
    y="something",
    xlabel="Time Step",
    ylabel="Something",
    title="Averaged Data Plot",
)

vec_averages_file = str(_fixtures_dir / "example_vec_avg_file.out.vec-avg.txt")

# Read sectioned averages
# (e.g., from vector quantities from e.g. ``fix ave/time ... vector``)
sectioned_data = read_averages_file(vec_averages_file)

# Group by timestep for sectioned data
for timestep, group in sectioned_data.groupby("TimeStep"):
    print(f"Timestep {timestep}: {len(group)} data points")
```

**Total running time of the script:** (0 minutes 0.044 seconds)

<a id="sphx-glr-download-auto-examples-readers-writers-plot-time-averaged-data-reader-py"></a>

[`Download Jupyter notebook: plot_time_averaged_data_reader.ipynb`](_downloads/cb3d76a475c6f5dcd93f25df87baef20/plot_time_averaged_data_reader.ipynb)

[`Download Python source code: plot_time_averaged_data_reader.py`](_downloads/aa14c15fe8080a6a71f3c4edae7f2b37/plot_time_averaged_data_reader.py)

[`Download zipped: plot_time_averaged_data_reader.zip`](_downloads/a4c029f3b363c948612656b8b0321727/plot_time_averaged_data_reader.zip)

[Gallery generated by Sphinx-Gallery](https://sphinx-gallery.github.io)
