From a86ff3e3e52d7a19bda3191b9d72b2e73429e34d Mon Sep 17 00:00:00 2001
From: Coda Phillips <cphillips@sean.ssec.wisc.edu>
Date: Fri, 26 Aug 2016 20:18:42 -0500
Subject: [PATCH] Fix bug when SUM and CXS differ in size

---
 interpret_qc.py | 1 +
 main.py         | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/interpret_qc.py b/interpret_qc.py
index 862f186..322e6e2 100644
--- a/interpret_qc.py
+++ b/interpret_qc.py
@@ -51,6 +51,7 @@ def ignore_error(func, error):
 def plot_check(nc, check, sum_hk):
     check_var = nc.variables[check]
     passes_qc = check_var[:] < .95
+    assert len(passes_qc) == len(sum_hk)
     for depend in check_var.depends.split(','):
         if depend in sum_hk.columns:
             fig = plt.figure()
diff --git a/main.py b/main.py
index 353075d..039fee7 100644
--- a/main.py
+++ b/main.py
@@ -102,7 +102,8 @@ def read_frame(cxs_file, sum_file):
     sum_.index.name = 'sum_index'
     
     # Combine extra data from SUM into CXS
-    non_cal_records = non_cal_records.combine_first(sum_)
+    # also non_cal_records may have a different number of records than the sum, so limit by the sum
+    non_cal_records = non_cal_records.combine_first(sum_).ix[sum_.index]
     hk = cxs.combine_first(non_cal_records.reset_index().set_index('cxs_index'))
     hk.calibration_graph = compute_calibration_graph(hk.sceneMirrorPosition)
     return hk
-- 
GitLab