def test_data(): arr = [float(val) for val in range(25)] arr_int = [int(val % 4) for val in range(25)] proj = omf.Project() surf = omf.SurfaceElement( geometry=omf.SurfaceGridGeometry( tensor_u=[1., 1., 1., 1., 1.], tensor_v=[1., 1., 1., 1., 1.], ), data=[ omf.ScalarData(name='my data', description='my desc', location='faces', array=arr, colormap=omf.ScalarColormap( gradient=[ 'red', 'blue', 'black', 'orange', ] * 32, limits=[min(arr), max(arr)], )), omf.MappedData( name='my data', description='my desc', location='faces', array=arr_int, legends=[ omf.Legend(values=[ 'yellow', 'black', 'brown', 'green', ], ), omf.Legend(values=[ 'yellow!', 'black!!', 'brown!!!', 'green!!!!', ], ), ], ) ], ) proj.elements = [surf] proj.validate() view = get_view_from_proj(proj) view.validate() assert len(view.contents) == 9
def to_omf(self, cell_location): self.validate() if self.location == 'nodes': location = 'vertices' else: location = cell_location omf_data = omf.ScalarData( name=self.name or '', description=self.description or '', location=location, array=self.array.array, ) return omf_data
def test_from_omf(self): omf_element = omf.VolumeElement( name="vol_ir", geometry=omf.VolumeGridGeometry( axis_u=[1, 1, 0], axis_v=[0, 0, 1], axis_w=[1, -1, 0], tensor_u=np.ones(10).astype(float), tensor_v=np.ones(15).astype(float), tensor_w=np.ones(20).astype(float), origin=[10.0, 10.0, -10], ), data=[ omf.ScalarData( name="Random Data", location="cells", array=np.random.rand(10, 15, 20).flatten(), ) ], ) # Make a discretize mesh mesh, models = discretize.TensorMesh.from_omf(omf_element) geom = omf_element.geometry # Check geometry self.assertEqual(mesh.nC, geom.num_cells) self.assertEqual(mesh.nN, geom.num_nodes) self.assertTrue(np.allclose(mesh.hx, geom.tensor_u)) self.assertTrue(np.allclose(mesh.hy, geom.tensor_v)) self.assertTrue(np.allclose(mesh.hz, geom.tensor_w)) self.assertTrue(np.allclose(mesh.axis_u, geom.axis_u)) self.assertTrue(np.allclose(mesh.axis_v, geom.axis_v)) self.assertTrue(np.allclose(mesh.axis_w, geom.axis_w)) self.assertTrue(np.allclose(mesh.x0, geom.origin)) # Check data arrays self.assertEqual(len(models.keys()), len(omf_element.data)) for i in range(len(omf_element.data)): name = list(models.keys())[i] scalar_data = omf_element.data[i] self.assertEqual(name, scalar_data.name) arr = ravel_data_array( models[name], len(geom.tensor_u), len(geom.tensor_v), len(geom.tensor_w), ) self.assertTrue(np.allclose(np.array(scalar_data.array), arr))
def _to_omf(self): if self.order != 'c': raise ValueError('OMF data must be "c" order') import omf data = omf.ScalarData( name=self.title or '', description=self.description or '', array=omf.ScalarArray(self.array), ) if self.colormap: data.colormap = omf.ScalarColormap( gradient=omf.ColorArray(self.colormap, ), limits=[np.min(self.array), np.max(self.array)], ) return data
import tempfile import numpy as np import omf import omfvista import pyvista PROJECT = omf.Project(name='Test project', description='Just some assorted elements') POINTSET = omf.PointSetElement( name='Random Points', description='Just random points', geometry=omf.PointSetGeometry(vertices=np.random.rand(100, 3)), data=[ omf.ScalarData(name='rand data', array=np.random.rand(100), location='vertices'), omf.ScalarData(name='More rand data', array=np.random.rand(100), location='vertices') ], # textures=[ # omf.ImageTexture( # name='test image', # image='test_image.png', # origin=[0, 0, 0], # axis_u=[1, 0, 0], # axis_v=[0, 1, 0] # ), # omf.ImageTexture( # name='test image',
def _tensor_mesh_to_omf(mesh, models=None): """ Constructs an :class:`omf.VolumeElement` object of this tensor mesh and the given models as cell data of that grid. Parameters ---------- mesh : discretize.TensorMesh The tensor mesh to convert to a :class:`omf.VolumeElement` models : dict(numpy.ndarray) Name('s) and array('s). Match number of cells """ if models is None: models = {} # Make the geometry geometry = omf.VolumeGridGeometry() # Set tensors tensors = mesh.h if len(tensors) < 1: raise RuntimeError( "Your mesh is empty... fill it out before converting to OMF") elif len(tensors) == 1: geometry.tensor_u = tensors[0] geometry.tensor_v = np.array([ 0.0, ]) geometry.tensor_w = np.array([ 0.0, ]) elif len(tensors) == 2: geometry.tensor_u = tensors[0] geometry.tensor_v = tensors[1] geometry.tensor_w = np.array([ 0.0, ]) elif len(tensors) == 3: geometry.tensor_u = tensors[0] geometry.tensor_v = tensors[1] geometry.tensor_w = tensors[2] else: raise RuntimeError("This mesh is too high-dimensional for OMF") # Set rotation axes geometry.axis_u = mesh.axis_u geometry.axis_v = mesh.axis_v geometry.axis_w = mesh.axis_w # Set the origin geometry.origin = mesh.origin # Make sure the geometry is built correctly geometry.validate() # Make the volume elemet (the OMF object) omfmesh = omf.VolumeElement(geometry=geometry, ) # Add model data arrays onto the cells of the mesh omfmesh.data = [] for name, arr in models.items(): data = omf.ScalarData( name=name, array=ravel_data_array(arr, *mesh.shape_cells), location="cells", ) omfmesh.data.append(data) # Validate to make sure a proper OMF object is returned to the user omfmesh.validate() return omfmesh
############################################################################### omfvista.wrap(opal_mound_fault).plot(show_edges=False) ############################################################################### # temp_175c: '175C_vertices.csv' description='vertices of meshed/interpolated surfaces of the ' \ 'interpolated temperature isosurfaces for 175 degrees C used ' \ 'in the Phase 2B earth model. All data are georeferenced to ' \ 'UTM, zone 12N, NAD 83, NAVD 88.' temp_175c = gdc19.surf_to_omf('175C_vertices.csv', 'temp_175c', description) temp_175c.data = [ omf.ScalarData(name='constant temperature value of 175 for surface', array=np.full(temp_175c.geometry.num_nodes, 175.), location='vertices'), ] temp_175c.validate() ############################################################################### omfvista.wrap(temp_175c).plot(show_edges=False) ############################################################################### # temp_225c: '225C_vertices.csv' description='vertices of meshed/interpolated surfaces of the '\ 'interpolated temperature isosurfaces for 225 degrees C used '\ 'in the Phase 2B earth model. All data are georeferenced to ' \ 'UTM, zone 12N, NAD 83, NAVD 88.'
############################################################################### temperature = omf.PointSetElement( name='temperature', description='cumulative record of one-dimensional temperature modeling '\ 'based off of well data. Temperature log data were exampled and '\ 'extrapolated below the bottom of a number of wells. Temperatures '\ 'are in degrees Celsius, and all location data are georeferenced to ' 'UTM, zone 12N, NAD 83, NAVD 88.', subtype='point', geometry=omf.PointSetGeometry( vertices=_temp[['x', 'y', 'z']].values ), data=[omf.ScalarData( name='temperature (C)', array=_temp['T'].values, location='vertices' ),] ) temperature.validate() ############################################################################### omfvtk.wrap(temperature).plot(show_edges=False) ############################################################################### # Geostatistical Model # ++++++++++++++++++++ # # Load the kriged temperature model fkrig = gdc19.get_krig_path("Geotherm_kriged_0.sgems")
def test_doc_ex(self): dirname, _ = os.path.split(os.path.abspath(__file__)) pngfile = os.path.sep.join(dirname.split(os.path.sep)[:-1] + ['docs', 'images', 'PointSetGeometry.png']) proj = omf.Project( name='Test project', description='Just some assorted elements' ) pts = omf.PointSetElement( name='Random Points', description='Just random points', geometry=omf.PointSetGeometry( vertices=np.random.rand(100, 3) ), data=[ omf.ScalarData( name='rand data', array=np.random.rand(100), location='vertices' ), omf.ScalarData( name='More rand data', array=np.random.rand(100), location='vertices' ) ], textures=[ omf.ImageTexture( name='test image', image=pngfile, origin=[0, 0, 0], axis_u=[1, 0, 0], axis_v=[0, 1, 0] ), omf.ImageTexture( name='test image', image=pngfile, origin=[0, 0, 0], axis_u=[1, 0, 0], axis_v=[0, 0, 1] ) ], color='green' ) lin = omf.LineSetElement( name='Random Line', geometry=omf.LineSetGeometry( vertices=np.random.rand(100, 3), segments=np.floor(np.random.rand(50, 2)*100).astype(int) ), data=[ omf.ScalarData( name='rand vert data', array=np.random.rand(100), location='vertices' ), omf.ScalarData( name='rand segment data', array=np.random.rand(50), location='segments' ) ], color='#0000FF' ) surf = omf.SurfaceElement( name='trisurf', geometry=omf.SurfaceGeometry( vertices=np.random.rand(100, 3), triangles=np.floor(np.random.rand(50, 3)*100).astype(int) ), data=[ omf.ScalarData( name='rand vert data', array=np.random.rand(100), location='vertices' ), omf.ScalarData( name='rand face data', array=np.random.rand(50), location='faces' ) ], color=[100, 200, 200] ) grid = omf.SurfaceElement( name='gridsurf', geometry=omf.SurfaceGridGeometry( tensor_u=np.ones(10).astype(float), tensor_v=np.ones(15).astype(float), origin=[50., 50., 50.], axis_u=[1., 0, 0], axis_v=[0, 0, 1.], offset_w=np.random.rand(11, 16).flatten() ), data=[ omf.ScalarData( name='rand vert data', array=np.random.rand(11, 16).flatten(), location='vertices' ), omf.ScalarData( name='rand face data', array=np.random.rand(10, 15).flatten(order='f'), location='faces' ) ], textures=[ omf.ImageTexture( name='test image', image=pngfile, origin=[2., 2., 2.], axis_u=[5., 0, 0], axis_v=[0, 2., 5.] ) ] ) vol = omf.VolumeElement( name='vol', geometry=omf.VolumeGridGeometry( tensor_u=np.ones(10).astype(float), tensor_v=np.ones(15).astype(float), tensor_w=np.ones(20).astype(float), origin=[10., 10., -10] ), data=[ omf.ScalarData( name='Random Data', location='cells', array=np.random.rand(10, 15, 20).flatten() ) ] ) proj.elements = [pts, lin, surf, grid, vol] assert proj.validate() serial_file = os.path.sep.join([dirname, 'out.omf']) omf.OMFWriter(proj, serial_file) reader = omf.OMFReader(serial_file) new_proj = reader.get_project() assert new_proj.validate() assert str(new_proj.elements[3].textures[0].uid) == \ str(proj.elements[3].textures[0].uid) del reader os.remove(serial_file)