From c0b76a489a5ce84bd2cfedf7fec9401285b45771 Mon Sep 17 00:00:00 2001
From: Coda Phillips <cphillips@sean.ssec.wisc.edu>
Date: Mon, 11 Jul 2016 13:50:32 -0500
Subject: [PATCH] Add covariance check

---
 thermal_checks.py | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/thermal_checks.py b/thermal_checks.py
index d0080fa..ce87a35 100644
--- a/thermal_checks.py
+++ b/thermal_checks.py
@@ -1,7 +1,26 @@
 from util import BaseCheckList
+import sklearn.covariance
+import scipy.stats
+import numpy as np
 
 def thermal_correlation_check(frame, parameters):
     return frame
 
+def hbb_covariance_check(frame, parameters):
+    hbbb_mean = parameters.get('HBBbottomTemp_mean', 333.101)
+    hbbt_mean = parameters.get('HBBtopTemp_mean', 332.993)
+    hbba_mean = parameters.get('HBBapexTemp_mean', 332.818)
+
+    hbb_contamination = parameters.get('hbb_contamination', .01)
+    envelope = sklearn.covariance.EllipticEnvelope(store_precision=False, contamination=hbb_contamination)
+    envelope.location_ = np.array([hbbb_mean, hbbt_mean, hbba_mean])
+    envelope.covariance_ = np.array([[ 0.0179306 ,  0.0164418 ,  0.01817402],
+                                     [ 0.0164418 ,  0.01898899,  0.02326341],
+                                     [ 0.01817402,  0.02326341,  0.02968953]])
+    distances = envelope.mahalanobis(frame[['HBBbottomTemp','HBBtopTemp','HBBapexTemp']]) ** .5
+    frame['hbb_covariance_check'] = (distances > 6) * 1
+    return frame
+    
+
 class CheckList(BaseCheckList):
-    checks = [ thermal_correlation_check ]
+    checks = [ thermal_correlation_check , hbb_covariance_check]
-- 
GitLab