Skip to content

Commit f2ac760

Browse files
committed
#21 Run qc6 on all test data
1 parent 467fae2 commit f2ac760

File tree

1 file changed

+183
-47
lines changed

1 file changed

+183
-47
lines changed

tests/test_herg_qc.py

+183-47
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def setUp(self):
6363
plot_dir=plot_dir,
6464
voltage=self.voltage,
6565
)
66+
self.hergqc._debug = False # Turn this on to output plots
6667

6768
def clone_herg_qc(self, plot_dir):
6869
hergqc = copy.deepcopy(self.hergqc)
@@ -72,8 +73,19 @@ def clone_herg_qc(self, plot_dir):
7273
return hergqc
7374

7475
def test_qc_inputs(self):
75-
self.assertTrue(np.all(np.isfinite(self.voltage)))
76-
self.assertTrue(np.all(np.isfinite(self.times)))
76+
times = self.times
77+
voltage = self.hergqc.voltage
78+
qc6_win = self.hergqc.qc6_win
79+
qc6_1_win = self.hergqc.qc6_1_win
80+
qc6_2_win = self.hergqc.qc6_2_win
81+
82+
self.assertTrue(np.all(np.isfinite(times)))
83+
self.assertTrue(np.all(np.isfinite(voltage)))
84+
85+
# Ensure thats the windows are correct by checking the voltage trace
86+
assert np.all(np.abs(voltage[qc6_win[0]: qc6_win[1]] - 40.0)) < 1e-8
87+
assert np.all(np.abs(voltage[qc6_1_win[0]: qc6_1_win[1]] - 40.0)) < 1e-8
88+
assert np.all(np.abs(voltage[qc6_2_win[0]: qc6_2_win[1]] - 40.0)) < 1e-8
7789

