Esempio n. 1
0
    def click_estimate_parameters(self):
        window = (15, 120)
        idx = self.trace_idx
        data = self.cf.get_trace_data(idx)
        tattrs = self.cf.get_trace_attrs(idx)
        data = process_data(data, tattrs, key="_log")

        pre = decode(tattrs["samples_pre_event"])
        shift = decode(tattrs["onset_shift"]) or 0
        fs = decode(tattrs["samplingrate"])
        onset = pre - shift
        print(shift, fs)
        minlat = int(window[0] * fs / 1000)
        maxlat = int(window[1] * fs / 1000)
        a = onset + minlat
        b = onset + maxlat
        mep = data[a:b]
        nlat = mep.argmin()
        plat = mep.argmax()
        namp = float(mep[nlat])
        pamp = float(mep[plat])
        nlat = mep.argmin() * 1000 / fs
        plat = mep.argmax() * 1000 / fs
        print("Estimating latencies to be", nlat, plat)
        print("Estimating amplitudes to be", namp, pamp)
        tattrs["neg_peak_latency_ms"] = encode(float(nlat + window[0]))
        tattrs["neg_peak_magnitude_uv"] = encode(namp)
        tattrs["pos_peak_latency_ms"] = encode(float(plat + window[0]))
        tattrs["pos_peak_magnitude_uv"] = encode(pamp)
        self.cf.set_trace_attrs(idx, tattrs)
        self.draw_hasmep_button()
        self.callback()
Esempio n. 2
0
 def click_hasmep(self):
     print(self.hasmep_button.text())
     if self.hasmep_button.text() == "MEP positive":
         tattrs = self.cf.get_trace_attrs(self.trace_idx)
         tattrs["neg_peak_latency_ms"] = encode(0)
         tattrs["pos_peak_latency_ms"] = encode(0)
         tattrs["neg_peak_magnitude_uv"] = encode(0)
         tattrs["pos_peak_magnitude_uv"] = encode(0)
         self.cf.set_trace_attrs(self.trace_idx, tattrs)
         self.draw_hasmep_button()
         self.callback()
Esempio n. 3
0
def rescale_coords(attrs: TraceAttributes,
                   scaling_factor: float = 1.0) -> TraceAttributes:
    """scale the coordinates of this trace by a scaling factor"""
    coords = decode(attrs["xyz_coords"])
    coords = [float * c for c in coords]
    attrs["xyz_coords"] = encode(coords)
    return attrs
Esempio n. 4
0
def translate_coords(
        attrs: TraceAttributes,
        translation: List[float] = [0.0, 0.0, 0.0]) -> TraceAttributes:
    """move the coordinates of this trace by a translation"""
    coords = decode(attrs["xyz_coords"])
    coords = [c - t for c, t in zip(coords, translation)]
    attrs["xyz_coords"] = encode(coords)
    return attrs
Esempio n. 5
0
def save(cf, idx: int, key: str, read: Callable):
    tattr = cf.get_trace_attrs(idx)
    text = read()
    if tattr[key] == text:
        return
    else:
        tattr[key] = encode(text)
        cf.set_trace_attrs(idx, tattr)
        print(f"CF: Wrote {idx}: {key} {text}")
Esempio n. 6
0
 def log(self, event: str, idx: int):
     attrs = self.cf.get_trace_attrs(idx)
     if "_log" in attrs.keys():
         log = decode(attrs["_log"])
     else:
         log = []
     happening = str(event) + " on " + datetime.now().strftime(
         "%Y-%m-%d %H:%M:%S")
     print("Logging", happening, "to", log)
     log.append(happening)
     attrs["_log"] = encode(log)
     self.cf.set_trace_attrs(self.trace_idx, attrs)
Esempio n. 7
0
    def click_estimate_amplitudes(self):
        idx = self.trace_idx
        data = self.cf.get_trace_data(idx)
        tattrs = self.cf.get_trace_attrs(idx)
        data = process_data(data, tattrs, key="_log")

        fs = decode(tattrs["samplingrate"])
        nlat = int((decode(tattrs["neg_peak_latency_ms"]) or 0) * fs / 1000)
        plat = int((decode(tattrs["pos_peak_latency_ms"]) or 0) * fs / 1000)
        # MEP negative trials
        if nlat == plat:
            print("MEP negative or identical latencies", nlat, plat)
            tattrs["neg_peak_latency_ms"] = encode(0)
            tattrs["pos_peak_latency_ms"] = encode(0)
            tattrs["neg_peak_magnitude_uv"] = encode(0)
            tattrs["pos_peak_magnitude_uv"] = encode(0)
        else:
            pre = decode(tattrs["samples_pre_event"])
            shift = decode(tattrs["onset_shift"]) or 0
            namp = float(data[nlat + pre + shift])
            pamp = float(data[plat + pre + shift])
            print("Estimating amplitudes to be", namp, pamp)
            tattrs["neg_peak_magnitude_uv"] = encode(namp)
            tattrs["pos_peak_magnitude_uv"] = encode(pamp)

        self.cf.set_trace_attrs(idx, tattrs)
        self.draw_hasmep_button()
        self.callback()
Esempio n. 8
0
def save_global(cf, idx: int, key: str, read: Callable):
    tattr = cf.get_trace_attrs(idx)
    text = read()
    if tattr[key] == text:
        return
    else:
        origin = tattr["origin"]
        for idx in range(len(cf)):
            tattr = cf.get_trace_attrs(idx)
            if tattr["origin"] == origin:
                tattr[key] = encode(text)
                cf.set_trace_attrs(idx, tattr)
        print(f"CF: Wrote globaly {origin}: {key} {text}")
Esempio n. 9
0
    def undo(self, idx):
        attrs = self.cf.get_trace_attrs(idx)
        if "_log" in attrs.keys():
            log = decode(attrs["_log"])
        else:
            log = []

        if len(log) > 0:
            event = log.pop()
            step, when = event.split(" on ")
            print("Undoing", step, "from", when)
        else:
            print("Nothing to undo")
        attrs["_log"] = encode(log)
        self.cf.set_trace_attrs(self.trace_idx, attrs)
Esempio n. 10
0
 def get_cleaned_tattrs(self, cf, idx):
     tattrs = cf.get_trace_attrs(idx)
     initialize_with_zero = [
         "onset_shift",
         "neg_peak_latency_ms",
         "pos_peak_latency_ms",
         "neg_peak_magnitude_uv",
         "pos_peak_magnitude_uv",
     ]
     for key in initialize_with_zero:
         tattrs[key] = encode(decode(tattrs[key]) or 0)
     cf.set_trace_attrs(idx, tattrs)
     keys = get_valid_trace_keys(tattrs["readin"], tattrs["readout"]).copy()
     keys.remove("reject")
     keys.remove("onset_shift")
     keys.remove("comment")
     show_tattrs = dict()
     for key in sorted(keys):
         if key[0] != "_":
             show_tattrs[key] = tattrs[key]
     return show_tattrs