#!/usr/bin/env python3 """ Super simple wrapper to run nagg & aggregate any data we need aggregated. Adapted from the SDR code. Copyright (C) 2017-2018 University of Wisconsin Space Science and Engineering Center This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . """ import os import subprocess import glob import logging LOG = logging.getLogger(__name__) geo_product_ids = \ ["GATMO", "GCRSO", "GAERO", "GCLDO", "GDNBO", "GNCCO", "GIGTO", "GIMGO", "GITCO", "GMGTO", "GMODO", "GMTCO", "GNHFO", "GOTCO", "GOSCO", "GONPO", "GONCO", "GCRIO", "GATRO", "ICDBG","GOTCO"] edr_product_ids = \ ["ICALI", "ICALM", "ICCCR", "ICISE", "ICMSE", "ICSTT", "ICTLI", "ICTLM", "IICMO", "IICMS", "SATMR", "SATMS", "SCRIS", "SOMPS", "SOMTC", "SOMSC", "SOMNC", "SVDNB", "SVI01", "SVI02", "SVI03", "SVI04", "SVI05", "SVM01", "SVM02", "SVM03", "SVM04", "SVM05", "SVM06", "SVM07", "SVM08", "SVM09", "SVM10", "SVM11", "SVM12", "SVM13", "SVM14", "SVM15", "SVM16", "TATMS", "REDRO", "OOTCO", "VAOOO", "VCBHO", "VCCLO", "VCEPO", "VCOTO", "VCTHO", "VCTPO", "VCTTO", "VI1BO", "VI2BO", "VI3BO", "VI4BO", "VI5BO", "VISTO", "VLSTO", "VM01O", "VM02O", "VM03O", "VM04O", "VM05O", "VM06O", "VNCCO", "VNHFO", "VOCCO", "VISAO", "VSCDO", "VSCMO", "VSICO", "VSSTO", "VSTYO", "VSUMO", "VIVIO", "REDRS", "OOTCS", "VAOOS", "VCBHS", "VCCLS", "VCEPS", "VCOTS", "VCTHS", "VCTPS", "VCTTS", "VISTS", "VLSTS", "VNCCS", "VNHFS", "VOCCS", "VISAS", "VSCDS", "VSCMS", "VSICS", "VSSTS", "VSTPS", "VSUMS", "VIVIS", "INCTO", "INPAK", "IIROO", "IIROS", "IMOPO", "IMOPS", "IVAMI", "IVAOT", "IVBPX", "IVCBH", "IVCDB", "IVCLT", "IVCOP", "IVCTP", "IVICC", "IVIIC", "IVIIW", "IVIQF", "IVIRT", "IVISR", "IVIWT", "IVPCM", "IVPCP", "IVPTP", "IVSIC", "IVSTP"] NAGG = "nagg" # FIXME: is it ok to assume this is in $PATH? def nagg(input_dir, datasets, required): """ datasets: list of dataset strings (from geo_product_ids and edr_product_ids) required: list of required datasets (processing will fail if any of these are missing) """ LOG.info("Aggregating datasets:") LOG.info(datasets) for dataset in datasets: if dataset in geo_product_ids: args = [NAGG, "-g", dataset, "--onefile", "-O", "cspp", "-D", "dev", "-S"] elif dataset in edr_product_ids: args = [NAGG, "-g", "no", "--onefile", "-O", "cspp", "-D", "dev", "-S", "-t", dataset] else: raise RuntimeError("dataset %s not recognized!" % (dataset)) input_glob = os.path.join(input_dir, "%s*.h5" % (dataset)) input_files = glob.glob(input_glob) if len(input_files) == 0: if dataset not in required: LOG.warning("%s missing, but not required. Continuing..." % (dataset)) continue else: LOG.error("%s missing, processing cannot continue." % (dataset)) raise RuntimeError("%s missing, processing cannot continue." % (dataset)) # if len(input_files) == 1: # LOG.info("%s only has one file; doesn't need aggregation just a link from the working dir." % (dataset)) # os.symlink(input_files[0], os.path.basename(input_files[0])) # continue args = args + input_files LOG.debug(" ".join(args)) subprocess.check_call(args=args) if __name__ == "__main__": """ Simple aggregate everything in a provided directory test. """ DATASET_KEYS = ['GITCO', 'GMTCO', 'IICMO', 'SVI01', 'SVI02', 'SVI03', 'SVI04', 'SVI05'] import sys nagg(sys.argv[1], DATASET_KEYS, DATASET_KEYS)