Skip to content

Commit cadf297

Browse files
Some plot updates
1 parent ec8b6f5 commit cadf297

File tree

3 files changed

+52
-46
lines changed

3 files changed

+52
-46
lines changed

scripts/figures/plot_fig2.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pandas as pd
66
import matplotlib.pyplot as plt
77

8-
from util import literature_reference_values
8+
from util import literature_reference_values, SYNAPSE_DIR_ROOT
99

1010
png_dpi = 300
1111

@@ -66,10 +66,10 @@ def fig_02c(save_path, plot=False, all_versions=False):
6666
# Plot
6767
plt.figure(figsize=(8, 5))
6868

69-
main_label_size = 20
69+
main_label_size = 22
7070
sub_label_size = 16
71-
main_tick_size = 12
72-
legendsize = 16
71+
main_tick_size = 16
72+
legendsize = 18
7373

7474
plt.scatter(x - offset, precision, label="Precision", marker="o", s=80)
7575
plt.scatter(x, recall, label="Recall", marker="^", s=80)
@@ -100,7 +100,7 @@ def fig_02c(save_path, plot=False, all_versions=False):
100100
# Load the synapse counts for all IHCs from the relevant tables.
101101
def _load_ribbon_synapse_counts():
102102
ihc_version = "ihc_counts_v4c"
103-
synapse_dir = f"/mnt/vast-nhr/projects/nim00007/data/moser/cochlea-lightsheet/predictions/synapses/{ihc_version}"
103+
synapse_dir = os.path.join(SYNAPSE_DIR_ROOT, ihc_version)
104104
tables = [entry.path for entry in os.scandir(synapse_dir) if "ihc_count_M_LR" in entry.name]
105105
syn_counts = []
106106
for tab in tables:
@@ -112,8 +112,8 @@ def _load_ribbon_synapse_counts():
112112
def fig_02d_01(save_path, plot=False, all_versions=False, plot_average_ribbon_synapses=False):
113113
"""Box plot showing the counts for SGN and IHC per (mouse) cochlea in comparison to literature values.
114114
"""
115-
main_tick_size = 16
116-
main_label_size = 24
115+
main_tick_size = 20
116+
main_label_size = 26
117117

