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() cs.initialize() # 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.queryVals(["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 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() cs.initialize() # 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.queryVals(["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_initialize(self): from spatialdata.geocoords.CSCart import CSCart cs = CSCart() cs.inventory.units = "km" cs.inventory.spaceDim = 2 cs._configure() cs.initialize() self.assertEqual(1.0e+3, cs.toMeters()) self.assertEqual(2, cs.spaceDim()) return
points = numpy.zeros((numY*numZ, 3), dtype=numpy.float64) for iY in xrange(numY): points[:,0] = 0.0 points[iY*numZ:(iY+1)*numZ,1] = y[iY] points[iY*numZ:(iY+1)*numZ,2] = z r = (points[:,1]**2+(points[:,2]+7500.0)**2)**0.5 maskO = numpy.bitwise_and(r > radiusInner, r <= radiusOuter) maskI = r <= radiusInner tractionShearLL = maskO*-5.80*(1.0+numpy.cos(numpy.pi*(r-1400.0)/600.0)) + maskI*-11.60 tractionShearUD = 0*tractionShearLL tractionNormal = 0*tractionShearLL cs = CSCart() cs._configure() cs.initialize() dataOut = {'points': points, 'coordsys': cs, 'data_dim': 1, 'values': [{'name': 'traction-shear-leftlateral', 'units': 'MPa', 'data': tractionShearLL}, {'name': 'traction-shear-updip', 'units': 'MPa', 'data': tractionShearUD}, {'name': 'traction-normal', 'units': 'MPa', 'data': tractionNormal}, ], }
def test_io(self): from spatialdata.spatialdb.SimpleGridAscii import SimpleGridAscii filename = "data/gridio.spatialdb" x = numpy.array([-2.0, 0.0, 3.0], dtype=numpy.float64) y = numpy.array([0.0, 1.0], dtype=numpy.float64) z = numpy.array([-2.0, -1.0, 2.0], dtype=numpy.float64) points = numpy.array( [ [-2.0, 0.0, -2.0], [-2.0, 1.0, -2.0], [-2.0, 0.0, -1.0], [-2.0, 1.0, -1.0], [-2.0, 0.0, 2.0], [-2.0, 1.0, 2.0], [0.0, 0.0, -2.0], [0.0, 1.0, -2.0], # query (5.7, 8.2) [0.0, 0.0, -1.0], [0.0, 1.0, -1.0], [0.0, 0.0, 2.0], [0.0, 1.0, 2.0], [3.0, 0.0, -2.0], [3.0, 1.0, -2.0], [3.0, 0.0, -1.0], [3.0, 1.0, -1.0], [3.0, 0.0, 2.0], [3.0, 1.0, 2.0], ], dtype=numpy.float64, ) one = numpy.array( [6.6, 5.5, 2.3, 5.7, 6.3, 3.4, 7.2, 5.7, 3.4, 5.7, 9.4, 7.2, 4.8, 9.2, 5.8, 4.7, 7.8, 2.9], dtype=numpy.float64, ) two = numpy.array( [3.4, 6.7, 4.1, 2.0, 6.7, 6.4, 6.8, 8.2, 9.8, 2.3, 8.5, 9.3, 7.5, 8.3, 8.5, 8.9, 6.2, 8.3], dtype=numpy.float64, ) cs = CSCart() cs.initialize() writer = SimpleGridAscii() writer.inventory.filename = filename writer._configure() writer.write( { "points": points, "x": x, "y": y, "z": z, "coordsys": cs, "data_dim": 3, "values": [{"name": "one", "units": "m", "data": one}, {"name": "two", "units": "m", "data": two}], } ) db = SimpleGridDB() db.inventory.label = "test" db.inventory.queryType = "nearest" db.inventory.filename = filename db._configure() self._db = db locs = numpy.array([[0.1, 0.95, -1.8]], numpy.float64) cs = CSCart() cs._configure() queryVals = ["two", "one"] dataE = numpy.array([[8.2, 5.7]], numpy.float64) errE = [0] db = self._db db.open() db.queryVals(queryVals) data = numpy.zeros(dataE.shape, dtype=numpy.float64) err = [] nlocs = locs.shape[0] for i in xrange(nlocs): e = db.query(data[i, :], locs[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) return
def test_io_3d(self): from spatialdata.spatialdb.SimpleGridAscii import SimpleGridAscii filename = "data/gridio3d.spatialdb" x = numpy.array([-2.0, 0.0, 3.0], dtype=numpy.float64) y = numpy.array([0.0, 1.0], dtype=numpy.float64) z = numpy.array([-2.0, -1.0, 2.0], dtype=numpy.float64) points = numpy.array( [ [-2.0, 0.0, -2.0], [-2.0, 1.0, -2.0], [-2.0, 0.0, -1.0], [-2.0, 1.0, -1.0], [-2.0, 0.0, 2.0], [-2.0, 1.0, 2.0], [0.0, 0.0, -2.0], [0.0, 1.0, -2.0], # query (5.7, 8.2) [0.0, 0.0, -1.0], [0.0, 1.0, -1.0], [0.0, 0.0, 2.0], [0.0, 1.0, 2.0], [3.0, 0.0, -2.0], [3.0, 1.0, -2.0], [3.0, 0.0, -1.0], [3.0, 1.0, -1.0], [3.0, 0.0, 2.0], [3.0, 1.0, 2.0], ], dtype=numpy.float64) one = numpy.array([ 6.6, 5.5, 2.3, 5.7, 6.3, 3.4, 7.2, 5.7, 3.4, 5.7, 9.4, 7.2, 4.8, 9.2, 5.8, 4.7, 7.8, 2.9 ], dtype=numpy.float64) two = numpy.array([ 3.4, 6.7, 4.1, 2.0, 6.7, 6.4, 6.8, 8.2, 9.8, 2.3, 8.5, 9.3, 7.5, 8.3, 8.5, 8.9, 6.2, 8.3 ], dtype=numpy.float64) cs = CSCart() cs.initialize() writer = SimpleGridAscii() writer.inventory.filename = filename writer._configure() writer.write({ 'points': points, 'x': x, 'y': y, 'z': z, 'coordsys': cs, 'data_dim': 3, 'values': [ { 'name': "one", 'units': "m", 'data': one }, { 'name': "two", 'units': "m", 'data': two }, ] }) db = SimpleGridDB() db.inventory.label = "test" db.inventory.queryType = "nearest" db.inventory.filename = filename db._configure() self._db = db locs = numpy.array([[0.1, 0.95, -1.8]], numpy.float64) cs = CSCart() cs._configure() queryVals = ["two", "one"] dataE = numpy.array([[8.2, 5.7]], numpy.float64) errE = [0] db = self._db db.open() db.queryVals(queryVals) data = numpy.zeros(dataE.shape, dtype=numpy.float64) err = [] nlocs = locs.shape[0] for i in xrange(nlocs): e = db.query(data[i, :], locs[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) return
def test_write(self): """ Test write(). """ # Database info cs = CSCart() cs.initialize() 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 SimpleIOAscii writer = SimpleIOAscii() writer.inventory.filename = filename writer._configure() 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.queryVals(["two", "one"]) vals = numpy.zeros(valsE.shape, dtype=numpy.float64) err = [] nlocs = qlocs.shape[0] for i in xrange(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
def test_io_2d(self): from spatialdata.spatialdb.SimpleGridAscii import SimpleGridAscii filename = "data/gridio2d.spatialdb" x = numpy.array([-2.0, 0.0, 3.0], dtype=numpy.float64) y = numpy.array([0.0, 1.0], dtype=numpy.float64) points = numpy.array([ [-2.0, 0.0], [-2.0, 1.0], [ 0.0, 0.0], [ 0.0, 1.0], # query (5.7, 8.2) [ 3.0, 0.0], [ 3.0, 1.0], ], dtype=numpy.float64) one = numpy.array([6.6, 5.5, 7.2, 5.7, 4.8, 9.2], dtype=numpy.float64) two = numpy.array([3.4, 6.7, 6.8, 8.2, 7.5, 8.3], dtype=numpy.float64) cs = CSCart() cs.inventory.spaceDim = 2 cs._configure() cs.initialize() writer = SimpleGridAscii() writer.inventory.filename = filename writer._configure() writer.write({'points': points, 'x': x, 'y': y, 'coordsys': cs, 'data_dim': 2, 'values': [{'name': "one", 'units': "m", 'data': one}, {'name': "two", 'units': "m", 'data': two}, ]}) db = SimpleGridDB() db.inventory.label = "test" db.inventory.queryType = "nearest" db.inventory.filename = filename db._configure() self._db = db locs = numpy.array( [[0.1, 0.95]], numpy.float64) queryVals = ["two", "one"] dataE = numpy.array( [[8.2, 5.7]], numpy.float64) errE = [0] db = self._db db.open() db.queryVals(queryVals) data = numpy.zeros(dataE.shape, dtype=numpy.float64) err = [] nlocs = locs.shape[0] for i in xrange(nlocs): e = db.query(data[i,:], locs[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) return
def test_write(self): """ Test write(). """ # Database info cs = CSCart() cs.initialize() 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 SimpleIOAscii writer = SimpleIOAscii() writer.inventory.filename = filename writer._configure() 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.queryVals(["two", "one"]) vals = numpy.zeros(valsE.shape, dtype=numpy.float64) err = [] nlocs = qlocs.shape[0] for i in xrange(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