From e738d6336886a4e472995e56a6832859c1c10871 Mon Sep 17 00:00:00 2001 From: Coda Phillips <cphillips@sean.ssec.wisc.edu> Date: Wed, 6 Jul 2016 15:57:41 -0500 Subject: [PATCH] Add hbb stability check --- state_checks.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/state_checks.py b/state_checks.py index 88c2ae7..be91118 100644 --- a/state_checks.py +++ b/state_checks.py @@ -52,6 +52,27 @@ def hbb_thermistor_check(frame, parameters): return frame 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 + + variable_qcs = pd.DataFrame({ + 'qc_HBBbottomTemp':hbbb_diff_problem * 1, + 'qc_HBBapexTemp' : hbba_diff_problem * 1, + 'qc_HBBtopTemp' : hbbt_diff_problem * 1 + }, index=frame.index) + frame = update_variable_qc(frame, variable_qcs) + + frame['hbb_stable_check'] = (hbbb_diff_problem | hbbt_diff_problem | hbbt_diff_problem) * 1 + annotate_all(frame, hbbb_diff_problem, 'HBB bottom temperature not stable') + annotate_all(frame, hbba_diff_problem, 'HBB apex temperature not stable') + annotate_all(frame, hbbt_diff_problem, 'HBB top temperature not stable') + frame = invalidate_records(frame, 'hbb_stable_check') return frame class CheckList(BaseCheckList): @@ -60,6 +81,32 @@ class CheckList(BaseCheckList): #### TESTS #### +def test_hbb_stable_check(): + # Check with rates of .0016 + dummy_data = pd.DataFrame({ + 'HBBbottomTemp':np.arange(0,2,.1), + 'HBBapexTemp':np.arange(0,2,.1), + 'HBBtopTemp':np.arange(0,2,.1), + 'datetime':pd.date_range('1/1/2000', periods=20, freq='60s'), + 'qc_notes':'', + 'qc_percent':0, + 'sceneMirrorPosition':ord('S') + }) + frame = hbb_stable_check( + dummy_data, {'hbb_stable_rate':.002} + ) + assert all(frame['hbb_stable_check'] == 0) + + dummy_data.ix[10:,'HBBbottomTemp'] = np.arange(1,3,.2) + dummy_data.ix[10:,'HBBtopTemp'] = np.arange(1,3,.2) + dummy_data.ix[10:,'HBBbottomTemp'] = np.arange(1,3,.2) + + frame = hbb_stable_check( + dummy_data, {'hbb_stable_rate':.002} + ) + assert all(frame.ix[:10, 'hbb_stable_check'] == 0) + assert all(frame.ix[11:, 'hbb_stable_check'] == 1) + def test_hbb_thermistor_check(): frame = hbb_thermistor_check(pd.DataFrame({ 'HBBbottomTemp':[300,333,336], -- GitLab