Skip to content
Snippets Groups Projects
Commit 00111a19 authored by Nick Bearson's avatar Nick Bearson
Browse files

moving more input handling out of grid_setup; prep-work for calling the gridder once per minute

parent 83b42a46
No related branches found
No related tags found
1 merge request!26group inputs by minute and process accordingly
...@@ -185,26 +185,21 @@ def get_outpath_base(args): ...@@ -185,26 +185,21 @@ def get_outpath_base(args):
return dsname return dsname
def grid_setup(args, work_dir=os.getcwd()): def grid_setup(glm_files, args, work_dir=os.getcwd()):
# When passed None for the minimum event or group counts, the gridder will skip # When passed None for the minimum event or group counts, the gridder will skip
# the check, saving a bit of time. # the check, saving a bit of time.
min_events = None min_events = None
min_groups = None min_groups = None
for f in args.filenames:
if not os.path.exists(f):
log.error("Tried to grid file that does not exist: {}".format(f))
exit(1)
if args.goes_sector == "meso" and (args.ctr_lat == None or args.ctr_lon == None): if args.goes_sector == "meso" and (args.ctr_lat == None or args.ctr_lon == None):
log.error("sector 'meso' requires --ctr-lat & --ctr-lon") log.error("sector 'meso' requires --ctr-lat & --ctr-lon")
exit(1) exit(1)
try: try:
start_time, end_time = get_start_end(args.filenames) start_time, end_time = get_start_end(glm_files)
except: except:
log.error("Could not parse start & end times from one or more of the files provided:") log.error("Could not parse start & end times from one or more of the files provided:")
log.error(", ".join(args.filenames)) log.error(", ".join(glm_files))
exit(1) exit(1)
base_date = datetime(start_time.year, start_time.month, start_time.day) base_date = datetime(start_time.year, start_time.month, start_time.day)
...@@ -212,7 +207,7 @@ def grid_setup(args, work_dir=os.getcwd()): ...@@ -212,7 +207,7 @@ def grid_setup(args, work_dir=os.getcwd()):
outputpath = os.path.join(work_dir, get_outpath_base(args)) # GLMTools expects a template in addition to the path outputpath = os.path.join(work_dir, get_outpath_base(args)) # GLMTools expects a template in addition to the path
goes_position = get_goes_position(args.filenames) goes_position = get_goes_position(glm_files)
resln = get_resolution(args) resln = get_resolution(args)
view = get_GOESR_grid(position=goes_position, view = get_GOESR_grid(position=goes_position,
...@@ -276,7 +271,7 @@ def grid_setup(args, work_dir=os.getcwd()): ...@@ -276,7 +271,7 @@ def grid_setup(args, work_dir=os.getcwd()):
if (proj_name == 'pixel_grid') or (proj_name == 'geos'): if (proj_name == 'pixel_grid') or (proj_name == 'geos'):
grid_kwargs['pixel_coords'] = fixed_grid grid_kwargs['pixel_coords'] = fixed_grid
grid_kwargs['ellipse_rev'] = -1 # -1 (default) = infer from date in each GLM file grid_kwargs['ellipse_rev'] = -1 # -1 (default) = infer from date in each GLM file
return gridder, args.filenames, start_time, end_time, grid_kwargs return gridder, glm_files, start_time, end_time, grid_kwargs
def get_cspp_gglm_version(): def get_cspp_gglm_version():
...@@ -318,6 +313,7 @@ if __name__ == '__main__': ...@@ -318,6 +313,7 @@ if __name__ == '__main__':
log.info("Starting GLM Gridding") log.info("Starting GLM Gridding")
log.debug("Starting script with: %s", sys.argv) log.debug("Starting script with: %s", sys.argv)
# handle the realtime flag
if args.realtime: if args.realtime:
if len(args.filenames) != 1: if len(args.filenames) != 1:
log.error("realtime mode only accepts one input file") log.error("realtime mode only accepts one input file")
...@@ -331,6 +327,12 @@ if __name__ == '__main__': ...@@ -331,6 +327,12 @@ if __name__ == '__main__':
exit(0) exit(0)
args.filenames = fileglob args.filenames = fileglob
# check that all of our inputs exist
for f in args.filenames:
if not os.path.exists(f):
log.error("Tried to grid file that does not exist: {}".format(f))
exit(1)
# set up output dir # set up output dir
os.makedirs(args.output_dir, exist_ok=True) os.makedirs(args.output_dir, exist_ok=True)
...@@ -341,7 +343,7 @@ if __name__ == '__main__': ...@@ -341,7 +343,7 @@ if __name__ == '__main__':
atexit.register(shutil.rmtree, tempdir_path) atexit.register(shutil.rmtree, tempdir_path)
# do the gridding # do the gridding
gridder, glm_filenames, start_time, end_time, grid_kwargs = grid_setup(args, work_dir=tempdir_path) gridder, glm_filenames, start_time, end_time, grid_kwargs = grid_setup(args.filenames, args, work_dir=tempdir_path)
gridder_return = gridder(glm_filenames, start_time, end_time, **grid_kwargs) gridder_return = gridder(glm_filenames, start_time, end_time, **grid_kwargs)
gridded_files = [] gridded_files = []
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment