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 rungx(): project = gxpj.Geosoft_project() # there must be grids in the project if len(project.project_grids) == 0: raise Exception('This project contains no grids.') # default grid will be the current grid, or the first grid in the list of project grids if project.current_grid: default_grid = project.current_grid else: default_grid = project.project_grids[0] # ask the user to select a grid grid_name = gxpj.get_user_input(title='Vertical derivative of a grid', prompt='Grid to process', kind='list', items=project.project_grids, default=default_grid) # ask for a new grid file name new_grid = gxpj.get_user_input( title='Vertical derivative of a grid', prompt='Output vertical derivative grid name', kind='file', filemask='*.grd') # calculate vertical derivative with gxgrd.Grid(grid_name) as g_input: with gxgrd.Grid.new(new_grid, properties=g_input.properties(), overwrite=True) as g_output: gxapi.GXIMU.grid_vd(g_input.gximg, g_output.gximg) # open the vertical derivative grid gxpj.add_document(new_grid)
import geosoft.gxpy.gx as gx import geosoft.gxpy.view as gxview import geosoft.gxpy.group as gxgroup import geosoft.gxpy.agg as gxagg import geosoft.gxpy.grid as gxgrd import geosoft.gxpy.viewer as gxviewer gxc = gx.GXpy() grid_file = 'Wittichica Creek Residual Total Field.grd' # create a 3D view with gxview.View_3d.new("TMI on a plane", area_2d=gxgrd.Grid(grid_file).extent_2d(), coordinate_system=gxgrd.Grid(grid_file).coordinate_system, overwrite=True) as v: v3d_name = v.file_name # add the grid image to the view, with shading, ands contour gxgroup.Aggregate_group.new(v, gxagg.Aggregate_image.new(grid_file, shade=True, contour=20)) gxgroup.contour(v, 'TMI_contour', grid_file) # display the map in a Geosoft viewer gxviewer.view_document(v3d_name, wait_for_close=False)
import geosoft.gxpy.gx as gx import geosoft.gxpy.map as gxmap import geosoft.gxpy.view as gxview import geosoft.gxpy.group as gxgroup import geosoft.gxpy.agg as gxagg import geosoft.gxpy.grid as gxgrd import geosoft.gxpy.viewer as gxviewer gxc = gx.GXpy() # create a map from grid coordinate system and extent with gxgrd.Grid('Wittichica Creek Residual Total Field.grd') as grd: grid_file_name = grd.file_name_decorated # create a map for this grid on A4 media, scale to fit the extent with gxmap.Map.new('Wittichica residual TMI', data_area=grd.extent_2d(), media="A4", margins=(1, 3.5, 3, 1), coordinate_system=grd.coordinate_system, overwrite=True) as gmap: map_file_name = gmap.file_name # draw into the views on the map. We are reopening the map as the Aggregate class only works with a closed grid. with gxmap.Map.open(map_file_name) as gmap: # work with the data view, draw a line around the data view with gxview.View.open(gmap, "data") as v: # add the grid image to the view, with shading, 20 nT contour interval to match default contour lines with gxagg.Aggregate_image.new(grid_file_name, shade=True, contour=20) as agg: