def read_xdf(cls, path): raise NotImplementedError import openxdf # TODO: below is a place holder and needs to be finalize xdf = openxdf.OpenXDF(path) signals = openxdf.Signal(xdf, path.with_suffix(".nkamp")) # TODO: automate this, why are the xdf.header names different from signals.list_channels? for label in ["ECG", "Chin"]: # logger.info(f'reading {label} channel') sig = signals.read_file(label)[label] wav = Wave(sig.ravel(), 200) wav.label = label # wav.path = file.with_name(file.stem + '-' + label + '.wav') wav.min = -3200 wav.max = 3200 wav.unit = "1"
def add_view_from_file(self, file: Path, panel_index: int = None): # TODO: both edf and xdf should be moved to tracking!!! if file.suffix == '.edf': import pyedflib with pyedflib.EdfReader(str(file)) as f: labels = f.getSignalLabels() for label in labels: index = labels.index(label) wav = tracking.Wave(f.readSignal(index), f.getSampleFrequency(index)) wav.label = label wav.path = file.with_name(file.stem + '-' + label + '.wav') wav.min = f.getPhysicalMinimum(index) wav.max = f.getPhysicalMaximum(index) wav.unit = f.getPhysicalDimension(index) self.add_view(wav, panel_index=panel_index, y_min=wav.min, y_max=wav.max) elif file.suffix == '.xdf': import openxdf xdf = openxdf.OpenXDF(file) signals = openxdf.Signal(xdf, file.with_suffix('.nkamp')) # TODO: automate this, why are the xdf.header names different from signals.list_channels? for label in ['ECG', 'Chin']: logger.info(f'reading {label} channel') sig = signals.read_file(label)[label] wav = tracking.Wave(sig.ravel(), 200) wav.label = label wav.path = file.with_name(file.stem + '-' + label + '.wav') wav.min = -3200 wav.max = 3200 wav.unit = '1' self.add_view(wav, panel_index=panel_index, y_min=wav.min, y_max=wav.max) else: try: track_obj = tracking.Track.read(file) except Exception as e: logging.exception(e) else: self.add_view(track_obj, panel_index=panel_index)
def load_data(xdf_path, signal_path): xdf = openxdf.OpenXDF(xdf_path) signal = openxdf.Signal(xdf, signal_path) return xdf, signal