def _to_omf(self): import omf element = omf.PointSetElement( name=self.title or '', description=self.description or '', geometry=self.mesh._to_omf(), color=self.opts.color or 'random', data=[], textures=[tex._to_omf() for tex in self.textures] ) for data in self.data: location = 'vertices' omf_data = data.data._to_omf() omf_data.location = location element.data.append(omf_data) return element
def to_omf(self): self.validate() omf_point_set = omf.PointSetElement( name=self.name or '', description=self.description or '', geometry=omf.PointSetGeometry(vertices=self.vertices.array, ), data=[ attr.to_omf(cell_location='vertices') for attr in self.data if not isinstance(attr, TextureProjection) ], textures=[ tex.to_omf() for tex in self.data if isinstance(tex, TextureProjection) ], color=self.defaults.color.value, ) return omf_point_set
def test_points(): proj = omf.Project(origin=[5., 5, 5]) pts = omf.PointSetElement( name='my elem', description='my desc', geometry=omf.PointSetGeometry( vertices=[[i / 3, i / 4, i / 5] for i in range(10)], origin=[5., 5, 5], ), color='red', ) proj.elements = [pts] proj.validate() view = get_view_from_proj(proj) view.validate() assert len(view.contents) == 2 pointset = find(view, spatial.ElementPointSet) defaults = pointset.defaults.serialize() assert defaults['__class__'] == 'OptionsPoints' assert defaults['color']['value'] == '#FF0000' assert list(pointset.vertices.array[0]) == [10., 10, 10] assert pointset.name == 'my elem' assert pointset.description == 'my desc'
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', # image='test_image.png', # origin=[0, 0, 0], # axis_u=[1, 0, 0], # axis_v=[0, 0, 1] # ) # ], color='green') LINESET = omf.LineSetElement(name='Random Line',
# ++++++++++++++++++++++ # Load the temperature data _temp = pd.read_csv(gdc19.get_temperature_path('well_based_temperature.csv')) _temp.head() ############################################################################### 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
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)