Skip to content

Commit

Permalink
Merge pull request #1304 from anarkiwi/wfm
Browse files Browse the repository at this point in the history
waterfall plot manager
  • Loading branch information
anarkiwi authored Jun 7, 2024
2 parents 346b2a0 + e375a09 commit dab0080
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docker/Dockerfile.base
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
libvulkan-dev \
python3-numpy
WORKDIR /root
RUN git clone https://github.com/iqtlabs/gr-iqtlabs -b 1.0.107
RUN git clone https://github.com/iqtlabs/gr-iqtlabs -b 1.0.108
COPY --from=iqtlabs/gamutrf-vkfft:latest /root /root/gr-iqtlabs
WORKDIR /root/gr-iqtlabs/build
COPY --from=iqtlabs/gamutrf-sigmf:latest /usr/local /usr/local
Expand Down
18 changes: 9 additions & 9 deletions gamutrfwaterfall/gamutrfwaterfall/waterfall.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)
from gamutrfwaterfall.waterfall_plot import (
make_config,
WaterfallPlot,
WaterfallPlotManager,
)

warnings.filterwarnings(action="ignore", message="Mean of empty slice")
Expand Down Expand Up @@ -90,7 +90,7 @@ def sig_handler(_sig=None, _frame=None):
if not scan_configs:
return

plot = None
plot_manager = WaterfallPlotManager(peak_finder)

while zmqr.healthy() and running:
if need_reconfig:
Expand Down Expand Up @@ -119,7 +119,8 @@ def sig_handler(_sig=None, _frame=None):
config.fft_len,
config.freq_resolution,
)
plot = WaterfallPlot(config, base_save_path, peak_finder, 1)
plot_manager.close()
plot_manager.add_plot(config, 0)
results = [
(scan_configs, frame_resample(scan_df, config.freq_resolution * 1e6))
]
Expand All @@ -131,11 +132,11 @@ def sig_handler(_sig=None, _frame=None):
need_reconfig = False
need_init = True
if need_init:
plot.init_fig(onresize)
plot_manager.init_fig(onresize)
need_init = False
need_reset_fig = True
if need_reset_fig:
plot.reset_fig()
plot_manager.reset_fig()
need_reset_fig = False
last_gap = time.time()
while True:
Expand Down Expand Up @@ -167,7 +168,7 @@ def sig_handler(_sig=None, _frame=None):
rotate_secs,
save_time,
)
if last_config != config:
if plot_manager.config_changed(last_config):
logging.info("scanner config change detected")
results = []
need_reconfig = True
Expand All @@ -184,9 +185,8 @@ def sig_handler(_sig=None, _frame=None):
if need_reconfig:
continue
if results:
plot.update_fig(results)
if plot.need_init():
need_init = True
plot_manager.update_fig(results)
need_init = plot_manager.need_init()
results = []
else:
time.sleep(0.1)
Expand Down
47 changes: 45 additions & 2 deletions gamutrfwaterfall/gamutrfwaterfall/waterfall_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,11 @@ def make_config(


class WaterfallPlot:
def __init__(self, config, base_save_path, peak_finder, num):
def __init__(self, peak_finder, config, num):
self.config = config
self.num = num
X, Y = self.meshgrid(1, config.waterfall_height, config.waterfall_height)
self.state = WaterfallState(base_save_path, peak_finder, X, Y)
self.state = WaterfallState(config.base_save_path, peak_finder, X, Y)
matplotlib.use(self.config.engine)
style.use("fast")

Expand Down Expand Up @@ -218,6 +218,11 @@ def init_fig(self, onresize):
if not self.config.batch:
self.state.fig.canvas.mpl_connect("resize_event", onresize)

def close(self):
if self.state.fig:
plt.close(self.state.fig)
self.state.fig = None

def reset_mesh_psd(self, data=None):
if self.state.mesh_psd:
self.state.mesh_psd.remove()
Expand Down Expand Up @@ -821,3 +826,41 @@ def safe_savefig(self, path):
os.rename(tmp_path, path)
logging.debug("wrote %s", path)
return path


class WaterfallPlotManager:
def __init__(self, peak_finder):
self.plots = []
self.config = None
self.peak_finder = peak_finder

def config_changed(self, config):
return self.config != config

def add_plot(self, config, num):
if not self.plots:
self.config = config
self.plots.append(WaterfallPlot(self.peak_finder, config, num))

def close(self):
for plot in self.plots:
plot.close()
self.plots = []
self.config = None

def update_fig(self, results):
for plot in self.plots:
plot.update_fig(results)

def reset_fig(self):
for plot in self.plots:
plot.reset_fig()

def init_fig(self, onresize):
for plot in self.plots:
plot.init_fig(onresize)

def need_init(self):
if self.plots:
return self.plots[0].need_init()
return False

0 comments on commit dab0080

Please sign in to comment.