def runFetchConvert(options, isSouth, cameraFolder, imageFolder, jpegFolder, orthoFolder,
                    fireballFolder, corrFireballFolder, lidarFolder, processedFolder,
                    navFolder, navCameraFolder, refDemPath, logger):
    '''Fetch and/or convert. Return 0 on success.'''

    if options.noFetch:
        logger.info('Skipping fetch.')
    else:
        # Call data fetch routine and check the result
        fetchResult = fetchAllRunData(options, options.startFrame, options.stopFrame,
                                      jpegFolder, orthoFolder, fireballFolder, lidarFolder,
                                      navFolder)
        if fetchResult < 0:
            logger.error("Fetching failed!") 
            return -1

        # This step is slow, so run it here as part of fetching and save its result
        # We certainly don't want it to throw any exception at this stage.
        try:
            forceAllFramesInRange = True
            availableFrames = []
            (autoStereoInterval, breaks) = \
                                 process_icebridge_run.getImageSpacing(orthoFolder, availableFrames,
                                                                       options.startFrame,
                                                                       options.stopFrame,
                                                                       forceAllFramesInRange)
        except Exception as e:
            pass
        
    if options.stopAfterFetch or options.dryRun:
        logger.info('Fetching complete, finished!')
        return 0

    # Keep track of how we are doing
    isGood = True
    
    if options.noConvert:        
        logger.info('Skipping convert.')
    else:

        # When files fail in these conversion functions we log the error and keep going

        if not options.skipFastConvert:

            if not options.skipValidate:
                # Validate orthos and dems for this frame range.
                ans = validateOrthosAndFireball(options, 'ortho', logger)
                isGood = (isGood and ans)
                ans = validateOrthosAndFireball(options, 'fireball', logger)
                isGood = (isGood and ans)
            
            # Run non-ortho conversions without any multiprocessing (they are pretty fast)
            # TODO: May be worth doing the faster functions with multiprocessing in the future

            if not options.noLidarConvert:
                ans = input_conversions.convertLidarDataToCsv(lidarFolder,
                                                              options.startFrame, options.stopFrame,
                                                              options.skipValidate,
                                                              logger)
                isGood = (isGood and ans)
                
                ans = input_conversions.pairLidarFiles(lidarFolder, options.skipValidate, logger)
                isGood = (isGood and ans)
                
            ans = input_conversions.correctFireballDems(fireballFolder, corrFireballFolder,
                                                        options.startFrame, options.stopFrame,
                                                        (not isSouth), options.skipValidate,
                                                        logger)
            isGood = (isGood and ans)

            ans = input_conversions.convertJpegs(jpegFolder, imageFolder, 
                                                 options.startFrame, options.stopFrame,
                                                 options.skipValidate, options.cameraMounting,
                                                 logger)
            isGood = (isGood and ans)
            
        if not options.noNavFetch:
            # Single process call to parse the nav files.
            input_conversions.getCameraModelsFromNav(imageFolder, orthoFolder, 
                                                     options.inputCalFolder,
                                                     options.inputCalCamera,
                                                     options.cameraLookupFile,
                                                     navFolder, navCameraFolder,
                                                     options.yyyymmdd, options.site, 
                                                     options.startFrame, options.stopFrame,
                                                     options.cameraMounting,
                                                     logger)
        else:
            navCameraFolder = ""
            options.simpleCameras = False

        if not options.noOrthoConvert:
            # Multi-process call to convert ortho images
            input_conversions.getCameraModelsFromOrtho(imageFolder, orthoFolder,
                                                       options.inputCalFolder,
                                                       options.inputCalCamera,
                                                       options.cameraLookupFile,
                                                       options.noNavFetch,
                                                       navCameraFolder,
                                                       options.yyyymmdd, options.site, 
                                                       refDemPath, cameraFolder, 
                                                       options.simpleCameras,
                                                       options.startFrame, options.stopFrame,
                                                       options.framesFile,
                                                       options.numOrthoProcesses, options.numThreads,
                                                       logger)


    os.system("rm -f core.*") # these keep on popping up
    
    if isGood:
        return 0

    return -1
