Skip to content

Commit 478bc0f

Browse files
Update frequency mapping plots to accept custom bins
1 parent 90740e6 commit 478bc0f

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

scripts/figures/plot_fig6.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,26 @@ def fig_06e_octave(otof_data, save_path, plot=False, use_alias=True, trendline_m
153153
color_dict[alias] = COCHLEAE_DICT[name]["color"]
154154
if mapping == "default":
155155
freq = values["frequency[kHz]"].values
156+
bin_edges, bin_labels = None, None
156157
elif mapping == "mueller":
157158
freq = values["frequency-mueller[kHz]"].values
159+
# We need custom bin edges and bin labels in this case.
160+
bin_edges = [0, 8, 12, 16, 24, np.inf]
161+
bin_labels = [
162+
"4-8", "8-12", "12–16", "16-24", "24-32"
163+
]
164+
assert len(bin_edges) == len(bin_labels) + 1
158165
else:
159166
raise ValueError("Choose either 'default' or 'mueller' for tonotopic mapping.")
160167
marker_labels = values["expression_classification"].values
161168
marker_pos = len([1 for i in marker_labels if i == 1])
162169
marker_neg = len([1 for i in marker_labels if i == 2])
163170
expression_eff = marker_pos / (marker_pos + marker_neg)
164171
print(f"Cochlea {name}, average expression efficiency {expression_eff}")
165-
octave_binned = frequency_mapping(freq, marker_labels, animal="mouse", transduction_efficiency=True)
172+
octave_binned = frequency_mapping(
173+
freq, marker_labels, animal="mouse", transduction_efficiency=True,
174+
bin_edges=bin_edges, bin_labels=bin_labels
175+
)
166176

167177
result["cochlea"].extend([alias] * len(octave_binned))
168178
result["octave_band"].extend(octave_binned.axes[0].values.tolist())

scripts/figures/util.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,13 @@ def _get_mapping(animal):
144144
return bin_edges, bin_labels
145145

146146

147-
def frequency_mapping(frequencies, values, animal="mouse", transduction_efficiency=False):
147+
def frequency_mapping(
148+
frequencies, values, animal="mouse", transduction_efficiency=False, bin_edges=None, bin_labels=None
149+
):
148150
# Get the mapping of frequencies to octave bands for the given species.
149-
bin_edges, bin_labels = _get_mapping(animal)
151+
if bin_edges is None:
152+
assert bin_labels is None
153+
bin_edges, bin_labels = _get_mapping(animal)
150154

151155
# Construct the data frame with octave bands.
152156
df = pd.DataFrame({"freq_khz": frequencies, "value": values})

0 commit comments

Comments
 (0)