signature
stringlengths 8
3.44k
| body
stringlengths 0
1.41M
| docstring
stringlengths 1
122k
| id
stringlengths 5
17
|
|---|---|---|---|
def view(self):
|
return self.paramList<EOL>
|
Gets the AutoParameter View
:returns: :class:`AutoParameterTableView<sparkle.gui.stim.auto_parameter_view.AutoParameterTableView>`
|
f10647:c0:m1
|
def setModel(self, model):
|
self.paramList.setModel(model)<EOL>model.hintRequested.connect(self.hintRequested)<EOL>model.rowsInserted.connect(self.updateTitle)<EOL>model.rowsRemoved.connect(self.updateTitle)<EOL>self.updateTitle()<EOL>
|
sets the model for the auto parameters
:param model: The data stucture for this editor to provide access to
:type model: :class:`QAutoParameterModel<sparkle.gui.stim.qauto_parameter_model.QAutoParameterModel>`
|
f10647:c0:m2
|
def updateTitle(self):
|
title = '<STR_LIT>'.format(self.paramList.model().rowCount())<EOL>self.titleChange.emit(title)<EOL>self.setWindowTitle(title)<EOL>
|
Updates the Title of this widget according to how many parameters are currently in the model
|
f10647:c0:m3
|
def showEvent(self, event):
|
selected = self.paramList.selectedIndexes()<EOL>model = self.paramList.model()<EOL>self.visibilityChanged.emit(<NUM_LIT:1>)<EOL>if len(selected) > <NUM_LIT:0>:<EOL><INDENT>self.paramList.parameterChanged.emit(model.selection(selected[<NUM_LIT:0>]))<EOL>self.hintRequested.emit('<STR_LIT>')<EOL><DEDENT>elif model.rowCount() > <NUM_LIT:0>:<EOL><INDENT>self.paramList.selectRow(<NUM_LIT:0>)<EOL>self.paramList.parameterChanged.emit(model.selection(model.index(<NUM_LIT:0>,<NUM_LIT:0>)))<EOL>self.hintRequested.emit('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>model.emptied.emit(True)<EOL>self.hintRequested.emit('<STR_LIT>')<EOL><DEDENT>
|
When this widget is shown it has an effect of putting
other widgets in the parent widget into different editing modes, emits
signal to notify other widgets. Restores the previous selection the last
time this widget was visible
|
f10647:c0:m4
|
def hideEvent(self, event):
|
self.visibilityChanged.emit(<NUM_LIT:0>)<EOL>self.hintRequested.emit('<STR_LIT>')<EOL>
|
notifies other widgets this editor is not longer visible
|
f10647:c0:m5
|
def closeEvent(self, event):
|
self.visibilityChanged.emit(<NUM_LIT:0>)<EOL>model = self.paramList.model()<EOL>model.hintRequested.disconnect()<EOL>model.rowsInserted.disconnect()<EOL>model.rowsRemoved.disconnect()<EOL>
|
Emits a signal to update start values on components
|
f10647:c0:m6
|
def updateTitle(self, title):
|
self.title.setText(title)<EOL>
|
Updates the title of this widget
|
f10647:c1:m1
|
def grabImage(self, index):
|
<EOL>row_height = self.rowHeight(<NUM_LIT:0>)<EOL>y = (row_height*index.row()) + row_height - <NUM_LIT:5><EOL>x = self.width()<EOL>rect = QtCore.QRect(<NUM_LIT:5>,y,x,row_height)<EOL>pixmap = QtGui.QPixmap()<EOL>pixmap = pixmap.grabWidget(self, rect)<EOL>return pixmap<EOL>
|
Returns an image of the parameter row.
Re-implemented from :meth:`AbstractDragView<sparkle.gui.abstract_drag_view.AbstractDragView.grabImage>`
|
f10650:c1:m1
|
def mousePressEvent(self, event):
|
index = self.indexAt(event.pos())<EOL>if index.isValid():<EOL><INDENT>self.selectRow(index.row())<EOL>self.setCurrentIndex(index)<EOL>self.parameterChanged.emit(self.model().selection(index))<EOL>self.edit(index, QtGui.QAbstractItemView.DoubleClicked, event)<EOL><DEDENT>super(AutoParameterTableView, self).mousePressEvent(event)<EOL>
|
Begins edit on cell clicked, if allowed, and passes event to super class
|
f10650:c1:m2
|
def paintEvent(self, event):
|
super(AutoParameterTableView, self).paintEvent(event)<EOL>if self.dragline is not None:<EOL><INDENT>pen = QtGui.QPen(QtCore.Qt.blue)<EOL>painter = QtGui.QPainter(self.viewport())<EOL>painter.setPen(pen)<EOL>painter.drawLine(self.dragline)<EOL><DEDENT>
|
Adds cursor line for view if drag active. Passes event to superclass
see :qtdoc:`qtdocs<qabstractscrollarea.paintEvent>`
|
f10650:c1:m3
|
def cursor(self, pos):
|
row = self.indexAt(pos).row()<EOL>if row == -<NUM_LIT:1>:<EOL><INDENT>row = self.model().rowCount()<EOL><DEDENT>row_height = self.rowHeight(<NUM_LIT:0>)<EOL>y = (row_height*row)<EOL>x = self.width()<EOL>return QtCore.QLine(<NUM_LIT:0>,y,x,y)<EOL>
|
Returns a line at the nearest row split between parameters.
Re-implemented from :meth:`AbstractDragView<sparkle.gui.abstract_drag_view.AbstractDragView.cursor>`
|
f10650:c1:m4
|
def dropped(self, param, event):
|
if event.source() == self or isinstance(param, AddLabel):<EOL><INDENT>index = self.indexAt(event.pos())<EOL>self.model().insertRows(index.row(),<NUM_LIT:1>)<EOL>if event.source() == self:<EOL><INDENT>self.model().setData(index, param)<EOL><DEDENT>else:<EOL><INDENT>self.hintRequested.emit('<STR_LIT>')<EOL>row = index.row()<EOL>if row == -<NUM_LIT:1>:<EOL><INDENT>row = self.model().rowCount() - <NUM_LIT:1><EOL><DEDENT>self.selectRow(row)<EOL>self.parameterChanged.emit(self.model().selection(index))<EOL><DEDENT><DEDENT>self.dragActive.emit(False)<EOL>
|
Adds the dropped parameter *param* into the protocol list.
Re-implemented from :meth:`AbstractDragView<sparkle.gui.abstract_drag_view.AbstractDragView.dropped>`
|
f10650:c1:m5
|
def indexXY(self, index):
|
row = index.row()<EOL>if row == -<NUM_LIT:1>:<EOL><INDENT>row = self.model().rowCount()<EOL><DEDENT>y = self.rowHeight(<NUM_LIT:0>)*row<EOL>return <NUM_LIT:0>, y<EOL>
|
Coordinates for the parameter row at *index*
Re-implemented from :meth:`AbstractDragView<sparkle.gui.abstract_drag_view.AbstractDragView.indexXY>`
|
f10650:c1:m6
|
def componentSelection(self, comp):
|
<EOL>indexes = self.selectedIndexes()<EOL>index = indexes[<NUM_LIT:0>]<EOL>self.model().toggleSelection(index, comp)<EOL>
|
Toggles the selection of *comp* from the currently active parameter
|
f10650:c1:m7
|
def wrapComponent(comp):
|
<EOL>if hasattr(comp, '<STR_LIT>'):<EOL><INDENT>return comp<EOL><DEDENT>current_module = sys.modules[__name__]<EOL>module_classes = {name[<NUM_LIT:1>:]: obj for name, obj in inspect.getmembers(sys.modules[__name__], inspect.isclass) if<EOL>obj.__module__ == __name__}<EOL>stimclass = comp.__class__.__name__<EOL>qclass = module_classes.get(stimclass, QStimulusComponent)<EOL>return qclass(comp)<EOL>
|
Wraps a StimulusComponent with a class containing methods
for painting and editing. Class will in fact, be the same as
the component provided, but will also be a subclass of
QStimulusComponent
:param comp: Component to wrap
:type comp: subclass of AbstractStimulusComponent
:returns: sublass of AbstractStimulusComponent and QStimulusComponent
|
f10653:m0
|
def paint(self, painter, rect, palette):
|
painter.save()<EOL>image = img.default()<EOL>painter.drawImage(rect, image)<EOL>painter.setPen(QtGui.QPen(QtCore.Qt.red))<EOL>painter.drawText(rect, QtCore.Qt.AlignLeft, self.__class__.__name__)<EOL>painter.restore()<EOL>
|
Draws a generic visual representation for this component
Re-implement this to get a custom graphic in builder editor
:param painter: Use this class to do the drawing
:type painter: :qtdoc:`QPainter`
:param rect: boundary of the delegate for this component, painting should be done inside this boundary
:type rect: :qtdoc:`QRect`
:param palette: contains color groups to use, if wanted
:type palette: :qtdoc:`QPalette`
|
f10653:c0:m1
|
def showEditor(self):
|
editor = GenericParameterWidget(self)<EOL>return editor<EOL>
|
Generates a default editor that creates fields based on this
components auto_details.
Re-implement this method to use custom editor, subclassing :class:`AbstractComponentWidget<sparkle.gui.stim.abstract_component_editor.AbstractComponentWidget>`
:returns: :class:`GenericParameterWidget<sparkle.gui.stim.generic_parameters.GenericParameterWidget>`
|
f10653:c0:m2
|
def setContentFocus(self):
|
self.duration_input.setFocus()<EOL>self.duration_input.selectAll()<EOL>
|
Builder calls this to get cursor in editor
|
f10654:c0:m3
|
def setContentFocus(self):
|
self.duration_input.setFocus()<EOL>self.duration_input.selectAll()<EOL>
|
Builder calls this to get cursor in editor
|
f10656:c0:m3
|
@staticmethod<EOL><INDENT>def purgeDeletedWidgets():<DEDENT>
|
toremove = []<EOL>for field in AbstractEditorWidget.funit_fields:<EOL><INDENT>if sip.isdeleted(field):<EOL><INDENT>toremove.append(field)<EOL><DEDENT><DEDENT>for field in toremove:<EOL><INDENT>AbstractEditorWidget.funit_fields.remove(field)<EOL><DEDENT>toremove = []<EOL>for field in AbstractEditorWidget.tunit_fields:<EOL><INDENT>if sip.isdeleted(field):<EOL><INDENT>toremove.append(field)<EOL><DEDENT><DEDENT>for field in toremove:<EOL><INDENT>AbstractEditorWidget.tunit_fields.remove(field)<EOL><DEDENT>
|
Finds old references to stashed fields and deletes them
|
f10657:c0:m1
|
def setModel(self, model):
|
<EOL>try:<EOL><INDENT>self.ui.parametizer.randomizeCkbx.toggled.disconnect()<EOL>self.ui.parametizer.randomizeCkbx.disconnect()<EOL><DEDENT>except TypeError:<EOL><INDENT>pass<EOL><DEDENT>self.ui.trackview.setModel(model)<EOL>self.ui.nrepsSpnbx.setValue(model.repCount())<EOL>self.ui.parametizer.randomizeCkbx.toggled.connect(model.randomToggle)<EOL>self.ui.parametizer.randomizeCkbx.setChecked(bool(model.reorder()))<EOL>autoParamModel = model.autoParams()<EOL>self.ui.parametizer.setModel(autoParamModel)<EOL>autoParamModel.emptied.connect(self.ui.trackview.emptySelection)<EOL>autoParamModel.countChanged.connect(self.updateTraceCount)<EOL>self.updateTraceCount()<EOL>
|
Sets the QStimulusModel *model* for the StimulusView
|
f10658:c0:m1
|
def setRepCount(self, count):
|
self._rep_default_cache[<NUM_LIT:0>] = count<EOL>self.ui.trackview.model().setRepCount(count)<EOL>
|
Sets the repetition *count* for the stimulus model
|
f10658:c0:m2
|
def updateTraceCount(self):
|
self.ui.ntracesLbl.setNum(self.ui.trackview.model().traceCount())<EOL>
|
Updates the trace count label with the data from the model
|
f10658:c0:m4
|
def preview(self):
|
msg = self.ui.trackview.model().verify()<EOL>if msg:<EOL><INDENT>answer = QtGui.QMessageBox.warning(self, "<STR_LIT>", '<STR_LIT>'.format(msg))<EOL>return<EOL><DEDENT>stim_signal, atten, ovld = self.ui.trackview.model().signal()<EOL>fig = SpecWidget()<EOL>fig.setWindowModality(<NUM_LIT:2>) <EOL>fig.updateData(stim_signal, self.ui.trackview.model().samplerate())<EOL>fig.setTitle('<STR_LIT>')<EOL>fig.show()<EOL>self.previewFig = fig<EOL>
|
Assemble the current components in the QStimulusModel and generate a spectrogram
plot in a separate window
|
f10658:c0:m5
|
def model(self):
|
return self.ui.trackview.model()<EOL>
|
Returns the QStimulusModel for this editor
|
f10658:c0:m6
|
def setHint(self, message):
|
self.ui.hintTxedt.setText(message)<EOL>
|
Sets the hint text to *message*
|
f10658:c0:m7
|
def widgetForName(self, name):
|
for iwidget in range(len(self)):<EOL><INDENT>if self.widget(iwidget).name() == name:<EOL><INDENT>return self.widget(iwidget)<EOL><DEDENT><DEDENT>
|
Gets a widget with *name*
:param name: the widgets in this container should all have
a name() method. This is the string to match to that result
:type name: str
|
f10659:c0:m0
|
def widgets(self):
|
w = []<EOL>for i in range(self.count()):<EOL><INDENT>w.append(self.widget(i))<EOL><DEDENT>return w<EOL>
|
Gets all (first) child wigets
|
f10659:c0:m1
|
def create(self):
|
raise NotImplementedError<EOL>
|
create a new stimulus model object
:returns: :class:`StimulusModel<sparkle.stim.stimulus_model.StimulusModel>`
|
f10660:c0:m0
|
def name(self):
|
return self._component.name<EOL>
|
Gets the component name
:returns: str -- name of component
|
f10661:c0:m1
|
def component(self):
|
return self._component<EOL>
|
Gets the component for this editor
:returns: AbstractStimulusComponent
|
f10661:c0:m2
|
def setComponent(self, component):
|
raise NotImplementedError<EOL>
|
Sets the component for this editor, updates fields
appropriately.
Must be implemented by subclass
:param component: component this editor is acting on
:type component: (sublcass of) :class:`AbstractStimulusComponent<sparkle.stim.abstract_component.AbstractStimulusComponent>`
|
f10661:c0:m3
|
def saveToObject(self):
|
raise NotImplementedError<EOL>
|
Saves the values in the editor fields to the component
object
Must be implemented by subclass
|
f10661:c0:m4
|
def setComponent(self, component):
|
details = component.auto_details()<EOL>state = component.stateDict()<EOL>for field, detail in details.items():<EOL><INDENT>val = state[field]<EOL>self.inputWidgets[field].setValue(val)<EOL><DEDENT>self._component = component<EOL>
|
Re-implemented from :meth:`AbstractComponentWidget<sparkle.gui.stim.abstract_component_editor.AbstractComponentWidget.setComponent>`
|
f10662:c0:m1
|
def saveToObject(self):
|
details = self._component.auto_details()<EOL>for field, widget in self.inputWidgets.items():<EOL><INDENT>self._component.set(field, widget.value())<EOL><DEDENT>self.attributesSaved.emit(self._component.__class__.__name__, self._component.stateDict())<EOL>
|
Re-implemented from :meth:`AbstractComponentWidget<sparkle.gui.stim.abstract_component_editor.AbstractComponentWidget.saveToObject>`
|
f10662:c0:m2
|
def setContentFocus(self):
|
self.inputWidgets['<STR_LIT>'].setFocus()<EOL>self.inputWidgets['<STR_LIT>'].selectAll()<EOL>
|
Builder calls this to get cursor in editor
|
f10662:c0:m3
|
def durationInputWidget(self):
|
if '<STR_LIT>' in self.inputWidgets:<EOL><INDENT>return self.inputWidgets['<STR_LIT>']<EOL><DEDENT>
|
Gets the widget responsible for duration input
|
f10662:c0:m4
|
def select(self, index, command=QtGui.QItemSelectionModel.Toggle):
|
component = self.model().data(index, QtCore.Qt.UserRole)<EOL>self.selectComponent(component, index)<EOL>
|
Changes the inclusion of the given *index* in the selection model
|
f10663:c0:m1
|
def selectComponent(self, component, index=None, command=QtGui.QItemSelectionModel.Toggle):
|
if command == QtGui.QItemSelectionModel.Toggle:<EOL><INDENT>if component in self._selectedComponents:<EOL><INDENT>self._selectedComponents.remove(component)<EOL>if index is None:<EOL><INDENT>index = self.model().indexByComponent(component)<EOL><DEDENT>self.selectionChanged.emit(self.selection(), QtGui.QItemSelection(index, index))<EOL>if len(self._selectedComponents) == <NUM_LIT:0>:<EOL><INDENT>self.hintRequested.emit('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>self._selectedComponents.append(component)<EOL>self.selectionChanged.emit(self.selection(), QtGui.QItemSelection())<EOL>self.hintRequested.emit('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>
|
Selects the given *component* according to *command* policy
(actually, only toggle supported). If index is None, looks up index
of component in model
|
f10663:c0:m2
|
def selectedIndexes(self):
|
model = self.model()<EOL>indexes = []<EOL>for comp in self._selectedComponents:<EOL><INDENT>index = model.indexByComponent(comp)<EOL>if index is None:<EOL><INDENT>self._selectedComponents.remove(comp)<EOL><DEDENT>else:<EOL><INDENT>indexes.append(index)<EOL><DEDENT><DEDENT>return indexes<EOL>
|
Returns a list of QModelIndex currently in the model
|
f10663:c0:m3
|
def selection(self):
|
sel = QtGui.QItemSelection()<EOL>for index in self.selectedIndexes():<EOL><INDENT>sel.select(index, index)<EOL><DEDENT>return sel<EOL>
|
Returns items in selection as a QItemSelection object
|
f10663:c0:m4
|
def selectionComponents(self):
|
comps = []<EOL>model = self.model()<EOL>for comp in self._selectedComponents:<EOL><INDENT>index = model.indexByComponent(comp)<EOL>if index is not None:<EOL><INDENT>comps.append(comp)<EOL><DEDENT><DEDENT>return comps<EOL>
|
Returns the names of the component types in this selection
|
f10663:c0:m5
|
def switchDisplay(self, display):
|
self.dock.switchDisplay(display)<EOL>
|
See :meth:`PlotDockWidget<sparkle.gui.plotdock.PlotDockWidget.switchDisplay>`
|
f10666:c0:m1
|
def mousePressEvent(self, event):
|
if event.x() < <NUM_LIT:50>:<EOL><INDENT>super(PlotMenuBar, self).mousePressEvent(event)<EOL><DEDENT>else:<EOL><INDENT>event.ignore()<EOL><DEDENT>
|
Marshalls behaviour depending on location of the mouse click
|
f10666:c0:m2
|
def mouseMoveEvent(self, event):
|
event.ignore()<EOL>
|
Passes event on to allow dragging of window
|
f10666:c0:m3
|
def mouseReleaseEvent(self, event):
|
event.ignore()<EOL>
|
Passes event on to allow dragging of window
|
f10666:c0:m4
|
def hide(self, event):
|
if self.content.isHidden():<EOL><INDENT>self.content.show()<EOL>self.hideBtn.setIcon(self.hideIcon)<EOL>self.setMaximumHeight(<NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>self.content.hide()<EOL>self.hideBtn.setIcon(self.showIcon)<EOL>self.setFixedHeight(<NUM_LIT:30>)<EOL><DEDENT>
|
Toggles the visiblity of the content widget
|
f10667:c0:m1
|
def stash_calibration(self, attenuations, freqs, frange, calname):
|
self.calibration_vector = attenuations<EOL>self.calibration_freqs = freqs<EOL>self.calibration_frange = frange<EOL>self.calname = calname<EOL>
|
Save it for later
|
f10668:c0:m0
|
def stashed_calibration(self):
|
return self.calibration_vector, self.calibration_freqs<EOL>
|
Gets a stashed calibration
:returns: numpy.ndarray, numpy.ndarray -- frequency response values, frequencies
|
f10668:c0:m1
|
def apply_calibration(self, apply_cal):
|
self.apply_cal = apply_cal<EOL>
|
Whether to apply a stashed calibration to the outgoing stimulus
:param apply_cal: True if calibration should be applied
:type apply_cal: bool
|
f10668:c0:m2
|
def set_duration(self, dur):
|
raise NotImplementedError<EOL>
|
Sets the duration of the stimulus (seconds)
:param dur: desired duration of the stimulus
:type dur: float
|
f10668:c0:m4
|
def get_stims(self):
|
return self.stim_components<EOL>
|
Gets the stimuli available for setting as the current calibration stimulus
:returns: list<:class:`StimulusModel<sparkle.stim.stimulus_model.StimulusModel>`>
|
f10668:c1:m1
|
def set_stim_by_index(self, index):
|
<EOL>self.stimulus.clearComponents()<EOL>self.stimulus.insertComponent(self.stim_components[index])<EOL>
|
Sets the stimulus to be generated to the one referenced by index
:param index: index number of stimulus to set from this class's internal list of stimuli
:type index: int
|
f10668:c1:m2
|
def set_duration(self, dur):
|
<EOL>for comp in self.stim_components:<EOL><INDENT>comp.setDuration(dur)<EOL><DEDENT>self.reftone.setDuration(dur)<EOL>
|
See :meth:`AbstractCalibrationRunner<sparkle.run.calibration_runner.AbstractCalibrationRunner.set_duration>`
|
f10668:c1:m3
|
def process_calibration(self, save=True):
|
if not self.save_data:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>avg_signal = np.mean(self.datafile.get_data(self.current_dataset_name + '<STR_LIT>'), axis=<NUM_LIT:0>)<EOL>diffdB = attenuation_curve(self.stimulus.signal()[<NUM_LIT:0>], avg_signal,<EOL>self.stimulus.samplerate(), self.calf)<EOL>logger = logging.getLogger('<STR_LIT>')<EOL>logger.debug('<STR_LIT>'.format(max(diffdB), self.caldb))<EOL>self.datafile.init_data(self.current_dataset_name, mode='<STR_LIT>',<EOL>dims=diffdB.shape,<EOL>nested_name='<STR_LIT>')<EOL>self.datafile.append(self.current_dataset_name, diffdB,<EOL>nested_name='<STR_LIT>')<EOL>relevant_info = {'<STR_LIT>': '<STR_LIT:all>', '<STR_LIT>':self.caldb,<EOL>'<STR_LIT>': self.calv, '<STR_LIT>': self.calf,<EOL>}<EOL>self.datafile.set_metadata('<STR_LIT:/>'.join([self.current_dataset_name, '<STR_LIT>']),<EOL>relevant_info)<EOL>mean_reftone = np.mean(self.datafile.get_data(self.current_dataset_name + '<STR_LIT>'), axis=<NUM_LIT:0>)<EOL>tone_amp = signal_amplitude(mean_reftone, self.player.get_aifs())<EOL>db = calc_db(tone_amp, self.mphonesens, self.mphonedb)<EOL>self.protocol_model.remove(<NUM_LIT:0>)<EOL>return diffdB, self.current_dataset_name, self.calf, db<EOL>
|
processes calibration control signal. Determines transfer function
of speaker to get frequency vs. attenuation curve.
:param save: Whether to save this calibration data to file
:type save: bool
:returns: numpy.ndarray, str, int, float -- frequency response (in dB), dataset name, calibration reference frequency, reference intensity
|
f10668:c1:m7
|
def set_reps(self, reps):
|
self.stimulus.setRepCount(reps)<EOL>self.refstim.setRepCount(reps)<EOL>
|
set the number of repetitions for the stimuli (reference tone and cal stim)
:param reps: number of times to present the same stimulus
:type reps: int
|
f10668:c1:m8
|
def set_duration(self, dur):
|
self.stimulus.component(<NUM_LIT:0>,<NUM_LIT:0>).setDuration(dur)<EOL>
|
See :meth:`AbstractCalibrationRunner<sparkle.run.calibration_runner.AbstractCalibrationRunner.set_duration>`
|
f10668:c2:m1
|
def process_calibration(self, save=False):
|
if not self.save_data:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>vfunc = np.vectorize(calc_db, self.mphonesens, self.mphonedb)<EOL>if USE_FFT:<EOL><INDENT>peaks = np.mean(abs(self.datafile.get_data(self.current_dataset_name + '<STR_LIT>')), axis=<NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>peaks = np.mean(abs(self.datafile.get_data(self.current_dataset_name + '<STR_LIT>')), axis=<NUM_LIT:1>)<EOL><DEDENT>resultant_dB = vfunc(peaks, self.calpeak) * -<NUM_LIT:1> <EOL>print('<STR_LIT>', self.calibration_frequencies, '<STR_LIT>', self.calibration_indexes)<EOL>print('<STR_LIT>', resultant_dB)<EOL>calibration_vector = resultant_dB[self.calibration_indexes].squeeze()<EOL>return resultant_dB, '<STR_LIT>', self.calf<EOL>
|
processes the data gathered in a calibration run (does not work if multiple
calibrations), returns resultant dB
|
f10668:c2:m5
|
def set_reps(self, reps):
|
self.stimulus.setRepCount(reps)<EOL>
|
set the number of repetitions for the stimul(us/i)
:param reps: number of times to present the same stimulus
:type reps: int
|
f10668:c2:m6
|
def count(self):
|
total = <NUM_LIT:0><EOL>for test in self.protocol_model.allTests():<EOL><INDENT>total += test.traceCount()*test.loopCount()*test.repCount()<EOL><DEDENT>return total<EOL>
|
Total number of all tests/traces/reps currently in this protocol
:returns: int -- the total
|
f10668:c2:m7
|
def start_chart(self):
|
self.current_dataset_name = self.chart_name<EOL>self.datafile.init_data(self.current_dataset_name, mode='<STR_LIT>')<EOL>self.chart_name = increment_title(self.chart_name)<EOL>self.player.start_continuous([self.aichan, u"<STR_LIT>"])<EOL>
|
Begin on-going chart style acqusition
|
f10669:c0:m2
|
def stimulus(self):
|
return self._stimulus<EOL>
|
Gets a list of all the stimuli this runner has access to. Order
of the list matches the index order which stimuli can be set by.
:returns: (subclasses of) list<:class:`AbstractStimulusComponent<sparkle.stim.abstract_component.AbstractStimulusComponent>`>
|
f10670:c0:m1
|
def set_calibration(self, attenuations, freqs, frange, calname):
|
self._stimulus.setCalibration(attenuations, freqs, frange)<EOL>
|
See :meth:`AbstractAcquisitionRunner<sparkle.run.abstract_acquisition.AbstractAcquisitionRunner.set_calibration>`
|
f10670:c0:m2
|
def update_reference_voltage(self):
|
self._stimulus.setReferenceVoltage(self.caldb, self.calv)<EOL>
|
See :meth:`AbstractAcquisitionRunner<sparkle.run.abstract_acquisition.AbstractAcquisitionRunner.update_reference_voltage>`
|
f10670:c0:m3
|
def set_current_stim_parameter(self, param, val):
|
component = self._stimulus.component(<NUM_LIT:0>,<NUM_LIT:1>)<EOL>component.set(param, val)<EOL>
|
Sets a parameter on the current stimulus
:param param: name of the parameter of the stimulus to set
:type param: str
:param val: new value to set the parameter to
|
f10670:c0:m5
|
def current_signal(self):
|
return self._stimulus.signal()<EOL>
|
Signal of the currently set stimulus
:returns: numpy.ndarray
|
f10670:c0:m6
|
def run(self, interval):
|
self._halt = False<EOL>if self.save_data:<EOL><INDENT>self.current_dataset_name = self.set_name<EOL>self.datafile.init_data(self.current_dataset_name, self.aitimes.shape, mode='<STR_LIT>')<EOL>self.set_name = increment_title(self.set_name)<EOL><DEDENT>self.start_time = time.time()<EOL>self.last_tick = self.start_time - (interval/<NUM_LIT:1000>)<EOL>self.interval = interval<EOL>self.acq_thread = threading.Thread(target=self._worker)<EOL>self.player.set_aochan(self.aochan)<EOL>self.player.set_aichan(self.aichan)<EOL>self.reset_stim()<EOL>self.acq_thread.start()<EOL>return self.acq_thread<EOL>
|
See :meth:`AbstractAcquisitionRunner<sparkle.run.abstract_acquisition.AbstractAcquisitionRunner.run>`
|
f10670:c0:m7
|
def save_to_file(self, data, stamp):
|
self.datafile.append(self.current_dataset_name, data)<EOL>info = dict(list(self._stimulus.componentDoc().items()) + list(self._stimulus.testDoc().items()))<EOL>print('<STR_LIT>', info)<EOL>info['<STR_LIT>'] = [stamp]<EOL>info['<STR_LIT>'] = self.player.aifs<EOL>self.datafile.append_trace_info(self.current_dataset_name, info)<EOL>
|
Saves data to current dataset.
:param data: data to save to file
:type data: numpy.ndarray
:param stamp: time stamp of when the data was acquired
:type stamp: str
|
f10670:c0:m9
|
def update_reference_voltage(self):
|
raise NotImplementedError<EOL>
|
Updates the voltage intensity combination used to calculate
the appropriate amplitude for outgoing signals. Uses internal
values to class that may have changed
|
f10671:c0:m1
|
def set_calibration(self, attenuations, freqs, frange, calname):
|
raise NotImplementedError<EOL>
|
Sets the calibration for all tests controlled by this class.
:param attenuations: Vector of frequency attenuations in dB.
i.e. the frequency response of the system.
:type attenuations: list or numpy.ndarray
:param freqs: Matching frequencyes for the attenuation vector
:type freqs: list or numpy.ndarray
:param frange: Frequency range (min, max) to restrict the application of the
calibration to (in Hz)
:type frange: (int, int)
:param calname: Name of the calibration, for documentation purposes
:type calname: str
|
f10671:c0:m2
|
def set_threshold(self, threshold):
|
self.threshold = threshold<EOL>
|
Spike detection threshold
:param threshold: electrical potential to determine spikes (V)
:type threshold: float
|
f10671:c0:m3
|
def set(self, **kwargs):
|
self.player_lock.acquire()<EOL>if '<STR_LIT>' in kwargs:<EOL><INDENT>self.player.set_aidur(kwargs['<STR_LIT>'])<EOL><DEDENT>if '<STR_LIT>' in kwargs:<EOL><INDENT>self.player.set_aifs(kwargs['<STR_LIT>'])<EOL>self.aifs = kwargs['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT>' in kwargs or '<STR_LIT>' in kwargs:<EOL><INDENT>t = kwargs.get('<STR_LIT>', self.player.get_aidur())<EOL>npoints = t*float(kwargs.get('<STR_LIT>', self.player.get_aifs()))<EOL>self.aitimes = np.linspace(<NUM_LIT:0>, t, npoints)<EOL><DEDENT>if '<STR_LIT>' in kwargs:<EOL><INDENT>self.player.set_trigger(kwargs['<STR_LIT>'])<EOL><DEDENT>self.player_lock.release()<EOL>if '<STR_LIT>' in kwargs:<EOL><INDENT>self.aochan = kwargs['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT>' in kwargs:<EOL><INDENT>self.aichan = kwargs['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT>' in kwargs:<EOL><INDENT>self.binsz = kwargs['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT>' in kwargs:<EOL><INDENT>self.save_data = kwargs['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT>' in kwargs:<EOL><INDENT>self.caldb = kwargs['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT>' in kwargs:<EOL><INDENT>self.calv = kwargs['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT>' in kwargs:<EOL><INDENT>self.calf = kwargs['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT>' in kwargs or '<STR_LIT>' in kwargs:<EOL><INDENT>self.update_reference_voltage()<EOL><DEDENT>if '<STR_LIT>' in kwargs:<EOL><INDENT>self.datafile = kwargs['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT>' in kwargs:<EOL><INDENT>self.reprate = kwargs['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT>' in kwargs:<EOL><INDENT>self.save_data = kwargs['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT>' in kwargs:<EOL><INDENT>self.average = kwargs['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT>' in kwargs:<EOL><INDENT>self.reject = kwargs['<STR_LIT>']<EOL><DEDENT>if '<STR_LIT>' in kwargs:<EOL><INDENT>self.rejectrate = kwargs['<STR_LIT>']<EOL><DEDENT>
|
Sets an internal setting for acquistion, using keywords.
Available parameters to set:
:param acqtime: duration of recording (input) window (seconds)
:type acqtime: float
:param aifs: sample rate of the recording (input) operation (Hz)
:type aifs: int
:param aochan: AO (generation) channel name
:type aochan: str
:param aichan: AI (recording) channel name
:type aichan: str
:param nreps: number of repetitions for each unique stimulus
:type nreps: int
:param binsz: time bin duration for spike sorting (seconds)
:type binsz: float
:param caldb: See :meth:`StimulusModel<sparkle.stim.stimulus_model.StimulusModel.setReferenceVoltage>`
:type caldb: float
:param calv: See :meth:`StimulusModel<sparkle.stim.stimulus_model.StimulusModel.setReferenceVoltage>`
:type calv: float
:param datafile: a reference to an open file to save data to
:type datafile: :class:`AcquisitionData<sparkle.data.dataobjects.AcquisitionData>`
:param average: whether to average repetitions of a trace, saving only the averaged signal
:type average: bool
:param reject: whether to reject values higher than a defined threshold. Only used while average is true
:type reject: bool
:param rejectrate: the value to base artifact rejection on
:type rejectrate: float
|
f10671:c0:m4
|
def run(self, interval, **kwargs):
|
raise NotImplementedError<EOL>
|
Runs the acquisiton
:param interval: time between the start of each acquistion sweep (seconds)
:type interval: float
|
f10671:c0:m5
|
def halt(self):
|
self._halt = True<EOL>
|
Stop the current on-going generation/acquisition
|
f10671:c0:m6
|
def interval_wait(self):
|
<EOL>now = time.time()<EOL>elapsed = (now - self.last_tick)*<NUM_LIT:1000><EOL>if elapsed < self.interval:<EOL><INDENT>time.sleep((self.interval-elapsed)/<NUM_LIT:1000>)<EOL>now = time.time()<EOL><DEDENT>elif elapsed > self.interval:<EOL><INDENT>pass<EOL><DEDENT>self.last_tick = now<EOL>
|
Pauses the correct amount of time according to this
acquisition object's interval setting, and the last time this
function was called
|
f10671:c0:m7
|
def putnotify(self, name, *args):
|
<EOL>self.queues[name][<NUM_LIT:0>].put(*args)<EOL>self.queues[name][<NUM_LIT:1>].set()<EOL>
|
Puts data into queue and alerts listeners
|
f10671:c0:m8
|
def setReferenceVoltage(self, caldb, calv):
|
self.caldb = caldb<EOL>self.calv = calv<EOL>for test in self._tests:<EOL><INDENT>test.setReferenceVoltage(caldb, calv)<EOL><DEDENT>
|
See :meth:`StimulusModel<sparkle.stim.stimulus_model.StimulusModel.setReferenceVoltage>`
|
f10672:c0:m1
|
def setCalibration(self, db_boost_array, frequencies, frange):
|
self.calibrationVector = db_boost_array<EOL>self.calibrationFrequencies = frequencies<EOL>self.calibrationFrange = frange<EOL>for test in self._tests:<EOL><INDENT>test.setCalibration(db_boost_array, frequencies, frange)<EOL><DEDENT>
|
Sets calibration for all tests
See :meth:`StimulusModel<sparkle.stim.stimulus_model.StimulusModel.setCalibration>`
|
f10672:c0:m2
|
def rowCount(self):
|
return len(self._tests)<EOL>
|
The number of tests in this protocol
:returns: int -- test count
|
f10672:c0:m3
|
def allTests(self):
|
return copy.deepcopy(self._tests)<EOL>
|
Gets all tests
:returns: list<:class:`StimulusModel<sparkle.stim.stimulus_model.StimulusModel>`>
|
f10672:c0:m5
|
def remove(self, position):
|
return self._tests.pop(position)<EOL>
|
Removes the test at position from the protocol
:param position: index of stimulus to remove
:type position: int
|
f10672:c0:m6
|
def insert(self, stim, position):
|
if position == -<NUM_LIT:1>:<EOL><INDENT>position = self.rowCount()<EOL><DEDENT>stim.setReferenceVoltage(self.caldb, self.calv)<EOL>stim.setCalibration(self.calibrationVector, self.calibrationFrequencies, self.calibrationFrange)<EOL>self._tests.insert(position, stim)<EOL>
|
Inserts a new stimulus into the list at the given position
:param stim: stimulus to insert into protocol
:type stim: :class:`StimulusModel<sparkle.stim.stimulus_model.StimulusModel>`
:param position: index (row) of location to insert to
:type position: int
|
f10672:c0:m7
|
def clear(self):
|
self._tests = []<EOL>
|
Clears all tests from protocol
|
f10672:c0:m8
|
def verify(self, windowSize=None):
|
if self.rowCount() == <NUM_LIT:0>:<EOL><INDENT>return "<STR_LIT>"<EOL><DEDENT>if self.caldb is None or self.calv is None:<EOL><INDENT>return "<STR_LIT>"<EOL><DEDENT>for test in self._tests:<EOL><INDENT>msg = test.verify(windowSize)<EOL>if msg:<EOL><INDENT>return msg<EOL><DEDENT><DEDENT>return <NUM_LIT:0><EOL>
|
Verify that this protocol model is valid. Return 0 if sucessful,
a failure message otherwise
:param windowSize: acquistion window size (seconds), to check against duration, check is not performed is None provided
:type windowSize: float
:returns: 0 (int) for success, fail message (str) otherwise
|
f10672:c0:m9
|
def set_calibration(self, attenuations, freqs, frange, calname):
|
self.protocol_model.setCalibration(attenuations, freqs, frange)<EOL>self.calname = calname<EOL>self.cal_frange = frange<EOL>
|
See :meth:`AbstractAcquisitionRunner<sparkle.run.abstract_acquisition.AbstractAcquisitionRunner.set_calibration>`
|
f10673:c1:m1
|
def update_reference_voltage(self):
|
self.protocol_model.setReferenceVoltage(self.caldb, self.calv)<EOL>
|
See :meth:`AbstractAcquisitionRunner<sparkle.run.abstract_acquisition.AbstractAcquisitionRunner.update_reference_voltage>`
|
f10673:c1:m2
|
def count(self):
|
total = <NUM_LIT:0><EOL>for test in self.protocol_model.allTests():<EOL><INDENT>total += test.traceCount()*test.loopCount()*test.repCount() + test.repCount()<EOL><DEDENT>return total<EOL>
|
Total number of all tests/traces/reps currently in this protocol
:returns: int -- the total
|
f10673:c1:m3
|
def setup(self, interval):
|
self.trace_counter = <NUM_LIT:0><EOL>self._halt = False<EOL>self.interval = interval<EOL>
|
Prepares the tests for execution, interval in ms
|
f10673:c1:m5
|
def run(self):
|
self._initialize_run()<EOL>stimuli = self.protocol_model.allTests()<EOL>self.acq_thread = threading.Thread(target=self._worker, <EOL>args=(stimuli,), )<EOL>if self.save_data:<EOL><INDENT>info = {'<STR_LIT>': self.calname, '<STR_LIT>': self.cal_frange}<EOL>self.datafile.set_metadata(self.current_dataset_name, info)<EOL><DEDENT>self.start_time = time.time()<EOL>self.last_tick = self.start_time - (self.interval/<NUM_LIT:1000>)<EOL>self.acq_thread.start()<EOL>return self.acq_thread<EOL>
|
Runs the acquisition
|
f10673:c1:m6
|
def _initialize_run(self):
|
<EOL>raise NotImplementedError<EOL>
|
This needs to set up data structures
|
f10673:c1:m7
|
def set_comment(self, cellid, comment):
|
info = {'<STR_LIT>': cellid, '<STR_LIT>': comment}<EOL>self.datafile.set_metadata(self.current_dataset_name, info)<EOL>
|
Saves the provided comment to the current dataset.
:param cellid: number of the current cell
:type cellid: int
:param comment: a message to add documentation to data
:type comment: str
|
f10674:c0:m4
|
def clear(self):
|
self.protocol_model.clear()<EOL>
|
Clears all tests from protocol list
|
f10674:c0:m5
|
def start_listening(self):
|
self._qlisten()<EOL>self._halt_threads = False<EOL>for t in self.queue_threads:<EOL><INDENT>t.start()<EOL><DEDENT>
|
Start listener threads for acquistion callback queues
|
f10676:c0:m3
|
def stop_listening(self):
|
self._halt_threads = True<EOL>for name, queue_waker in list(self.recieved_signals.items()):<EOL><INDENT>q, wake_event = queue_waker<EOL>wake_event.set()<EOL><DEDENT>
|
Stop listener threads for acquistion queues
|
f10676:c0:m4
|
def set_queue_callback(self, name, func):
|
if name in self.acquisition_hooks:<EOL><INDENT>self.acquisition_hooks[name].append(func)<EOL><DEDENT>else:<EOL><INDENT>self.acquisition_hooks[name] = [func]<EOL><DEDENT>
|
Sets a function to execute when the named acquistion queue
has data placed in it.
:param name: name of the queue to pull data from
:type name: str
:param func: function reference to execute, expects queue contents as argument(s)
:type func: callable
|
f10676:c0:m5
|
def increment_cellid(self):
|
self.current_cellid +=<NUM_LIT:1><EOL>
|
Increments the current cellid number that is saved for each test run
|
f10676:c0:m6
|
def explore_stimulus(self):
|
return self.explorer.stimulus()<EOL>
|
Get a list of the stimuli for search operation
:returns: list<:class:`AbstractStimulusComponent<sparkle.stim.abstract_component.AbstractStimulusComponent>`> -- list of the stimuli classes instances in the search operation
|
f10676:c0:m7
|
def set_calibration(self, datakey, calf=None, frange=None):
|
if datakey is None:<EOL><INDENT>calibration_vector, calibration_freqs = None, None<EOL><DEDENT>else:<EOL><INDENT>if calf is None:<EOL><INDENT>raise Exception('<STR_LIT>') <EOL><DEDENT>try:<EOL><INDENT>cal = self.datafile.get_calibration(datakey, calf)<EOL><DEDENT>except:<EOL><INDENT>print("<STR_LIT>", datakey)<EOL>raise<EOL><DEDENT>calibration_vector, calibration_freqs = cal<EOL><DEDENT>StimulusModel.clearCache()<EOL>logger = logging.getLogger('<STR_LIT>')<EOL>logger.debug('<STR_LIT>')<EOL>logger.debug('<STR_LIT>')<EOL>self.explorer.set_calibration(calibration_vector, calibration_freqs, frange, datakey)<EOL>logger.debug('<STR_LIT>')<EOL>self.protocoler.set_calibration(calibration_vector, calibration_freqs, frange, datakey)<EOL>logger.debug('<STR_LIT>')<EOL>self.charter.set_calibration(calibration_vector, calibration_freqs, frange, datakey)<EOL>logger.debug('<STR_LIT>')<EOL>self.bs_calibrator.stash_calibration(calibration_vector, calibration_freqs, frange, datakey)<EOL>logger.debug('<STR_LIT>')<EOL>self.tone_calibrator.stash_calibration(calibration_vector, calibration_freqs, frange, datakey)<EOL>
|
Sets a calibration for all of the acquisition operations,
from an already gathered calibration data set.
:param datakey: name of the calibration to set. This key must be present in the current data file. A value of ``None`` clears calibration.
:type datakey: str
:param calf: Calibration frequency for the attenuation vector to be in relation to. All other frequencies will be in attenutaion from this frequency.
:type calf: int
:param frange: Frequency range, low and high, for which to restrict the calibration to
:type frange: (int, int)
|
f10676:c0:m8
|
def current_calibration(self):
|
return self.bs_calibrator.stashed_calibration()<EOL>
|
The currently employed calibration
:returns: (numpy.ndarray, numpy.ndarray) -- Attenuation vector, and associated frequencies
|
f10676:c0:m9
|
def set_calibration_duration(self, dur):
|
self.bs_calibrator.set_duration(dur)<EOL>self.tone_calibrator.set_duration(dur)<EOL>
|
Sets the stimulus duration for the calibration stimulus. Sets for calibration chirp, test tone, and calibration curve tones
:param dur: Duration (seconds) of output signal
:type dur: float
|
f10676:c0:m10
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.