Skip to content

Commit 0a8a7fe

Browse files
committed
rm conf.scaling.dimensional: no longer perform auto-scaling
The implementation to automatically make values dimensional was a little clunky and caused complexity in the code preventing further refactoring. This option is disabled for now. The function performing the dimensionalization is still available to be called in user scripts.
1 parent 9a129a7 commit 0a8a7fe

File tree

7 files changed

+13
-72
lines changed

7 files changed

+13
-72
lines changed

stagpy/_step.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,7 @@ class _Rprofs:
471471
472472
:class:`_Rprofs` implements the getitem mechanism. Keys are profile names
473473
defined in :data:`stagpy.phyvars.RPROF[_EXTRA]`. Items are
474-
:class:`stagpy.datatypes.Rprof` instances. Note that
475-
profiles are automatically scaled if conf.scaling.dimensional is True.
474+
:class:`stagpy.datatypes.Rprof` instances.
476475
477476
Attributes:
478477
step: the :class:`Step` owning the :class:`_Rprofs` instance
@@ -518,8 +517,6 @@ def __getitem__(self, name: str) -> Rprof:
518517
meta = rpf.meta
519518
else:
520519
raise error.UnknownRprofVarError(name)
521-
rprof, _ = step.sdat.scale(rprof, meta.dim)
522-
rad, _ = step.sdat.scale(rad, "m")
523520

524521
return Rprof(rprof, rad, meta)
525522

stagpy/commands.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
from shutil import get_terminal_size
1010
from textwrap import TextWrapper, indent
1111

12-
import pandas
13-
1412
from . import __version__, phyvars, stagyydata
1513
from ._helpers import baredoc
1614
from .config import CONFIG_LOCAL, Config
@@ -55,24 +53,6 @@ def info_cmd() -> None:
5553
else:
5654
print()
5755
series = step.timeinfo.loc[list(conf.info.output)]
58-
if conf.scaling.dimensional:
59-
series = series.copy()
60-
dimensions = []
61-
for var, val in series.iteritems():
62-
meta = phyvars.TIME.get(var)
63-
dim = meta.dim if meta is not None else "1"
64-
if dim == "1":
65-
dimensions.append("")
66-
else:
67-
series[var], dim = sdat.scale(val, dim)
68-
dimensions.append(dim)
69-
series = pandas.concat(
70-
[
71-
series,
72-
pandas.Series(data=dimensions, index=series.index, name="dim"),
73-
],
74-
axis=1,
75-
) # type: ignore
7656
print(indent(series.to_string(header=False), " "))
7757
print()
7858

stagpy/config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ class Scaling(Section):
7878