Example #2
0
def runFetchConvert(options, isSouth, cameraFolder, imageFolder, jpegFolder,
                    orthoFolder, fireballFolder, corrFireballFolder,
                    lidarFolder, processedFolder, navFolder, navCameraFolder,
                    refDemPath, logger):
    '''Fetch and/or convert. Return 0 on success.'''

    if options.noFetch:
        logger.info('Skipping fetch.')
    else:
        # Call data fetch routine and check the result
        fetchResult = fetchAllRunData(options, options.startFrame,
                                      options.stopFrame, jpegFolder,
                                      orthoFolder, fireballFolder, lidarFolder,
                                      navFolder)
        if fetchResult < 0:
            logger.error("Fetching failed!")
            return -1

        # This step is slow, so run it here as part of fetching and save its result
        # We certainly don't want it to throw any exception at this stage.
        try:
            forceAllFramesInRange = True
            availableFrames = []
            (autoStereoInterval, breaks) = \
                                 process_icebridge_run.getImageSpacing(orthoFolder, availableFrames,
                                                                       options.startFrame,
                                                                       options.stopFrame,
                                                                       options.maxOverlapRatio,
                                                                       forceAllFramesInRange)
        except Exception as e:
            pass

    if options.stopAfterFetch or options.dryRun:
        logger.info('Fetching complete, finished!')
        return 0

    # Keep track of how we are doing
    isGood = True

    if options.noConvert:
        logger.info('Skipping convert.')
    else:

        # When files fail in these conversion functions we log the error and keep going

        if not options.skipFastConvert:

            if not options.skipValidate:
                # Validate orthos and dems for this frame range.
                ans = validateOrthosAndFireball(options, 'ortho', logger)
                isGood = (isGood and ans)
                ans = validateOrthosAndFireball(options, 'fireball', logger)
                isGood = (isGood and ans)

            # Run non-ortho conversions without any multiprocessing (they are pretty fast)
            # TODO: May be worth doing the faster functions with multiprocessing in the future

            if not options.noLidarConvert:
                ans = input_conversions.convertLidarDataToCsv(
                    lidarFolder, options.startFrame, options.stopFrame,
                    options.skipValidate, logger)
                isGood = (isGood and ans)

                ans = input_conversions.pairLidarFiles(lidarFolder,
                                                       options.skipValidate,
                                                       logger)
                isGood = (isGood and ans)

            ans = input_conversions.correctFireballDems(
                fireballFolder, corrFireballFolder, options.startFrame,
                options.stopFrame, (not isSouth), options.skipValidate, logger)
            isGood = (isGood and ans)

            ans = input_conversions.convertJpegs(
                jpegFolder, imageFolder, options.startFrame, options.stopFrame,
                options.skipValidate, options.cameraMounting, logger)
            isGood = (isGood and ans)

        if not options.noNavFetch:
            # Single process call to parse the nav files.
            input_conversions.getCameraModelsFromNav(
                imageFolder, orthoFolder, options.inputCalFolder,
                options.inputCalCamera, options.cameraLookupFile, navFolder,
                navCameraFolder, options.yyyymmdd, options.site,
                options.startFrame, options.stopFrame, options.cameraMounting,
                logger)
        else:
            navCameraFolder = ""
            options.simpleCameras = False

        if not options.noOrthoConvert:
            # Multi-process call to convert ortho images
            input_conversions.getCameraModelsFromOrtho(
                imageFolder, orthoFolder, options.inputCalFolder,
                options.inputCalCamera, options.cameraLookupFile,
                options.noNavFetch, navCameraFolder, options.yyyymmdd,
                options.site, refDemPath, cameraFolder, options.simpleCameras,
                options.startFrame, options.stopFrame, options.framesFile,
                options.numOrthoProcesses, options.numThreads, logger)

    os.system("rm -f core.*")  # these keep on popping up

    if isGood:
        return 0

    return -1
            ans = input_conversions.correctFireballDems(
                fireballFolder, corrFireballFolder, options.startFrame,
                options.stopFrame, (not isSouth), options.skipValidate, logger)
            isGood = (isGood and ans)

            ans = input_conversions.convertJpegs(
                jpegFolder, imageFolder, options.startFrame, options.stopFrame,
                options.skipValidate, options.cameraMounting, logger)
            isGood = (isGood and ans)

        if not options.noNavFetch:
            # Single process call to parse the nav files.
            input_conversions.getCameraModelsFromNav(
                imageFolder, orthoFolder, options.inputCalFolder,
                options.inputCalCamera, options.cameraLookupFile, navFolder,
                navCameraFolder, options.yyyymmdd, options.site,
                options.startFrame, options.stopFrame, options.cameraMounting,
                logger)
        else:
            navCameraFolder = ""
            options.simpleCameras = False

        if not options.noOrthoConvert:
            # Multi-process call to convert ortho images
            input_conversions.getCameraModelsFromOrtho(
                imageFolder, orthoFolder, options.inputCalFolder,
                options.inputCalCamera, options.cameraLookupFile,
                options.noNavFetch, navCameraFolder, options.yyyymmdd,
                options.site, refDemPath, cameraFolder, options.simpleCameras,
                options.startFrame, options.stopFrame, options.framesFile,
                options.numOrthoProcesses, options.numThreads, logger)
                isGood = (isGood and ans)

            ans = input_conversions.correctFireballDems(
                fireballFolder, corrFireballFolder, options.startFrame,
                options.stopFrame, (not isSouth), options.skipValidate, logger)
            isGood = (isGood and ans)

            ans = input_conversions.convertJpegs(
                jpegFolder, imageFolder, options.startFrame, options.stopFrame,
                options.skipValidate, options.cameraMounting, logger)
            isGood = (isGood and ans)

        if not options.noNavFetch:
            # Single process call to parse the nav files.
            input_conversions.getCameraModelsFromNav(
                imageFolder, orthoFolder, options.inputCalFolder, navFolder,
                navCameraFolder, options.startFrame, options.stopFrame,
                options.cameraMounting, logger)
        else:
            navCameraFolder = ""
            options.simpleCameras = False

        if not options.noOrthoConvert:
            # Multi-process call to convert ortho images
            input_conversions.getCameraModelsFromOrtho(
                imageFolder, orthoFolder, options.inputCalFolder,
                options.inputCalCamera, options.cameraLookupFile,
                options.noNavFetch, navCameraFolder, options.yyyymmdd,
                options.site, refDemPath, cameraFolder, options.simpleCameras,
                options.startFrame, options.stopFrame, options.framesFile,
                options.numOrthoProcesses, options.numThreads, logger)