diff --git a/gridded_glm/libexec/_minute_gridder.py b/gridded_glm/libexec/_minute_gridder.py index f8a1840f66c791a2ce3e788b6870caa5970d34f0..1b33248803b22a45511d69063e0849b809ee54fa 100644 --- a/gridded_glm/libexec/_minute_gridder.py +++ b/gridded_glm/libexec/_minute_gridder.py @@ -369,6 +369,11 @@ if __name__ == '__main__': minute_files.append(f) minute_files = sorted(minute_files) + # do we have three input files for this minute? + if len(minute_files) != 3: + log.error("Minute {} only has {} input file(s). A gridded file will not be generated.".format(m, len(minute_files))) + continue + # do the gridding gridder, glm_filenames, start_time, end_time, grid_kwargs = grid_setup(minute_files, args, work_dir=tempdir_path) gridder_return = gridder(glm_filenames, start_time, end_time, **grid_kwargs) @@ -377,54 +382,54 @@ if __name__ == '__main__': for gridded_file in subgrid[1]: gridded_files.append(gridded_file) - # we need to add attributes here due to an issue where satpy (or its dependencies) are - # holding the input gridded file open until the process exits - for f in gridded_files: - add_gglm_attrs(f, glm_filenames) - - # (optionally) do tiling - if args.create_tiles: - - sector = get_goes_position(glm_filenames) - if sector == "east": - sector_id = "GOES_EAST" - elif sector == "west": - sector_id = "GOES_WEST" - else: - raise RuntimeError("could not determine sector_id") - - from satpy import Scene - for gridded_file in gridded_files: - log.info("TILING: {}".format(gridded_files)) - scn = Scene(reader='glm_l2', filenames=[gridded_file]) # n.b. satpy requires a list of filenames - scn.load([ - 'DQF', - 'flash_extent_density', - 'minimum_flash_area', - 'total_energy', - ]) - - scn.save_datasets(writer='awips_tiled', - template='glm_l2_radf', - sector_id=sector_id, # sector_id becomes an attribute in the output files and may be another legacy kind of thing. I'm not sure how much is is actually used here. - source_name="", # You could probably make source_name an empty string. I think it is required by the writer for legacy reasons but isn't actually used for the glm output - base_dir=tempdir_path, # base_dir is the output directory. I think blank is the same as current directory. - tile_size=(506, 904), # tile_size is set to the size of the GLMF sample tiles we were given and should match the full disk ABI tiles which is what they wanted - check_categories=False, # check_categories is there because of that issue I mentioned where DQF is all valid all the time so there is no way to detect empty tiles unless we ignore the "category" products - environment_prefix=args.system_environment_prefix_tiles, - compress=True) - - # pick up output files from the tempdir - # output looks like: CG_GLM-L2-GLMC-M3_G17_T03_20200925160040.nc - log.debug("files in {}".format(tempdir_path)) - log.debug(os.listdir(tempdir_path)) - log.debug("moving output to {}".format(args.output_dir)) - tiled_path = os.path.join(tempdir_path, '{}_GLM-L2-GLM*-M?_G??_T??_*.nc'.format(args.system_environment_prefix_tiles)) - tiled_files = glob(tiled_path) - for f in tiled_files: - add_gglm_attrs(f, glm_filenames) - shutil.move(f, os.path.join(args.output_dir, os.path.basename(f))) - for f in gridded_files: - shutil.move(f, os.path.join(args.output_dir, os.path.basename(f))) + # we need to add attributes here due to an issue where satpy (or its dependencies) are + # holding the input gridded file open until the process exits + for f in gridded_files: + add_gglm_attrs(f, glm_filenames) + + # (optionally) do tiling + if args.create_tiles: + + sector = get_goes_position(glm_filenames) + if sector == "east": + sector_id = "GOES_EAST" + elif sector == "west": + sector_id = "GOES_WEST" + else: + raise RuntimeError("could not determine sector_id") + + from satpy import Scene + for gridded_file in gridded_files: + log.info("TILING: {}".format(gridded_files)) + scn = Scene(reader='glm_l2', filenames=[gridded_file]) # n.b. satpy requires a list of filenames + scn.load([ + 'DQF', + 'flash_extent_density', + 'minimum_flash_area', + 'total_energy', + ]) + + scn.save_datasets(writer='awips_tiled', + template='glm_l2_radf', + sector_id=sector_id, # sector_id becomes an attribute in the output files and may be another legacy kind of thing. I'm not sure how much is is actually used here. + source_name="", # You could probably make source_name an empty string. I think it is required by the writer for legacy reasons but isn't actually used for the glm output + base_dir=tempdir_path, # base_dir is the output directory. I think blank is the same as current directory. + tile_size=(506, 904), # tile_size is set to the size of the GLMF sample tiles we were given and should match the full disk ABI tiles which is what they wanted + check_categories=False, # check_categories is there because of that issue I mentioned where DQF is all valid all the time so there is no way to detect empty tiles unless we ignore the "category" products + environment_prefix=args.system_environment_prefix_tiles, + compress=True) + + # pick up output files from the tempdir + # output looks like: CG_GLM-L2-GLMC-M3_G17_T03_20200925160040.nc + log.debug("files in {}".format(tempdir_path)) + log.debug(os.listdir(tempdir_path)) + log.debug("moving output to {}".format(args.output_dir)) + tiled_path = os.path.join(tempdir_path, '{}_GLM-L2-GLM*-M?_G??_T??_*.nc'.format(args.system_environment_prefix_tiles)) + tiled_files = glob(tiled_path) + for f in tiled_files: + add_gglm_attrs(f, glm_filenames) + shutil.move(f, os.path.join(args.output_dir, os.path.basename(f))) + for f in gridded_files: + shutil.move(f, os.path.join(args.output_dir, os.path.basename(f))) # tempdir cleans itself up via atexit, above \ No newline at end of file