def get_plane_relief_surface_info(self, plane): """ Get relief surface parameters for a plane. :param plane: plane number or plane name :returns: relief surface properties :rtype: :class:`geosoft.gxpy.view.PlaneReliefSurfaceInfo` .. versionadded::9.2 """ if isinstance(plane, str): plane = self.plane_number(plane) surface_grid_name = gxapi.str_ref() sample = gxapi.int_ref() base = gxapi.float_ref() scale = gxapi.float_ref() min_ref = gxapi.float_ref() max_ref = gxapi.float_ref() self.gxview.get_plane_surface(plane, surface_grid_name) self.gxview.get_plane_surf_info(plane, sample, base, scale, min_ref, max_ref) refine = 1 + int(sample.value / 16) min_val = None if min_ref.value == gxapi.rDUMMY else min_ref.value max_val = None if max_ref.value == gxapi.rDUMMY else max_ref.value return PlaneReliefSurfaceInfo(surface_grid_name.value, refine, base.value, scale.value, min_val, max_val)
def map_to_view(self, x, y): xr = gxapi.float_ref() xr.value = x * 1000.0 yr = gxapi.float_ref() yr.value = y * 1000.0 self.gxview.plot_to_view(xr, yr) return xr.value, yr.value
def _extent(self, what): xmin = gxapi.float_ref() ymin = gxapi.float_ref() xmax = gxapi.float_ref() ymax = gxapi.float_ref() self.gxview.extent(what, UNIT_VIEW, xmin, ymin, xmax, ymax) return xmin.value, ymin.value, xmax.value, ymax.value
def extent_group(self, group, unit=UNIT_VIEW): """ Extent of a group :param group: group name :param unit: units: :: UNIT_VIEW UNIT_MAP :returns: extent as (x_min, y_min, x_max, y_max) .. versionadded: 9.2 """ xmin = gxapi.float_ref() ymin = gxapi.float_ref() xmax = gxapi.float_ref() ymax = gxapi.float_ref() self.gxview.get_group_extent(group, xmin, ymin, xmax, ymax, unit) if unit == UNIT_MAP: xmin.value *= 0.1 xmax.value *= 0.1 ymin.value *= 0.1 ymax.value *= 0.1 return xmin.value, ymin.value, xmax.value, ymax.value
def view_to_map(self, x, y): xr = gxapi.float_ref() xr.value = x yr = gxapi.float_ref() yr.value = y self.gxview.view_to_plot(xr, yr) return xr.value / 10.0, yr.value / 10.0
def extent(self, extent=EXTENT_VIEW): xmin = gxapi.float_ref() ymin = gxapi.float_ref() xmax = gxapi.float_ref() ymax = gxapi.float_ref() self.gxview.extent(EXTENT_VIEW, UNIT_VIEW, xmin, ymin, xmax, ymax) if extent == EXTENT_MAP: xmin.value, ymin.value = self.view_to_map(xmin.value, ymin.value) xmax.value, ymax.value = self.view_to_map(xmax.value, ymax.value) return xmin.value, ymin.value, xmax.value, ymax.value
def current_map_state(self): """ Return the state of the current map. :returns: dict of the current map state, {} if no current map. =============== ========================================================= 'current_view' name of the current view 'display_area' (min_x, min_y, max_x, max_y) in units of the current view '3d_view_name' if a 3D view, name of the view 'point' (x, y) of the current selection point 'cursor' (x, y) of the current cursor location =============== ========================================================= .. versionadded:: 9.2 """ smap = {} if self.current_map: fx = gxapi.float_ref() fy = gxapi.float_ref() fx2 = gxapi.float_ref() fy2 = gxapi.float_ref() s = gxapi.str_ref() smap = {} emap = gxapi.GXEMAP.current_no_activate() emap.get_current_view(s) smap['current_view'] = s.value emap.get_display_area(fx, fy, fx2, fy2) smap['display_area'] = (fx.value, fy.value, fx2.value, fy2.value) if emap.is_3d_view(): emap.get_3d_view_name(s) smap['3d_view'] = s.value else: # 2D emap.get_cur_point(fx, fy) smap["point"] = (fx.value, fy.value, None) emap.get_cursor(fx, fy) smap["cursor"] = (fx.value, fy.value, None) return smap
def min_max(self): """ Return the minimum and maximum values as doubles. Strings are converted if possible. :return: (minimum, maximum), or if all dummy, (None, None) .. versionadded:: 9.3.1 """ rmin = gxapi.float_ref() rmax = gxapi.float_ref() self._gxvv.range_double(rmin, rmax) if rmin.value == gxapi.rDUMMY: return (None, None) return rmin.value, rmax.value
def render_properties(self): """The rendering properties for this surface as (color, opacity, style). Can be set.""" color = gxapi.int_ref() trans = gxapi.float_ref() style = gxapi.int_ref() self._gxsurfaceitem.get_default_render_properties(color, trans, style) return gxg.Color(color.value), trans.value, style.value
def mdf(self): """ Returns the Map Description File specification for maps that contain both a base view and a data view. ((x_size, y_size, margin_bottom, margin_right, margin_top, margin_left), (scale, units_per_metre, x_origin, y_origin))\ .. versionadded: 9.2 """ views = self.view_list() if not(self.has_view("*Data") and self.has_view("*Base")): raise MapException('The map must have both a "*Base" view and a "*Data" view.') xmn = gxapi.float_ref() ymn = gxapi.float_ref() xmx = gxapi.float_ref() ymx = gxapi.float_ref() with gxvw.GXview(self, "*Base", gxvw.READ_ONLY) as v: v.gxview.extent(gxapi.MVIEW_EXTENT_CLIP, gxapi.MVIEW_EXTENT_UNIT_MM, xmn, ymn, xmx, ymx) mapx = (xmx.value - xmn.value) * 0.1 mapy = (ymx.value - ymn.value) * 0.1 with gxvw.GXview(self, "*Data", gxvw.READ_ONLY) as v: v.gxview.extent(gxapi.MVIEW_EXTENT_CLIP, gxapi.MVIEW_EXTENT_UNIT_MM, xmn, ymn, xmx, ymx) view_map = (xmn.value * 0.1, ymn.value * 0.1, xmx.value * 0.1, ymx.value * 0.1) v.gxview.extent(gxapi.MVIEW_EXTENT_CLIP, gxapi.MVIEW_EXTENT_UNIT_VIEW, xmn, ymn, xmx, ymx) view_view = (xmn.value, ymn.value, xmx.value, ymx.value) m1 = (mapx, mapy, view_map[1], mapx - view_map[2], mapy - view_map[3], view_map[0]) sc = (view_view[2] - view_view[0]) / ((view_map[2] - view_map[0]) / 100.0) ufac = 1.0 x0 = view_view[0] y0 = view_view[1] m2 = (sc, ufac, x0, y0) return m1, m2
def draw_controls(self): """ Vox drawing settings, returned as a tuple: (box_on, opacity, extent) as (boolean, float, (min_x, min_y, min_z, max_x, max_y, max_z)) Can be set. .. versionadded:: 9.3.1 """ if self.is_vector: return None, None, None box = gxapi.int_ref() trans = gxapi.float_ref() x0 = gxapi.float_ref() x1 = gxapi.float_ref() y0 = gxapi.float_ref() y1 = gxapi.float_ref() z0 = gxapi.float_ref() z1 = gxapi.float_ref() self.gxvoxd.get_draw_controls(box, trans, x0, y0, z0, x1, y1, z1) return bool(box.value), trans.value, (x0.value, y0.value, z0.value, x1.value, y1.value, z1.value)
def trace_sample_interval(self): """ The interval between successive values in the trace data. E.g. microseconds or millimetres. """ ref = gxapi.float_ref() self._gx_segy_reader.get_sample_interval(ref) return ref.value
def view_to_map_cm(self, x, y=None): """ Returns the location of this point on the map in the view. :param x: x, or a tuple (x,y), in view units :param y: y if x is not a tuple .. versionadded:: 9.2 """ if y is None: y = x[1] x = x[0] xr = gxapi.float_ref() xr.value = x yr = gxapi.float_ref() yr.value = y self.gxview.view_to_plot(xr, yr) return xr.value / 10.0, yr.value / 10.0
def shell_limits(self): """ The data limits of the visible data shell for scalar data. Can be set. returns: (min, max) limits, data outside this range is transparent, None for no limit .. versionadded 9.3.1 """ vmin = gxapi.float_ref() vmax = gxapi.float_ref() self.gxvoxd.get_shell_controls(vmin, vmax) vmin = vmin.value vmax = vmax.value if vmin == gxapi.rDUMMY: vmin = None if vmax == gxapi.rDUMMY: vmax = None return vmin, vmax
def map_cm_to_view(self, x, y=None): """ Returns the location of this point on the map (in cm) to the view location in view units. :param x: x, or a tuple (x,y), in map cm :param y: y if x is not a tuple .. versionadded:: 9.2 """ if y is None: y = x[1] x = x[0] xr = gxapi.float_ref() xr.value = x * 10.0 yr = gxapi.float_ref() yr.value = y * 10.0 self.gxview.plot_to_view(xr, yr) return xr.value, yr.value
def properties(self, refresh=False): """ Surface properties from `geosoft.gxapi.GXSURFACEITEM.get_properties_ex`. :param refresh: if True, computed properties will be refreshed on next access. .. versionadded:: 9.3.1 """ if refresh: self._properties = None if not self._properties: stype = gxapi.str_ref() name = gxapi.str_ref() source_guid = gxapi.str_ref() source_name = gxapi.str_ref() source_measure = gxapi.float_ref() second_source_guid = gxapi.str_ref() second_source_name = gxapi.str_ref() second_source_option = gxapi.int_ref() second_source_measure = gxapi.float_ref() second_source_measure2 = gxapi.float_ref() self._gxsurfaceitem.get_properties_ex( stype, name, source_guid, source_name, source_measure, second_source_guid, second_source_name, second_source_option, second_source_measure, second_source_measure2) self._properties = { 'type': stype.value, 'name': name.value, 'source_guid': source_guid.value, 'source_dataset': source_name.value, 'source_measure': source_measure.value, 'second_source_guid': second_source_guid.value, 'second_source_dataset': second_source_name.value, 'second_source_option': second_source_option.value, 'second_source_measure': second_source_measure.value, 'second_source_measure2': second_source_measure2.value } return self._properties
def units(self): """ :return: tuple (factor, abbreviation), where factor is multiplier to convert to metres .. versionadded:: 9.2 """ sref = gxapi.str_ref() fref = gxapi.float_ref() self.gxipj.get_units(fref, sref) return fref.value, sref.value
def extent(self): """ Object extent as a `Point2` instance.""" if self._gxobj and hasattr(self._gxobj, 'get_extents'): rx0 = gxapi.float_ref() ry0 = gxapi.float_ref() rz0 = gxapi.float_ref() rx1 = gxapi.float_ref() ry1 = gxapi.float_ref() rz1 = gxapi.float_ref() self._gxobj.get_extents(rx0, ry0, rz0, rx1, ry1, rz1) cs = self.coordinate_system return Point2(((rx0.value, ry0.value, rz0.value), (rx1.value, ry1.value, rz1.value)), cs) else: return None
def extent(self): """ extent to the outer-cell edges of the vox as a `geosoft.gxpy.geometry.Point2`.""" rx0 = gxapi.float_ref() ry0 = gxapi.float_ref() rz0 = gxapi.float_ref() rx1 = gxapi.float_ref() ry1 = gxapi.float_ref() rz1 = gxapi.float_ref() self.gxvox.get_area(rx0, ry0, rz0, rx1, ry1, rz1) if self.is_depth: return gxgm.Point2(((rx0.value, ry0.value, -rz1.value), (rx1.value, ry1.value, -rz0.value))) return gxgm.Point2(((rx0.value, ry0.value, rz0.value), (rx1.value, ry1.value, rz1.value)), self.coordinate_system)
def _setup_locations(self): xvv = gxvv.GXvv() yvv = gxvv.GXvv() zvv = gxvv.GXvv() self.gxvox.get_location_points(xvv.gxvv, yvv.gxvv, zvv.gxvv) self._locations = (list(xvv.np), list(yvv.np), list(zvv.np)) x0 = gxapi.float_ref() y0 = gxapi.float_ref() z0 = gxapi.float_ref() self.gxvox.get_location(x0, y0, z0, xvv.gxvv, yvv.gxvv, zvv.gxvv) self._origin = (x0.value, y0.value, z0.value) self._cells = (list(xvv.np), list(yvv.np), list(zvv.np)) dx = gxapi.float_ref() dy = gxapi.float_ref() dz = gxapi.float_ref() self._gxvox.get_simple_location(x0, y0, z0, dx, dy, dz) self._uniform_cell_size = (dx.value, dy.value, dz.value)
def test_voxel(self): self.start() if self.skip(): name = 'voxel.geosoft_voxel' gxapi.GXVOX.generate_constant_value(name, 1.0, 5, 0, 0, 0, 1, 1, 1, 300, 200, 50, gxcs.Coordinate_system().gxipj, gxmeta.Metadata().gxmeta) gxvox = gxapi.GXVOX.create(name) minx = gxapi.float_ref() miny = gxapi.float_ref() minz = gxapi.float_ref() maxx = gxapi.float_ref() maxy = gxapi.float_ref() maxz = gxapi.float_ref() gxvox.get_area(minx, miny, minz, maxx, maxy, maxz) self.assertEqual(minx.value, -0.5) self.assertEqual(maxz.value, 49.5) vvx = gxvv.GXvv() vvy = gxvv.GXvv() vvz = gxvv.GXvv() gxvox.get_location_points(vvx.gxvv, vvy.gxvv, vvz.gxvv) gxvoxe = gxapi.GXVOXE.create(gxvox) vvd = gxvv.GXvv([float(n) for n in range(500)]) gxvoxe.vector(0., 0., 0., 1.5, 1.5, 0.5, vvd.gxvv, gxapi.VOXE_EVAL_INTERP) self.assertEqual(vvd.length, 500) self.assertEqual(vvd[0][0], 1.0) self.assertTrue(np.isnan(vvd[499][0])) gxvoxe = None gxvox = None try: os.remove(name) os.remove(name + '.xml') except: pass
import geosoft.gxapi as gxapi gxc = gxapi.GXContext.create(__name__, '0.1') img = gxapi.GXIMG.create_file(gxapi.GS_FLOAT, 'test.grd(GRD)', gxapi.IMG_FILE_READONLY) x_sep = gxapi.float_ref() y_sep = gxapi.float_ref() x_origin = gxapi.float_ref() y_origin = gxapi.float_ref() rotation = gxapi.float_ref() img.get_info(x_sep, y_sep, x_origin, y_origin, rotation) print(' dimension (nx, ny): ({}, {})'.format(img.nx(), img.ny()), '\n separation (x, y): ({}, {})'.format(x_sep.value, y_sep.value), '\n origin (x, y): ({}, {})'.format(x_origin.value, y_origin.value), '\n rotation: {}'.format(rotation.value))
def z_offset(self): """The Z-coordinate of the start (top) of each trace""" ref = gxapi.float_ref() self._gx_segy_reader.get_z_offset(ref) return ref.value
def state(): """ Return a dictionary that contains the current Oasis montaj state: .. code:: { 'gdb' { 'open_list': [list of open databases] 'current': current database name 'disp_chan_list': [ list of channels in the database 'selection': [ line, channel, start_fid, end_fid] # line is "*" if all lines selected # channel is '' if no channel selected # start_fid is '' if no fiducials selected # start_fid is '*' is all fiducials selected } 'map' { 'open_list': [list of open maps] 'current': current map name 'point': [ x, y, z] 'cursor': [ x, y, z] 'display_area':[ xmin, ymin, xmax, ymax] } } .. versionadded:: 9.1 """ s = gxapi.str_ref() glst = gxapi.GXLST.create(4096) state = {} # databases ndb = gxapi.GXEDB.get_databases_lst(glst, gxapi.EDB_PATH_FULL) if ndb > 0: sdb = {} edb = gxapi.GXEDB.current_no_activate() edb.get_name(s) sdb['current'] = os.path.normpath(s.value) sdb['open_list'] = [os.path.normpath(f) for f in list(dict_from_lst(glst).keys())] n = edb.disp_chan_lst(glst) if n > 0: sdb['disp_chan_list'] = list(dict_from_lst(glst).keys()) else: sdb['disp_chan_list'] = [] sch = gxapi.str_ref() sln = gxapi.str_ref() sfd = gxapi.str_ref() edb.get_current_selection(s, sch, sln, sfd) if sch.value == '[All]': sch.value = '*' if sln.value == '[All]': sln.value = '*' if sfd.value == '[All]': fd = ('*', '*') elif sfd.value == "[None]": fd = ('', '') else: fd = sfd.value.split(' to ') fd = (fd[0], fd[1]) sdb['selection'] = (sln.value, sch.value, fd[0], fd[1]) state['gdb'] = sdb # maps nmaps = gxapi.GXEMAP.get_maps_lst(glst, gxapi.EMAP_PATH_FULL) if nmaps > 0: fx = gxapi.float_ref() fy = gxapi.float_ref() fx2 = gxapi.float_ref() fy2 = gxapi.float_ref() smap = {} emap = gxapi.GXEMAP.current_no_activate() emap.get_name(s) smap['current'] = os.path.normpath(s.value) smap['open_list'] = [os.path.normpath(f) for f in list(dict_from_lst(glst).keys())] emap.get_display_area(fx, fy, fx2, fy2) smap['display_area'] = (fx.value, fy.value, fx2.value, fy2.value) if emap.is_3d_view(): emap.get_3d_view_name(s) smap['3d_view_name'] = s.value else: # 2D emap.get_cur_point(fx, fy) smap["point"] = (fx.value, fy.value, None) emap.get_cursor(fx, fy) smap["cursor"] = (fx.value, fy.value, None) state['map'] = smap return state
def __init__(self, ipj=None): self._ipj = gxapi.GXIPJ.create() self._coordinate_dict_() self._sr = gxapi.str_ref() self._fr = gxapi.float_ref()
def simple_set_get_string(dn, s): print("simple_set_get_string start") tstart = time.perf_counter() for i in range(0, 1000000): dn.get_axis_font(s) dn.set_axis_font("NewFont") elapsed = time.perf_counter() - tstart print("simple_set_get_string end: {}".format(elapsed)) ctx = gxa.GXContext.create("", "") ctxo = gxo.GXContext.create("", "") dn = gxa.GX3DN.create() dno = gxo.GX3DN.create() x = gxa.float_ref() y = gxa.float_ref() z = gxa.float_ref() s = gxa.str_ref() xo = gxo.float_ref() yo = gxo.float_ref() zo = gxo.float_ref() so = gxo.str_ref() print("OldAPI") simple_set_get_doubles(dno, xo, yo, zo) simple_set_get_string(dno, so) print("NewAPI") simple_set_get_doubles_baremetal(dn) simple_set_get_doubles(dn, x, y, z) simple_set_get_string_baremetal(dn)
def trace_range(self): """The depth of the top and bottom of the traces.""" top = self.z_offset bottom_ref = gxapi.float_ref() self._gx_segy_reader.get_last_sample_at(bottom_ref) return (top, bottom_ref.value)
def metres_per_unit(self): """ the number metres per distance unit of the coordinate system.""" fr = gxapi.float_ref() sr = gxapi.str_ref() self.gxipj.get_units(fr, sr) return fr.value