import pandas as pd import numpy as np from aeri_qc.all_checks import checklist @checklist.add_check(depends=['detectorTemp'], affects_calibration=True, description='detector temperature too high') def detector_check(frame, parameters): """ Check that the detector temp is in range """ return frame['detectorTemp'] > 90 @checklist.add_check(depends=['HBBapexTemp','HBBbottomTemp','HBBtopTemp'], affects_calibration=True, description='HBB thermistors outside range') def hbb_thermistor_check(frame, parameters): return thermistor_check(frame, 'HBB', 331, 335) @checklist.add_check(depends=['ABBapexTemp','ABBbottomTemp','ABBtopTemp'], affects_calibration=True, description='ABB thermistors outside range') def abb_thermistor_check(frame, parameters): return thermistor_check(frame, 'ABB', 150, 335) @checklist.add_check(depends=['datetime', 'HBBbottomTemp','HBBtopTemp','HBBapexTemp'], affects_calibration=True, description='HBB temperature is changing too quickly') def hbb_stable_check(frame, parameters): interval_seconds = frame['datetime'].diff().astype(np.int64) / 1e9 hbbb_diff = frame['HBBbottomTemp'].diff() / interval_seconds hbba_diff = frame['HBBapexTemp'].diff() / interval_seconds hbbt_diff = frame['HBBtopTemp'].diff() / interval_seconds hsr = parameters.get('hbb_stable_rate', .002) hbbb_diff_problem = abs(hbbb_diff.fillna(0)) > hsr hbba_diff_problem = abs(hbba_diff.fillna(0)) > hsr hbbt_diff_problem = abs(hbbt_diff.fillna(0)) > hsr return (hbbb_diff_problem | hbbt_diff_problem | hbbt_diff_problem) def thermistor_check(frame, bb, low, high): """ Check that all thermistor temps are in range """ bbb_too_low = frame['{}bottomTemp'.format(bb)] < low bba_too_low = frame['{}apexTemp'.format(bb)] < low bbt_too_low = frame['{}topTemp'.format(bb)] < low bbb_too_high = frame['{}bottomTemp'.format(bb)] > high bba_too_high = frame['{}apexTemp'.format(bb)] > high bbt_too_high = frame['{}topTemp'.format(bb)] > high bbb_problem = bbb_too_low | bbb_too_high bba_problem = bba_too_low | bba_too_high bbt_problem = bbt_too_low | bbt_too_high return (bbb_problem | bba_problem | bbt_problem)