Skip to content
Snippets Groups Projects

glm_grids_updates

Merged Nick Bearson requested to merge nickb-2020-11-17-glm-grids-position-auto into master
1 file
+ 37
20
Compare changes
  • Side-by-side
  • Inline
#!/usr/bin/env python3
#!/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
import numpy as np
from datetime import datetime
from datetime import datetime
@@ -14,19 +28,6 @@ import logging
@@ -14,19 +28,6 @@ import logging
log = logging.getLogger(__name__)
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():
def create_parser():
import argparse
import argparse
parser = argparse.ArgumentParser(description=parse_desc)
parser = argparse.ArgumentParser(description=parse_desc)
@@ -34,8 +35,8 @@ def create_parser():
@@ -34,8 +35,8 @@ def create_parser():
help='each occurrence increases verbosity 1 level through ERROR-WARNING-INFO-DEBUG (default INFO)')
help='each occurrence increases verbosity 1 level through ERROR-WARNING-INFO-DEBUG (default INFO)')
parser.add_argument('-l', '--log', dest="log_fn", default=None,
parser.add_argument('-l', '--log', dest="log_fn", default=None,
help="specify the log filename")
help="specify the log filename")
parser.add_argument('-o', '--output-dir', metavar='directory',
parser.add_argument('-o', '--output-dir', metavar='output directory',
default='.')
default=os.getcwd())
parser.add_argument('--ctr-lat', metavar='latitude',
parser.add_argument('--ctr-lat', metavar='latitude',
type=float, help='center latitude')
type=float, help='center latitude')
parser.add_argument('--ctr-lon', metavar='longitude',
parser.add_argument('--ctr-lon', metavar='longitude',
@@ -70,7 +71,7 @@ def create_parser():
@@ -70,7 +71,7 @@ def create_parser():
help="subdivide the grid this many times along "
help="subdivide the grid this many times along "
"each dimension")
"each dimension")
parser.add_argument('--goes-position',
parser.add_argument('--goes-position',
help="One of [east|west|test]. "
help="One of [east|west|test|auto]. "
"Requires '--goes-sector'.")
"Requires '--goes-sector'.")
parser.add_argument('--goes-sector',
parser.add_argument('--goes-sector',
help="One of [full|conus|meso]. "
help="One of [full|conus|meso]. "
@@ -104,6 +105,17 @@ def nearest_resolution(args):
@@ -104,6 +105,17 @@ def nearest_resolution(args):
return resln
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):
def get_start_end(filenames, start_time=None, end_time=None):
"""Compute start and end time of data based on filenames."""
"""Compute start and end time of data based on filenames."""
base_filenames = [os.path.basename(p) for p in filenames]
base_filenames = [os.path.basename(p) for p in filenames]
@@ -150,8 +162,13 @@ def grid_setup(args):
@@ -150,8 +162,13 @@ def grid_setup(args):
date = datetime(start_time.year, start_time.month, start_time.day)
date = datetime(start_time.year, start_time.month, start_time.day)
os.makedirs(args.output_dir, exist_ok=True)
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'
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:
if args.goes_position is not None and args.goes_sector is not None:
resln = nearest_resolution(args)
resln = nearest_resolution(args)
view = get_GOESR_grid(position=args.goes_position,
view = get_GOESR_grid(position=args.goes_position,
@@ -215,16 +232,16 @@ def grid_setup(args):
@@ -215,16 +232,16 @@ def grid_setup(args):
base_date=date, do_3d=False,
base_date=date, do_3d=False,
dx=dx, dy=dy, frame_interval=float(args.dt),
dx=dx, dy=dy, frame_interval=float(args.dt),
x_bnd=x_bnd, y_bnd=y_bnd,
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,
min_points_per_flash=min_events,
output_writer=output_writer, subdivide=args.subdivide_grid,
output_writer=output_writer, subdivide=args.subdivide_grid,
output_filename_prefix=output_filename_prefix,
output_filename_prefix=output_filename_prefix,
output_kwargs={'scale_and_offset': args.output_scale_and_offset},
output_kwargs={'scale_and_offset': args.output_scale_and_offset},
spatial_scale_factor=1.0)
spatial_scale_factor=1.0)
if args.fixed_grid:
#if args.fixed_grid:
grid_kwargs['fixed_grid'] = True
# grid_kwargs['fixed_grid'] = True
grid_kwargs['nadir_lon'] = nadir_lon
# grid_kwargs['nadir_lon'] = nadir_lon
# if args.split_events:
# if args.split_events:
grid_kwargs['clip_events'] = True
grid_kwargs['clip_events'] = True
if min_groups is not None:
if min_groups is not None:
Loading