def main(argsIn): # Command line parsing try: usage = "usage: fetch_icebridge_data.py [options] output_folder" parser = optparse.OptionParser(usage=usage) parser.add_option( "--year", dest="year", type='int', default=None, help= "Number of processes to use (default program tries to choose best)" ) parser.add_option( "--month", dest="month", type='int', default=None, help= "Number of processes to use (default program tries to choose best)" ) parser.add_option( "--day", dest="day", type='int', default=None, help= "Number of processes to use (default program tries to choose best)" ) parser.add_option( "--yyyymmdd", dest="yyyymmdd", default=None, help="Specify the year, month, and day in one YYYYMMDD string.") parser.add_option("--site", dest="site", default=None, help="Name of the location of the images (AN or GR)") parser.add_option("--start-frame", dest="startFrame", type='int', default=icebridge_common.getSmallestFrame(), help="Frame number or start of frame sequence") parser.add_option("--stop-frame", dest="stopFrame", type='int', default=icebridge_common.getLargestFrame(), help="End of frame sequence to download.") parser.add_option("--all-frames", action="store_true", dest="allFrames", default=False, help="Fetch all frames for this flight.") parser.add_option("--skip-validate", action="store_true", dest="skipValidate", default=False, help="Skip input data validation.") parser.add_option("--ignore-missing-lidar", action="store_true", dest="ignoreMissingLidar", default=False, help="Keep going if the lidar is missing.") parser.add_option("--frame-skip", dest="frameSkip", type='int', default=0, help="Skip this many frames between downloads.") parser.add_option( "--dry-run", action="store_true", dest="dryRun", default=False, help="Just print the image/ortho/fireball download commands.") parser.add_option("--refetch-index", action="store_true", dest="refetchIndex", default=False, help="Force refetch of the index file.") parser.add_option("--stop-after-index-fetch", action="store_true", dest="stopAfterIndexFetch", default=False, help="Stop after fetching the indices.") parser.add_option('--max-num-lidar-to-fetch', dest='maxNumLidarToFetch', default=-1, type='int', help='The maximum number of lidar files to fetch. ' + \ 'This is used in debugging.') # This call handles all the parallel_mapproject specific options. (options, args) = parser.parse_args(argsIn) if len(args) != 1: logger.info('Error: Missing output folder.\n' + usage) return -1 outputFolder = os.path.abspath(args[0]) # TODO: Restore "type" input parameter so that outside users who do not use # our folder convention can use this tool. options.type = icebridge_common.folderToType(outputFolder) if options.type == 'lidar': options.type = LIDAR_TYPES[0] print 'Detected type: ' + options.type # Handle unified date option if options.yyyymmdd: options.year = int(options.yyyymmdd[0:4]) options.month = int(options.yyyymmdd[4:6]) options.day = int(options.yyyymmdd[6:8]) if not options.stopFrame: options.stopFrame = options.startFrame # Error checking if (not options.year) or (not options.month) or (not options.day): logger.error('Error: year, month, and day must be provided.\n' + usage) return -1 # Ortho and Fireball DEM files don't need this information to find them. if (options.type == 'jpeg') and not (options.site == 'AN' or options.site == 'GR'): logger.error('Error, site must be AN or GR for images.\n' + usage) return -1 KNOWN_TYPES = ['jpeg', 'ortho', 'fireball', 'nav'] + LIDAR_TYPES if not (options.type.lower() in KNOWN_TYPES): logger.error( 'Error, type must be image, ortho, fireball, or a lidar type.\n' + usage) return -1 except optparse.OptionError, msg: raise Exception(msg)
def main(argsIn): # Command line parsing try: usage = "usage: fetch_icebridge_data.py [options] output_folder" parser = optparse.OptionParser(usage=usage) parser.add_option("--year", dest="year", type='int', default=None, help="Number of processes to use (default program tries to choose best)") parser.add_option("--month", dest="month", type='int', default=None, help="Number of processes to use (default program tries to choose best)") parser.add_option("--day", dest="day", type='int', default=None, help="Number of processes to use (default program tries to choose best)") parser.add_option("--yyyymmdd", dest="yyyymmdd", default=None, help="Specify the year, month, and day in one YYYYMMDD string.") parser.add_option("--site", dest="site", default=None, help="Name of the location of the images (AN or GR)") parser.add_option("--start-frame", dest="startFrame", type='int', default=icebridge_common.getSmallestFrame(), help="Frame number or start of frame sequence") parser.add_option("--stop-frame", dest="stopFrame", type='int', default=icebridge_common.getLargestFrame(), help="End of frame sequence to download.") parser.add_option("--all-frames", action="store_true", dest="allFrames", default=False, help="Fetch all frames for this flight.") parser.add_option("--skip-validate", action="store_true", dest="skipValidate", default=False, help="Skip input data validation.") parser.add_option("--ignore-missing-lidar", action="store_true", dest="ignoreMissingLidar", default=False, help="Keep going if the lidar is missing.") parser.add_option("--frame-skip", dest="frameSkip", type='int', default=0, help="Skip this many frames between downloads.") parser.add_option("--dry-run", action="store_true", dest="dryRun", default=False, help="Just print the image/ortho/fireball download commands.") parser.add_option("--refetch-index", action="store_true", dest="refetchIndex", default=False, help="Force refetch of the index file.") parser.add_option("--refetch-nav", action="store_true", dest="refetchNav", default=False, help="Force refetch of the nav file.") parser.add_option("--stop-after-index-fetch", action="store_true", dest="stopAfterIndexFetch", default=False, help="Stop after fetching the indices.") parser.add_option('--max-num-lidar-to-fetch', dest='maxNumLidarToFetch', default=-1, type='int', help='The maximum number of lidar files to fetch. ' + \ 'This is used in debugging.') # This call handles all the parallel_mapproject specific options. (options, args) = parser.parse_args(argsIn) if len(args) != 1: logger.info('Error: Missing output folder.\n' + usage) return -1 outputFolder = os.path.abspath(args[0]) # TODO: Restore "type" input parameter so that outside users who do not use # our folder convention can use this tool. options.type = icebridge_common.folderToType(outputFolder) if options.type == 'lidar': options.type = LIDAR_TYPES[0] print ('Detected type: ' + options.type) # Handle unified date option if options.yyyymmdd: options.year = int(options.yyyymmdd[0:4]) options.month = int(options.yyyymmdd[4:6]) options.day = int(options.yyyymmdd[6:8]) if not options.stopFrame: options.stopFrame = options.startFrame # Error checking if (not options.year) or (not options.month) or (not options.day): logger.error('Error: year, month, and day must be provided.\n' + usage) return -1 # Ortho and Fireball DEM files don't need this information to find them. if (options.type == 'jpeg') and not (options.site == 'AN' or options.site == 'GR'): logger.error('Error, site must be AN or GR for images.\n' + usage) return -1 KNOWN_TYPES = ['jpeg', 'ortho', 'fireball', 'nav'] + LIDAR_TYPES if not (options.type.lower() in KNOWN_TYPES): logger.error('Error, type must be image, ortho, fireball, or a lidar type.\n' + usage) return -1 except optparse.OptionError as msg: raise Exception(msg) # Make several attempts. Stop if there is no progress. numPrevFailed = -1 numFailed = -1 for attempt in range(10): numFailed = doFetch(options, outputFolder) if numFailed == 0: return 0 # Success if numFailed == numPrevFailed: logger.info("No progress in attempt %d" % (attempt+1)) return -1 # Try again logger.info("Failed to fetch all in attempt %d, will try again.\n" % (attempt+1)) numPrevFailed = numFailed return -1 # We should not come all the way to here