def evaluateLocations(targetFolderPath, geoDiameter, actualLocationPath, predictedLocationPath, regionGeoFrames):
    # Load
    rawActualLocations, spatialReference1 = point_store.load(actualLocationPath)
    rawPredictedLocations, spatialReference2 = point_store.load(predictedLocationPath)
    # Make sure the points have the same spatial reference
    if spatialReference1 != spatialReference2:
        raise point_store.ShapeDataError('Both locations must have the same spatial reference')
    spatialReference = spatialReference1
    # Compare
    heap, information = compareLocations(geoDiameter, rawActualLocations, rawPredictedLocations, regionGeoFrames)
    # Define
    def save(fileName, points):
        targetPath = os.path.join(targetFolderPath, fileName)
        point_store.save(targetPath, points, spatialReference)
    # Save
    save('actual', heap['actual'])
    save('predicted', heap['predicted'])
    save('actualNotPredicted', heap['actualNotPredicted'])
    save('predictedNotActual', heap['predictedNotActual'])
    # Return
    return information
 def getPackage(self):
     # Get
     windowGeoLength = self.getWindowLengthInMeters()
     multispectralImage, panchromaticImage = self.getImagePack()
     actualLocationPath = self.expandPath(self.imageInformation.getPositiveLocationPath())
     windowPixelDimensions = multispectralImage.convertGeoDimensionsToPixelDimensions(windowGeoLength, windowGeoLength)
     # Filter actual locations by scanned regions
     actualGeoLocations = point_store.load(actualLocationPath)[0]
     actualPointMachine = point_process.PointMachine(actualGeoLocations, 'REAL')
     filteredGeoLocations = set()
     for multispectralPixelFrame in region_store.load(self.getRegionPath()).getRegionFrames():
         geoFrame = multispectralImage.convertPixelFrameToGeoFrame(multispectralPixelFrame)
         filteredGeoLocations.update(actualPointMachine.getPointsInsideFrame(geoFrame))
     # Return
     return multispectralImage, panchromaticImage, filteredGeoLocations, windowPixelDimensions
def extractDataset(targetDatasetPath, paths, parameters):
    # Unpack
    multispectralImagePath, panchromaticImagePath, positiveLocationPath = paths
    windowGeoLength, negativeRatio, multispectralPixelShiftValue, shiftCount = parameters
    # Show feedback
    view.sendFeedback('Extracting dataset...\n\ttargetDatasetPath = %s' % targetDatasetPath)
    # Extract samples
    extractor = Extractor(targetDatasetPath, windowGeoLength, multispectralPixelShiftValue, shiftCount, negativeRatio)
    extractor.extractSamples(positiveLocationPath, multispectralImagePath, panchromaticImagePath)
    # Record
    targetDataset = extractor.getSampleDatabase()
    multispectralImage = image_store.load(multispectralImagePath)
    panchromaticImage = image_store.load(panchromaticImagePath)
    points, spatialReference = point_store.load(positiveLocationPath)
    store.saveInformation(targetDatasetPath, {
        'multispectral image': {
            'path': multispectralImagePath,
            'pixel width': multispectralImage.getPixelWidth(),
            'pixel height': multispectralImage.getPixelHeight(),
            'geo transform': multispectralImage.getGeoTransform(),
        },
        'panchromatic image': {
            'path': panchromaticImagePath,
            'pixel width': panchromaticImage.getPixelWidth(),
            'pixel height': panchromaticImage.getPixelHeight(),
            'geo transform': panchromaticImage.getGeoTransform(),
        },
        'positive location': {
            'path': positiveLocationPath,
            'location count': len(points),
            'spatial reference': spatialReference,
        },
        'windows': {
            'path': targetDatasetPath,
            'sample count': targetDataset.countSamples(),
            'positive sample count': targetDataset.countPositiveSamples(),
            'negative sample count': targetDataset.countNegativeSamples(),
        },
        'parameters': {
            'window geo length': windowGeoLength,
            'multispectral pixel shift value': multispectralPixelShiftValue,
            'shift count': shiftCount,
            'negative ratio': negativeRatio,
        }
    })
    # Return
    return targetDataset
def evaluateWindows(probabilityPath, actualLocationPath, multispectralImagePath, windowGeoLength):
    # Initialize
    print 'Evaluating windows...'
    multispectralImage = image_store.load(multispectralImagePath)
    # Load
    probabilityPacks = probability_store.load(probabilityPath)
    windowLocations = [(x[0], x[1]) for x in probabilityPacks]
    windowPixelWidth, windowPixelHeight = multispectralImage.convertGeoDimensionsToPixelDimensions(windowGeoLength, windowGeoLength)
    windowCount = len(windowLocations)
    # Load predicted
    predictedWindowLocations = set((x[0], x[1]) for x in probabilityPacks if x[2] == 1)
    # Load actual
    actualGeoLocations = point_store.load(actualLocationPath)[0]
    actualPixelLocations = multispectralImage.convertGeoLocationsToPixelLocations(actualGeoLocations)
    actualPixelPointMachine = point_process.PointMachine(actualPixelLocations, 'INTEGER', windowPixelWidth, windowPixelHeight)
    actualWindowLocations = set(filter(lambda x: actualPixelPointMachine.getPointsInsideWindow(x), windowLocations))
    # Get
    predictedNotActualWindowLocations = predictedWindowLocations - actualWindowLocations
    actualNotPredictedWindowLocations = actualWindowLocations - predictedWindowLocations
    wrongWindowLocations = predictedNotActualWindowLocations.union(actualNotPredictedWindowLocations)
    wrongPixelCenters = [image_store.getWindowCenter(x, windowPixelWidth, windowPixelHeight) for x in wrongWindowLocations]
    # Compute
    actualTrue_predictedFalse = len(actualNotPredictedWindowLocations)
    actualFalse_predictedTrue = len(predictedNotActualWindowLocations)
    actualTrue = len(actualWindowLocations)
    actualFalse = windowCount - actualTrue
    predictedTrue = len(predictedWindowLocations)
    predictedFalse = windowCount - predictedTrue
    percentError, falsePositiveError, falseNegativeError = computePercentages(actualTrue_predictedFalse, actualFalse_predictedTrue, actualTrue, actualFalse)
    # Save
    windowPerformance = {
        'percent error': percentError, 
        'false positive error': falsePositiveError,
        'false negative error': falseNegativeError,
        'actual true': actualTrue,
        'actual false': actualFalse,
        'predicted true': predictedTrue,
        'predicted false': predictedFalse,
        'actual true predicted true': actualTrue - actualTrue_predictedFalse,
        'actual true predicted false': actualTrue_predictedFalse,
        'actual false predicted true': actualFalse_predictedTrue,
        'actual false predicted false': actualFalse - actualFalse_predictedTrue,
        'window count': windowCount,
    }
    return windowPerformance, wrongPixelCenters, actualPixelPointMachine
 def loadPixelCenters(self, image, shapePath):
     originalGeoLocations = point_store.load(shapePath)[0]
     originalPixelLocations = image.convertGeoLocationsToPixelLocations(originalGeoLocations)
     return shiftCopyPoints(originalPixelLocations, self.multispectralPixelShiftValue, self.shiftCount)
Пример #6
0
import point_store
points, spatialReferenceAsProj4 = point_store.load('PaddyRice.shp')
print(points)