From 1085012c6b0666dcfdeff454546762c162c4f695 Mon Sep 17 00:00:00 2001
From: Coda Phillips <cphillips@sean.ssec.wisc.edu>
Date: Mon, 25 Jul 2016 13:29:48 -0500
Subject: [PATCH] Save only records pertaining to calibrated radiance (SUM
 file)

---
 main.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/main.py b/main.py
index d559600..b8c30ef 100644
--- a/main.py
+++ b/main.py
@@ -3,6 +3,8 @@ from glob import glob
 import re
 import netCDF4
 from aeri_tools.io.dmv.housekeeping import get_all_housekeeping
+import pandas as pd
+import numpy as np
 
 
 from electronic_checks import electronic_checks
@@ -22,6 +24,7 @@ levels = [
 ]
 
 def save_quality(frame, qc_path):
+    frame = frame.ix[pd.notnull(frame.sum_index)].set_index('sum_index')
     ncdf = netCDF4.Dataset(qc_path, 'w')
     time = ncdf.createDimension('time', len(frame))
     base_time = ncdf.createVariable('base_time', 'i8', ())
@@ -41,8 +44,11 @@ def save_quality(frame, qc_path):
     
 
 def read_frame(cxs_file, sum_file):
-    hk = get_all_housekeeping(cxs_file).combine_first(
-        get_all_housekeeping(sum_file))
+    cxs = get_all_housekeeping(cxs_file)
+    cxs['cxs_index'] = np.arange(len(cxs))
+    sum_ = get_all_housekeeping(sum_file)
+    sum_['sum_index'] = np.arange(len(sum_))
+    hk = cxs.combine_first(sum_).sort_values(['cxs_index','sum_index'])
     hk.index.name = 'datetime'
     return hk.reset_index()
 
-- 
GitLab