save redetected spikes in extra folder
This commit is contained in:
parent
8e6ef4869c
commit
a3882f0a24
@ -4,6 +4,7 @@ from DatParser import DatParser
|
||||
import numpy as np
|
||||
from warnings import warn
|
||||
import os
|
||||
from redetector import detect_spiketimes
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
@ -39,7 +40,6 @@ class Controller:
|
||||
def save_parameters(self, folder_path):
|
||||
header = "trial_index,threshold,min_window,step_size\n"
|
||||
for repro in self.thresholds.keys():
|
||||
# TODO change '.' to self.data_path after testing:
|
||||
with open(folder_path + "/{}_thresholds.csv".format(repro), "w") as threshold_file:
|
||||
threshold_file.write(header)
|
||||
for i in range(len(self.sorting[repro])):
|
||||
@ -56,11 +56,32 @@ class Controller:
|
||||
|
||||
def save_redetected_spikes(self, folder_path):
|
||||
# TODO save redetected spikes:
|
||||
header = "trial_index,threshold,min_window,step_size\n"
|
||||
redetection_folder = folder_path + "/redetected_spikes/"
|
||||
if not os.path.exists(redetection_folder):
|
||||
os.mkdir(redetection_folder)
|
||||
|
||||
for repro in self.thresholds.keys():
|
||||
# TODO change '.' to self.data_path after testing:
|
||||
with open(folder_path + "/{}_thresholds.csv".format(repro), "w") as threshold_file:
|
||||
threshold_file.write(header)
|
||||
for i in range(len(self.sorting[repro])):
|
||||
if len(self.thresholds[repro][i]) == 0:
|
||||
continue # If no params were saved, saving a redetection file makes no sense
|
||||
else:
|
||||
# format and write given thresholding parameters
|
||||
# i is the trial idx
|
||||
thresh = self.thresholds[repro][i][0]
|
||||
min_window = self.thresholds[repro][i][1]
|
||||
step = self.thresholds[repro][i][2]
|
||||
|
||||
traces, spiketimes, recording_times = self.get_traces_with_spiketimes(repro)
|
||||
trace = traces[i]
|
||||
spiketimes = spiketimes[i]
|
||||
recording_times = recording_times
|
||||
sampling_interval = self.sampling_interval
|
||||
|
||||
time = np.arange(len(trace)) * sampling_interval - recording_times[0]
|
||||
redetect = detect_spiketimes(time, trace, thresh, min_window, step)
|
||||
|
||||
np.save(redetection_folder + "spikes_repro_{}_trial_{}.npy".format(repro, i), np.array(redetect))
|
||||
print("Redetected spikes saved!")
|
||||
|
||||
def get_repros(self):
|
||||
return self.parser.get_measured_repros()
|
||||
@ -193,4 +214,4 @@ def average_spike_height(spike_train: np.ndarray, v1: np.ndarray, sampling_rate,
|
||||
# spike_values = [v1[i] for i in indices if 0 <= i < len(v1)]
|
||||
# average_height = np.mean(spike_values)
|
||||
#
|
||||
# return average_height
|
||||
# return average_height
|
||||
|
14
ReadMe.md
14
ReadMe.md
@ -1,15 +1,15 @@
|
||||
# Spike redetector
|
||||
# Spike Redetector
|
||||
|
||||
###redetection parameters:
|
||||
### Redetection Parameters:
|
||||
|
||||
- **Threshold**: number of standard deviations between a maximum and a minimum to count as a spike.
|
||||
- **Min window size**: The minimum size of a window (as number of indices) in which spikes are detected. The voltage trace is split into parts
|
||||
- ***Threshold***: number of standard deviations between a maximum and a minimum to count as a spike.
|
||||
- ***Min window size***: The minimum size of a window (as number of indices) in which spikes are detected. The voltage trace is split into parts
|
||||
if the maximum or minimum of the next part are too different from the current part.
|
||||
This makes the estimation of the STD a lot more stable between trials where the absolute voltage might wander.
|
||||
- **step size**: The number of indices that are used in each step while trying to increase the size of the window.
|
||||
- ***step size***: The number of indices that are used in each step while trying to increase the size of the window.
|
||||
|
||||
### plot controls:
|
||||
### Plot Controls:
|
||||
|
||||
- Drag and drop with LMB
|
||||
|
||||
- zoom control with RMB -> press and hold; up down is zoom on y-axis while left right is zoom on x-axis
|
||||
- zoom control with RMB -> press and hold; up down is zoom on y-axis while left right is zoom on x-axis
|
||||
|
@ -219,7 +219,6 @@ class SpikeRedetectGui(QWidget):
|
||||
|
||||
@pyqtSlot()
|
||||
def save_threshold_parameters(self):
|
||||
# TODO add question for save_path
|
||||
data_path = QFileDialog.getExistingDirectory(self, directory=self.controller.data_path, caption='Select a folder to save the parameters:')
|
||||
if data_path is None:
|
||||
return
|
||||
|
3
main.py
3
main.py
@ -1,12 +1,11 @@
|
||||
|
||||
import sys
|
||||
|
||||
from PyQt5.QtWidgets import QApplication
|
||||
|
||||
from SpikeRedetectGui import SpikeRedetectGui
|
||||
|
||||
|
||||
test_file = "../neuronModel/data/final_sam/2010-11-08-al-invivo-1"
|
||||
test_file = "../neuronModel/data/final/2010-11-08-al-invivo-1"
|
||||
sam_file = "../neuronModel/data/final_sam/2011-10-25-ad-invivo-1"
|
||||
# TODO CLI
|
||||
|
||||
|
@ -14,6 +14,11 @@ failure_to_read_sam = ["2012-06-27-an-invivo-1", "2012-12-13-ag-invivo-1"]
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
test = np.load("redetected_spikes/spikes_repro_BaselineActivity_trial_0.npy")
|
||||
print()
|
||||
|
||||
|
||||
for cell in sorted(os.listdir(DATA_FOLDER)):
|
||||
if cell in failure_to_read_sam:
|
||||
continue
|
||||
@ -77,4 +82,4 @@ def test_getting_repros(data_provider: Controller):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user