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_new_mesh(self): self.start() # make a copy by copying each surface with gxsurf.SurfaceDataset.new() as new_sd: sd_fn = new_sd.file_name with gxsurf.SurfaceDataset.open(self.sfile) as sd: for s in sd: snew = gxsurf.Surface(s.name) snew.add_mesh(s.mesh(), (gxgrp.C_MAGENTA, 0.25, gxsurf.STYLE_FLAT)) new_sd.add_surface(snew) with gxsurf.SurfaceDataset.open(sd_fn) as sd: self.assertEqual(sd.surface_count, 3) self.assertTrue('Isosurface 0.005' in sd.surface_name_list) self.assertTrue('Isosurface 0.01' in sd.surface_name_list) self.assertTrue('Isosurface 0.02' in sd.surface_name_list) self.assertEqual(sd['Isosurface 0.01'].render_opacity, 0.25) self.assertEqual(sd['Isosurface 0.02'].render_color.cmy, (0, 255, 0)) self.assertEqual(sd['Isosurface 0.01'].render_style, gxsurf.STYLE_FLAT) with gxview.View_3d.new() as v3d: v3d_file = v3d.file_name gxsurf.render(v3d, sd_fn, group_name='billy') self.crc_map(v3d_file)
def test_copy(self): self.start() # make a copy by copying each surface with gxsurf.SurfaceDataset.new() as new_sd: sd_fn = new_sd.file_name with gxsurf.SurfaceDataset.open(self.sfile) as sd: for s in sd: new_sd.add_surface(s) with gxsurf.SurfaceDataset.open(sd_fn) as sd: self.assertEqual(sd.surface_count, 3) self.assertTrue('Isosurface 0.005' in sd.surface_name_list) self.assertTrue('Isosurface 0.01' in sd.surface_name_list) self.assertTrue('Isosurface 0.02' in sd.surface_name_list) self.assertAlmostEqual(sd['Isosurface 0.01'].render_opacity, 0.6666666666666666) surf = sd['Isosurface 0.01'] self.assertEqual(surf.extent_xyz, (440718.65079365077, 6129015.476190476, -954.3756313323975, 441475.0, 6129475.0, 512.5)) with gxsurf.Surface('maki') as s: s.add_mesh(surf.mesh()) self.assertEqual(s.extent_xyz, (440718.65079365077, 6129015.476190476, -954.3756313323975, 441475.0, 6129475.0, 512.5))
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 t1(): verts = np.array([[0, 0, 0], [5, 0, 0], [5, 5, 0], [0, 3, 5], [2.5, 2, 10], [-3, 6, 8], [-4, 0, 12]], dtype=np.float64) faces = np.array([[0, 1, 2], [0, 2, 3], [3, 2, 4], [1, 2, 4], [3, 4, 5], [6, 4, 5]], dtype=np.int32) with gxsurf.Surface('maki') as s: s.add_mesh_np(faces, verts) s.render_color = gxgrp.C_CYAN s.render_style = gxsurf.STYLE_FLAT with gxview.View_3d.new() as v3d: v3d_file = v3d.file_name gxsurf.draw_surface(v3d, s)
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'))