From cd99ce3448834a1794f24fff954265cdeea5a072 Mon Sep 17 00:00:00 2001
From: nickb <nickb@ssec.wisc.edu>
Date: Tue, 17 Nov 2020 20:32:13 +0000
Subject: [PATCH] adds a basic position: auto argument to determine the
 position from the input filenames

---
 gridded_glm/bin/_make_glm_grids.py | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/gridded_glm/bin/_make_glm_grids.py b/gridded_glm/bin/_make_glm_grids.py
index 000e35e..7103cc7 100644
--- a/gridded_glm/bin/_make_glm_grids.py
+++ b/gridded_glm/bin/_make_glm_grids.py
@@ -71,7 +71,7 @@ def create_parser():
                         help="subdivide the grid this many times along "
                              "each dimension")
     parser.add_argument('--goes-position',
-                        help="One of [east|west|test]. "
+                        help="One of [east|west|test|auto]. "
                              "Requires '--goes-sector'.")
     parser.add_argument('--goes-sector',
                         help="One of [full|conus|meso]. "
@@ -105,6 +105,17 @@ def nearest_resolution(args):
     return resln
 
 
+# if provided "auto" position, we determine the sensor from the filename
+def get_goes_position(filenames):
+    if all("_G16_" in f for f in filenames):
+        return "east"
+    if all("_G17_" in f for f in filenames):
+        return "west"
+
+    # we require that all files are from the same sensor and raise an exception if not
+    raise ValueError("position 'auto' but could not determine position - did you provide a mix of satellites?")
+
+
 def get_start_end(filenames, start_time=None, end_time=None):
     """Compute start and end time of data based on filenames."""
     base_filenames = [os.path.basename(p) for p in filenames]
@@ -154,6 +165,10 @@ def grid_setup(args):
     output = os.path.join(args.output_dir, "{dataset_name}") # GLMTools expects a template in addition to the path
     proj_name = 'geos'
 
+    if args.goes_position == "auto":
+        # auto-create the goes-position from the input filename
+        args.goes_position = get_goes_position(args.filenames)
+
     if args.goes_position is not None and args.goes_sector is not None:
         resln = nearest_resolution(args)
         view = get_GOESR_grid(position=args.goes_position,
-- 
GitLab