• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zincware / MDSuite / 3999396905

pending completion
3999396905

push

github-actions

GitHub
[merge before other PRs] ruff updates (#580)

960 of 1311 branches covered (73.23%)

Branch coverage included in aggregate %.

15 of 15 new or added lines in 11 files covered. (100.0%)

4034 of 4930 relevant lines covered (81.83%)

3.19 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

26.23
/mdsuite/time_series/base.py
1
"""
2
MDSuite: A Zincwarecode package.
3

4
License
5
-------
6
This program and the accompanying materials are made available under the terms
7
of the Eclipse Public License v2.0 which accompanies this distribution, and is
8
available at https://www.eclipse.org/legal/epl-v20.html
9

10
SPDX-License-Identifier: EPL-2.0
11

12
Copyright Contributors to the Zincwarecode Project.
13

14
Contact Information
15
-------------------
16
email: zincwarecode@gmail.com
17
github: https://github.com/zincware
18
web: https://zincwarecode.com/
19

20
Citation
21
--------
22
If you use this module please cite us with:
23

24
Summary
25
-------
26
"""
27
from __future__ import annotations
4✔
28

29
from typing import TYPE_CHECKING
4✔
30

31
import matplotlib.pyplot as plt
4✔
32
import numpy as np
4✔
33
import tensorflow as tf
4✔
34

35
from mdsuite.database.simulation_database import Database
4✔
36

37
if TYPE_CHECKING:
4!
38
    from mdsuite import Experiment
×
39

40

41
def running_mean(x, size):
4✔
42
    """Perform a rolling window mean."""
43
    cumsum = np.cumsum(np.insert(x, 0, 0))
×
44
    return (cumsum[size:] - cumsum[:-size]) / float(size)
×
45

46

47
class TimeSeries:
4✔
48
    """Time Series class."""
49

50
    def __init__(self, experiment: Experiment):
4✔
51
        """
52

53
        Parameters
54
        ----------
55
        experiment: Experiment
56
            The parent experiment class to perform the time series operation on
57
        """
58
        self.experiment = experiment
×
59

60
        self.loaded_property = None
×
61
        self.fig_labels = {"x": None, "y": None}
×
62
        self.species = experiment.species
×
63
        self.rolling_window = 0
×
64
        self.reduce_sum = True
×
65

66
        # Properties
67
        self._database = None
×
68
        self._data = None
×
69

70
    def __call__(self, species: list = None, rolling_window: int = 0):
4✔
71
        if species is not None:
×
72
            self.species = species
×
73
        self.rolling_window = rolling_window
×
74
        self.plot()
×
75

76
    @property
4✔
77
    def database(self):
3✔
78
        """Get the database."""
79
        if self._database is None:
×
80
            self._database = Database(self.experiment.database_path / "database.hdf5")
×
81
        return self._database
×
82

83
    @property
4✔
84
    def data(self):
3✔
85
        """Get the data for all species and timesteps for the loaded_property."""
86
        if self._data is None:
×
87
            self._data = tf.concat(
×
88
                [
89
                    self.database.load_data([f"{species}/{self.loaded_property}"])
90
                    for species in self.species
91
                ],
92
                axis=0,
93
            )
94
        return self._data
×
95

96
    @property
4✔
97
    def preprocess_data(self):
3✔
98
        """Perform some data preprocessing before plotting it."""
99
        data = self.data
×
100
        if self.reduce_sum:
×
101
            data = tf.einsum("atx -> t", data)
×
102
            # perform a reduce sum over atoms "a" and property dimension "x" to
103
            # yield time steps "t"
104
        if self.rolling_window > 0:
×
105
            data = running_mean(data, self.rolling_window)
×
106

107
        return data
×
108

109
    def plot(self):
4✔
110
        """Plot the data over timesteps."""
111
        fig, ax = plt.subplots()
×
112
        ax.plot(self.preprocess_data)
×
113
        ax.set_xlabel(self.fig_labels["x"])
×
114
        ax.set_ylabel(self.fig_labels["y"])
×
115
        fig.show()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc