def test_gxpy(self): with gx.GXpy() as gxc: self.assertIsNone(gxc._reset) self.assertTrue(gxc.gid.find('@') > 0) self.assertEqual(gxc.main_wind_id, 0) self.assertEqual(gxc.active_wind_id, 0) self.assertEqual(gx.__version__, geosoft.__version__)
def setUpGXPYTest(cls, res_stack=6, context_name=__name__, parent_window=0): _verify_no_gx_context() cls._cls_unique_id_count = 0 cls._test_case_py = os.path.join(os.getcwd(), inspect.getfile(cls)) cls._test_case_filename = os.path.split(cls._test_case_py)[1] if cls._test_case_filename == os.path.split(__file__)[1]: raise Exception( _t("GXPYTest base class incorrectly detected as test case!")) cur_dir = os.path.dirname(cls._test_case_py) cls._result_base_dir = os.path.join(cur_dir, 'results', cls._test_case_filename) os.makedirs(cls._result_base_dir, exist_ok=True) os.chdir(cls._result_base_dir) gxu._temp_folder_override = os.path.join(cls._result_base_dir, '__tmp__') if os.path.exists(gxu._temp_folder_override): shutil.rmtree(gxu._temp_folder_override) os.makedirs(gxu._temp_folder_override, exist_ok=True) gxu._uuid_callable = cls._cls_uuid set_geosoft_bin_path() cls._gx = gx.GXpy(name=context_name, log=print, res_stack=res_stack, max_warnings=12, suppress_progress=True, parent_window=parent_window)
def setUpGXPYTest(cls, res_stack=6, context_name=__name__, parent_window=0, per_user_key=False): _verify_no_gx_context() cls._cls_unique_id_count = 0 cls._test_case_py = os.path.join(os.getcwd(), inspect.getfile(cls)) cls._test_case_filename = os.path.split(cls._test_case_py)[1] if cls._test_case_filename == os.path.split(__file__)[1]: raise Exception(_t("GXPYTest base class incorrectly detected as test case!")) cur_dir = os.path.dirname(cls._test_case_py) cls._result_base_dir = os.path.join(cur_dir, 'results', cls._test_case_filename) if _external_result_base_dir is None else _external_result_base_dir os.makedirs(cls._result_base_dir, exist_ok=True) os.chdir(cls._result_base_dir) gxu._temp_folder_override = os.path.join(cls._result_base_dir, '__tmp__') if os.path.exists(gxu._temp_folder_override): shutil.rmtree(gxu._temp_folder_override) os.makedirs(gxu._temp_folder_override, exist_ok=True) gxu._uuid_callable = cls._cls_uuid if not _dev_test_run: # This ensures clean global and other settings for consistent test runs _, user_dir, _ = gxapi.GXContext.get_key_based_product_dirs(per_user_key=per_user_key) if os.path.exists(user_dir): shutil.rmtree(user_dir) os.makedirs(user_dir, exist_ok=True) cls._gx = gx.GXpy(name=context_name, log=print, res_stack=res_stack, max_warnings=12, suppress_progress=True, parent_window=parent_window, per_user_key=per_user_key)
def test_entitlements(self): with gx.GXpy() as gxc: ent = gxc.entitlements() self.assertTrue(ent['1000'], 'Oasis montaj™ Base') self.assertTrue(gxc.has_entitlement(1000)) self.assertTrue(gxc.has_entitlement('Oasis montaj™ Base')) self.assertTrue(gxc.has_entitlement(2000)) self.assertTrue(gxc.has_entitlement("ArcGIS")) self.assertTrue(gxc.has_entitlement(3000)) self.assertTrue(gxc.has_entitlement("MapInfo")) self.assertFalse(gxc.has_entitlement("bogus")) #for e in ent: # print('{}: "{}"'.format(e, ent[e])) if gxc.entitled: self.assertTrue(gxc.has_entitlement(10000) or gxc.has_entitlement(30000) or gxc.has_entitlement(30101) or gxc.has_entitlement(40000) or gxc.has_entitlement(41000)) else: self.assertTrue(gxc.has_entitlement(1000) and gxc.has_entitlement(2000) and gxc.has_entitlement(3000)) self.assertFalse(gxc.has_entitlement(10000)) self.assertFalse(gxc.has_entitlement(30000)) self.assertFalse(gxc.has_entitlement(30101)) self.assertFalse(gxc.has_entitlement(40000)) self.assertFalse(gxc.has_entitlement(41000))
def test_elapsed_time(self): self.start(gsys.func_name()) with gx.GXpy() as gxc: self.assertTrue(gxc.elapsed_seconds("startup") > 0.0) time.sleep(0.25) self.assertTrue(gxc.elapsed_seconds("0.25 seconds later") > 0.25)
def test_gxpy(self): self.start(gsys.func_name()) with gx.GXpy(log=print) as gxc: self.assertTrue(gxc.gid.find('@') > 0) self.assertEqual(gxc.main_wind_id(), 0) self.assertEqual(gxc.active_wind_id(), 0) self.assertEqual(gx.__version__, geosoft.__version__)
def setUpClass(cls): cls.gx = gx.GXpy(log=print, res_stack=4) os.chdir(os.path.dirname(os.path.realpath(__file__))) cls.folder, files = gsys.unzip(os.path.join(os.path.dirname(__file__), 'testgrids.zip'), folder=cls.gx.temp_folder()) cls.g1f = os.path.join(cls.folder, 'test_grid_1.grd') cls.g2f = os.path.join(cls.folder, 'test_grid_2.grd') pass
def new_test_map(mapname='test', rescale=1.0, locate=None): test_map = os.path.join(gx.GXpy().temp_folder(), mapname) with gxmap.GXmap.new(test_map, overwrite=True) as gmap: with gxv.GXview(gmap, "rectangle_test") as view: view.start_group('rectangle') view.xy_rectangle((gxgm.Point((0, 0)), gxgm.Point((250, 110))), pen={'line_thick': 1}) p1 = gxgm.Point((5, 5)) * rescale p2 = gxgm.Point((100, 100)) * rescale poff = gxgm.Point((10, 5)) * rescale view.pen = {'fill_color': gxapi.C_LT_GREEN} view.xy_rectangle((p1, p2)) view.pen = {'line_style': (2, 2.0)} view.xy_line((p1 + poff, p2 - poff)) with gxv.GXview(gmap, "poly") as view: view.start_group('poly') plinelist = [[110, 5], [120, 20], [130, 15], [150, 50], [160, 70], [175, 35], [190, 65], [220, 50], [235, 18.5]] pp = gxgm.PPoint.from_list(plinelist) * rescale view.pen = {'line_style': (2, 2.0)} view.xy_poly_line(pp) view.pen = { 'line_style': (4, 2.0), 'line_smooth': gxv.SMOOTH_AKIMA } view.xy_poly_line(pp) ppp = np.array(plinelist) pp = gxgm.PPoint(ppp[3:, :]) * rescale view.pen = { 'line_style': (5, 5.0), 'line_smooth': gxv.SMOOTH_CUBIC, 'line_color': gxapi.C_RED, 'line_thick': 0.25, 'fill_color': gxapi.C_LT_BLUE } view.xy_poly_line(pp, close=True) view.pen = {'fill_color': gxapi.C_LT_GREEN} pp = (pp - (100, 0, 0)) / 2 + (100, 0, 0) view.xy_poly_line(pp, close=True) pp += (0, 25, 0) view.pen = {'fill_color': gxapi.C_LT_RED} view.xy_poly_line(pp, close=True) return gmap.filename
def loadGRDFile(fileName, plotIt=False): """ Load a data matrix in Geosoft *.grd format and return a dictionary with gridded data """ try: import geosoft.gxpy.grid as gxgrd import geosoft.gxpy.gx as gx except ImportError: print("geosoft module not installed. loadGRDFile ") return gxc = gx.GXpy() data = dataGrid() with gxgrd.Grid(fileName) as grid: lim = grid.extent_2d() data.limits = np.r_[lim[0], lim[2], lim[1], lim[3]] # coordinate_system = grid.coordinate_system temp = grid.xyzv()[:, :, 3] temp[temp == -99999] = np.nan data._values = temp data.nx, data.ny = grid.nx, grid.ny data.dx, data.dy = grid.dx, grid.dy data.x0, data.y0 = grid.x0 - grid.dx / 2, grid.y0 - grid.dy / 2 if plotIt: xLoc = np.asarray(range(data.nx)) * data.dx + data.x0 yLoc = np.asarray(range(data.ny)) * data.dy + data.y0 fig, axs = plt.figure(figsize=(8, 8)), plt.subplot() fig, im, cbar = Simulator.plotData2D(xLoc, yLoc, data.values, marker=False, fig=fig, ax=axs, colorbar=True) axs.grid(True) cbar.set_label("TMI (nT)") plt.show() fig.savefig("./images/SearchQuestII.png", bbox_inches="tight") return data
def test_env(self): self.start(gsys.func_name()) with gx.GXpy(log=print) as gxc: env = gxc.environment() self.assertFalse(env.get('gid') is None) self.assertFalse(env.get('current_date') is None) self.assertFalse(env.get('current_utc_date') is None) self.assertFalse(env.get('current_time') is None) self.assertFalse(env.get('current_utc_time') is None) self.assertFalse(env.get('license_class') is None) self.assertFalse(env.get('folder_workspace') is None) self.assertFalse(env.get('folder_temp') is None) self.assertFalse(env.get('folder_user') is None) env = gxc.environment(2) self.assertTrue(isinstance(env, str))
def test_temp(self): self.start(gsys.func_name()) with gx.GXpy(log=print) as gxc: tf = gxc.temp_folder() self.assertTrue(os.path.isdir(tf)) tf = gxc.temp_file() self.assertFalse(os.path.exists(tf)) tf = gxc.temp_file(ext=".dummy") self.assertFalse(os.path.exists(tf)) self.assertEqual(tf[-6:], ".dummy") try: with open(tf, 'x'): pass except: self.assertTrue(False)
!pip install geosoft==9.2 !pip install geosoft --upgrade import geosoft import geosoft.gxpy.gx as gx gxp = gx.GXpy() print(gxp.gid) print(gxp.entitlements)
def setUpClass(cls): cls.gxc = gx.GXpy() cls.folder, files = gsys.unzip('test_data.zip', folder=cls.gxc.temp_folder()) cls.grid_file = os.path.join(cls.folder, 'bhn_tmi_250m.grd')
def setUpClass(cls): cls.gx = gx.GXpy(log=print, parent_window=-1, max_warnings=8) os.chdir(os.path.dirname(os.path.realpath(__file__))) pass
import geosoft.gxpy.gx as gx import geosoft.gxpy.voxset as gxvox gx = gx.GXpy() with gxvox.Voxset.new("test_new", dimension=(35, 50, 12), overwrite=True) as vox: print(vox.nx, vox.ny, vox.nz)
def setUpClass(cls): gx.GXpy(log=print)
def setUpClass(cls): global logfile cls.gxc = gx.GXpy(parent_window=0, log=print)
def test_entitlements(self): self.start(gsys.func_name()) with gx.GXpy(log=print) as gxc: ent = gxc.entitlements() self.assertTrue(ent.get('1000'), 'Oasis montaj™ Base')
def setUpClass(cls): cls.gxp = gx.GXpy(log=print)
def setUpClass(cls): cls.gx = gx.GXpy(log=print) cls.folder, files = gsys.unzip(os.path.join(os.path.dirname(__file__), 'test_database.zip'), folder=cls.gx.temp_folder()) cls.gdb_name = os.path.join(cls.folder, files[0])
############################################################################################### if __name__ == '__main__': ''' Self-Organizing maps ''' # get command line parameters parser = argp.ArgumentParser( description=_("SOM analysis of data in a Geosoft database")) args = parser.parse_args() print("GeoSOM copyright 2016 Geosoft Inc.\n") gxc = gxp.GXpy() settings = gxu.get_shared_dict() print(settings) #input('continue...') # defaults if 'CLASS_ERR' not in settings: settings['CLASS_ERR'] = ('Class', 'EuD') if 'FILTER' not in settings: settings['FILTER'] = ('', '') if 'SOM_PARAMETERS' not in settings: settings['SOM_PARAMETERS'] = (4, 2, mvar.similarity_functions()[0]) gdb_name = os.path.normpath(settings['GDB_NAME']) gdb = gxgdb.Geosoft_gdb.open(gdb_name)
def _get_thread_gx_context(cls, use_gxpy_context: bool): if use_gxpy_context: return gx.GXpy('ThreadGXContext', geosoft.__version__) else: return geosoft.gxapi.GXContext.create('ThreadGXContext', geosoft.__version__)
view.pen = {'fill_color': gxapi.C_LT_GREEN} pp = (pp - (100, 0, 0)) / 2 + (100, 0, 0) view.xy_poly_line(pp, close=True) pp += (0, 25, 0) view.pen = {'fill_color': "B"} view.xy_poly_line(pp, close=True) #TODO - viewer does not properly disply items on the plane if the box_3d is called view.box_3d(((20, 10, 30), (80, 50, 50)), pen={'fill_color': 'R255G100B50'}) return gmap.filename def test_mapviewer(gxp): sample = sample_map(gxp, mapname=os.path.join(gxp.temp_folder(), 'test_3d')) #sample = sample_map(gxp, mapname= 'test_3d') gxvwr.map( sample ) #TODO where is the 3D view? It is a tiny dot in the bottom left. I can't figure out how to locate it. gxvwr.v3d(sample) if __name__ == '__main__': os.chdir(os.path.dirname(os.path.realpath(__file__))) with gx.GXpy(parent_window=-1, log=print) as gxp: test_mapviewer(gxp)
from tkinter import * from tkinter import ttk from tkinter import filedialog import numpy as np from math import log import geosoft.gxpy.gx as gx import geosoft.gxpy.gdb as gxdb gsc=gx.GXpy() class Root(Tk): def __init__(self): super (Root, self).__init__() self.minsize(400,400) self.title('Time decay constant') self.button=ttk.Button(self, text='Open GDB file', command=self.openDB).pack() self.label=ttk.Label(self,text='__GDB file__') self.label.pack() self.buttonrd=ttk.Button(self,text='Read GDB file', command=self.read_DB) self.buttonrd.pack() self.EM_channel=StringVar() self.comboxchan=ttk.Combobox(self, postcommand=self.InitUI, textvariable=self.EM_channel) self.comboxchan.pack() self.labelnumchannel=ttk.Label(self, text='Number of channels used for calculation :').pack() self.numberusedchannel=IntVar() self.boxnumber=ttk.Entry(self, textvariable=self.numberusedchannel) self.boxnumber.pack() self.buttontime=ttk.Button(self, text='Open TEM file', command=self.openTEM).pack() self.labeltime=ttk.Label(self, text='__TEM file__') self.labeltime.pack()
import geosoft.gxpy.gx as gx import geosoft.gxpy.grid as gxgrd gxc = gx.GXpy() # create a memory grid as an example of a spatial object for this exercise grid = gxgrd.Grid.new(properties=({'nx': 10, 'ny': 10})) print(grid.coordinate_system) # define by a Geosoft-style coordinate system name. Parameters are derived from internal Geosoft tables. grid.coordinate_system = "NAD83 / UTM zone 17N" print(grid.coordinate_system) print(grid.coordinate_system.gxf) print(grid.coordinate_system.coordinate_dict()) # example use of GXF strings to change the datum to NAD27. Here we remove the name and local datum transform # and allow the Coordinate_system class to complete parameters for NAD27 from the tables. gxf = grid.coordinate_system.gxf gxf[0] = '' gxf[1] = "NAD27" gxf[4] = '' grid.coordinate_system = gxf print('gxf:', grid.coordinate_system.gxf) # fully explicit definition of UTM zone 17N on NAD27 datum using GXF string. grid.coordinate_system = [ '', 'NAD27', '"Transverse Mercator",0,-87,0.9996,500000,0', 'm,1', '"*local_datum",-8,160,176,0,0,0,0' ] print('gxf:', grid.coordinate_system.gxf)
def setUpClass(cls): cls.gx = gx.GXpy(log=print) os.chdir(os.path.dirname(os.path.realpath(__file__))) pass