Skip to content

Commit 507ffa7

Browse files
Merge pull request #255 from katzlabbrandeis/239-voltage-cutoff-detection-params
feat: Add red horizontal lines to indicate voltage cutoff thresholds …
2 parents 4ca29ac + effd259 commit 507ffa7

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

utils/blech_process_utils.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,7 @@ def __init__(self, hdf5_path, electrode_num, params_dict):
788788
hf5.close()
789789

790790
def filter_electrode(self):
791+
# Raw units get multiplied by 0.195 to get MICROVOLTS
791792
self.filt_el = clust.get_filtered_electrode(
792793
self.raw_el,
793794
freq=[self.params_dict['bandpass_lower_cutoff'],
@@ -846,16 +847,33 @@ def make_cutoff_plot(self):
846847
recording_cutoff: int
847848
"""
848849
fig = plt.figure()
850+
# filt_el is in microvolts
849851
second_data = np.reshape(
850852
self.filt_el,
851853
(-1, self.params_dict['sampling_rate']))
852-
plt.plot(np.mean(second_data, axis=1))
854+
mean_data = np.mean(second_data, axis=1)
855+
std_data = np.std(second_data, axis=1)
856+
plt.plot(mean_data, label = 'Mean')
857+
plt.fill_between(
858+
x = np.arange(len(mean_data)),
859+
y1 = mean_data + std_data,
860+
y2 = mean_data - std_data,
861+
label = 'STD',
862+
)
853863
plt.axvline(self.recording_cutoff,
854-
color='k', linewidth=4.0, linestyle='--')
864+
color='k', linewidth=2, linestyle='--',
865+
label = 'Recording cutoff')
866+
plt.axhline(self.params_dict['voltage_cutoff'],
867+
color='r', linewidth=2.0, linestyle='--',
868+
label='Voltage cutoff')
869+
plt.axhline(-self.params_dict['voltage_cutoff'],
870+
color='r', linewidth=2.0, linestyle='--')
855871
plt.xlabel('Recording time (secs)')
856872
plt.ylabel('Average voltage recorded per sec (microvolts)')
857873
plt.title(f'Recording length : {len(second_data)}s' + '\n' +
858874
f'Cutoff time : {self.recording_cutoff}s')
875+
plt.legend()
876+
plt.yscale('symlog')
859877
fig.savefig(
860878
f'./Plots/{self.electrode_num:02}/cutoff_time.png',
861879
bbox_inches='tight')
@@ -996,6 +1014,24 @@ def return_cutoff_values(
9961014
max_secs_above_cutoff,
9971015
max_mean_breach_rate_persec
9981016
):
1017+
"""
1018+
Return the cutoff values for the electrode recording
1019+
1020+
Inputs:
1021+
filt_el: numpy array (in
1022+
sampling_rate: int
1023+
voltage_cutoff: float
1024+
max_breach_rate: float
1025+
max_secs_above_cutoff: float
1026+
max_mean_breach_rate_persec: float
1027+
1028+
Outputs:
1029+
breach_rate: float
1030+
breaches_per_sec: numpy array
1031+
secs_above_cutoff: int
1032+
mean_breach_rate_persec: float
1033+
recording_cutoff: int
1034+
"""
9991035

10001036
breach_rate = float(len(np.where(filt_el > voltage_cutoff)[0])
10011037
* int(sampling_rate))/len(filt_el)

0 commit comments

Comments
 (0)