118118
rows = 1
119119
columns = 3 if plot_average_ribbon_synapses else 2
@@ -217,7 +217,7 @@ def fig_02d_02(save_path, filter_zeros=True, plot=False):
217217
"""
218218
cochleae = ["M_LR_000226_L", "M_LR_000226_R", "M_LR_000227_L", "M_LR_000227_R"]
219219
ihc_version = "ihc_counts_v4b"
220-
synapse_dir = f"/mnt/vast-nhr/projects/nim00007/data/moser/cochlea-lightsheet/predictions/synapses/{ihc_version}"
220+
synapse_dir = os.path.join(SYNAPSE_DIR_ROOT, ihc_version)
221221

222222
max_dist = 3
223223
bins = 10

scripts/figures/plot_fig3.py

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,29 @@
33
import imageio.v3 as imageio
44
from glob import glob
55

6+
import matplotlib
67
import matplotlib.pyplot as plt
78
import numpy as np
89
import pandas as pd
910
from matplotlib import cm, colors
1011

11-
from util import sliding_runlength_sum, frequency_mapping
12+
from util import sliding_runlength_sum, frequency_mapping, SYNAPSE_DIR_ROOT
1213

1314
INPUT_ROOT = "/home/pape/Work/my_projects/flamingo-tools/scripts/M_LR_000227_R/scale3/frequency_mapping"
1415

1516
png_dpi = 300
1617

1718

18-
def fig_03a(save_path):
19-
import napari
20-
21-
path = os.path.join(INPUT_ROOT, "frequencies_IHC_v4c.tif")
22-
vol = imageio.imread(path)
19+
def _plot_colormap(vol, title, plot, save_path):
20+
# before creating the figure:
21+
matplotlib.rcParams.update({
22+
"font.size": 14, # base font size
23+
"axes.titlesize": 18, # for plt.title / ax.set_title
24+
"figure.titlesize": 18, # for fig.suptitle (if you use it)
25+
"xtick.labelsize": 14,
26+
"ytick.labelsize": 14,
27+
"legend.fontsize": 14,
28+
})
2329

2430
# Create the colormap
2531
fig, ax = plt.subplots(figsize=(6, 1.3))
@@ -32,43 +38,37 @@ def fig_03a(save_path):
3238

3339
cb = plt.colorbar(cm.ScalarMappable(norm=norm, cmap=cmap), cax=ax, orientation="horizontal")
3440
cb.set_label("Frequency [kHz]")
35-
plt.title("Tonotopic Mapping: IHCs")
41+
plt.title(title)
3642
plt.tight_layout()
37-
out_path = os.path.join(save_path)
38-
plt.savefig(out_path)
39-
40-
# Show the image in napari for rendering.
41-
v = napari.Viewer()
42-
v.add_image(vol, colormap="viridis")
43-
napari.run()
44-
43+
if plot:
44+
plt.show()
45+
plt.savefig(save_path)
46+
plt.close()
4547

46-
def fig_03b(save_path):
47-
import napari
4848

49-
path = os.path.join(INPUT_ROOT, "frequencies_SGN_v2.tif")
49+
def fig_03a(save_path, plot, plot_napari):
50+
path = os.path.join(INPUT_ROOT, "frequencies_IHC_v4c.tif")
5051
vol = imageio.imread(path)
52+
_plot_colormap(vol, title="Tonotopic Mapping: IHCs", plot=plot, save_path=save_path)
5153

52-
# Create the colormap
53-
fig, ax = plt.subplots(figsize=(6, 1.3))
54-
fig.subplots_adjust(bottom=0.5)
54+
# Show the image in napari for rendering.
55+
if plot_napari:
56+
import napari
57+
v = napari.Viewer()
58+
v.add_image(vol, colormap="viridis")
59+
napari.run()
5560

56-
freq_min = np.min(np.nonzero(vol))
57-
freq_max = vol.max()
58-
norm = colors.Normalize(vmin=freq_min, vmax=freq_max, clip=True)
59-
cmap = plt.get_cmap("viridis")
6061

61-
cb = plt.colorbar(cm.ScalarMappable(norm=norm, cmap=cmap), cax=ax, orientation="horizontal")
62-
cb.set_label("Frequency [kHz]")
63-
plt.title("Tonotopic Mapping: SGNs")
64-
plt.tight_layout()
65-
out_path = os.path.join(save_path)
66-
plt.savefig(out_path)
62+
def fig_03b(save_path, plot, plot_napari):
63+
path = os.path.join(INPUT_ROOT, "frequencies_SGN_v2.tif")
64+
vol = imageio.imread(path)
65+
_plot_colormap(vol, title="Tonotopic Mapping: SGNs", plot=plot, save_path=save_path)
6766

6867
# Show the image in napari for rendering.
69-
v = napari.Viewer()
70-
v.add_image(vol, colormap="viridis")
71-
napari.run()
68+
if plot_napari:
69+
import napari
70+
v = napari.Viewer()
71+
v.add_image(vol, colormap="viridis")
7272

7373

7474
def fig_03c_rl(save_path, plot=False):
@@ -102,7 +102,9 @@ def fig_03c_rl(save_path, plot=False):
102102

103103

104104
def fig_03c_octave(save_path, plot=False):
105-
tables = glob("./ihc_counts/ihc_count_M_LR*.tsv")
105+
# TODO update this table
106+
ihc_version = "ihc_counts_v4c"
107+
tables = glob(os.path.join(SYNAPSE_DIR_ROOT, ihc_version, "ihc_count_M_LR*.tsv"))
106108

107109
result = {"cochlea": [], "octave_band": [], "value": []}
108110
for tab_path in tables:
@@ -152,14 +154,14 @@ def main():
152154
os.makedirs(args.figure_dir, exist_ok=True)
153155

154156
# Panel A: Tonotopic mapping of IHCs (rendering in napari)
155-
# fig_03a(save_path=os.path.join(args.figure_dir, "fig_03a.png"))
157+
fig_03a(save_path=os.path.join(args.figure_dir, "fig_03a.png"), plot=args.plot, plot_napari=False)
156158

157159
# Panel B: Tonotopic mapping of SGNs (rendering in napari)
158-
# fig_03b(save_path=os.path.join(args.figure_dir, "fig_03b.png"))
160+
fig_03b(save_path=os.path.join(args.figure_dir, "fig_03b.png"), plot=args.plot, plot_napari=False)
159161

160162
# Panel C: Spatial distribution of synapses across the cochlea.
161163
# We have two options: running sum over the runlength or per octave band
162-
fig_03c_rl(save_path=os.path.join(args.figure_dir, "fig_03c_runlength.png"), plot=args.plot)
164+
# fig_03c_rl(save_path=os.path.join(args.figure_dir, "fig_03c_runlength.png"), plot=args.plot)
163165
fig_03c_octave(save_path=os.path.join(args.figure_dir, "fig_03c_octave.png"), plot=args.plot)
164166

165167
# TODO: Panel D: Spatial distribution of SGN sub-types.

scripts/figures/util.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import pandas as pd
22
import numpy as np
33

4+
# Directory with synapse measurement tables
5+
SYNAPSE_DIR_ROOT = "/mnt/vast-nhr/projects/nim00007/data/moser/cochlea-lightsheet/predictions/synapses"
6+
# SYNAPSE_DIR_ROOT = "./synapses"
7+
48

59
# Define the animal specific octave bands.
610
def _get_mapping(animal):

0 commit comments

Comments
 (0)