7890
def test_qc1(self):
7991
hergqc = self.clone_herg_qc("test_qc1")
@@ -757,60 +769,184 @@ def test_qc6(self):
757769
# qc6 checks that the first step up to +40 mV, before the staircase, in
758770
# the subtracted trace is bigger than -2 x estimated noise level.
759771
test_matrix = [
760-
(-100, False), # valc - val = 9.9
761-
(-10, False), # valc - val = 0.9
762-
(-2, False), # valc - val = 0.1
763-
(-1, True), # valc - val = 0
764-
(1, True), # valc - val = -0.2
765-
(2, True), # valc - val = -0.3
766-
(10, True), # valc - val = -1.1
767-
(100, True), # valc - val = -10.1
772+
(-100, False, 9.9),
773+
(-10, False, 0.9),
774+
(-1, True, 0),
775+
(0, True, -0.1),
776+
(1, True, -0.2),
777+
(10, True, -1.1),
778+
(100, True, -10.1),
768779
]
769-
for i, ex_pass in test_matrix:
780+
781+
for i, ex_pass, ex_d_val in test_matrix:
770782
recording = np.asarray(
771-
[0, 0.1] * (NOISE_LEN // 2) + [0.1 * i] * 500)
772-
result = hergqc.qc6(recording, win=[NOISE_LEN, -1])
773-
self.assertEqual(result[0], ex_pass, f"({i}: {result[1]})")
783+
[0, 0.1] * (NOISE_LEN // 2) + [0.1 * i] * 500
784+
)
785+
pass_, d_val = hergqc.qc6(recording, win=[NOISE_LEN, -1])
786+
self.assertAlmostEqual(
787+
d_val,
788+
ex_d_val,
789+
1,
790+
f"QC6: ({i}) {d_val} != {ex_d_val}",
791+
)
792+
self.assertEqual(pass_, ex_pass, f"QC6: ({i}) {pass_} != {ex_pass}")
793+
794+
# Test on data
795+
failed_wells_0 = [
796+
'A05', 'A07', 'A11', 'A12', 'A13', 'A20', 'A22', 'A24', 'B02', 'B05',
797+
'B07', 'B09', 'B10', 'B15', 'B23', 'C02', 'C04', 'C14', 'C18', 'C22',
798+
'D01', 'D12', 'E04', 'E09', 'E10', 'E15', 'E16', 'E17', 'E19', 'E21',
799+
'F02', 'F03', 'F07', 'F10', 'F18', 'F20', 'F21', 'F22', 'G06', 'G08',
800+
'G10', 'G15', 'G16', 'G20', 'G23', 'H01', 'H09', 'H11', 'H15', 'H17',
801+
'H19', 'H21', 'H23', 'H24', 'I04', 'I06', 'I10', 'I12', 'I15', 'I21',
802+
'J07', 'J09', 'J16', 'J21', 'K01', 'K02', 'K03', 'K09', 'K13', 'K14',
803+
'K18', 'K22', 'K23', 'L01', 'L02', 'L05', 'L07', 'L08', 'L10', 'L11',
804+
'L13', 'L17', 'L18', 'L21', 'L23', 'L24', 'M01', 'M04', 'M06', 'M07',
805+
'M11', 'M12', 'M17', 'N06', 'N11', 'N14', 'N20', 'N24', 'O01', 'O07',
806+
'O08', 'O16', 'O17', 'O19', 'O22', 'O24', 'P01', 'P06', 'P08', 'P12',
807+
'P14', 'P15', 'P17', 'P18', 'P21'
808+
]
809+
810+
failed_wells_1 = [
811+
'A05', 'A07', 'A11', 'A12', 'A13', 'A20', 'A22', 'A24', 'B02', 'B05',
812+
'B07', 'B10', 'B15', 'C02', 'C04', 'C14', 'C18', 'C22', 'D01', 'D12',
813+
'E04', 'E09', 'E10', 'E14', 'E15', 'E16', 'E19', 'E21', 'F02', 'F03',
814+
'F07', 'F10', 'F12', 'F18', 'F20', 'F21', 'F22', 'G06', 'G08', 'G09',
815+
'G10', 'G15', 'G16', 'G20', 'G23', 'H01', 'H09', 'H11', 'H15', 'H17',
816+
'H19', 'H21', 'H23', 'H24', 'I04', 'I06', 'I10', 'I12', 'I15', 'I21',
817+
'J07', 'J16', 'J21', 'K01', 'K02', 'K09', 'K13', 'K14', 'K23', 'L01',
818+
'L02', 'L05', 'L07', 'L08', 'L10', 'L11', 'L13', 'L17', 'L18', 'L21',
819+
'L24', 'M01', 'M04', 'M06', 'M07', 'M11', 'M12', 'M17', 'N06', 'N11',
820+
'N14', 'N20', 'N24', 'O01', 'O06', 'O07', 'O08', 'O17', 'O19', 'O22',
821+
'O24', 'P01', 'P06', 'P08', 'P12', 'P14', 'P15', 'P17', 'P18', 'P21'
822+
]
823+
824+
failed_wells_2 = [
825+
'A05', 'A07', 'A10', 'A11', 'A12', 'A13', 'A20', 'A22', 'A24', 'B02',
826+
'B05', 'B07', 'B10', 'B15', 'C02', 'C04', 'C14', 'C22', 'D01', 'D12',
827+
'E04', 'E09', 'E10', 'E14', 'E15', 'E16', 'E21', 'F02', 'F03', 'F07',
828+
'F10', 'F12', 'F18', 'F20', 'F21', 'F22', 'G06', 'G08', 'G09', 'G10',
829+
'G15', 'G16', 'G20', 'G23', 'H01', 'H07', 'H09', 'H11', 'H15', 'H17',
830+
'H19', 'H21', 'H23', 'H24', 'I06', 'I10', 'I12', 'I15', 'I21', 'J07',
831+
'J16', 'J21', 'K01', 'K02', 'K09', 'K13', 'K14', 'K23', 'L01', 'L02',
832+
'L08', 'L10', 'L11', 'L13', 'L17', 'L18', 'L21', 'L24', 'M01', 'M04',
833+
'M06', 'M07', 'M11', 'M12', 'M17', 'N06', 'N11', 'N14', 'N24', 'O01',
834+
'O06', 'O07', 'O08', 'O17', 'O19', 'O24', 'P01', 'P06', 'P08', 'P12',
835+
'P14', 'P15', 'P17', 'P18', 'P21'
836+
]
837+
838+
for well in self.all_wells:
839+
before = np.array(self.trace_sweeps_before[well])
840+
after = np.array(self.trace_sweeps_after[well])
841+
842+
subtracted_0 = []
843+
subtracted_1 = []
844+
subtracted_2 = []
845+
846+
for i in range(before.shape[0]):
847+
subtracted_0.append(
848+
hergqc.qc6(
849+
(before[i, :] - after[i, :]), hergqc.qc6_win, label="0"
850+
)
851+
)
852+
853+
subtracted_1.append(
854+
hergqc.qc6(
855+
(before[i, :] - after[i, :]),
856+
hergqc.qc6_1_win,
857+
label="1",
858+
)
859+
)
860+
861+
subtracted_2.append(
862+
hergqc.qc6(
863+
(before[i, :] - after[i, :]),
864+
hergqc.qc6_2_win,
865+
label="2",
866+
)
867+
)
868+
869+
ex_pass_0 = well not in failed_wells_0
870+
self.assertEqual(
871+
all_passed(subtracted_0),
872+
ex_pass_0,
873+
f"QC6 (0): {well} {subtracted_0}",
874+
)
774875

775-
# TODO: Test on select data
876+
ex_pass_1 = well not in failed_wells_1
877+
self.assertEqual(
878+
all_passed(subtracted_1),
879+
ex_pass_1,
880+
f"QC6 (1): {well} {subtracted_1}",
881+
)
882+
883+
ex_pass_2 = well not in failed_wells_2
884+
self.assertEqual(
885+
all_passed(subtracted_2),
886+
ex_pass_2,
887+
f"QC6 (2): {well} {subtracted_2}",
888+
)
776889

777890
def test_run_qc(self):
778-
# Spot check a few wells; could check all, but it's time consuming.
891+
# Test all wells
779892
hergqc = self.clone_herg_qc("test_run_qc")
780893

781-
test_matrix = [
782-
("A01", True),
783-
("A02", True),
784-
("A03", True),
785-
("A04", False),
786-
("A05", False),
787-
("D01", False),
894+
failed_wells = [
895+
'A04', 'A05', 'A06', 'A07', 'A08', 'A10', 'A11', 'A12', 'A13', 'A15',
896+
'A16', 'A19', 'A20', 'A21', 'A22', 'A23', 'A24', 'B02', 'B04', 'B05',
897+
'B07', 'B09', 'B10', 'B11', 'B12', 'B13', 'B14', 'B15', 'B16', 'B18',
898+
'B19', 'B21', 'B23', 'C01', 'C02', 'C04', 'C05', 'C07', 'C08', 'C09',
899+
'C10', 'C11', 'C12', 'C14', 'C17', 'C18', 'C19', 'C20', 'C21', 'C22',
900+
'C23', 'C24', 'D01', 'D02', 'D03', 'D04', 'D05', 'D09', 'D10', 'D11',
901+
'D12', 'D13', 'D14', 'D15', 'D16', 'D17', 'D18', 'D19', 'D21', 'D23',
902+
'E01', 'E02', 'E03', 'E04', 'E06', 'E07', 'E09', 'E10', 'E11', 'E13',
903+
'E14', 'E15', 'E16', 'E17', 'E18', 'E19', 'E20', 'E21', 'E22', 'E23',
904+
'E24', 'F01', 'F02', 'F03', 'F04', 'F05', 'F06', 'F07', 'F09', 'F10',
905+
'F11', 'F12', 'F13', 'F14', 'F15', 'F16', 'F18', 'F19', 'F20', 'F21',
906+
'F22', 'F23', 'F24', 'G03', 'G06', 'G08', 'G09', 'G10', 'G12', 'G13',
907+
'G14', 'G15', 'G16', 'G17', 'G18', 'G19', 'G20', 'G21', 'G23', 'G24',
908+
'H01', 'H02', 'H03', 'H04', 'H06', 'H07', 'H08', 'H09', 'H10', 'H11',
909+
'H13', 'H14', 'H15', 'H16', 'H17', 'H18', 'H19', 'H20', 'H21', 'H23',
910+
'H24', 'I01', 'I03', 'I04', 'I05', 'I06', 'I07', 'I08', 'I10', 'I11',
911+
'I12', 'I13', 'I14', 'I15', 'I16', 'I17', 'I18', 'I19', 'I20', 'I21',
912+
'J03', 'J06', 'J07', 'J08', 'J09', 'J10', 'J11', 'J12', 'J14', 'J15',
913+
'J16', 'J17', 'J18', 'J19', 'J20', 'J21', 'J23', 'J24', 'K01', 'K02',
914+
'K03', 'K05', 'K06', 'K07', 'K09', 'K10', 'K11', 'K12', 'K13', 'K14',
915+
'K16', 'K17', 'K18', 'K20', 'K22', 'K23', 'K24', 'L01', 'L02', 'L03',
916+
'L04', 'L05', 'L06', 'L07', 'L08', 'L10', 'L11', 'L12', 'L13', 'L16',
917+
'L17', 'L18', 'L20', 'L21', 'L23', 'L24', 'M01', 'M02', 'M03', 'M04',
918+
'M05', 'M06', 'M07', 'M08', 'M09', 'M10', 'M11', 'M12', 'M13', 'M14',
919+
'M15', 'M16', 'M17', 'M18', 'M19', 'M20', 'M21', 'N01', 'N02', 'N03',
920+
'N04', 'N06', 'N07', 'N08', 'N09', 'N11', 'N13', 'N14', 'N16', 'N17',
921+
'N18', 'N19', 'N20', 'N21', 'N22', 'N23', 'N24', 'O01', 'O02', 'O03',
922+
'O04', 'O05', 'O06', 'O07', 'O08', 'O10', 'O11', 'O12', 'O13', 'O14',
923+
'O15', 'O16', 'O17', 'O18', 'O19', 'O20', 'O21', 'O22', 'O24', 'P01',
924+
'P03', 'P05', 'P06', 'P07', 'P08', 'P09', 'P10', 'P11', 'P12', 'P13',
925+
'P14', 'P15', 'P16', 'P17', 'P18', 'P19', 'P20', 'P21', 'P22', 'P24'
788926
]
789927

790-
for well, ex_pass in test_matrix:
791-
with self.subTest(well):
792-
# Take values from the first sweep only
793-
before = np.array(self.trace_sweeps_before[well])
794-
after = np.array(self.trace_sweeps_after[well])
795-
796-
qc_vals_before = np.array(self.qc_vals_before[well])[0, :]
797-
qc_vals_after = np.array(self.qc_vals_after[well])[0, :]
798-
799-
QC = hergqc.run_qc(
800-
voltage_steps=self.voltage_steps,
801-
times=self.times,
802-
before=before,
803-
after=after,
804-
qc_vals_before=qc_vals_before,
805-
qc_vals_after=qc_vals_after,
806-
n_sweeps=self.n_sweeps,
807-
)
928+
for well in self.all_wells:
929+
before = np.array(self.trace_sweeps_before[well])
930+
after = np.array(self.trace_sweeps_after[well])
808931

809-
logging.debug(well, QC.all_passed())
932+
# Take values from the first sweep only
933+
qc_vals_before = np.array(self.qc_vals_before[well])[0, :]
934+
qc_vals_after = np.array(self.qc_vals_after[well])[0, :]
810935

811-
trace = ""
812-
for label, result in QC.items():
813-
if not QC.qc_passed(label):
814-
trace += f"{well} {label}: {result}\n"
936+
QC = hergqc.run_qc(
937+
voltage_steps=self.voltage_steps,
938+
times=self.times,
939+
before=before,
940+
after=after,
941+
qc_vals_before=qc_vals_before,
942+
qc_vals_after=qc_vals_after,
943+
n_sweeps=self.n_sweeps,
944+
)
815945

816-
self.assertEqual(QC.all_passed(), ex_pass, trace)
946+
trace = ""
947+
for label, result in QC.items():
948+
if not QC.qc_passed(label):
949+
trace += f"{well} {label}: {result}\n"
950+
951+
ex_pass = well not in failed_wells
952+
self.assertEqual(QC.all_passed(), ex_pass, trace)

0 commit comments

Comments
 (0)