stim values extraction but without functionality

This commit is contained in:
alexanderott 2021-03-07 18:33:21 +01:00
parent 8b10dba43b
commit df346b2a35
4 changed files with 52 additions and 28 deletions

View File

@ -3,6 +3,7 @@ from DatParser import DatParser
import numpy as np
from warnings import warn
import os
import matplotlib.pyplot as plt
@ -32,6 +33,7 @@ class Controller:
self.sorting = {}
self.thresholds = {}
self.stim_values = {}
self.recording_times = {}
def save_parameters(self):
@ -84,9 +86,10 @@ class Controller:
[time_traces, v1_traces, eod_traces, local_eod_traces, stimulus_traces] = self.get_unsorted_traces(repro)
(spiketimes, metadata) = self.get_unsorted_spiketimes(repro)
repro_stim_values = self.extract_stim_values(repro, metadata)
self.stim_values[repro] = repro_stim_values
if len(v1_traces) != len(spiketimes):
warn("get_traces_with_spiketimes():Unequal number of traces and spiketimes for repro {}!"
"Returning only according to the number of traces!".format(repro))
warn("get_traces_with_spiketimes():Unequal number of traces ({}) and spiketimes ({}) for repro {}! Returning only according to the number of traces!".format(len(v1_traces), len(spiketimes), repro))
ash = calculate_distance_matrix_traces_spikes(v1_traces, spiketimes, self.parser.get_sampling_interval(), before)
@ -102,13 +105,35 @@ class Controller:
return v1_traces, sorted_spiketimes, (before, after)
def get_stim_values(self, repro):
return sorted(np.unique(self.stim_values[repro]))
def extract_stim_values(self, repro, metadata_list):
stim_values = []
if repro == "BaselineActivity":
return ["None"]
for i in range(len(metadata_list)):
stim_values.append("None")
elif repro == "FICurve":
# TODO other function that just provides the contrasts
return sorted([str(x[0]) for x in self.parser.get_fi_curve_contrasts()])
current_intensity = None
for i in range(len(metadata_list)):
if len(metadata_list[i]) != 0:
current_intensity = float(metadata_list[i][-1]["intensity"][:-2])
stim_values.append(current_intensity)
elif repro == "FileStimulus":
for i in range(len(metadata_list)):
stim_values.append(os.path.basename(metadata_list[i][0]["file"]))
elif repro == "SAM":
for i in range(len(metadata_list)):
deltaf = metadata_list[i][0]["----- Stimulus -------------------------------------------------------"]["deltaf"]
contrast = metadata_list[i][0]["----- Stimulus -------------------------------------------------------"]["contrast"]
stim_values.append("{} {}".format(deltaf, contrast))
if len(stim_values) == 0:
return ["Stimulus values of repro not supported"]
return ["repro not supported"]
return stim_values
def get_trials(self, repro, stimulus_value):
pass

View File

@ -1,7 +1,7 @@
from PyQt5.QtWidgets import QWidget, QPushButton, QSizePolicy, QLineEdit,\
QMessageBox, QVBoxLayout, QHBoxLayout, QGridLayout, QLabel, QFrame,\
QDoubleSpinBox, QComboBox, QSpinBox, QCheckBox
QDoubleSpinBox, QComboBox, QSpinBox, QCheckBox, QFileDialog
from PyQt5.QtCore import pyqtSlot
import numpy as np
@ -14,9 +14,13 @@ from redetector import detect_spiketimes
class SpikeRedetectGui(QWidget):
def __init__(self, controller: Controller):
def __init__(self, data_path=None):
super().__init__()
self.controller = controller
if data_path is None:
data_path = QFileDialog.getExistingDirectory(self, caption='Select a cell directory:')
self.controller = Controller(data_path)
self.title = 'Spike Redetection'
self.left = 10
self.top = 10
@ -188,6 +192,9 @@ class SpikeRedetectGui(QWidget):
def repro_change(self):
repro = self.repro_box.currentText()
redetection = (self.threshold_spinbox.value(), self.window_spinbox.value(), self.step_spinbox.value())
self.canvas.plot(self.trial_idx, self.repro_box.currentText(), self.controller, redetection)
# reset trials and stim values
self.trial_change(0)
self.stim_val_box.clear()
@ -195,8 +202,7 @@ class SpikeRedetectGui(QWidget):
for val in self.controller.get_stim_values(repro):
self.stim_val_box.addItem(str(val))
redetection = (self.threshold_spinbox.value(), self.window_spinbox.value(), self.step_spinbox.value())
self.canvas.plot(self.trial_idx, self.repro_box.currentText(), self.controller, redetection)
@pyqtSlot()
def accept_redetection(self):
@ -320,9 +326,9 @@ class PlotCanvas(FigureCanvas):
ax.clear()
time = np.arange(len(trace)) * sampling_interval - recording_times[0]
ax.plot(time, trace)
ax.eventplot(spiketimes, lineoffsets=max(trace) + 1, colors="black")
ax.eventplot(spiketimes, lineoffsets=max(trace) + 2, colors="black")
redetect = detect_spiketimes(time, trace, redetection_vars[0], redetection_vars[1], redetection_vars[2])
ax.eventplot(redetect, lineoffsets=max(trace) + 2, colors="red")
ax.eventplot(redetect, lineoffsets=max(trace) + 1, colors="red")
ax.set_title('Trial XYZ')
if self.current_repro == repro:

19
main.py
View File

@ -1,28 +1,21 @@
import sys
import os
from PyQt5.QtWidgets import QApplication, QFileDialog
from PyQt5.QtWidgets import QApplication
from Controller import Controller
from SpikeRedetectGui import SpikeRedetectGui
test_file = "../neuronModel/data/final_sam/2010-11-08-al-invivo-1"
sam_file = "../neuronModel/data/final_sam/2011-10-25-ad-invivo-1"
# TODO CLI
def main():
app = QApplication(sys.argv)
data_path = QFileDialog.getExistingDirectory(caption='Select a directory')
if os.path.isdir(data_path):
data_provider = Controller(data_path)
else:
print("Cell loading didn't work!\n Cell folder: {}".format(data_path))
return
#data_provider = Controller(test_file)
ex = SpikeRedetectGui(data_provider)
sys.exit(app.exec_())
ex = SpikeRedetectGui(sam_file)
sys.exit(app.exec_())
if __name__ == '__main__':

View File

@ -16,14 +16,14 @@ def detect_spike_indices_automatic_split(v1, threshold, min_length=5000, split_s
break_threshold = 0.25
splits = []
if len(v1) < min_length:
if len(v1) <= min_length:
splits = [(0, len(v1))]
else:
last_max = max(v1[0:min_length])
last_min = min(v1[0:min_length])
idx = min_length
while idx < len(v1):
while idx <= len(v1):
if idx + step_size > len(v1):
splits.append((split_start, len(v1)))
break