1111from matplotlib import colors
1212from scipy .signal import argrelmax , argrelmin
1313
14- from . import _helpers , conf , error , field , phyvars
14+ from . import _helpers , error , field , phyvars
1515from ._helpers import saveplot
16+ from .config import Config
1617from .datatypes import Field
1718from .stagyydata import StagyyData
1819
1920if typing .TYPE_CHECKING :
20- from typing import Sequence , TextIO , Tuple , Union
21+ from typing import Optional , Sequence , TextIO , Tuple , Union
2122
2223 from matplotlib .axes import Axes
2324 from numpy import ndarray
@@ -120,7 +121,7 @@ def _annot_pos(
120121 return p_beg , p_end
121122
122123
123- def _plot_plate_limits_field (axis : Axes , snap : Step ) -> None :
124+ def _plot_plate_limits_field (axis : Axes , snap : Step , conf : Config ) -> None :
124125 """Plot arrows designating ridges and trenches in 2D field plots."""
125126 itrenches , iridges = detect_plates (snap , conf .plates .vzratio )
126127 for itrench in itrenches :
@@ -206,7 +207,11 @@ def _continents_location(snap: Step, at_surface: bool = True) -> ndarray:
206207 return csurf >= 2
207208
208209
209- def plot_at_surface (snap : Step , names : Sequence [Sequence [Sequence [str ]]]) -> None :
210+ def plot_at_surface (
211+ snap : Step ,
212+ names : Sequence [Sequence [Sequence [str ]]],
213+ conf : Optional [Config ],
214+ ) -> None :
210215 """Plot surface diagnostics.
211216
212217 Args:
@@ -215,6 +220,8 @@ def plot_at_surface(snap: Step, names: Sequence[Sequence[Sequence[str]]]) -> Non
215220 figures, plots and subplots. Surface diagnotics can be valid
216221 surface field names, field names, or `"dv2"` which is d(vphi)/dphi.
217222 """
223+ if conf is None :
224+ conf = Config .default_ ()
218225 for vfig in names :
219226 fig , axes = plt .subplots (
220227 nrows = len (vfig ), sharex = True , figsize = (12 , 2 * len (vfig ))
@@ -258,7 +265,9 @@ def plot_at_surface(snap: Step, names: Sequence[Sequence[Sequence[str]]]) -> Non
258265 saveplot (fig , fname , snap .isnap )
259266
260267
261- def _write_trench_diagnostics (step : Step , vrms_surf : float , fid : TextIO ) -> None :
268+ def _write_trench_diagnostics (
269+ step : Step , vrms_surf : float , fid : TextIO , conf : Config
270+ ) -> None :
262271 """Print out some trench diagnostics."""
263272 assert step .isnap is not None
264273 itrenches , _ = detect_plates (step , conf .plates .vzratio )
@@ -319,14 +328,20 @@ def _write_trench_diagnostics(step: Step, vrms_surf: float, fid: TextIO) -> None
319328 )
320329
321330
322- def plot_scalar_field (snap : Step , fieldname : str ) -> None :
331+ def plot_scalar_field (
332+ snap : Step ,
333+ fieldname : str ,
334+ conf : Optional [Config ] = None ,
335+ ) -> None :
323336 """Plot scalar field with plate information.
324337
325338 Args:
326339 snap: a :class:`~stagpy._step.Step` of a StagyyData instance.
327340 fieldname: name of the field that should be decorated with plate
328341 informations.
329342 """
343+ if conf is None :
344+ conf = Config .default_ ()
330345 fig , axis , _ , _ = field .plot_scalar (snap , fieldname )
331346
332347 if conf .plates .continents :
@@ -349,7 +364,7 @@ def plot_scalar_field(snap: Step, fieldname: str) -> None:
349364 field .plot_vec (axis , snap , "sx" if conf .plates .stress else "v" )
350365
351366 # Put arrow where ridges and trenches are
352- _plot_plate_limits_field (axis , snap )
367+ _plot_plate_limits_field (axis , snap , conf )
353368
354369 saveplot (fig , f"plates_{ fieldname } " , snap .isnap , close = conf .plates .zoom is None )
355370
@@ -381,6 +396,8 @@ def cmd() -> None:
381396 conf.plot
382397 conf.core
383398 """
399+ from . import conf
400+
384401 sdat = StagyyData (conf .core .path )
385402
386403 isurf = _isurf (next (iter (sdat .walk )))
@@ -398,9 +415,9 @@ def cmd() -> None:
398415
399416 for step in sdat .walk .filter (fields = ["T" ]):
400417 # could check other fields too
401- _write_trench_diagnostics (step , vrms_surf , fid )
402- plot_at_surface (step , conf .plates .plot )
403- plot_scalar_field (step , conf .plates .field )
418+ _write_trench_diagnostics (step , vrms_surf , fid , conf )
419+ plot_at_surface (step , conf .plates .plot , conf )
420+ plot_scalar_field (step , conf .plates .field , conf )
404421 if conf .plates .nbplates :
405422 time .append (step .timeinfo .loc ["t" ])
406423 itr , ird = detect_plates (step , conf .plates .vzratio )
0 commit comments