From 7d2f324dcadcfaf7a6b7d2940a7f7c8862118959 Mon Sep 17 00:00:00 2001
From: tomrink <rink@ssec.wisc.edu>
Date: Sun, 9 Jan 2022 14:15:30 -0600
Subject: [PATCH] snapshot...

---
 modules/amv/caliop_clavrx_amv.py | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/modules/amv/caliop_clavrx_amv.py b/modules/amv/caliop_clavrx_amv.py
index bfb078c3..780a7e1d 100644
--- a/modules/amv/caliop_clavrx_amv.py
+++ b/modules/amv/caliop_clavrx_amv.py
@@ -29,9 +29,7 @@ def get_search_box(cc, ll):
     return c_rng, l_rng
 
 
-def match_calipso_clavrx_to_amvs(calipso_clavrx_path, calipso_clavrx_file, amv_files_path, amv_source='OPS', band='14', amv_files=None):
-    if amv_files is None:
-        amv_files = get_datasource(amv_files_path, amv_source, band=band)
+def match_calipso_clavrx_to_amvs(calipso_clavrx_ds, calipso_clavrx_file, amv_files, amv_source='OPS', band='14'):
     nav = amv_files.get_navigation()
     amv_params = amv_files.get_parameters()
     all_params = [amv_files.lon_name, amv_files.lat_name, amv_files.elem_name, amv_files.line_name] + amv_params
@@ -39,18 +37,18 @@ def match_calipso_clavrx_to_amvs(calipso_clavrx_path, calipso_clavrx_file, amv_f
     coords = {'num_params': all_params}
     dims = ['num_params', 'num_amvs']
 
-    calipso_clavrx_ds = CLAVRx_CALIPSO(calipso_clavrx_path)
+    #calipso_clavrx_ds = CLAVRx_CALIPSO(calipso_clavrx_path)
 
     nom_time = calipso_clavrx_ds.get_datetime(calipso_clavrx_file).timestamp()
     calipso_clavrx_nc4 = Dataset(calipso_clavrx_file)
 
-    fname, ftime, f_idx = amv_files.get_file_containing_time(nom_time)
+    amv_fname, ftime, f_idx = amv_files.get_file_containing_time(nom_time)
     if f_idx is None:
         return
 
     match_dict[nom_time] = []
 
-    amv_ds = Dataset(fname)
+    amv_ds = Dataset(amv_fname)
     amv_lons = amv_ds[amv_files.lon_name][:]
     amv_lats = amv_ds[amv_files.lat_name][:]
     if amv_files.elem_name is not None:
@@ -261,6 +259,20 @@ def create_file(match_dct, filename, caliop_clavrx_params, amv_params):
     rootgrp.close()
 
 
+def run_caliop_clavrx_amv_match(output_file, path_to_caliop_clavrx, path_to_amvs, amv_source='OPS', band='14'):
+
+    caliop_clavrx_ds = CLAVRx_CALIPSO(path_to_caliop_clavrx)
+
+    amv_files = get_datasource(path_to_amvs, amv_source, band=band)
+    amv_params = amv_files.get_parameters()
+
+    match_dict = match_calipso_clavrx_to_amvs(caliop_clavrx_ds, None, amv_files, amv_source=amv_source, band=band)
+
+    caliop_clavrx_params = get_parameters_caliop_clavrx()
+
+    create_file(match_dict, output_file, caliop_clavrx_params, amv_params)
+
+
 # def run_clavrx_to_aeolus_match(aeolus_files_dir, clvrx_files_dir, outfile, chan='mie'):
 #     if os.path.isdir(aeolus_files_dir):
 #         a_dct = get_aeolus_time_dict_s(aeolus_files_dir, chan=chan)
-- 
GitLab