1111import numpy as np
1212from mpl_toolkits .axes_grid1 import make_axes_locatable
1313
14- from . import _helpers , conf , phyvars
14+ from . import _helpers , phyvars
15+ from .config import Config
1516from .error import NotAvailableError
1617from .stagyydata import StagyyData
1718
3334
3435
3536def _threed_extract (
36- step : Step , var : str , walls : bool = False
37+ conf : Config , step : Step , var : str , walls : bool = False
3738) -> Tuple [Tuple [ndarray , ndarray ], ndarray ]:
3839 """Return suitable slices and coords for 3D fields."""
3940 is_vector = not valid_field_var (var )
@@ -86,7 +87,7 @@ def valid_field_var(var: str) -> bool:
8687
8788
8889def get_meshes_fld (
89- step : Step , var : str , walls : bool = False
90+ conf : Config , step : Step , var : str , walls : bool = False
9091) -> Tuple [ndarray , ndarray , ndarray , Varf ]:
9192 """Return scalar field along with coordinates meshes.
9293
@@ -108,7 +109,7 @@ def get_meshes_fld(
108109 or fld .values .shape [1 ] != step .geom .nytot
109110 )
110111 if step .geom .threed and step .geom .cartesian :
111- (xcoord , ycoord ), vals = _threed_extract (step , var , walls )
112+ (xcoord , ycoord ), vals = _threed_extract (conf , step , var , walls )
112113 elif step .geom .twod_xz :
113114 xcoord = step .geom .x_walls if hwalls else step .geom .x_centers
114115 ycoord = step .geom .z_walls if walls else step .geom .z_centers
@@ -125,7 +126,9 @@ def get_meshes_fld(
125126 return xmesh , ymesh , vals , fld .meta
126127
127128
128- def get_meshes_vec (step : Step , var : str ) -> Tuple [ndarray , ndarray , ndarray , ndarray ]:
129+ def get_meshes_vec (
130+ conf : Config , step : Step , var : str
131+ ) -> Tuple [ndarray , ndarray , ndarray , ndarray ]:
129132 """Return vector field components along with coordinates meshes.
130133
131134 Only works properly in 2D geometry and 3D cartesian.
@@ -139,7 +142,7 @@ def get_meshes_vec(step: Step, var: str) -> Tuple[ndarray, ndarray, ndarray, nda
139142 requested vector field.
140143 """
141144 if step .geom .threed and step .geom .cartesian :
142- (xcoord , ycoord ), (vec1 , vec2 ) = _threed_extract (step , var )
145+ (xcoord , ycoord ), (vec1 , vec2 ) = _threed_extract (conf , step , var )
143146 elif step .geom .twod_xz :
144147 xcoord , ycoord = step .geom .x_walls , step .geom .z_centers
145148 vec1 = step .fields [var + "1" ].values [:, 0 , :, 0 ]
@@ -168,6 +171,7 @@ def plot_scalar(
168171 var : str ,
169172 field : Optional [ndarray ] = None ,
170173 axis : Optional [Axes ] = None ,
174+ conf : Optional [Config ] = None ,
171175 ** extra : Any ,
172176) -> Tuple [Figure , Axes , QuadMesh , Optional [Colorbar ]]:
173177 """Plot scalar field.
@@ -191,10 +195,12 @@ def plot_scalar(
191195 :func:`~matplotlib.axes.Axes.pcolormesh`, and the colorbar returned
192196 by :func:`matplotlib.pyplot.colorbar`.
193197 """
198+ if conf is None :
199+ conf = Config .default_ ()
194200 if step .geom .threed and step .geom .spherical :
195201 raise NotAvailableError ("plot_scalar not implemented for 3D spherical geometry" )
196202
197- xmesh , ymesh , fld , meta = get_meshes_fld (step , var , walls = True )
203+ xmesh , ymesh , fld , meta = get_meshes_fld (conf , step , var , walls = True )
198204 # interpolate at cell centers, this should be abstracted by field objects
199205 # via an "at_cell_centers" method or similar
200206 if fld .shape [0 ] > max (step .geom .nxtot , step .geom .nytot ):
@@ -262,7 +268,12 @@ def plot_scalar(
262268
263269
264270def plot_iso (
265- axis : Axes , step : Step , var : str , field : Optional [ndarray ] = None , ** extra : Any
271+ axis : Axes ,
272+ step : Step ,
273+ var : str ,
274+ field : Optional [ndarray ] = None ,
275+ conf : Optional [Config ] = None ,
276+ ** extra : Any ,
266277) -> None :
267278 """Plot isocontours of scalar field.
268279
@@ -278,7 +289,9 @@ def plot_iso(
278289 extra: options that will be passed on to
279290 :func:`matplotlib.axes.Axes.contour`.
280291 """
281- xmesh , ymesh , fld , _ = get_meshes_fld (step , var )
292+ if conf is None :
293+ conf = Config .default_ ()
294+ xmesh , ymesh , fld , _ = get_meshes_fld (conf , step , var )
282295
283296 if field is not None :
284297 fld = field
@@ -296,7 +309,12 @@ def plot_iso(
296309 axis .contour (xmesh , ymesh , fld , ** extra_opts )
297310
298311
299- def plot_vec (axis : Axes , step : Step , var : str ) -> None :
312+ def plot_vec (
313+ axis : Axes ,
314+ step : Step ,
315+ var : str ,
316+ conf : Optional [Config ] = None ,
317+ ) -> None :
300318 """Plot vector field.
301319
302320 Args:
@@ -305,7 +323,9 @@ def plot_vec(axis: Axes, step: Step, var: str) -> None:
305323 step: a :class:`~stagpy._step.Step` of a StagyyData instance.
306324 var: the vector field name.
307325 """
308- xmesh , ymesh , vec1 , vec2 = get_meshes_vec (step , var )
326+ if conf is None :
327+ conf = Config .default_ ()
328+ xmesh , ymesh , vec1 , vec2 = get_meshes_vec (conf , step , var )
309329 dipz = step .geom .nztot // 10
310330 if conf .field .shift :
311331 vec1 = np .roll (vec1 , conf .field .shift , axis = 0 )
@@ -351,6 +371,8 @@ def cmd() -> None:
351371 conf.field
352372 conf.core
353373 """
374+ from . import conf
375+
354376 sdat = StagyyData (conf .core .path )
355377 # no more than two fields in a subplot
356378 lovs = [[slov [:2 ] for slov in plov ] for plov in conf .field .plot ]
@@ -372,12 +394,12 @@ def cmd() -> None:
372394 opts : Dict [str , Any ] = {}
373395 if var [0 ] in minmax :
374396 opts = dict (vmin = minmax [var [0 ]][0 ], vmax = minmax [var [0 ]][1 ])
375- plot_scalar (step , var [0 ], axis = axis , ** opts )
397+ plot_scalar (step , var [0 ], axis = axis , conf = conf , ** opts )
376398 if len (var ) == 2 :
377399 if valid_field_var (var [1 ]):
378- plot_iso (axis , step , var [1 ])
400+ plot_iso (axis , step , var [1 ], conf = conf )
379401 elif valid_field_var (var [1 ] + "1" ):
380- plot_vec (axis , step , var [1 ])
402+ plot_vec (axis , step , var [1 ], conf = conf )
381403 if conf .field .timelabel :
382404 time , unit = sdat .scale (step .timeinfo ["t" ], "s" )
383405 time = _helpers .scilabel (time )
0 commit comments