|
| 1 | +#!/usr/bin/env python3 |
| 2 | +import os |
| 3 | +import unittest |
| 4 | + |
| 5 | +from syncropatch_export.trace import Trace |
| 6 | + |
| 7 | +from pcpostprocess import infer_reversal, leak_correct |
| 8 | +from pcpostprocess.detect_ramp_bounds import detect_ramp_bounds |
| 9 | + |
| 10 | + |
| 11 | +class TestInferReversal(unittest.TestCase): |
| 12 | + def setUp(self): |
| 13 | + test_data_dir = os.path.join('tests', 'test_data', '13112023_MW2_FF', |
| 14 | + "staircaseramp (2)_2kHz_15.01.07") |
| 15 | + json_file = "staircaseramp (2)_2kHz_15.01.07.json" |
| 16 | + |
| 17 | + self.output_dir = os.path.join('test_output', self.__class__.__name__) |
| 18 | + |
| 19 | + if not os.path.exists(self.output_dir): |
| 20 | + os.makedirs(self.output_dir) |
| 21 | + |
| 22 | + self.test_trace = Trace(test_data_dir, json_file) |
| 23 | + |
| 24 | + # get currents and QC from trace object |
| 25 | + self.currents = self.test_trace.get_all_traces(leakcorrect=False) |
| 26 | + self.currents['times'] = self.test_trace.get_times() |
| 27 | + self.currents['voltages'] = self.test_trace.get_voltage() |
| 28 | + |
| 29 | + self.protocol_desc = self.test_trace.get_voltage_protocol().get_all_sections() |
| 30 | + self.leak_ramp_bound_indices = detect_ramp_bounds(self.currents['times'], |
| 31 | + self.protocol_desc, |
| 32 | + ramp_index=0) |
| 33 | + |
| 34 | + self.voltages = self.test_trace.get_voltage() |
| 35 | + self.correct_Erev = -89.57184330525791438049054704606533050537109375 |
| 36 | + |
| 37 | + def test_plot_leak_fit(self): |
| 38 | + well = "A03" |
| 39 | + sweep = 0 |
| 40 | + |
| 41 | + voltage = self.test_trace.get_voltage() |
| 42 | + times = self.test_trace.get_times() |
| 43 | + |
| 44 | + current = self.test_trace.get_trace_sweeps(sweeps=[sweep])[well][0, :] |
| 45 | + params, Ileak = leak_correct.fit_linear_leak(current, voltage, times, |
| 46 | + *self.leak_ramp_bound_indices, |
| 47 | + output_dir=self.output_dir, |
| 48 | + save_fname=f"{well}_sweep{sweep}_leak_correction") |
| 49 | + |
| 50 | + I_corrected = current - Ileak |
| 51 | + |
| 52 | + E_rev = infer_reversal.infer_reversal_potential( |
| 53 | + I_corrected, times, self.protocol_desc, |
| 54 | + self.voltages, |
| 55 | + output_path=os.path.join(self.output_dir, |
| 56 | + f"{well}_staircase"), |
| 57 | + known_Erev=self.correct_Erev) |
| 58 | + self.assertLess(abs(E_rev - self.correct_Erev), 1e-5) |
| 59 | + |
| 60 | + |
| 61 | +if __name__ == "__main__": |
| 62 | + pass |
0 commit comments