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

Merge branch '17-integrate-trio-picker-with-the-main-script-as-an-option' into 'master'

Resolve "integrate trio picker with the main script, as an option"

Closes #17

See merge request !7
parents bef47676 40efefc0
No related branches found
No related tags found
1 merge request!7Resolve "integrate trio picker with the main script, as an option"
#!/usr/bin/env bash
# encoding: utf-8
if [ -z "$CSPP_GEO_GGLM_HOME" ]; then
export CSPP_GEO_GGLM_HOME="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
fi
# Setup necessary environments
source $CSPP_GEO_GGLM_HOME/libexec/env.sh
# Call the python module to do the processing, passing all arguments
python3 $CSPP_GEO_GGLM_HOME/libexec/_glm_trio_picker.py "$@"
#!/usr/bin/env python3
import sys
import os
from glob import glob
from datetime import datetime
import subprocess
from glmtools.io.glm import parse_glm_filename
if __name__ == '__main__':
# FIXME: handle args better if this goes beyond my testing
_, glmfile = sys.argv
# bad (start of period)
# glmfile = '/scratch/nickb/cspp-geo-grb-1.0/output/product/OR_GLM-L2-LCFA_G16_s20210131854000_e20210131854204_c20210131854225.nc'
# good (end of period)
# glmfile = '/scratch/nickb/cspp-geo-grb-1.0/output/product/OR_GLM-L2-LCFA_G16_s20210131854400_e20210131855004_c20210131855027.nc'
# glmfile = '/data/users/nickb/cspp-geo-gridded-glm/testing/2020-11-05/CLASS/OR_GLM-L2-LCFA_G16_s20203101529400_e20203101530004_c20203101530021.nc'
# check that glmfile is actually a GLM file
glminfo = parse_glm_filename(os.path.basename(glmfile))
filename_starts = glminfo[3]
filename_ends = glminfo[4]
# if this isn't the last file of the minute, exit
if filename_starts.second != 40:
print("This is not the last GLM file from this minute. Exiting.")
exit(0)
# if this is the last file of the minute, grab all files of the minute (three)
# example trio:
# OR_GLM-L2-LCFA_G16_s20203101529000_e20203101529205_c20203101529215.nc
# OR_GLM-L2-LCFA_G16_s20203101529200_e20203101529405_c20203101529430.nc
# OR_GLM-L2-LCFA_G16_s20203101529400_e20203101530004_c20203101530021.nc
globstring = "{}_{}_{}_s{}*".format(glminfo[0], glminfo[1], glminfo[2], glminfo[3].strftime("%Y%j%H%M"))
fileglob = glob(os.path.join(os.path.dirname(glmfile), globstring))
print("Gridding {} files".format(len(fileglob)))
# and run gridded glm a'la:
# minute_gridder.sh \
# --goes-sector full \
# --create-tiles \
# ./2020-11-05/CLASS/OR_GLM-L2-LCFA_G16_s20203101529000_e20203101529205_c20203101529215.nc \
# ./2020-11-05/CLASS/OR_GLM-L2-LCFA_G16_s20203101529200_e20203101529405_c20203101529430.nc \
# ./2020-11-05/CLASS/OR_GLM-L2-LCFA_G16_s20203101529400_e20203101530004_c20203101530021.nc
subprocess.run(["cspp-geo-gglm.sh",
"--goes-sector", "full",
"--create-tiles",
fileglob[0], fileglob[1], fileglob[2]]
)
......@@ -56,6 +56,10 @@ def create_parser():
type=float, help='center latitude (required for meso)')
parser.add_argument('--ctr-lon', metavar='longitude',
type=float, help='center longitude (required for meso)')
parser.add_argument('-1', "--realtime", default=False, action='store_true',
help="enable 'realtime' mode, where we expect only one input file,\n"
"find the surrounding trio, and automatically determine if a full minute\n"
"of data is available (default: off)")
# from Requirements: "Input is one or more GLM LCFA (L2+) files in mission standard format (nominally three 20-second input files)"
parser.add_argument(dest='filenames', metavar='filename', nargs='+')
return parser
......@@ -110,6 +114,19 @@ def grid_setup(args, work_dir=os.getcwd()):
min_events = None
min_groups = None
if args.realtime:
if len(args.filenames) != 1:
log.error("realtime mode only accepts one input file")
exit(1)
glminfo = parse_glm_filename(os.path.basename(args.filenames[0]))
globstring = "{}_{}_{}_s{}*".format(glminfo[0], glminfo[1], glminfo[2], glminfo[3].strftime("%Y%j%H%M"))
fileglob = glob(os.path.join(os.path.dirname(args.filenames[0]), globstring))
if len(fileglob) != 3:
print("There are not (yet) three GLM files from this minute. This may be expected. Exiting.")
exit(0)
args.filenames = fileglob
try:
start_time, end_time = get_start_end(args.filenames)
except ValueError:
......
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