def test_fig_map_legend(self): self.start() verts = np.array([[0, 0, 0], [5, 0, 0], [5, 5, 0], [0, 3, 5], [2.5, 2, 10]], dtype=np.float64) faces = np.array([[0, 1, 2], [0, 2, 3], [3, 2, 4]], dtype=np.int32) with gxsurf.SurfaceDataset.new() as sd: with gxsurf.Surface('maki 0', surface_dataset=sd) as s: s.add_mesh(gxgm.Mesh((faces, verts))) s.render_color = gxgrp.C_RED s.render_style = gxsurf.STYLE_FLAT s.render_opacity = 1 with gxsurf.Surface('maki 1', surface_dataset=sd) as s: verts[::, 2] *= 0.5 s.add_mesh(gxgm.Mesh((faces, verts))) s.render_color = gxgrp.C_LT_GREEN s.render_style = gxsurf.STYLE_FLAT s.render_opacity = 1 with gxsurf.Surface('Light-blue surface, with an extremely long name to test margin settings', surface_dataset=sd) as s: verts[::, 2] *= 0.5 s.add_mesh(gxgm.Mesh((faces, verts))) s.render_color = gxgrp.C_LT_BLUE s.render_style = gxsurf.STYLE_FLAT s.render_opacity = 1 fig_map = sd.figure_map().file_name self.crc_map(fig_map)
def test_fig_map_cs(self): self.start() verts = np.array([[0, 0, 0], [5, 0, 0], [5, 5, 0], [0, 3, 5], [2.5, 2, 10]], dtype=np.float64) faces = np.array([[0, 1, 2], [0, 2, 3], [3, 2, 4]], dtype=np.int32) mesh = gxgm.Mesh((faces, verts)) with gxsurf.SurfaceDataset.new() as sd: sd.coordinate_system = gxcs.Coordinate_system.local() with gxsurf.Surface('maki_red', surface_dataset=sd) as s: cs = gxcs.Coordinate_system.local(azimuth=20) s.add_mesh(mesh, coordinate_system=cs) s.render_color = gxgrp.C_RED with gxsurf.Surface('maki_green', surface_dataset=sd, coordinate_system=gxcs.Coordinate_system.local(azimuth=-20, elevation=3)) as s: s.add_mesh(mesh) s.render_color = gxgrp.C_GREEN with gxsurf.Surface('maki_blue', surface_dataset=sd) as s: s.add_mesh(mesh, coordinate_system=gxcs.Coordinate_system.local(azimuth=0, origin=(1.5, -2), elevation=-3)) s.render_color = gxgrp.C_BLUE fig_map = sd.figure_map(features=('NEATLINE',)).file_name self.crc_map(fig_map)
def test_doc_sample(self): self.start() faces = [[0, 1, 2], [0, 2, 3], [3, 2, 4]] verticies = [[0, 0, 0], [5, 0, 0], [5, 5, 0], [0, 3, 5], [2.5, 2, 10]] mesh = gxgm.Mesh((faces, verticies)) faces = np.array(faces, dtype=np.int32) verticies = np.array(verticies, dtype=np.float64) mesh = gxgm.Mesh((faces, verticies)) f1vv, f2vv, f3vv = gxvv.vvset_from_np(faces) xvv, yvv, zvv = gxvv.vvset_from_np(verticies) mesh = gxgm.Mesh(((f1vv, f2vv, f3vv), (xvv, yvv, zvv)))
def test_fig_map(self): self.start() verts = np.array([[0, 0, 0], [5, 0, 0], [5, 5, 0], [0, 3, 5], [2.5, 2, 10]], dtype=np.float64) faces = np.array([[0, 1, 2], [0, 2, 3], [3, 2, 4]], dtype=np.int32) with gxsurf.SurfaceDataset.new() as sd: with gxsurf.Surface('maki', surface_dataset=sd) as s: s.add_mesh(gxgm.Mesh((faces, verts))) s.render_color = gxgrp.C_RED s.render_style = gxsurf.STYLE_FLAT s.render_opacity = 1 fig_map = sd.figure_map(features=('NEATLINE',)).file_name self.crc_map(fig_map)
def test_make_my_own_2(self): self.start() verts = np.array([[0, 0, 0], [5, 0, 0], [5, 5, 0], [0, 3, 5], [2.5, 2, 10]], dtype=np.float64) faces = np.array([[0, 1, 2], [0, 2, 3], [3, 2, 4]], dtype=np.int32) with gxsurf.Surface('maki') as s: s.add_mesh(gxgm.Mesh((faces, verts))) s.render_color = gxgrp.C_RED s.render_style = gxsurf.STYLE_EDGE s.render_opacity = 1 with gxview.View_3d.new() as v3d: v3d_file = v3d.file_name gxsurf.render(v3d, s) self.crc_map(v3d_file)
def test_mesh(self): self.start() v = list(np.array(range(27), dtype=np.float).reshape(-1, 3)) f = list(np.array(range(len(v))).reshape(-1, 3)) m = gxgeo.Mesh((f, v)) self.assertEqual(len(m.faces), len(f)) self.assertEqual(len(m.verticies), len(v)) self.assertEqual(tuple(m[2][2]), (24., 25., 26.)) self.assertEqual(tuple(m.extent_minimum), (0, 1, 2)) m2 = m + 1.5 self.assertEqual(tuple(m2[2][2]), (25.5, 26.5, 27.5)) self.assertEqual(tuple(m2.extent_minimum), (1.5, 2.5, 3.5)) m2 = m2 - 1.5 self.assertEqual(tuple(m2[2][2]), (24., 25., 26.)) self.assertEqual(tuple(m2.extent_minimum), (0, 1, 2)) m2 = m + (1, 10, 50) self.assertEqual(tuple(m2[2][2]), (25., 35., 76.)) self.assertEqual(tuple(m2.extent_minimum), (1, 11, 52)) m2 = m2 - (1, 10, 50) self.assertEqual(tuple(m2[2][2]), (24., 25., 26.)) self.assertEqual(tuple(m2.extent_minimum), (0, 1, 2)) m2 = m + (m + (1, 10, 50)) self.assertEqual(tuple(m2.extent_maximum), (25., 35., 76.)) self.assertEqual(m2.extent_maximum_xyz, (25., 35., 76.)) self.assertEqual(m2.extent_minimum_xyz, (0, 1, 2)) self.assertEqual(m2.extent_maximum_xy, (25., 35.)) self.assertEqual(m2.extent_minimum_xy, (0, 1)) self.assertEqual(m2.centroid_xyz, (12.5, 18.0, 39.0)) self.assertEqual(m2.centroid_xy, (12.5, 18.0)) self.assertEqual(len(m2), 2 * len(m)) mm = gxgeo.Mesh((np.append(m2.faces, m2.faces, axis=0), m2.verticies)) self.assertEqual(len(mm), 12) self.assertEqual(len(mm.verticies), 18) mp = mm.point_array() self.assertEqual(len(mp), 18) mp = mm.point_array(unique=False) self.assertEqual(len(mp), 36) v = np.array(v) v[:, 0] += 500000 v[:, 1] += 6000000 m = gxgeo.Mesh((f, v), coordinate_system="NAD83 / UTM zone 17N") m = gxgeo.Mesh(m, coordinate_system="NAD27 / UTM zone 17N") self.assertEqual(str(m.coordinate_system), "NAD27 / UTM zone 17N") self.assertEqual(tuple(m[2][2]), (500006.87887296296, 5999802.6514122421, 26.0)) m83 = gxgeo.Mesh(m, coordinate_system="NAD83 / UTM zone 17N") self.assertEqual(m83.coordinate_system, "NAD83 / UTM zone 17N") self.assertEqual(tuple(m[2][2]), (500006.87887296296, 5999802.6514122421, 26.0)) self.assertEqual(tuple(m83[2][2]), (500024.00010005565, 6000025.0009018015, 26.0)) f = np.array(f) f1vv = gxvv.GXvv(f[:, 0]) f2vv = gxvv.GXvv(f[:, 1]) f3vv = gxvv.GXvv(f[:, 2]) xvv = gxvv.GXvv(v[:, 0]) yvv = gxvv.GXvv(v[:, 1]) zvv = gxvv.GXvv(v[:, 2]) m = gxgeo.Mesh(((f1vv, f2vv, f3vv), (xvv, yvv, zvv)), coordinate_system="NAD83 / UTM zone 17N", name='vv') self.assertEqual(m.name, 'vv') mm = gxgeo.Mesh(m, coordinate_system="NAD27 / UTM zone 17N") self.assertEqual(mm.name, '_mesh_') m2 = gxgeo.Mesh(mm, coordinate_system="NAD27 / UTM zone 17N", name='vv_copy') self.assertEqual(m2.name, 'vv_copy') self.assertEqual(str(m2.coordinate_system), "NAD27 / UTM zone 17N") self.assertEqual(tuple(m2[2][2]), (500006.87887296296, 5999802.6514122421, 26.0)) self.assertEqual(str(m2), 'vv_copy(3 faces)') self.assertTrue(mm == m2) self.assertEqual(len(list(m2)), 3) self.assertFalse(m == m2) m3 = m + m2 self.assertEqual(len(m3), 6) self.assertEqual(m3.length, 6) f1vv, f2vv, f3vv = m3.faces_vv() self.assertEqual(tuple(f1vv.np), (0, 3, 6, 9, 12, 15)) self.assertEqual(tuple(f2vv.np), (1, 4, 7, 10, 13, 16)) self.assertEqual(tuple(f3vv.np), (2, 5, 8, 11, 14, 17)) xvv, yvv, zvv = m3.verticies_vv() self.assertEqual(tuple(xvv.np[:3]), (500000.0, 500003.0, 500006.0)) self.assertEqual(tuple(yvv.np[:3]), (6000001.0, 6000004.0, 6000007.0)) self.assertEqual(tuple(zvv.np[:3]), (2.0, 5.0, 8.0))
def test_exceptions(self): self.start() verts = np.array([[0, 0, 0], [5, 0, 0], [5, 5, 0], [0, 3, 5], [2.5, 2, 10]], dtype=np.float64) faces = np.array([[0, 1, 2], [0, 2, 3], [3, 2, 4]], dtype=np.int32) fn = 'except.geosoft_surface' try: with open(fn, '+w') as f: f.write('maki') self.assertRaises(gxsurf.SurfaceException, gxsurf.SurfaceDataset.new, 'except') finally: gxsurf.delete_files(fn) with gxsurf.SurfaceDataset.new('test', temp=True, coordinate_system='WGS 84') as sd: s = gxsurf.Surface('maki') s.coordinate_system = 'NAD83' self.assertEqual(str(s.coordinate_system), 'NAD83') self.assertRaises(gxsurf.SurfaceException, sd.add_surface, s) fn = gxsurf.SurfaceDataset.vox_surface(gxvox.Vox.open(self.vox_file), 0.01, temp=True).file_name with gxsurf.SurfaceDataset.open(self.sfile) as sd: self.assertFalse(sd.is_new) self.assertTrue(sd.has_surface('Isosurface 0.01')) self.assertRaises(gxsurf.SurfaceException, gxsurf.Surface, 'Isosurface 0.01', 'none', sd) self.assertRaises(gxsurf.SurfaceException, sd.add_surface, gxsurf.Surface('Isosurface 0.01')) self.assertFalse(sd.has_surface('billy')) self.assertRaises(gxsurf.SurfaceException, sd.add_surface, gxsurf.Surface('billy', mesh=(faces, verts))) with gxsurf.SurfaceDataset.new() as new_sd: new_sd.add_surface_dataset(sd) self.assertTrue(new_sd.has_surface('Isosurface 0.01')) self.assertRaises(gxsurf.SurfaceException, gxsurf.Surface, 'Isosurface 0.01', 'none', new_sd) self.assertRaises(gxsurf.SurfaceException, new_sd.add_surface, gxsurf.Surface('Isosurface 0.01')) self.assertFalse(new_sd.has_surface('billy')) s = gxsurf.Surface('billy', mesh=(faces, verts)) new_sd.add_surface(s) self.assertTrue(new_sd.has_surface('billy')) with gxsurf.SurfaceDataset.new() as new_sd: new_sd.unit_of_measure = 'nT' new_sd.add_surface_dataset(fn) self.assertTrue(new_sd.has_surface('Isosurface 0.01')) s = new_sd['Isosurface 0.01'] self.assertEqual(s.surface_type, 'ISOSURFACE') self.assertTrue(bool(s.source_dataset)) self.assertEqual(s.unit_of_measure, 'nT') self.assertEqual(s.component_count, 1) new_sd.add_surface(gxsurf.Surface('billy', surface_type='maki', mesh=(faces, verts))) self.assertTrue(new_sd.has_surface('billy')) self.assertEqual(new_sd.surface_guid('billy'), new_sd['billy'].guid) s = new_sd['billy'] self.assertEqual(s.surface_type, 'maki') self.assertEqual(s.source_dataset, '') self.assertEqual(s.unit_of_measure, 'nT') self.assertEqual(s.component_count, 1) self.assertEqual(s.render_color, gxgrp.Color(gxgrp.C_GREY)) with gxsurf.SurfaceDataset.new() as new_sd: new_sd.add_surface_dataset(fn) self.assertTrue(new_sd.has_surface('Isosurface 0.01')) gxsurf.Surface('billy', surface_dataset=new_sd, mesh=gxgm.Mesh((faces, verts))) self.assertTrue(new_sd.has_surface('billy'))