Skip to content

Commit 300704b

Browse files
committed
time_series: reduce reliance on global conf
1 parent a9d0a23 commit 300704b

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

stagpy/time_series.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
import numpy as np
99
import pandas as pd
1010

11-
from . import _helpers, conf
11+
from . import _helpers
12+
from .config import Config
1213
from .error import InvalidTimeFractionError
1314
from .stagyydata import StagyyData
1415

@@ -18,7 +19,7 @@
1819
from pandas import DataFrame
1920

2021

21-
def _collect_marks(sdat: StagyyData) -> List[float]:
22+
def _collect_marks(sdat: StagyyData, conf: Config) -> List[float]:
2223
"""Concatenate mark* config variable."""
2324
times = list(conf.time.marktimes)
2425
times.extend(step.timeinfo["t"] for step in sdat.snaps[conf.time.marksnaps])
@@ -27,7 +28,9 @@ def _collect_marks(sdat: StagyyData) -> List[float]:
2728

2829

2930
def plot_time_series(
30-
sdat: StagyyData, names: Sequence[Sequence[Sequence[str]]]
31+
sdat: StagyyData,
32+
names: Sequence[Sequence[Sequence[str]]],
33+
conf: Optional[Config] = None,
3134
) -> None:
3235
"""Plot requested time series.
3336
@@ -39,7 +42,9 @@ def plot_time_series(
3942
conf.time.tstart: the starting time.
4043
conf.time.tend: the ending time.
4144
"""
42-
time_marks = _collect_marks(sdat)
45+
if conf is None:
46+
conf = Config.default_()
47+
time_marks = _collect_marks(sdat, conf)
4348
for vfig in names:
4449
tstart = conf.time.tstart
4550
tend = conf.time.tend
@@ -132,6 +137,8 @@ def cmd() -> None:
132137
conf.time
133138
conf.core
134139
"""
140+
from . import conf
141+
135142
sdat = StagyyData(conf.core.path)
136143
if sdat.tseries is None:
137144
return
@@ -144,7 +151,7 @@ def cmd() -> None:
144151
t_f = sdat.tseries.time[-1]
145152
conf.time.tstart = t_0 * conf.time.fraction + t_f * (1 - conf.time.fraction)
146153

147-
plot_time_series(sdat, conf.time.plot)
154+
plot_time_series(sdat, conf.time.plot, conf)
148155

149156
if conf.time.compstat:
150157
stats = compstat(

0 commit comments

Comments
 (0)