From 9701ef1a4d4587791a70953264b2f47ad96346c4 Mon Sep 17 00:00:00 2001 From: j-hartling Date: Fri, 13 Feb 2026 16:42:55 +0100 Subject: [PATCH] Syncing to home. --- .gitignore | 3 +- python/fig_pathway_stages.py | 60 ++++++++++++++++++++++++++++++++++++ python/plotstyle_plt.py | 48 +++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 python/fig_pathway_stages.py create mode 100644 python/plotstyle_plt.py diff --git a/.gitignore b/.gitignore index 07f43b8..3dc927c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -data/* \ No newline at end of file +data/* +./_pycache_/ \ No newline at end of file diff --git a/python/fig_pathway_stages.py b/python/fig_pathway_stages.py new file mode 100644 index 0000000..80e55d4 --- /dev/null +++ b/python/fig_pathway_stages.py @@ -0,0 +1,60 @@ +import glob +import plotstyle_plt +import numpy as np +import matplotlib.pyplot as plt +from thunderhopper.modeltools import load_data +from IPython import embed + +# GENERAL SETTINGS: +data_paths = glob.glob('../data/*.npz') +channel = 0 +stages_pre = ['raw', 'filt', 'env', 'log', 'inv'] +stages_feat = ['conv', 'bi', 'feat', 'norm'] + +# PLOT SETTINGS: +fig_kwargs = dict( + figsize = np.array([16, 9]) * 0.75, + layout = 'constrained', + sharex = 'col', + sharey = 'row' +) +zoom_rel = np.array([0.4, 0.6]) +colors_pre = ['k' for _ in range(len(stages_pre))] +colors_feat = ['k' for _ in range(len(stages_feat))] + +for data_path in data_paths: + # Load overall data: + data, config = load_data(data_path) + t_full = np.arange(data['raw'].shape[0]) / config['rate'] + + # Establish zoom frame: + zoom_abs = zoom_rel * t_full[-1] + zoom_mask = (t_full >= zoom_abs[0]) & (t_full <= zoom_abs[1]) + t_zoom = t_full[zoom_mask] + + # PART I: PREPROCESSING STAGE + fig, axes = plt.subplots(len(stages_pre), 2, **fig_kwargs) + + for i, stage in enumerate(stages_pre): + signal = data[stage][:, channel] + ax_full, ax_zoom = axes[i, :] + ax_full.plot(t_full, signal, c=colors_pre[i]) + ax_full.set_ylim(signal.min(), signal.max()) + + ax_zoom.plot(t_zoom, signal[zoom_mask], c=colors_pre[i]) + ax_full.set_xlim(t_full[0], t_full[-1]) + + # PART II: FEATURE EXTRACTION STAGE: + fig, axes = plt.subplots(len(stages_feat), 2, **fig_kwargs) + + for i, stage in enumerate(stages_feat): + signal = data[stage][:, ..., channel] + ax_full, ax_zoom = axes[i, :] + ax_full.plot(t_full, signal, c=colors_feat[i]) + ax_full.set_ylim(signal.min(), signal.max()) + + ax_zoom.plot(t_zoom, signal[zoom_mask, ...], c=colors_feat[i]) + ax_full.set_xlim(t_full[0], t_full[-1]) + plt.show() + + diff --git a/python/plotstyle_plt.py b/python/plotstyle_plt.py new file mode 100644 index 0000000..919545f --- /dev/null +++ b/python/plotstyle_plt.py @@ -0,0 +1,48 @@ +import matplotlib as mpl + +# Latex rendering disabled: +mpl.rcParams['text.usetex'] = False + +# Font style: +mpl.rcParams['font.style'] = 'normal' +mpl.rcParams['font.family'] = 'serif' +mpl.rcParams['mathtext.fontset'] = 'cm' +mpl.rcParams['mathtext.default'] = 'regular' +# Font sizes: +mpl.rcParams['font.size'] = 14 +mpl.rcParams['figure.titlesize'] = 15 +mpl.rcParams['axes.labelsize'] = 14 +mpl.rcParams['axes.titlesize'] = 14 +mpl.rcParams['xtick.labelsize'] = 13 +mpl.rcParams['ytick.labelsize'] = 13 +mpl.rcParams['legend.fontsize'] = 14 +mpl.rcParams['legend.title_fontsize'] = 14 +# Font weights: +single_weight = ['normal', 'bold'][0] +mpl.rcParams['font.weight'] = single_weight +mpl.rcParams['axes.labelweight'] = single_weight +mpl.rcParams['axes.titleweight'] = single_weight +mpl.rcParams['figure.titleweight'] = single_weight + +# Figure parameters: +mpl.rcParams['figure.figsize'] = (16/2.54, 9/2.54) +mpl.rcParams['figure.autolayout'] = False +mpl.rcParams['figure.raise_window'] = True +# mpl.rcParams['figure.dpi'] = 100 +# mpl.rcParams['savefig.dpi'] = 500 + +# Axes parameters: +mpl.rcParams['axes.spines.top'] = False +mpl.rcParams['axes.spines.right'] = False +mpl.rcParams['axes.xmargin'] = 0 +mpl.rcParams['axes.ymargin'] = 0 +mpl.rcParams['axes.autolimit_mode'] = 'round_numbers' +mpl.rcParams['axes.labelpad'] = 3 + +# Tick parameters: +mpl.rcParams['xtick.major.pad'] = 5 +mpl.rcParams['ytick.major.pad'] = 5 + +# Legend parameters: +mpl.rcParams['legend.frameon'] = False +mpl.rcParams['legend.scatterpoints'] = 3 \ No newline at end of file