Merge branch 'channel' into yaml

pull/357/head
nyanpasu64 2018-07-25 15:17:30 -07:00
commit 960770fec0
4 zmienionych plików z 37 dodań i 12 usunięć

22
ovgenpy/channel.py 100644
Wyświetl plik

@ -0,0 +1,22 @@
from typing import NamedTuple, TYPE_CHECKING, Any, Optional
if TYPE_CHECKING:
from ovgenpy.triggers import Trigger
from ovgenpy.wave import Wave
from ovgenpy.ovgenpy import Config
class ChannelConfig(NamedTuple):
_main_cfg: 'Config'
visible_ms: Optional[int]
scan_ratio: Optional[float]
line_color: Any
background_color: Any
class Channel:
def __init__(self, cfg: ChannelConfig, wave: 'Wave', trigger: 'Trigger'):
self.cfg = cfg
self.wave = wave
self.trigger = trigger

Wyświetl plik

@ -5,6 +5,7 @@ from pathlib import Path
from typing import Optional, List
import click
from ovgenpy.channel import Channel
from ovgenpy import outputs
from ovgenpy.config import register_config, yaml
@ -83,8 +84,9 @@ class Ovgen:
def __init__(self, cfg: Config):
self.cfg = cfg
self.waves: List[Wave] = []
self.nwaves: int = None
self.channels: List[Channel] = []
self.outputs: List[outputs.Output] = []
self.nchan: int = None
def write(self):
self._load_waves() # self.waves =
@ -101,16 +103,18 @@ class Ovgen:
)
wave = Wave(wcfg, str(path))
self.waves.append(wave)
trigger = self.cfg.trigger(
wave=wave,
scan_nsamp=round(
self.cfg.time_visible_s * self.cfg.scan_ratio * wave.smp_s),
# I tried extracting variable, but got confused as a result
)
wave.set_trigger(trigger)
self.waves.append(wave)
channel = Channel(None, wave, trigger)
self.channels.append(channel)
self.nwaves = len(self.waves)
self.nchan = len(self.waves)
def _load_outputs(self):
self.outputs = []
@ -127,7 +131,7 @@ class Ovgen:
nframes = fps * self.waves[0].get_s()
nframes = int(nframes) + 1
renderer = MatplotlibRenderer(self.cfg.render, self.nwaves, create_window)
renderer = MatplotlibRenderer(self.cfg.render, self.nchan, create_window)
if RENDER_PROFILING:
begin = time.perf_counter()
@ -144,11 +148,11 @@ class Ovgen:
datas = []
# Get data from each wave
for wave in self.waves:
for wave, channel in zip(self.waves, self.channels):
sample = round(wave.smp_s * time_seconds)
region_len = round(wave.smp_s * time_visible_s)
trigger_sample = wave.trigger.get_trigger(sample)
trigger_sample = channel.trigger.get_trigger(sample)
datas.append(wave.get_around(trigger_sample, region_len))
# Render frame

Wyświetl plik

@ -1,3 +1,4 @@
import weakref
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING
@ -15,7 +16,7 @@ if TYPE_CHECKING:
class Trigger(ABC):
def __init__(self, wave: 'Wave', scan_nsamp: int):
self._wave = wave
self._wave: Wave = weakref.proxy(wave)
self._scan_nsamp = scan_nsamp
@abstractmethod

Wyświetl plik

@ -13,6 +13,8 @@ if TYPE_CHECKING:
class WaveConfig:
amplification: float = 1
def dummy_wave_config() -> WaveConfig:
return WaveConfig(amplification=1)
FLOAT = np.single
@ -29,7 +31,6 @@ class Wave:
self.data = np.mean(self.data, axis=1, dtype=dtype)
self.nsamp = len(self.data)
self.trigger: Trigger = None
# Calculate scaling factor.
def is_type(parent: type) -> bool:
@ -97,9 +98,6 @@ class Wave:
begin = end - region_len
return self.get(begin, end)
def set_trigger(self, trigger: 'Trigger'):
self.trigger = trigger
def get_s(self) -> float:
"""
:return: time (seconds)