def _read_signal_file( filepaths: List[str], signal_unit: Quantity = None) -> IrregularlySampledSignal: # things are a bit complicated here as the signal is not necessarily covering the whole experiment! try: # get the continous signal file signal_file = [ file for file in filepaths if "continuous" in os.path.basename(file).lower() ][0] times = [] signal = [] # open the file for reading with open(signal_file, "r") as file: # and create a reader reader = csv.reader(file, delimiter=",") # this try/catch handles the exception that is raised by "next" if the reader reached the file ending try: while True: # read time and signal rows time_row = np.array([float(val) for val in next(reader)]) signal_row = np.array([float(val) for val in next(reader)]) assert len(time_row) == len(signal_row) times.append(time_row) signal.append(signal_row) except StopIteration: pass # concatenate our list of arrays times = np.concatenate(times) * second signal = np.concatenate(signal) assert len(times) == len(signal) if not signal_unit is None: signal = Quantity(signal, signal_unit) else: signal = Quantity(signal, "dimensionless") result = IrregularlySampledSignal(times=times, signal=signal, name="Irregularly Sampled Signal", file_origin=signal_file) channel_id = f"{TypeID.RAW_DATA.value}.0" result.annotate(id=channel_id, type_id=TypeID.RAW_DATA.value) return result # something might go wrong as we perform some IO operations here except Exception as ex: traceback.print_exc()
def create_all_annotated(cls): times = cls.rquant(1, pq.s) signal = cls.rquant(1, pq.V) blk = Block() blk.annotate(**cls.rdict(3)) cls.populate_dates(blk) seg = Segment() seg.annotate(**cls.rdict(4)) cls.populate_dates(seg) blk.segments.append(seg) asig = AnalogSignal(signal=signal, sampling_rate=pq.Hz) asig.annotate(**cls.rdict(2)) seg.analogsignals.append(asig) isig = IrregularlySampledSignal(times=times, signal=signal, time_units=pq.s) isig.annotate(**cls.rdict(2)) seg.irregularlysampledsignals.append(isig) epoch = Epoch(times=times, durations=times) epoch.annotate(**cls.rdict(4)) seg.epochs.append(epoch) event = Event(times=times) event.annotate(**cls.rdict(4)) seg.events.append(event) spiketrain = SpikeTrain(times=times, t_stop=pq.s, units=pq.s) d = cls.rdict(6) d["quantity"] = pq.Quantity(10, "mV") d["qarray"] = pq.Quantity(range(10), "mA") spiketrain.annotate(**d) seg.spiketrains.append(spiketrain) chx = ChannelIndex(name="achx", index=[1, 2], channel_ids=[0, 10]) chx.annotate(**cls.rdict(5)) blk.channel_indexes.append(chx) unit = Unit() unit.annotate(**cls.rdict(2)) chx.units.append(unit) return blk
def create_all_annotated(cls): times = cls.rquant(1, pq.s) signal = cls.rquant(1, pq.V) blk = Block() blk.annotate(**cls.rdict(3)) seg = Segment() seg.annotate(**cls.rdict(4)) blk.segments.append(seg) asig = AnalogSignal(signal=signal, sampling_rate=pq.Hz) asig.annotate(**cls.rdict(2)) seg.analogsignals.append(asig) isig = IrregularlySampledSignal(times=times, signal=signal, time_units=pq.s) isig.annotate(**cls.rdict(2)) seg.irregularlysampledsignals.append(isig) epoch = Epoch(times=times, durations=times) epoch.annotate(**cls.rdict(4)) seg.epochs.append(epoch) event = Event(times=times) event.annotate(**cls.rdict(4)) seg.events.append(event) spiketrain = SpikeTrain(times=times, t_stop=pq.s, units=pq.s) d = cls.rdict(6) d["quantity"] = pq.Quantity(10, "mV") d["qarray"] = pq.Quantity(range(10), "mA") spiketrain.annotate(**d) seg.spiketrains.append(spiketrain) chx = ChannelIndex(name="achx", index=[1, 2], channel_ids=[0, 10]) chx.annotate(**cls.rdict(5)) blk.channel_indexes.append(chx) unit = Unit() unit.annotate(**cls.rdict(2)) chx.units.append(unit) return blk