def corrFireball(demFolder, corrDemFolder, isNorth): '''Correct Fireball DEMs''' logger = logging.getLogger(__name__) logger.info('Correcting Fireball DEMs ...') # Loop through all the input images os.system('mkdir -p ' + corrDemFolder) demFiles = os.listdir(demFolder) for demFile in demFiles: inputPath = os.path.join(demFolder, demFile) if not icebridge_common.isDEM(inputPath): continue # Make sure the timestamp and frame number are in the output file name outputPath = os.path.join(corrDemFolder, os.path.basename(inputPath)) # Skip existing files if os.path.exists(outputPath): logger.info("File exists, skipping: " + outputPath) continue execPath = asp_system_utils.which('correct_icebridge_l3_dem') cmd = (('%s %s %s %d') % (execPath, inputPath, outputPath, isNorth)) logger.info(cmd) os.system(cmd) if not icebridge_common.isValidImage(outputPath): raise Exception('Failed to convert dem file: ' + demFile)
def correctFireballDems(fireballFolder, corrFireballFolder, startFrame, stopFrame, isNorth, skipValidate, logger): '''Fix the header problem in Fireball DEMs''' logger.info('Correcting Fireball DEMs ...') # Read the existing DEMs fireballIndexPath = icebridge_common.csvIndexFile(fireballFolder) if not os.path.exists(fireballIndexPath): raise Exception("Error: Missing fireball index file: " + fireballIndexPath + ".") (fireballFrameDict, fireballUrlDict) = \ icebridge_common.readIndexFile(fireballIndexPath, prependFolder = True) if not skipValidate: validFilesList = icebridge_common.validFilesList( os.path.dirname(fireballFolder), startFrame, stopFrame) validFilesSet = set() validFilesSet = icebridge_common.updateValidFilesListFromDisk( validFilesList, validFilesSet) numInitialValidFiles = len(validFilesSet) # Loop through all the input images os.system('mkdir -p ' + corrFireballFolder) badFiles = False for frame in sorted(fireballFrameDict.keys()): # Skip if outside the frame range if not ((frame >= startFrame) and (frame <= stopFrame)): continue inputPath = fireballFrameDict[frame] if not icebridge_common.isDEM(inputPath): continue outputPath = os.path.join(corrFireballFolder, os.path.basename(inputPath)) # Skip existing valid files if skipValidate: if os.path.exists(outputPath): logger.info("File exists, skipping: " + outputPath) continue else: if outputPath in validFilesSet and os.path.exists(outputPath): #logger.info('Previously validated: ' + outputPath) # very vebose continue if icebridge_common.isValidImage(outputPath): #logger.info("File exists and is valid, skipping: " + outputPath) validFilesSet.add(outputPath) # mark it as validated continue # Run the correction script execPath = asp_system_utils.which('correct_icebridge_l3_dem') cmd = (('%s %s %s %d') % (execPath, inputPath, outputPath, isNorth)) logger.info(cmd) # TODO: Run this as a subprocess and check the return code os.system(cmd) # Check if the output file is good if not icebridge_common.isValidImage(outputPath): logger.error('Failed to convert dem file, wiping: ' + inputPath + ' ' + outputPath) os.system('rm -f ' + inputPath) # will not throw os.system('rm -f ' + outputPath) # will not throw badFiles = True else: if not skipValidate: validFilesSet.add(outputPath) # mark it as validated if not skipValidate: # Write to disk the list of validated files, but only if new # validations happened. First re-read that list, in case a # different process modified it in the meantime, such as if two # managers are running at the same time. numFinalValidFiles = len(validFilesSet) if numInitialValidFiles != numFinalValidFiles: validFilesSet = icebridge_common.updateValidFilesListFromDisk( validFilesList, validFilesSet) icebridge_common.writeValidFilesList(validFilesList, validFilesSet) return (not badFiles)
def correctFireballDems(fireballFolder, corrFireballFolder, startFrame, stopFrame, isNorth, skipValidate, logger): '''Fix the header problem in Fireball DEMs''' logger.info('Correcting Fireball DEMs ...') # Read the existing DEMs fireballIndexPath = icebridge_common.csvIndexFile(fireballFolder) if not os.path.exists(fireballIndexPath): raise Exception("Error: Missing fireball index file: " + fireballIndexPath + ".") (fireballFrameDict, fireballUrlDict) = \ icebridge_common.readIndexFile(fireballIndexPath, prependFolder = True) if not skipValidate: validFilesList = icebridge_common.validFilesList(os.path.dirname(fireballFolder), startFrame, stopFrame) validFilesSet = set() validFilesSet = icebridge_common.updateValidFilesListFromDisk(validFilesList, validFilesSet) numInitialValidFiles = len(validFilesSet) # Loop through all the input images os.system('mkdir -p ' + corrFireballFolder) badFiles = False for frame in sorted(fireballFrameDict.keys()): # Skip if outside the frame range if not ( (frame >= startFrame) and (frame <= stopFrame) ): continue inputPath = fireballFrameDict[frame] if not icebridge_common.isDEM(inputPath): continue outputPath = os.path.join(corrFireballFolder, os.path.basename(inputPath)) # Skip existing valid files if skipValidate: if os.path.exists(outputPath): logger.info("File exists, skipping: " + outputPath) continue else: if outputPath in validFilesSet and os.path.exists(outputPath): #logger.info('Previously validated: ' + outputPath) # very vebose continue if icebridge_common.isValidImage(outputPath): #logger.info("File exists and is valid, skipping: " + outputPath) validFilesSet.add(outputPath) # mark it as validated continue # Run the correction script execPath = asp_system_utils.which('correct_icebridge_l3_dem') cmd = (('%s %s %s %d') % (execPath, inputPath, outputPath, isNorth)) logger.info(cmd) # TODO: Run this as a subprocess and check the return code os.system(cmd) # Check if the output file is good if not icebridge_common.isValidImage(outputPath): logger.error('Failed to convert dem file, wiping: ' + inputPath + ' ' + outputPath) os.system('rm -f ' + inputPath) # will not throw os.system('rm -f ' + outputPath) # will not throw badFiles = True else: if not skipValidate: validFilesSet.add(outputPath) # mark it as validated if not skipValidate: # Write to disk the list of validated files, but only if new # validations happened. First re-read that list, in case a # different process modified it in the meantime, such as if two # managers are running at the same time. numFinalValidFiles = len(validFilesSet) if numInitialValidFiles != numFinalValidFiles: validFilesSet = icebridge_common.updateValidFilesListFromDisk(validFilesList, validFilesSet) icebridge_common.writeValidFilesList(validFilesList, validFilesSet) return (not badFiles)