def __init__(self, idir, odir=None, north=None, south=None, west=None, east=None, spixl=None, epixl=None, sline=None, eline=None, verbose=False): # inputs self.idir = idir self.odir = odir self.north = north self.south = south self.west = west self.east = east self.spixl = spixl self.epixl = epixl self.sline = sline self.eline = eline self.verbose = verbose self.geofile = os.path.join(idir, 'geo_coordinates.nc') self.timefile = os.path.join(idir, 'time_coordinates.nc') self.tiefile = os.path.join(idir, 'tie_geo_coordinates.nc') # defaults self.runtime = None self.attrs = None # unused, but needed by setupenv.py self.dirs = {} self.ancdir = None self.curdir = False self.sensor = None env(self) # run setupenv
help="% of geo-populated pixels required to pass geocheck validation test", metavar="THRESHOLD") parser.add_option("-v", "--verbose", action="store_true", dest='verbose', default=False, help="print status messages") (options, args) = parser.parse_args() if args: geofile = args[0] if not os.path.exists(geofile): print ("*** ERROR: Provided geolocation file does not exist.") print ("*** Validation test failed for geolocation file:", geofile) sys.exit(1) else: parser.print_help() sys.exit(0) if options.geothresh: geothresh = options.geothresh if options.verbose: verbose = options.verbose # kluge: use geofile as l1afile for setup m = modisGEO.modis_geo(file=geofile, geofile=geofile, geothresh=geothresh, verbose=verbose ) env(m) modis_env(m) m.geochk()
resource.setrlimit(resource.RLIMIT_STACK, (resource.RLIM_INFINITY, resource.RLIM_INFINITY)) except Exception: pass m = ex.extract(file=file, parfile=parfile, geofile=geofile, outfile=sub_l1a, log=log, north=north, south=south, west=west, east=east, verbose=verbose) env(m) modis_env(m) m.chk() status = m.run() if not status: # Create geolocation file for extract g = ga.modis_geo(file=sub_l1a, geofile=extract_geo, ancdb=ancdb, ancdir=ancdir, a1=att1, a2=att2, a3=att3, e1=eph1, e2=eph2, e3=eph3,
def main(): """ This is the primary driver function for the modis_L1B.py program. """ l1a_file = None parfile = None geofile = None okm = None hkm = None qkm = None obc = None lutver = None lutdir = None delfiles = 0 log = False verbose = False version = "%prog 1.0" delfilekey = {'1KM': 1, 'HKM': 2, 'QKM': 4, 'OBC': 8} # Read commandline options... usage = ''' %prog [OPTIONS] L1AFILE [GEOFILE] if GEOFILE is not provided, assumed to be basename of L1AFILE + '.GEO' or %prog --parfile=parameter_file [OPTIONS] ''' parser = OptionParser(usage=usage, version=version) parser.add_option("-p", "--parfile", dest='par', help="Parameter file containing program inputs", metavar="PARFILE") parser.add_option("-o", "--okm", dest='okm', help="Output MODIS L1B 1KM HDF filename", metavar="1KMFILE") parser.add_option("-k", "--hkm", dest='hkm', help="Output MODIS L1B HKM HDF filename", metavar="HKMFILE") parser.add_option("-q", "--qkm", dest='qkm', help="Output MODIS L1B QKM HDF filename", metavar="QKMFILE") parser.add_option("-c", "--obc", dest='obc', help="Output MODIS L1B OBC HDF filename", metavar="OBCFILE") parser.add_option("-l", "--lutver", dest='lutver', help="L1B LUT version number", metavar="LUTVER") parser.add_option("-d", "--lutdir", dest='lutdir', help="Path of directory containing LUT files", metavar="LUTDIR") parser.add_option("-x", "--del-okm", action="store_true", dest='okmdel', default=False, help="Delete 1km resolution L1B file") parser.add_option("-y", "--del-hkm", action="store_true", dest='hkmdel', default=False, help="Delete 500m resolution L1B file") parser.add_option("-z", "--del-qkm", action="store_true", dest='qkmdel', default=False, help="Delete 250m resolution L1B file") parser.add_option("--keep-obc", action="store_false", dest='obcdel', default=True, help="Save onboard calibration file") parser.add_option("-v", "--verbose", action="store_true", dest='verbose', default=False, help="print status messages") parser.add_option("--log", action="store_true", dest='log', default=False, help="Save processing log file(s)") (options, args) = parser.parse_args() if args: l1a_file = args[0] if len(args) == 2: geofile = args[1] if options.okm: okm = options.okm elif options.okmdel: delfiles = delfiles + delfilekey['1KM'] if options.hkm: hkm = options.hkm elif options.hkmdel: delfiles = delfiles + delfilekey['HKM'] if options.qkm: qkm = options.qkm elif options.qkmdel: delfiles = delfiles + delfilekey['QKM'] if options.obc: obc = options.obc elif options.obcdel: delfiles = delfiles + delfilekey['OBC'] if options.lutver: lutver = options.lutver if options.lutdir: lutdir = options.lutdir if options.verbose: verbose = options.verbose if options.log: log = options.log if options.par: parfile = options.par if l1a_file is None and parfile is None: parser.print_help() exit(0) l1b_instance = modisL1B.ModisL1B(inp_file=l1a_file, parfile=parfile, geofile=geofile, okm=okm, hkm=hkm, qkm=qkm, obc=obc, lutver=lutver, lutdir=lutdir, delfiles=delfiles, log=log, verbose=verbose) env(l1b_instance) modis_env(l1b_instance) l1b_instance.chk() buildpcf(l1b_instance) l1b_instance.run() return 0
def main(): """ Driver function for the program. """ l1a_file = None parfile = None geofile = None att1 = None att2 = None att3 = None eph1 = None eph2 = None eph3 = None entrained = False dem = False refresh_db = False download = True ancdir = None ancdb = 'ancillary_data.db' curdir = False geothresh = 95 log = False verbose = False version = "%prog 1.0" timeout = 10.0 # Read commandline options... usage = ''' %prog [OPTIONS] MODIS_L1A_file or %prog --parfile=parameter_file [OPTIONS] ''' parser = OptionParser(usage=usage, version=version) parser.add_option("-p", "--parfile", dest='par', help="Parameter file containing program inputs", metavar="PARFILE") parser.add_option("-o", "--output", dest='geofile', help="Output filename", metavar="GEOFILE") parser.add_option("-a", "--att1", dest='att1', help="Input attitude file 1 (chronological)", metavar="ATT1") parser.add_option("-A", "--att2", dest='att2', help="Input attitude file 2 (chronological)", metavar="ATT2") parser.add_option("--att3", dest='att3', help="Input attitude file 3 (chronological)", metavar="ATT3") parser.add_option("-e", "--eph1", dest='eph1', help="Input ephemeris file 1 (chronological)", metavar="EPH1") parser.add_option("-E", "--eph2", dest='eph2', help="Input ephemeris file 2 (chronological)", metavar="EPH2") parser.add_option("--eph3", dest='eph3', help="Input ephemeris file 3 (chronological)", metavar="EPH3") parser.add_option("--ancdir", dest='ancdir', help="Use a custom directory tree for ancillary files", metavar="ANCDIR") ancdb_help_text = "Use a custom file for ancillary database. If " \ "full path not given, ANCDB is assumed to exist " \ "(or will be created) under " \ + anc_utils.DEFAULT_ANC_DIR_TEXT + \ "/log/. If " + anc_utils.DEFAULT_ANC_DIR_TEXT + \ "/log/ does not exist, " \ "ANCDB is assumed (or will be created) under the " \ "current working directory" parser.add_option("--ancdb", dest='ancdb', help=ancdb_help_text, metavar="ANCDB") parser.add_option( "-c", "--curdir", action="store_true", dest='curdir', default=False, help="Download ancillary files directly into current working directory" ) parser.add_option( "--threshold", dest='geothresh', help= "% of geo-populated pixels required to pass geocheck validation test", metavar="THRESHOLD") parser.add_option( "-r", "--refreshDB", action="store_true", dest='refreshDB', default=False, help="Remove existing database records and re-query for ancillary files" ) parser.add_option( "--disable-download", action="store_false", dest='download', default=True, help="Disable download of ancillary files not found on hard disk") parser.add_option("-d", "--enable-dem", action="store_true", dest='dem', default=False, help="Enable MODIS terrain elevation correction") parser.add_option("-v", "--verbose", action="store_true", dest='verbose', default=False, help="print status messages") # parser.add_option("-n", "--entrained", action="store_true", # dest='entrained', default=False, # help="Use entrained attitude for Terra") parser.add_option("--log", action="store_true", dest='log', default=False, help="Save processing log file(s)") parser.add_option("--timeout", dest='timeout', metavar="TIMEOUT", help="set the network timeout in seconds") options, args = parser.parse_args() if args: l1a_file = args[0] if options.geofile: geofile = options.geofile if options.verbose: verbose = options.verbose if options.att1: att1 = options.att1 if options.att2: att2 = options.att2 if options.att3: att3 = options.att3 if options.eph1: eph1 = options.eph1 if options.eph2: eph2 = options.eph2 if options.eph3: eph3 = options.eph3 if options.dem: dem = options.dem if options.geothresh: geothresh = options.geothresh if options.log: log = options.log if options.par: parfile = options.par if options.ancdir: ancdir = options.ancdir if options.ancdb: ancdb = options.ancdb if options.curdir: curdir = options.curdir if options.refreshDB: refresh_db = options.refreshDB if options.download is False: download = options.download # if options.entrained: # entrained = options.entrained if options.timeout: timeout = float(options.timeout) if l1a_file is None and parfile is None: parser.print_help() exit(0) m = modisGEO.modis_geo(file=l1a_file, parfile=parfile, geofile=geofile, a1=att1, a2=att2, a3=att3, e1=eph1, e2=eph2, e3=eph3, terrain=dem, geothresh=geothresh, ancdir=ancdir, curdir=curdir, ancdb=ancdb, refreshDB=refresh_db, download=download, entrained=entrained, log=log, verbose=verbose, timeout=timeout) env(m) modis_env(m) m.chk() m.utcleap() if entrained is False: try: m.atteph() except SystemExit: print("Cannot create geolocation from %s; exiting." % l1a_file) raise buildpcf(m) m.run() return 0
(options, args) = parser.parse_args() if args: mission = args[0] if options.verbose: verbose = options.verbose if mission is None: parser.print_help() sys.exit(0) if not (mission.lower() in msnlst): print "Mission needs to be one of:" for m in msnlst: print m sys.exit(0) l = lu.lut_utils(verbose=verbose, mission=mission.lower()) env(l) if mission.lower() == 'aquarius': l.update_aquarius() if mission.lower() == 'seawifs': l.update_seawifs() if mission.lower() in ['aqua', 'terra']: l.update_modis() exit(l.status)
def main(): """ The main function for the program. Gets and checks command line options, instantiates a getanc object (from the class defined in anc_utils) and then calls the methods to get the ancillary data. """ filename = None start = None stop = None ancdir = None ancdb = 'ancillary_data.db' curdir = False opt_flag = 5 # defaults to retrieving met, ozone, sst, and ice data download = True force = False refreshDB = False verbose = 0 printlist = True sensor = None timeout = 10. version = "%prog 2.1" # Read commandline options... usage = """ %prog [OPTIONS] FILE or -s,--start YYYYDDDHHMMSS [-e,--end YYYDDDHHMMSS] [OPTIONS] FILE Input L1A or L1B file NOTE: Currently NO2 climatological data is used for OBPG operational processing, so to match OBPG distributed data products, the default behaviour disables NO2 searching. This program queries an OBPG server and optionally downloads the optimal ancillary data files for Level-1 to Level-2 processing. If an input file is specified the start and end times are determined automatically, otherwise a start time must be provided by the user. A text file (with the extension '.anc') is created containing parameters that can be directly used as input to the l2gen program for optimal Level-1 to Level-2 processing, e.g.: l2gen ifile=<infile> ofile=<outfile> par=<the *.anc text file> EXIT STATUS: 0 : all optimal ancillary files exist and are present on the locally 99 : an error was encountered; no .anc parameter text file was created 31 : no ancillary files currently exist corresponding to the start time and therefore no .anc parameter text file was created 1-30 : bitwise value indicating one or more files are not optimal: bit 0 set = missing one or more MET files bit 1 set = missing one or more OZONE files bit 2 set = no SST file found bit 3 set = no NO2 file found bit 4 set = no ICE file found e.g. STATUS=11 indicates there are missing optimal MET, OZONE, and NO2 files """ parser = OptionParser(usage=usage, version=version) parser.add_option( "-s", "--start", dest='start', help="Time of the first scanline (if used, no input file is required)", metavar="START") parser.add_option("-e", "--stop", dest='stop', help="Time of last scanline", metavar="STOP") parser.add_option("--ancdir", dest='ancdir', help="Use a custom directory tree for ancillary files", metavar="ANCDIR") ancdb_help_text = "Use a custom file for ancillary database. If full " \ "path not given, ANCDB is assumed to exist (or " \ "will be created) under " + ga.DEFAULT_ANC_DIR_TEXT + \ "/log/. If " + ga.DEFAULT_ANC_DIR_TEXT + "/log/ does " \ "not exist, ANCDB is assumed (or will be created) " \ " under the current working directory" parser.add_option("--ancdb", dest='ancdb', help=ancdb_help_text, metavar="ANCDB") parser.add_option( "-c", "--curdir", action="store_true", dest='curdir', default=False, help="Download ancillary files directly into current working directory" ) parser.add_option("-m", "--mission", dest="sensor", help="Mission name", metavar="MISSION") parser.add_option( "-d", "--disable-download", action="store_false", dest='download', default=True, help="Disable download of ancillary files not found on hard disk") parser.add_option( "-f", "--force-download", action="store_true", dest='force', default=False, help="Force download of ancillary files, even if found on hard disk") parser.add_option( "-r", "--refreshDB", action="store_true", dest='refreshDB', default=False, help="Remove existing database records and re-query for ancillary files" ) parser.add_option("-i", "--ice", action="store_false", dest='ice', default=True, help="Do not search for sea-ice ancillary data") parser.add_option("-n", "--no2", action="store_true", dest='no2', default=False, help="Search for NO2 ancillary data") parser.add_option("-t", "--sst", action="store_false", dest='sst', default=True, help="Do not search for SST ancillary data") parser.add_option("-v", "--verbose", action="count", dest='verbose', default=0, help="print status messages") parser.add_option( "--noprint", action="store_false", dest='printlist', default=True, help="Suppress printing the resulting list of files to the screen") parser.add_option("--timeout", dest='timeout', metavar="TIMEOUT", help="set the network timeout in seconds") (options, args) = parser.parse_args() if args: filename = args[0] if options.verbose: verbose = options.verbose if options.start: start = options.start if options.stop: stop = options.stop if options.ancdir: ancdir = options.ancdir if options.ancdb: ancdb = options.ancdb if options.curdir: curdir = options.curdir if options.sensor: sensor = options.sensor if options.download is False: download = options.download if options.force: force = options.force if options.refreshDB: refreshDB = options.refreshDB if options.printlist is False: printlist = options.printlist if options.timeout: timeout = float(options.timeout) if filename is None and start is None: parser.print_help() sys.exit(0) g = ga.getanc(file=filename, start=start, stop=stop, ancdir=ancdir, ancdb=ancdb, curdir=curdir, sensor=sensor, opt_flag=opt_flag, verbose=verbose, printlist=printlist, download=download, timeout=timeout, refreshDB=refreshDB) if options.sst is False: g.set_opt_flag('sst', off=True) if options.no2: g.set_opt_flag('no2') if options.ice is False: g.set_opt_flag('ice', off=True) env(g) g.chk() if (filename and g.finddb()) or (start and g.finddb()): g.setup() else: g.setup() g.findweb() g.locate(forcedl=force) g.write_anc_par() g.cleanup() return (g.db_status)