Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update multirecording_spikeanalysis.py #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions multirecording_spikeanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pandas as pd
import matplotlib.pyplot as plt

from collections import defaultdict
from scipy.stats import sem, ranksums, fisher_exact, wilcoxon
from statistics import mean, StatisticsError
from sklearn.decomposition import PCA
Expand Down Expand Up @@ -439,9 +440,9 @@ def get_spike_specs(self):

def get_unit_timestamps(self):
"""
creates a dictionary of units to spike timestamps
keys are unit ids (int) and values are spike timestamps for
that unit (numpy arrays)and assigns dictionary to self.unit_timestamps
Creates a dictionary of units to spike timestamps.
Keys are unit ids (int) and values are spike timestamps for that unit (numpy arrays),
and assigns dictionary to self.unit_timestamps.

Args:
None
Expand All @@ -450,21 +451,16 @@ def get_unit_timestamps(self):
None
"""

unit_timestamps = {}
for spike in range(len(self.timestamps_var)):
if self.unit_array[spike] in unit_timestamps.keys():
timestamp_list = unit_timestamps[self.unit_array[spike]]
timestamp_list = np.append(
timestamp_list, self.timestamps_var[spike]
)
unit_timestamps[self.unit_array[spike]] = timestamp_list
else:
unit_timestamps[self.unit_array[spike]] = self.timestamps_var[
spike
]
# Initialize a defaultdict for holding lists
unit_timestamps = defaultdict(list)
default_dict = defaultdict(lambda: np.array([]))

self.unit_timestamps = unit_timestamps
# Loop through each spike only once
for spike, unit in enumerate(self.unit_array):
# Append the timestamp to the list for the corresponding unit
unit_timestamps[unit].append(self.timestamps_var[spike])

self.unit_timestamps = unit_timestamps

class EphysRecordingCollection:
"""
Expand Down