Skip to content

Commit

Permalink
#21 parameterise herg QC test
Browse files Browse the repository at this point in the history
  • Loading branch information
kwabenantim committed Aug 8, 2024
1 parent 264c697 commit b9ebc16
Showing 1 changed file with 43 additions and 50 deletions.
93 changes: 43 additions & 50 deletions tests/test_herg_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@

from pcpostprocess.hergQC import hERGQC

WELLS = ['A01', 'A02', 'A03', 'A04', 'A05', 'D01']


class TestHergQC(unittest.TestCase):

def setUp(self):
filepath = os.path.join('tests', 'test_data', '13112023_MW2_FF',
'staircaseramp (2)_2kHz_15.01.07')
Expand All @@ -32,68 +35,58 @@ def setUp(self):
self.test_trace_after = Trace(filepath2, json_file2)

def test_run_qc(self):
tr_before = self.test_trace_before
tr_after = self.test_trace_after

v = tr_before.get_voltage()

times = tr_after.get_times()

self.assertTrue(np.all(np.isfinite(v)))
self.assertTrue(np.all(np.isfinite(times)))
for well in WELLS:
with self.subTest(well):
tr_before = self.test_trace_before
tr_after = self.test_trace_after

# Calculate sampling rate in (use kHz)
sampling_rate = int(1.0 / (times[1] - times[0]))
v = tr_before.get_voltage()

plot_dir = os.path.join(self.output_dir,
'test_run_qc')
times = tr_after.get_times()

if not os.path.exists(plot_dir):
os.makedirs(plot_dir)
self.assertTrue(np.all(np.isfinite(v)))
self.assertTrue(np.all(np.isfinite(times)))

hergqc = hERGQC(sampling_rate=sampling_rate,
plot_dir=plot_dir,
voltage=v)
# Calculate sampling rate in (use kHz)
sampling_rate = int(1.0 / (times[1] - times[0]))

sweeps = [0, 1]
before = tr_before.get_trace_sweeps(sweeps)
after = tr_after.get_trace_sweeps(sweeps)
qc_vals_before = tr_before.get_onboard_QC_values(sweeps=sweeps)
qc_vals_after = tr_after.get_onboard_QC_values(sweeps=sweeps)
plot_dir = os.path.join(self.output_dir,
'test_run_qc')

res = {}
if not os.path.exists(plot_dir):
os.makedirs(plot_dir)

# Spot check a few wells
# We could check all of the wells but it's time consuming
hergqc = hERGQC(sampling_rate=sampling_rate,
plot_dir=plot_dir,
voltage=v)

test_wells = ['A01', 'A02', 'A03', 'A04', 'A05', 'D01']
sweeps = [0, 1]
before = tr_before.get_trace_sweeps(sweeps)
after = tr_after.get_trace_sweeps(sweeps)
qc_vals_before = tr_before.get_onboard_QC_values(sweeps=sweeps)
qc_vals_after = tr_after.get_onboard_QC_values(sweeps=sweeps)

voltage_protocol = tr_before.get_voltage_protocol()
# Spot check a few wells
# We could check all of the wells but it's time consuming

for well in test_wells:
# Take values from the first sweep only
qc_vals_before_well = np.array(qc_vals_before[well])[0, :]
qc_vals_after_well = np.array(qc_vals_after[well])[0, :]
voltage_protocol = tr_before.get_voltage_protocol()

before_well = np.array(before[well])
after_well = np.array(after[well])
# Take values from the first sweep only
qc_vals_before_well = np.array(qc_vals_before[well])[0, :]
qc_vals_after_well = np.array(qc_vals_after[well])[0, :]

#  Assume that there are no discontinuities at the start or end of ramps
voltage_steps = [tstart
for tstart, tend, vstart, vend in
voltage_protocol.get_all_sections() if vend == vstart]
before_well = np.array(before[well])
after_well = np.array(after[well])

passed, qcs = hergqc.run_qc(voltage_steps,
times, before_well, after_well,
qc_vals_before_well,
qc_vals_after_well, n_sweeps=2)
#  Assume that there are no discontinuities at the start or end of ramps
voltage_steps = [tstart
for tstart, tend, vstart, vend in
voltage_protocol.get_all_sections() if vend == vstart]

logging.debug(well, passed)
res[well] = passed
passed, qcs = hergqc.run_qc(voltage_steps,
times, before_well, after_well,
qc_vals_before_well,
qc_vals_after_well, n_sweeps=2)

self.assertTrue(res['A01'])
self.assertTrue(res['A02'])
self.assertTrue(res['A03'])
self.assertTrue(res['A04'])
self.assertFalse(res['A05'])
self.assertFalse(res['D01'])
logging.debug(well, passed)
self.assertTrue(passed)

0 comments on commit b9ebc16

Please sign in to comment.