def launchSpectrogram(self): curvenames = list(self.curves.keys()) q = Parameter('Select Curve', curvenames) curvename = dialogs.askUserValue(q) q = Parameter('Enter time window', 'time') window = dialogs.askUserValue(q) if not curvename: return curve = self.curves[curvename] spectro = SpectrogramWidget(curve.series, curve.samplerate, window, parent=self.parent) self.parent.addTab(spectro, curve.name())
def perfusionindex(plotwidget: PlotWidget) -> List[CurveItemWithPOI]: curvenames = list(plotwidget.curves.keys()) q = Parameter('Select Curve', curvenames) curvename = askUserValue(q) curve = plotwidget.curves[curvename] if ('start' not in curve.feetitem.indices or curve.feetitem.indices['start'].size < 1): raise ValueError('No start information for curve') wave = curve.series starts = curve.getFeetPoints('start') df = pd.concat([wave, starts], axis=1) df = df.interpolate(method='index') begins, durations = curve.getCycleIndices() pivalues = [] for begin, duration in zip(begins, durations): cycle = df.loc[begin:begin + duration] auctot = cycle[wave.name].sum() aucbase = cycle[starts.name].sum() aucpulse = auctot - aucbase pi = aucpulse / auctot pivalues.append(pi) piseries = pd.Series(pivalues, index=begins) piseries.name = f'{wave.name}-perf' newcurve = CurveItemWithPOI(parent=plotwidget, series=piseries, pen=plotwidget.getPen()) return [newcurve]
def launchPOIWidget(self): curvenames = list(self.curves.keys()) q = Parameter('Select Curve', curvenames) curvename = dialogs.askUserValue(q) if not curvename: return curve = self.curves[curvename] poiselector = POISelectorWidget(curve.series, parent=self.parent, properties=self.properties) self.parent.addTab(poiselector, curve.name())
def launchTransformation(self): param = Parameter( "Choose Transformation", list(transformations.Transformations.keys()), ) qresult = dialogs.askUserValue(param) if qresult is None: return trans = transformations.Transformations[qresult] for curve in trans(self): self.addCurve(curve)
def launchSEFExtract(self): q = Parameter('SEF percentage', int) sefperc = dialogs.askUserValue(q) if not sefperc: return curvename = f'{self.name}-sef{sefperc}' sef = self.calcsef(sefperc) sefseries = pd.Series(sef, index=self.genIndex(), name=curvename) data = {curvename: sefseries} plotdata = PlotData(data, name=curvename) self.parent.createNewPlotWithData(plotdata)
def feettocurve(plotwidget: PlotWidget) -> List[CurveItemWithPOI]: feetitemhash = {} for curve in plotwidget.curves.values(): feetitemhash.update({ f'{curve.name()}-{feetname}': (curve, feetname) for feetname in curve.feetitem.indices.keys() }) param = Parameter("Choose points to create curve", list(feetitemhash.keys())) qresult = askUserValue(param) curve, feetname = feetitemhash[qresult] newseries = curve.getFeetPoints(feetname) newseries.name = qresult newcurve = CurveItemWithPOI(parent=plotwidget, series=newseries, pen=plotwidget.getPen()) return [newcurve]
def curves_to_edf( curves: List[CurveItem], filepath: str, index_label: str = 'timens' ) -> None: headers = [] signals = [] beginns = min(c.series.index[0] for c in curves) endns = max(c.series.index[-1] for c in curves) begindt = datetime.fromtimestamp(beginns * 1e-9) # Use global min / max of values since some viewers need this (edfbrowser) physmax = max(c.series.max() for c in curves) physmin = min(c.series.min() for c in curves) # Ask the user for the physical dimension shared by all curves dim = askUserValue(Parameter('Enter physical dimension', str)) for c in curves: s = c.series header = { 'label': c.name(), 'sample_rate': c.samplerate, 'physical_max': physmax, 'physical_min': physmin, 'digital_max': 32767, 'digital_min': -32768, 'transducer': '', 'prefilter': '', 'dimension': dim, } headers.append(header) resampled = interp_series(s, c.samplerate, beginns, endns) signals.append(resampled) edf = pyedflib.EdfWriter( str(filepath), len(signals), file_type=pyedflib.FILETYPE_EDFPLUS ) edf.setStartdatetime(begindt) edf.setSignalHeaders(headers) edf.writeSamples(signals) edf.close()
def updateTFs(): tflist = list(TFs.keys()) if not tflist: return Filters['Transfer function'] = Filter( name='tf', parameters=[Parameter('Transfer function', tflist)])
self.den = den self.name = name def discretize(self, samplerate): systf = (self.num, self.den) (dnum, dden, _) = signal.cont2discrete(systf, 1 / samplerate) return (np.squeeze(dnum), np.squeeze(dden)) interpkind = ['linear', 'zero', 'pchip', 'nearest'] Filters = { 'Lowpass filter': Filter( name='lowpass', parameters=[ Parameter('Cutoff frequency (Hz)', int), Parameter('Filter order', int), ], ), 'Filter ventilation': Filter(name='ventilation', parameters=[]), 'Savitzky-Golay': Filter( name='savgol', parameters=[ Parameter('Window duration', 'time'), Parameter('Polynomial order', int), ], ), 'Interpolate': Filter(