Ejemplo n.º 1
0
def run():
    """
    Run tests of the ratapplier
    """
    riostestutils.reportStart(TESTNAME)
    allOK = True

    imgfile = 'test.img'
    makeTestFile(imgfile)

    ok = testOutputSameFile(imgfile)
    if not ok: allOK = False

    imgfile2 = "test2.img"
    ok = testDifferentOutput(imgfile, imgfile2)
    if not ok: allOK = False

    imgfile3 = "test3.img"
    ok = testReduceRat(imgfile, imgfile3)
    if not ok: allOK = False

    imgfile4 = "test4.img"
    ok = testNewRat(imgfile4)
    if not ok: allOK = False

    for tmpfile in [imgfile, imgfile2, imgfile3, imgfile4]:
        os.remove(tmpfile)

    if allOK:
        riostestutils.report(TESTNAME, "Passed")

    return allOK
Ejemplo n.º 2
0
def run():
    """
    Run the test
    """
    riostestutils.reportStart(TESTNAME)

    # Create a multi-band file with some data in it.
    tstfile = 'multilayer.img'
    numBands = 5
    ds = riostestutils.createTestFile(tstfile, numBands=numBands)

    onelayerArr = riostestutils.genRampArray()
    lyrList = []
    for i in range(numBands):
        lyr = (onelayerArr + 1)
        band = ds.GetRasterBand(i + 1)
        band.WriteArray(lyr)
        lyrList.append(lyr)
    del ds

    stack = numpy.array(lyrList)

    # Sum of all pixels in bands 2 & 4
    layerList = [2, 4]
    correctSum = sum([(stack[i - 1].astype(numpy.float64)).sum()
                      for i in layerList])

    # Now do it using RIOS
    infiles = applier.FilenameAssociations()
    outfiles = applier.FilenameAssociations()
    otherargs = applier.OtherInputs()
    controls = applier.ApplierControls()

    infiles.img = tstfile
    controls.selectInputImageLayers(layerList)
    otherargs.total = 0
    # We will use this to check the number of layers being read
    otherargs.numLayers = len(layerList)
    otherargs.numLayersIsOK = True

    applier.apply(doSum, infiles, outfiles, otherargs, controls=controls)

    if correctSum != otherargs.total:
        riostestutils.report(
            TESTNAME,
            "Totals do not match: %s != %s" % (correctSum, otherargs.total))
        ok = False
    else:
        riostestutils.report(TESTNAME, "Passed")
        ok = True

    os.remove(tstfile)

    return ok
Ejemplo n.º 3
0
def run():
    """
    Run tests of the rios.rat functions
    """
    riostestutils.reportStart(TESTNAME)
    allOK = True

    imgfile = 'test.img'
    ratValues = makeTestFile(imgfile)
    nValues = len(ratValues)

    columnList = [("Int32", numpy.int32), ("Float32", numpy.float32),
                  ("Unicode", numpy.dtype('U10'))]
    # Only test old string type for python 2
    if sys.version_info.major < 3:
        columnList.append(("String", numpy.dtype('S10')))

    allOK = True
    for (colName, arrayDtype) in columnList:
        # Write the array into the file, with the given datatype
        ratValues_type = ratValues.astype(arrayDtype)
        rat.writeColumn(imgfile, colName, ratValues_type)

        # Read it back, and check that the values are the same
        ratValues_fromFile = rat.readColumn(imgfile, colName)[:nValues].astype(
            ratValues.dtype)
        if not (ratValues_fromFile == ratValues).all():
            riostestutils.report(TESTNAME,
                                 "Value mis-match for column %s" % (colName))
            allOK = False

    if os.path.exists(imgfile):
        os.remove(imgfile)

    if allOK:
        riostestutils.report(TESTNAME, "Passed")

    return allOK
Ejemplo n.º 4
0
def run():
    """
    Run tests of the rios.colortable functions
    """
    riostestutils.reportStart(TESTNAME)
    allOK = True

    imgfile = 'test.img'
    ds = makeTestFile(imgfile)

    # test generating color tables
    tableNames = colortable.getRampNames()
    allOK = RAMPNAME in tableNames
    if not allOK:
        riostestutils.report(TESTNAME,
                             "Cannot find {} color ramp".format(RAMPNAME))

    if allOK:

        # write a table out
        table = colortable.genTable(NUMENTRIES, RAMPNAME, 0)

        colortable.setTable(ds, table)

        # now read it back
        table_fromfile = colortable.getTable(ds)
        if not (table == table_fromfile).all():
            riostestutils.report(TESTNAME, "Value mis-match for color table")
            allOK = False

    if os.path.exists(imgfile):
        os.remove(imgfile)

    if allOK:
        riostestutils.report(TESTNAME, "Passed")

    return allOK
Ejemplo n.º 5
0
def run():
    """
    Run tests of a number of more common output format drivers
    """
    riostestutils.reportStart(TESTNAME)

    usingExceptions = gdal.GetUseExceptions()
    gdal.UseExceptions()

    driverTestList = [
        ('HFA', ['COMPRESS=YES'], '.img'),
        ('GTiff', ['COMPRESS=LZW', 'TILED=YES', 'INTERLEAVE=BAND'], '.tif'),
        ('ENVI', ['INTERLEAVE=BSQ'], ''), ('KEA', [], '.kea')
    ]
    # Remove any which current GDAL not suporting
    driverTestList = [(drvrName, options, suffix)
                      for (drvrName, options, suffix) in driverTestList
                      if gdal.GetDriverByName(drvrName) is not None]
    riostestutils.report(
        TESTNAME,
        'Testing drivers {}'.format(str([d[0] for d in driverTestList])))

    filename = 'test.img'
    riostestutils.genRampImageFile(filename)

    ok = True
    outfileList = []
    errorList = []
    for (drvr, creationOptions, suffix) in driverTestList:
        infiles = applier.FilenameAssociations()
        outfiles = applier.FilenameAssociations()
        infiles.inimg = filename
        outfiles.outimg = "testout" + suffix
        outfileList.append(outfiles.outimg)

        controls = applier.ApplierControls()
        controls.setOutputDriverName(drvr)

        try:
            applier.apply(copyImg, infiles, outfiles, controls=controls)
        except Exception as e:
            ok = False
            errorList.append("{}:{}".format(drvr, str(e)))

    if ok:
        riostestutils.report(TESTNAME, "Passed")
    else:
        riostestutils.report(
            TESTNAME, "Resulted in these apparent errors:\n  {}".format(
                '\n  '.join(errorList)))

    for fn in [filename] + outfileList:
        if os.path.exists(fn):
            drvr = gdal.Open(fn).GetDriver()


#            drvr.Delete(fn)

    if not usingExceptions:
        gdal.DontUseExceptions()

    return ok