text
stringlengths
0
828
""""""
self.rasterBottom = lims[0]
self.rasterTop = lims[1]
self.updateRasterBounds()"
26,"def updateRasterBounds(self):
""""""Updates the y-coordinate slots where the raster points
are plotted, according to the current limits of the y-axis""""""
yrange = self.viewRange()[1]
yrange_size = yrange[1] - yrange[0]
rmax = self.rasterTop*yrange_size + yrange[0]
rmin = self.rasterBottom*yrange_size + yrange[0]
self.rasterYslots = np.linspace(rmin, rmax, self.nreps)
self.rasterBoundsUpdated.emit((self.rasterBottom, self.rasterTop), self.getTitle())"
27,"def askRasterBounds(self):
""""""Prompts the user to provide the raster bounds with a dialog.
Saves the bounds to be applied to the plot""""""
dlg = RasterBoundsDialog(bounds= (self.rasterBottom, self.rasterTop))
if dlg.exec_():
bounds = dlg.values()
self.setRasterBounds(bounds)"
28,"def rangeChange(self, pw, ranges):
""""""Adjusts the stimulus signal to keep it at the top of a plot,
after any ajustment to the axes ranges takes place.
This is a slot for the undocumented pyqtgraph signal sigRangeChanged.
From what I can tell the arguments are:
:param pw: reference to the emitting object (plot widget in my case)
:type pw: object
:param ranges: I am only interested when this turns out to be a nested list of axis bounds
:type ranges: object
""""""
if hasattr(ranges, '__iter__'):
# adjust the stim signal so that it falls in the correct range
yrange_size = ranges[1][1] - ranges[1][0]
stim_x, stim_y = self.stimPlot.getData()
if stim_y is not None:
stim_height = yrange_size*STIM_HEIGHT
# take it to 0
stim_y = stim_y - np.amin(stim_y)
# normalize
if np.amax(stim_y) != 0:
stim_y = stim_y/np.amax(stim_y)
# scale for new size
stim_y = stim_y*stim_height
# raise to right place in plot
stim_y = stim_y + (ranges[1][1] - (stim_height*1.1 + (stim_height*0.2)))
self.stimPlot.setData(stim_x, stim_y)
# rmax = self.rasterTop*yrange_size + ranges[1][0]
# rmin = self.rasterBottom*yrange_size + ranges[1][0]
self.updateRasterBounds()"
29,"def update_thresh(self):
""""""Emits a Qt signal thresholdUpdated with the current threshold value""""""
thresh_val = self.threshLine.value()
self.threshold_field.setValue(thresh_val)
self.thresholdUpdated.emit(thresh_val, self.getTitle())"
30,"def fromFile(self, fname):
""""""Displays a spectrogram of an audio file. Supported formats see :func:`sparkle.tools.audiotools.audioread`
:param fname: file path of the audiofile to display
:type fname: str
:returns: float -- duration of audio recording (seconds)
""""""
spec, f, bins, dur = audiotools.spectrogram(fname, **self.specgramArgs)
self.updateImage(spec, bins, f)
return dur"
31,"def updateImage(self, imgdata, xaxis=None, yaxis=None):
""""""Updates the Widget image directly.
:type imgdata: numpy.ndarray, see :meth:`pyqtgraph:pyqtgraph.ImageItem.setImage`
:param xaxis: x-axis values, length should match dimension 1 of imgdata
:param yaxis: y-axis values, length should match dimension 0 of imgdata
""""""
imgdata = imgdata.T
self.img.setImage(imgdata)
if xaxis is not None and yaxis is not None:
xscale = 1.0/(imgdata.shape[0]/xaxis[-1])
yscale = 1.0/(imgdata.shape[1]/yaxis[-1])
self.resetScale()
self.img.scale(xscale, yscale)
self.imgScale = (xscale, yscale)
self.imageArray = np.fliplr(imgdata)
self.updateColormap()"
32,"def resetScale(self):
""""""Resets the scale on this image. Correctly aligns time scale, undoes manual scaling""""""
self.img.scale(1./self.imgScale[0], 1./self.imgScale[1])
self.imgScale = (1.,1.)"
33,"def updateData(self, signal, fs):
""""""Displays a spectrogram of the provided signal
:param signal: 1-D signal of audio
:type signal: numpy.ndarray
:param fs: samplerate of signal
:type fs: int
""""""
# use a separate thread to calculate spectrogram so UI doesn't lag
t = threading.Thread(target=_doSpectrogram, args=(self.spec_done, (fs, signal),), kwargs=self.specgramArgs)
t.start()"
34,"def setSpecArgs(**kwargs):
""""""Sets optional arguments for the spectrogram appearance.