7979
yearins: float = entry(val=3.154e7, in_cli=False, doc="year in seconds")
8080
ttransit: float = entry(val=1.78e15, in_cli=False, doc="transit time in My")
81-
dimensional: bool = switch_opt(False, None, "use dimensional units")
8281
time_in_y: bool = switch_opt(True, None, "dimensional time is in year")
8382
vel_in_cmpy: bool = switch_opt(True, None, "dimensional velocity is in cm/year")
8483
factors: Dict[str, str] = entry(

stagpy/field.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,7 @@ def plot_scalar(
180180
step: a :class:`~stagpy._step.Step` of a StagyyData instance.
181181
var: the scalar field name.
182182
field: if not None, it is plotted instead of step.fields[var]. This is
183-
useful to plot a masked or rescaled array. Note that if
184-
conf.scaling.dimensional is True, this field will be scaled
185-
accordingly.
183+
useful to plot a masked or rescaled array.
186184
axis: the :class:`matplotlib.axes.Axes` object where the field should
187185
be plotted. If set to None, a new figure with one subplot is
188186
created.
@@ -216,8 +214,6 @@ def plot_scalar(
216214
if conf.field.shift:
217215
fld = np.roll(fld, conf.field.shift, axis=0)
218216

219-
fld, unit = step.sdat.scale(fld, meta.dim)
220-
221217
if axis is None:
222218
fig, axis = plt.subplots(ncols=1)
223219
else:
@@ -250,11 +246,7 @@ def plot_scalar(
250246
if conf.field.colorbar:
251247
cax = make_axes_locatable(axis).append_axes("right", size="3%", pad=0.15)
252248
cbar = plt.colorbar(surf, cax=cax)
253-
cbar.set_label(
254-
meta.description
255-
+ (" pert." if conf.field.perturbation else "")
256-
+ (f" ({unit})" if unit else "")
257-
)
249+
cbar.set_label(meta.description + (" pert." if conf.field.perturbation else ""))
258250
if step.geom.spherical or conf.plot.ratio is None:
259251
axis.set_aspect("equal")
260252
axis.set_axis_off()
@@ -283,9 +275,7 @@ def plot_iso(
283275
step: a :class:`~stagpy._step.Step` of a StagyyData instance.
284276
var: the scalar field name.
285277
field: if not None, it is plotted instead of step.fields[var]. This is
286-
useful to plot a masked or rescaled array. Note that if
287-
conf.scaling.dimensional is True, this field will be scaled
288-
accordingly.
278+
useful to plot a masked or rescaled array.
289279
extra: options that will be passed on to
290280
:func:`matplotlib.axes.Axes.contour`.
291281
"""
@@ -352,8 +342,7 @@ def _findminmax(
352342
for step in sdat.walk.filter(snap=True):
353343
for var in sovs:
354344
if var in step.fields:
355-
field = step.fields[var]
356-
vals, _ = sdat.scale(field.values, field.meta.dim)
345+
vals = step.fields[var].values
357346
if var in minmax:
358347
minmax[var] = (
359348
min(minmax[var][0], np.nanmin(vals)),
@@ -401,10 +390,10 @@ def cmd() -> None:
401390
elif valid_field_var(var[1] + "1"):
402391
plot_vec(axis, step, var[1], conf=conf)
403392
if conf.field.timelabel:
404-
time, unit = sdat.scale(step.timeinfo["t"], "s")
393+
time = step.timeinfo["t"]
405394
time = _helpers.scilabel(time)
406395
axes[0, 0].text(
407-
0.02, 1.02, f"$t={time}$ {unit}", transform=axes[0, 0].transAxes
396+
0.02, 1.02, f"$t={time}$", transform=axes[0, 0].transAxes
408397
)
409398
oname = "_".join(chain.from_iterable(vfig))
410399
plt.tight_layout(w_pad=3)

stagpy/rprof.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def plot_rprofs(
3131
if conf is None:
3232
conf = Config.default_()
3333
stepstr = rprofs.stepstr
34-
sdat = rprofs.step.sdat
3534

3635
for vfig in names:
3736
fig, axes = plt.subplots(
@@ -48,7 +47,7 @@ def plot_rprofs(
4847
rad = rpf.rad
4948
meta = rpf.meta
5049
if conf.rprof.depth:
51-
rad = sdat.scale(rprofs.bounds[1], "m")[0] - rad
50+
rad = rprofs.bounds[1] - rad
5251
axes[iplt].plot(rprof, rad, conf.rprof.style, label=meta.description)
5352
if xlabel is None:
5453
xlabel = meta.kind
@@ -57,8 +56,6 @@ def plot_rprofs(
5756
if ivar == 0:
5857
xlabel = meta.description
5958
if xlabel:
60-
_, unit = sdat.scale(1, meta.dim)
61-
xlabel += f" ({unit})" if unit else ""
6259
axes[iplt].set_xlabel(xlabel)
6360
if vplt[0][:3] == "eta": # list of log variables
6461
axes[iplt].set_xscale("log")
@@ -68,8 +65,6 @@ def plot_rprofs(
6865
if conf.rprof.depth:
6966
axes[0].invert_yaxis()
7067
ylabel = "Depth" if conf.rprof.depth else "Radius"
71-
_, unit = sdat.scale(1, "m")
72-
ylabel += f" ({unit})" if unit else ""
7368
axes[0].set_ylabel(ylabel)
7469
_helpers.saveplot(fig, fname + stepstr)
7570

@@ -84,14 +79,11 @@ def plot_grid(step: Step) -> None:
8479
instance.
8580
"""
8681
drprof = step.rprofs["dr"]
87-
_, unit = step.sdat.scale(1, "m")
88-
if unit:
89-
unit = f" ({unit})"
9082
fig, (ax1, ax2) = plt.subplots(2, sharex=True)
9183
ax1.plot(drprof.rad, "-ko")
92-
ax1.set_ylabel("$r$" + unit)
84+
ax1.set_ylabel("$r$")
9385
ax2.plot(drprof.values, "-ko")
94-
ax2.set_ylabel("$dr$" + unit)
86+
ax2.set_ylabel("$dr$")
9587
ax2.set_xlim([-0.5, len(drprof.rad) - 0.5])
9688
ax2.set_xlabel("Cell number")
9789
_helpers.saveplot(fig, "grid", step.istep)

stagpy/stagyydata.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ class _Tseries:
142142
143143
:class:`_Tseries` implements the getitem mechanism. Keys are series names
144144
defined in :data:`stagpy.phyvars.TIME[_EXTRA]`. Items are
145-
:class:`stagpy.datatypes.Tseries` instances. Note that series are
146-
automatically scaled if conf.scaling.dimensional is True.
145+
:class:`stagpy.datatypes.Tseries` instances.
147146
148147
Attributes:
149148
sdat: the :class:`StagyyData` instance owning the :class:`_Tseries`
@@ -194,8 +193,6 @@ def __getitem__(self, name: str) -> Tseries:
194193
meta = tseries.meta
195194
else:
196195
raise error.UnknownTimeVarError(name)
197-
series, _ = self.sdat.scale(series, meta.dim)
198-
time, _ = self.sdat.scale(time, "s")
199196
return Tseries(series, time, meta)
200197

201198
def tslice(
@@ -818,15 +815,8 @@ def scale(
818815
unit: the dimension of data as defined in phyvars.
819816
Return:
820817
scaled quantity and unit string.
821-
Other Parameters:
822-
conf.scaling.dimensional: if set to False (default), the factor is
823-
always 1.
824818
"""
825-
if (
826-
self.par.get("switches", "dimensional_units", True)
827-
or not conf.scaling.dimensional
828-
or unit == "1"
829-
):
819+
if self.par.get("switches", "dimensional_units", True) or unit == "1":
830820
return data, ""
831821
scaling = phyvars.SCALES[unit](self.scales)
832822
factor = conf.scaling.factors.get(unit, " ")

stagpy/time_series.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ def plot_time_series(
7979
if ivar == 0:
8080
ylabel = tseries.meta.description
8181
if ylabel:
82-
_, unit = sdat.scale(1, tseries.meta.dim)
83-
if unit:
84-
ylabel += f" ({unit})"
8582
axes[iplt].set_ylabel(ylabel)
8683
if vplt[0][:3] == "eta": # list of log variables
8784
axes[iplt].set_yscale("log")
@@ -91,10 +88,7 @@ def plot_time_series(
9188
axes[iplt].tick_params()
9289
for time_mark in time_marks:
9390
axes[iplt].axvline(time_mark, color="black", linestyle="--")
94-
_, unit = sdat.scale(1, "s")
95-
if unit:
96-
unit = f" ({unit})"
97-
axes[-1].set_xlabel("Time" + unit)
91+
axes[-1].set_xlabel("Time")
9892
axes[-1].set_xlim(tstart, tend)
9993
axes[-1].tick_params()
10094
_helpers.saveplot(fig, "_".join(fname))

0 commit comments

Comments
 (0)