Beispiel #1
0
def getCellSizeDB(points):

    from spatialdata.geocoords.CSCart import CSCart
    from spatialdata.spatialdb.SimpleDB import SimpleDB
    from spatialdata.spatialdb.SimpleIOAscii import SimpleIOAscii

    # Coordinate system for mesh (must match coordsys in ExodusII file)
    cs = CSCart()
    cs._configure()

    # Spatial database with physical properties (Vs)
    dbIO = SimpleIOAscii()
    dbIO.inventory.filename = filenameDB
    dbIO._configure()
    db = SimpleDB()
    db.inventory.iohandler = dbIO
    db.inventory.label = "Physical properties"
    db.inventory.queryType = "linear"
    db._configure()

    (npoints, spacedim) = points.shape

    # Query database
    db.open()
    db.setQueryValues(["vs"])
    data = numpy.zeros((npoints, 1), dtype=numpy.float64)
    err = numpy.zeros((npoints, ), dtype=numpy.int32)
    db.multiquery(data, err, points, cs)
    db.close()

    vs = data[:, 0]
    cellSize = minPeriod * vs / 10.0
    return cellSize
    def test(self):
        """
        Test GenSimpleDBApp with 1-D data in 2-D space.
        """
        from spatialdata.spatialdb.generator.GenSimpleDBApp import GenSimpleDBApp
        from spatialdata.geocoords.CSCart import CSCart
        from spatialdata.spatialdb.SimpleDB import SimpleDB

        app = GenSimpleDBApp()
        app.run()

        # Test write using query
        db = SimpleDB()
        db.inventory.iohandler.inventory.filename = "data/gen1Din2D.spatialdb"
        db.inventory.iohandler._configure()
        db.inventory.label = "test"
        db.inventory.queryType = "nearest"
        db._configure()

        qlocs = numpy.array([[-2.0, 2.0], [3.0, -4.0], [0.0, 0.7]],
                            numpy.float64)

        dataE = numpy.array([[-0.15, 3.45], [2.4, 6.4], [-0.6, 3.45]],
                            numpy.float64)
        errE = [0, 0, 0]

        from spatialdata.geocoords.CSCart import CSCart
        cs = CSCart()
        cs.inventory.spaceDim = 2
        cs._configure()

        db.open()
        db.setQueryValues(["two", "one"])
        data = numpy.zeros(dataE.shape, dtype=numpy.float64)
        err = []
        nlocs = qlocs.shape[0]
        for i in range(nlocs):
            e = db.query(data[i, :], qlocs[i, :], cs)
            err.append(e)
        db.close()

        self.assertEqual(len(errE), len(err))
        for vE, v in zip(errE, err):
            self.assertEqual(vE, v)

        self.assertEqual(len(dataE.shape), len(data.shape))
        for dE, d in zip(dataE.shape, data.shape):
            self.assertEqual(dE, d)
        for vE, v in zip(numpy.reshape(dataE, -1), numpy.reshape(data, -1)):
            self.assertAlmostEqual(vE, v, 6)
    def test_write(self):
        """
        Test write().
        """
        # Database info
        cs = CSCart()
        cs._configure()

        filename = "data/test.spatialdb"
        data = {
            'points':
            numpy.array([[1.0, 2.0, 3.0], [0.5, 3.0, -3.0]], numpy.float64),
            'coordsys':
            cs,
            'data_dim':
            1,
            'values': [{
                'name': "One",
                'units': "m",
                'data': numpy.array([2.0, 8.0], numpy.float64)
            }, {
                'name': "Two",
                'units': "m",
                'data': numpy.array([-2.0, 3.0], numpy.float64)
            }]
        }
        dataDim = 1

        qlocs = numpy.array(
            [[0.875, 2.25, 1.5], [0.6, 2.8, -1.8], [1.0, 2.0, 3.0]],
            numpy.float64)
        valsE = numpy.array([[-0.75, 3.5], [2.0, 6.8], [-2.0, 2.0]],
                            numpy.float64)
        errE = [0, 0, 0]

        # Write database
        from spatialdata.spatialdb.SimpleIOAscii import createWriter
        writer = createWriter(filename)
        writer.write(data)

        # Test write using query
        from spatialdata.spatialdb.SimpleDB import SimpleDB
        db = SimpleDB()
        db.inventory.label = "test"
        db.inventory.queryType = "linear"
        db.inventory.iohandler.inventory.filename = filename
        db.inventory.iohandler._configure()
        db._configure()

        db.open()
        db.setQueryValues(["two", "one"])
        vals = numpy.zeros(valsE.shape, dtype=numpy.float64)
        err = []
        nlocs = qlocs.shape[0]
        for i in range(nlocs):
            e = db.query(vals[i, :], qlocs[i, :], cs)
            err.append(e)
        db.close()

        self.assertEqual(len(valsE.shape), len(vals.shape))
        for dE, d in zip(valsE.shape, vals.shape):
            self.assertEqual(dE, d)
        for vE, v in zip(numpy.reshape(valsE, -1), numpy.reshape(vals, -1)):
            self.assertAlmostEqual(vE, v, 6)

        return