From 1572400419a9355c03f8281c5853a50f4b6905be Mon Sep 17 00:00:00 2001
From: tomrink <rink@ssec.wisc.edu>
Date: Mon, 10 Jan 2022 11:10:00 -0600
Subject: [PATCH] snapshot...

---
 modules/amv/caliop_clavrx_amv.py | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/modules/amv/caliop_clavrx_amv.py b/modules/amv/caliop_clavrx_amv.py
index b9fd448b..5b995f38 100644
--- a/modules/amv/caliop_clavrx_amv.py
+++ b/modules/amv/caliop_clavrx_amv.py
@@ -1,3 +1,4 @@
+import os
 import numpy as np
 import xarray as xr
 from netCDF4 import Dataset
@@ -106,10 +107,9 @@ def match_calipso_clavrx_to_amvs(calipso_clavrx_ds, calipso_clavrx_file, amv_fil
     return match_dict
 
 
-def create_file(match_dct, filename, caliop_clavrx_params, amv_params, amv_filenames):
+def create_file(match_dct, output_path, target_filepath, caliop_clavrx_params, amv_params, amv_filenames):
     num_aprofs = 0
     max_num_amvs = 0
-
     alons = []
     alats = []
     atimes = []
@@ -118,6 +118,12 @@ def create_file(match_dct, filename, caliop_clavrx_params, amv_params, amv_filen
     fidxs = []
     amvs_cnt = []
 
+    filename = os.path.split(target_filepath)[1]
+    w_o_ext, ext = os.path.splitext(filename)
+    filename = w_o_ext+'.amvs'+ext
+
+    output_filepath = output_path+filename
+
     amv_file_s = np.array(amv_filenames, dtype='object')
 
     # scan to get max num levels, amvs
@@ -154,7 +160,7 @@ def create_file(match_dct, filename, caliop_clavrx_params, amv_params, amv_filen
     caliop_clavrx_exmpl = Dataset('/data/Personal/rink/clavrx_calipso/g16_s20201050200_06kmCLay.matchup.calipso.h5', 'r')
 
     # the top level group for the output file
-    rootgrp = Dataset(filename, 'w', format='NETCDF4')
+    rootgrp = Dataset(output_filepath, 'w', format='NETCDF4')
 
     dim_amvs = rootgrp.createDimension('max_num_amvs', size=max_num_amvs)
     dim_num_aeolus_prof = rootgrp.createDimension('num_caliop_profs', size=num_aprofs)
@@ -262,7 +268,7 @@ def create_file(match_dct, filename, caliop_clavrx_params, amv_params, amv_filen
     rootgrp.close()
 
 
-def run_caliop_clavrx_amv_match(output_file, path_to_caliop_clavrx, path_to_amvs, amv_source='OPS', band='14'):
+def run_caliop_clavrx_amv_match(output_path, path_to_caliop_clavrx, path_to_amvs, amv_source='OPS', band='14'):
     caliop_clavrx_params = get_parameters_caliop_clavrx()
 
     caliop_clavrx_ds = CLAVRx_CALIPSO(path_to_caliop_clavrx)
@@ -274,5 +280,5 @@ def run_caliop_clavrx_amv_match(output_file, path_to_caliop_clavrx, path_to_amvs
     for file in caliop_clavrx_ds.flist:
         match_dict = match_calipso_clavrx_to_amvs(caliop_clavrx_ds, file, amv_ds, amv_source=amv_source, band=band)
 
-        create_file(match_dict, output_file, caliop_clavrx_params, amv_params, amv_filenames)
+        create_file(match_dict, output_path, file, caliop_clavrx_params, amv_params, amv_filenames)
 
-- 
GitLab