33import imageio .v3 as imageio
44from glob import glob
55
6+ import matplotlib
67import matplotlib .pyplot as plt
78import numpy as np
89import pandas as pd
910from 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
1314INPUT_ROOT = "/home/pape/Work/my_projects/flamingo-tools/scripts/M_LR_000227_R/scale3/frequency_mapping"
1415
1516png_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
7474def fig_03c_rl (save_path , plot = False ):
@@ -102,7 +102,9 @@ def fig_03c_rl(save_path, plot=False):
102102
103103
104104def 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.
0 commit comments