Skip to content

Commit

Permalink
latency fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zm711 committed Oct 3, 2023
1 parent c581243 commit e7c5529
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/spikeanalysis/analysis_utils/latency_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ def latency_core_stats(bsl_fr: float, firing_data: np.array, time_bin_size: floa
)
if final_prob <= 10e-6:
break
elif n_bin * time_bin_size >= 0.200: # past 200 ms is not really a true latency
elif n_bin * time_bin_size >= 0.400: # past 400 ms is not really a true latency
n_bin = np.shape(firing_data)[1] - 2
break

if n_bin == np.shape(firing_data)[1] - 2: # need to go to second last bin
latency[trial] = np.nan
else:
latency[trial] = (n_bin + 1) * time_bin_size
if n_bin == np.shape(firing_data)[1] - 2: # need to go to second last bin
latency[trial] = np.nan
else:
latency[trial] = (n_bin + 1) * time_bin_size

return latency

Expand All @@ -37,7 +37,7 @@ def latency_median(firing_counts: np.array, time_bin_size: float):
latency = np.zeros((np.shape(firing_counts)[0]))
for trial in range(np.shape(firing_counts)[0]):
min_spike_time = np.nonzero(firing_counts[trial])[0]
if len(min_spike_time) == 0:
if len(min_spike_time) == 0 or (np.min(min_spike_time) + 1) * time_bin_size > 0.400:
latency[trial] = np.nan
else:
latency[trial] = (np.min(min_spike_time) + 1) * time_bin_size
Expand Down
8 changes: 6 additions & 2 deletions test/test_latency_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ def test_latency_median():
]
)
test_array = np.expand_dims(test_array, axis=0)
lat = lf.latency_median(test_array, time_bin_size=1)
lat = lf.latency_median(test_array, time_bin_size=0.1)
print(lat)
assert lat == [3.0]
assert round(lat[0], 2) == 0.30

# nan test
lat = lf.latency_median(test_array, time_bin_size=1)
assert np.isnan(lat)


def test_latency_nan():
Expand Down

0 comments on commit e7c5529

Please sign in to comment.