Exemplo n.º 1
0
def getCubeCenterLatitude(cubePath, workDir='tmp'):
    """Calls caminfo on a cube and returns the CenterLatitude value"""

    # Make sure the requested file is present
    if not os.path.exists(cubePath):
        raise Exception('File ' + cubePath + ' does not exist!')

    # Call caminfo (from ISIS) on the input cube to find out the CenterLatitude value
    camInfoOuputPath = workDir + "/camInfoOutput.txt"
    cmd = 'caminfo from=' + cubePath + ' to=' + camInfoOuputPath
    print cmd
    os.system(cmd)

    if not os.path.exists(camInfoOuputPath):
        raise Exception('Call to caminfo failed on file ' + cubePath)

    # Read in the output file to extract the CenterLatitude value
    centerLatitude = -9999
    infoFile       = open(camInfoOuputPath, 'r')
    for line in infoFile:
        if (line.find('CenterLatitude') >= 0):
            centerLatitude = IrgStringFunctions.getNumberAfterEqualSign(line, )
            break
    # Make sure we found the desired value
    if (centerLatitude == -9999) or (isinstance(centerLatitude, basestring)):
        raise Exception("Unable to find CenterLatitude from file " + cubePath)

    # Clean up temporary file
    os.remove(camInfoOuputPath)
    
    return centerLatitude
Exemplo n.º 2
0
def getCubeCenterLatitude(cubePath, workDir='tmp'):
    """Calls caminfo on a cube and returns the CenterLatitude value"""

    # Make sure the requested file is present
    if not os.path.exists(cubePath):
        raise Exception('File ' + cubePath + ' does not exist!')

    # Call caminfo (from ISIS) on the input cube to find out the CenterLatitude value
    camInfoOuputPath = workDir + "/camInfoOutput.txt"
    cmd = 'caminfo from=' + cubePath + ' to=' + camInfoOuputPath
    print cmd
    os.system(cmd)

    if not os.path.exists(camInfoOuputPath):
        raise Exception('Call to caminfo failed on file ' + cubePath)

    # Read in the output file to extract the CenterLatitude value
    centerLatitude = -9999
    infoFile = open(camInfoOuputPath, 'r')
    for line in infoFile:
        if (line.find('CenterLatitude') >= 0):
            centerLatitude = IrgStringFunctions.getNumberAfterEqualSign(line, )
            break
    # Make sure we found the desired value
    if (centerLatitude == -9999) or (isinstance(centerLatitude, basestring)):
        raise Exception("Unable to find CenterLatitude from file " + cubePath)

    # Clean up temporary file
    os.remove(camInfoOuputPath)

    return centerLatitude
Exemplo n.º 3
0
def getImageStats(imagePath):
    """Obtains some image statistics from gdalinfo"""

    if not os.path.exists(imagePath):
        raise Exception('Image file ' + imagePath + ' not found!')

    # Call command line tool silently
    cmd = ['gdalinfo', imagePath, '-stats']
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
    textOutput, err = p.communicate()

    # Statistics are computed seperately for each band
    bandStats = []
    band = 0
    while (True):  # Loop until we run out of bands
        # Look for the stats line for this band
        bandString = 'Band ' + str(band + 1) + ' Block='
        bandLoc = textOutput.find(bandString)
        if bandLoc < 0:
            return bandStats  # Quit if we did not find it

        # Now parse out the statistics for this band
        bandMaxStart = textOutput.find('STATISTICS_MAXIMUM=', bandLoc)
        bandMeanStart = textOutput.find('STATISTICS_MEAN=', bandLoc)
        bandMinStart = textOutput.find('STATISTICS_MINIMUM=', bandLoc)
        bandStdStart = textOutput.find('STATISTICS_STDDEV=', bandLoc)

        bandMax = IrgStringFunctions.getNumberAfterEqualSign(
            textOutput, bandMaxStart)
        bandMean = IrgStringFunctions.getNumberAfterEqualSign(
            textOutput, bandMeanStart)
        bandMin = IrgStringFunctions.getNumberAfterEqualSign(
            textOutput, bandMinStart)
        bandStd = IrgStringFunctions.getNumberAfterEqualSign(
            textOutput, bandStdStart)

        # Add results to the output list
        bandStats.append((bandMin, bandMax, bandMean, bandStd))

        band = band + 1  # Move to the next band
Exemplo n.º 4
0
def getImageStats(imagePath):
    """Obtains some image statistics from gdalinfo"""
    
    if not os.path.exists(imagePath):
        raise Exception('Image file ' + imagePath + ' not found!')
    
    # Call command line tool silently
    cmd = ['gdalinfo', imagePath, '-stats']
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
    textOutput, err = p.communicate()
    
    # Statistics are computed seperately for each band
    bandStats = []
    band = 0
    while (True): # Loop until we run out of bands
        # Look for the stats line for this band
        bandString = 'Band ' + str(band+1) + ' Block='
        bandLoc = textOutput.find(bandString)
        if bandLoc < 0:
            return bandStats # Quit if we did not find it
            
        # Now parse out the statistics for this band
        bandMaxStart  = textOutput.find('STATISTICS_MAXIMUM=', bandLoc)
        bandMeanStart = textOutput.find('STATISTICS_MEAN=',    bandLoc)
        bandMinStart  = textOutput.find('STATISTICS_MINIMUM=', bandLoc)
        bandStdStart  = textOutput.find('STATISTICS_STDDEV=',  bandLoc)
               
        bandMax  = IrgStringFunctions.getNumberAfterEqualSign(textOutput, bandMaxStart)
        bandMean = IrgStringFunctions.getNumberAfterEqualSign(textOutput, bandMeanStart)
        bandMin  = IrgStringFunctions.getNumberAfterEqualSign(textOutput, bandMinStart)
        bandStd  = IrgStringFunctions.getNumberAfterEqualSign(textOutput, bandStdStart)
            
        # Add results to the output list
        bandStats.append( (bandMin, bandMax, bandMean, bandStd) )
            
        band = band + 1 # Move to the next band