diff --git a/gridded_glm/bin/_make_glm_grids.py b/gridded_glm/bin/_make_glm_grids.py index 5766989c789328777564e9f1f9a78b93aec2edfb..7103cc7ad31e730ebfe72ba8e507eba9339ab437 100644 --- a/gridded_glm/bin/_make_glm_grids.py +++ b/gridded_glm/bin/_make_glm_grids.py @@ -1,4 +1,18 @@ #!/usr/bin/env python3 +# Based on https://github.com/deeplycloudy/glmtools/blob/master/examples/grid/make_GLM_grids.py + +parse_desc = """Grid GLM flash data. + +The start and end times can be specified +independently, or if not provided they will be inferred from the filenames. + +Grid spacing is regular in latitude and longitude with the grid box +being sized to match the requested dx, dy at the center of the grid. + +By default, data will be saved to the current directory according to the +standard GOES imagery naming convention. This behavior can be fully controlled +by adjusting the -o argument. +""" import numpy as np from datetime import datetime @@ -14,19 +28,6 @@ import logging log = logging.getLogger(__name__) -parse_desc = """Grid GLM flash data. - -The start and end times can be specified -independently, or if not provided they will be inferred from the filenames. - -Grid spacing is regular in latitude and longitude with the grid box -being sized to match the requested dx, dy at the center of the grid. - -Therefore, this script can be used to process multiple days and they will -be written to a standardized directory structure. -""" - - def create_parser(): import argparse parser = argparse.ArgumentParser(description=parse_desc) @@ -34,8 +35,8 @@ def create_parser(): help='each occurrence increases verbosity 1 level through ERROR-WARNING-INFO-DEBUG (default INFO)') parser.add_argument('-l', '--log', dest="log_fn", default=None, help="specify the log filename") - parser.add_argument('-o', '--output-dir', metavar='directory', - default='.') + parser.add_argument('-o', '--output-dir', metavar='output directory', + default=os.getcwd()) parser.add_argument('--ctr-lat', metavar='latitude', type=float, help='center latitude') parser.add_argument('--ctr-lon', metavar='longitude', @@ -70,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]. " @@ -104,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] @@ -150,8 +162,13 @@ def grid_setup(args): date = datetime(start_time.year, start_time.month, start_time.day) os.makedirs(args.output_dir, exist_ok=True) + 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, @@ -215,16 +232,16 @@ def grid_setup(args): base_date=date, do_3d=False, dx=dx, dy=dy, frame_interval=float(args.dt), x_bnd=x_bnd, y_bnd=y_bnd, - ctr_lat=ctr_lat, ctr_lon=ctr_lon, outpath=args.output_dir, + ctr_lat=ctr_lat, ctr_lon=ctr_lon, outpath=output, min_points_per_flash=min_events, output_writer=output_writer, subdivide=args.subdivide_grid, output_filename_prefix=output_filename_prefix, output_kwargs={'scale_and_offset': args.output_scale_and_offset}, spatial_scale_factor=1.0) - if args.fixed_grid: - grid_kwargs['fixed_grid'] = True - grid_kwargs['nadir_lon'] = nadir_lon + #if args.fixed_grid: + # grid_kwargs['fixed_grid'] = True + # grid_kwargs['nadir_lon'] = nadir_lon # if args.split_events: grid_kwargs['clip_events'] = True if min_groups is not None: