Skip to content
Snippets Groups Projects
Commit b1eb8d42 authored by whuie2's avatar whuie2
Browse files

enable adding mogtables to sequence visualization

parent c2fbbe29
No related branches found
No related tags found
No related merge requests found
...@@ -24,6 +24,24 @@ def _fresh_filename(path: pathlib.Path, overwrite: bool=False) -> pathlib.Path: ...@@ -24,6 +24,24 @@ def _fresh_filename(path: pathlib.Path, overwrite: bool=False) -> pathlib.Path:
print(f"Write instead to {_path}") print(f"Write instead to {_path}")
return _path return _path
def min_n(generator, default=None):
x0 = None
for x in generator:
if x is None:
continue
elif x0 is None or x < x0:
x0 = x
return default if x0 is None else x0
def max_n(generator, default=None):
x0 = None
for x in generator:
if x is None:
continue
elif x0 is None or x > x0:
x0 = x
return default if x0 is None else x0
class SuperSequence: class SuperSequence:
""" """
Sequence of labeled Sequences. Mostly for visualization purposes. Sequence of labeled Sequences. Mostly for visualization purposes.
...@@ -167,8 +185,8 @@ class SuperSequence: ...@@ -167,8 +185,8 @@ class SuperSequence:
@staticmethod @staticmethod
def _gen_timeline(detailed=False, layout=(1, 4, 32, 1, 32, -10, 10)) \ def _gen_timeline(detailed=False, layout=(1, 4, 32, 1, 32, -10, 10)) \
-> pd.Plotter: -> pd.Plotter:
P = pd.Plotter() P = pd.Plotter().ggrid(True)
P.set_yticks([]).set_yticklabels([]).ggrid(True) P.set_yticks([]).set_yticklabels([])
return P return P
def draw_simple(self) -> pd.Plotter: def draw_simple(self) -> pd.Plotter:
...@@ -213,8 +231,9 @@ class SuperSequence: ...@@ -213,8 +231,9 @@ class SuperSequence:
P.set_xlabel("Time [s]") P.set_xlabel("Time [s]")
return P return P
def draw_detailed(self, connections: dict[str, Connection]=None) \ def draw_detailed(self, connections: dict[str, Connection]=None,
-> pd.Plotter: mogtables: list[(..., dict[str, ...] | None)]=None) \
-> pd.Plotter:
assert (connections is not None) ^ (self.defaults is not None) assert (connections is not None) ^ (self.defaults is not None)
_connections = list( _connections = list(
(connections if connections is not None (connections if connections is not None
...@@ -310,7 +329,92 @@ class SuperSequence: ...@@ -310,7 +329,92 @@ class SuperSequence:
history[i0].set_xdata(list(x) + [T1]) history[i0].set_xdata(list(x) + [T1])
history[i0].set_ydata(list(y) + [y[-1]]) history[i0].set_ydata(list(y) + [y[-1]])
P.set_xlim(T0, T1) # process any MOGTables
P.set_ylim(-2 - hk / 2, hk * len(_connections) + 2 + hk / 2) moghk = 6
mT0 = (T0 + T1) / 2
mT1 = (T0 + T1) / 2
def mogycoord(x, xlim, k, j):
xmin, xmax = xlim
return moghk * k + j * 4 / 3 + 1 + (x - xmin) / (xmax - xmin)
mogtables = list() if mogtables is None else mogtables
for k, (mogtable, opt) \
in zip(range(-1, -len(mogtables) - 1, -1), mogtables):
opt = dict() if opt is None else opt
t0 = opt.get("offset", 0.0)
name = opt.get("name", f"mogtable {k}")
color = "C7" if mogtable.color is None else mogtable.color
mT0 = min(T0, t0 + mogtable.min_time())
mT1 = max(T1, t0 + mogtable.max_time())
# default min/max taken from the MOGRF manual
fmin = min_n((e.frequency for e in mogtable), 10.0)
fmax = max_n((e.frequency for e in mogtable), 200.0)
pmin = min_n((e.power for e in mogtable), -70.0)
pmax = max_n((e.power for e in mogtable), 33.0)
phmin = min_n((e.phase for e in mogtable), 0.0)
phmax = max_n((e.phase for e in mogtable), 360.0)
# set up lines in the analog style for frequency, power, and phase
for j, (param, lim) in enumerate([
("phase", (phmin, phmax)),
("power", (pmin, pmax)),
("frequency", (fmin, fmax))
]):
P.ax.axhline(
moghk * k + j * 4 / 3 + 1, color="0.85", linestyle="--",
linewidth=linewidth / 2, zorder=100)
P.ax.axhline(
moghk * k + j * 4 / 3 + 1.5, color="0.85", linestyle="-",
linewidth=linewidth / 2, zorder=100)
P.ax.axhline(
moghk * k + j * 4 / 3 + 2, color="0.85", linestyle="--",
linewidth=linewidth / 2, zorder=100)
P.ax.text(
mT0, moghk * k + j * 4 / 3 + 1.5, _titlecase(param) + " ",
horizontalalignment="right", verticalalignment="center",
zorder=101)
P.ax.text(
mT1, moghk * k + j * 4 / 3 + 1.5, " " + _titlecase(param),
horizontalalignment="left", verticalalignment="center",
zorder=101)
P.axvline(
t0, color="0.25", linestyle=":", linewidth=linewidth / 2,
zorder=102)
P.ax.text(
t0, moghk * k + 1, _titlecase(name),
horizontalalignment="left", verticalalignment="top",
zorder=101)
t = [(mT0 + t0 + mogtable.min_time()) / 2]
s = [mogycoord(lim[0], lim, k, j)]
for i, mogevent in enumerate(mogtable):
t += [t0 + mogevent.time, t0 + mogevent.time]
s += [
s[-1],
mogycoord(getattr(mogevent, param), lim, k, j)
if getattr(mogevent, param) is not None else s[-1]
]
t += [(t[-1] + mT1) / 2]
s += [s[-1]]
P.plot(
[mT0, t[0]],
2 * [mogycoord(lim[0], lim, k, j)],
color="0.65", linewidth=linewidth, zorder=103
)
P.plot(
[t[-1], mT1],
2 * [s[-1]],
color="0.65", linewidth=linewidth, zorder=103
)
P.plot(t, s, color=color, linewidth=linewidth, zorder=103)
P.set_xlim(min(mT0, T0), max(mT1, T1))
P.set_ylim(
-moghk * len(mogtables) - 2 - hk / 2,
hk * len(_connections) + 2 + hk / 2
)
return P return P
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment