def analyzeRegions(frames, probabilityPacks, isGoodWindow):
    # Initialize
    frameCount = len(frames)
    performances = []
    # Get
    for frameIndex, frame in enumerate(frames):
        # Load
        regionalPacks = filter(lambda x: point_process.isInsideRegion(x, frame), probabilityPacks)
        # Evaluate
        correctVector = []
        for probabilityPack in regionalPacks:
            windowX, windowY, predictedLabel = probabilityPack[:3]
            actualLabel = True if isGoodWindow((windowX, windowY)) else False
            correctVector.append(predictedLabel == actualLabel)
        # Compute performance
        performances.append(sum(correctVector) / float(len(correctVector)))
        # Show feedback
        if frameIndex % 100 == 0:
            view.printPercentUpdate(frameIndex + 1, frameCount)
    view.printPercentFinal(frameCount)
    # Return
    return performances
def sampleWindows(targetWindowPath, region, location, parameterByName, options=None):
    # Get parameters
    exampleCountPerRegion = parameterByName['example count per region']
    multispectralPixelShiftValue = parameterByName['multispectral pixel shift value']
    shiftCount = parameterByName['shift count']
    # Prepare regionFrames



    regionSet = region.getDataset()
    # regionDataset = region_store.load(region.path)
    regionFrames = regionDataset.getRegionFrames()
    regionFrameCount = len(regionFrames)
    # Prepare counts
    testRegionSet = region.getTestDataset()
    # testRegionDataset = region_store.load(regionInformation.getTestRegionPath())
    testFractionPerRegion = regionInformation.getTestFractionPerRegion()
    # Load imageDataset
    imagePath = folderStore.getImagePath(regionInformation.getImageName())
    imageInformation = image_store.Information(imagePath)
    multispectralImage = image_store.load(imageInformation.getMultispectralImagePath())
    panchromaticImage = image_store.load(imageInformation.getPanchromaticImagePath())
    # Load locations
    positiveGeoLocations, spatialReference = point_store.load(imageInformation.getPositiveLocationPath())
    # Convert
    windowLengthInMeters = regionInformation.getWindowLengthInMeters()
    windowPixelDimensions = multispectralImage.convertGeoDimensionsToPixelDimensions(windowLengthInMeters, windowLengthInMeters)
    positivePixels = multispectralImage.convertGeoLocationsToPixelLocations(positiveGeoLocations)
    # Place examples
    exampleMachine = region_process.ExampleMachine(positivePixels, exampleCountPerRegion, testFractionPerRegion, testRegionDataset, windowPixelDimensions, multispectralPixelShiftValue, shiftCount)
    examplePacks = []
    if options and not options.is_test:
        print 'Placing examples in %s regions for "%s"...' % (regionFrameCount, taskName)
        for regionFrame in regionFrames:
            examplePacks.append(exampleMachine.placeInFrame(regionFrame))
            exampleCount = len(examplePacks)
            if exampleCount % 10 == 0: 
                view.printPercentUpdate(exampleCount, regionFrameCount)
        view.printPercentFinal(regionFrameCount)
    exampleInformation = {}
    trainingPaths = []
    testPaths = []
    # Set
    targetWindowFolderPath = os.path.dirname(targetWindowPath)
    if options and not options.is_test:
        # For each exampleName,
        for exampleName in examplePacks[0].keys():
            # Convert
            examplePixelLocations = sum((x[exampleName] for x in examplePacks), [])
            exampleGeoLocations = multispectralImage.convertPixelLocationsToGeoLocations(examplePixelLocations)
            examplePath = os.path.join(targetWindowFolderPath, exampleName)
            exampleLabel = 1 if 'positive' in exampleName else 0
            # Save
            point_store.save(examplePath, exampleGeoLocations, spatialReference)
            exampleInformation[exampleName + ' count'] = len(examplePixelLocations)
            # Extract
            print 'Extracting %s windows for %s...' % (len(examplePixelLocations), exampleName)
            window_process.extract(examplePath, exampleGeoLocations, exampleLabel, windowLengthInMeters, multispectralImage, panchromaticImage)
            (testPaths if 'test' in exampleName else trainingPaths).append(examplePath)
    # Record
    information = {
        'windows': {
            'window length in meters': windowLengthInMeters,
            'spatial reference': spatialReference,
        },
        'regions': {
            'name': regionName,
            'path': regionPath,
            'count': regionFrameCount,
        },
        'examples': exampleInformation,
    }
    # Combine
    if options and not options.is_test:
        information['training set'] = sample_process.combineDatasets(sample_process.makeTrainingPath(targetWindowFolderPath), trainingPaths).getStatistics()
        information['test set'] = sample_process.combineDatasets(sample_process.makeTestPath(targetWindowFolderPath), testPaths).getStatistics()
    # Save information
    store.saveInformation(targetWindowPath, information)