diff --git a/electronic_checks.py b/electronic_checks.py index 5bd1af4e75e0b52b0f4db8dbde95e991579ca5fd..b41d1f809c88fdf9954e9d59d81d187be4093a0b 100644 --- a/electronic_checks.py +++ b/electronic_checks.py @@ -6,18 +6,19 @@ import itertools electronic_checks = BaseCheckList() def find_bb_outliers(frame, parameters, bb): + """ + Find outliers in blackbody temperatures. + Annotate any problems, and set quality flags for each thermistor + """ window_length = parameters.get('window_length', 50) if bb == 'HBB': delta_thresh = .001 - bbb_outliers = np.array(list(_scan_for_outliers(frame, '{}bottomTemp'.format(bb), delta_thresh))) - bba_outliers = np.array(list(_scan_for_outliers(frame, '{}apexTemp'.format(bb), delta_thresh))) - bbt_outliers = np.array(list(_scan_for_outliers(frame, '{}topTemp'.format(bb), delta_thresh))) else: delta_thresh = .01 - bbb_outliers = np.array(list(_scan_for_outliers(frame, '{}bottomTemp'.format(bb), delta_thresh))) - bba_outliers = np.array(list(_scan_for_outliers(frame, '{}apexTemp'.format(bb), delta_thresh))) - bbt_outliers = np.array(list(_scan_for_outliers(frame, '{}topTemp'.format(bb), delta_thresh))) + bbb_outliers = np.array(list(_scan_for_outliers(frame, '{}bottomTemp'.format(bb), delta_thresh))) + bba_outliers = np.array(list(_scan_for_outliers(frame, '{}apexTemp'.format(bb), delta_thresh))) + bbt_outliers = np.array(list(_scan_for_outliers(frame, '{}topTemp'.format(bb), delta_thresh))) variable_qcs = pd.DataFrame({ 'qc_{}bottomTemp'.format(bb) : bbb_outliers * 1, @@ -53,12 +54,17 @@ def _find_6sigma_outliers(frame, window_length, estimation_func=_compute_robust_ return estimation_func(frame, window_length) > 6 def _scan_for_outliers(frame, variable, delta_thresh): + """ + Check for temperature changes exceeding the delta_thresh rate in degK / sec + """ last = None for i, row in frame.iterrows(): + # First row cannot be an outlier if last is None: yield False last = row else: + # Compare each row to previous non-outlier row time_diff = (row.datetime - last.datetime).total_seconds() variable_diff = row[variable] - last[variable] if abs(variable_diff / time_diff) < delta_thresh: