save redetected spikes in extra folder

This commit is contained in:
Alexander Ott 2021-07-02 15:06:04 +02:00
parent 8e6ef4869c
commit a3882f0a24
5 changed files with 41 additions and 17 deletions

View File

@ -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()

View File

@ -1,14 +1,14 @@
# 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

View File

@ -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

View File

@ -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

View File

@ -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