geosoft.gxpy.grd submodule

exception geosoft.gxpy.grd.GRDException

Bases: Exception

Exceptions from this module.

New in version 9.1.

class geosoft.gxpy.grd.GXgrd(fileName=None, dtype=None, mode=None, kx=1, dim=None)

Bases: object

Grid and image class.

Creation options:

open() open an existing grid/image
new() create a new grid/image

New in version 9.1.

static decorate_name(name, decorations='')

Properly decorate a grid name.

Parameters:
  • name – file name
  • decorations – file decorations, semicolon delimited
Returns:

decorated file name

New in version 9.1.

delete_files(delete=True)

Delete the files associated with this grid when deleting the grid object. Note that files are not deleted until all references to this object are deleted and garbage collection is performed.

Parameters:delete – set to False to reverse a previous delete request

New in version 9.1.

dtype()
Returns:numpy data type for the grid

New in version 9.1.

classmethod from_data_array(data, filename, properties={})

Create grid from a 2D numpy array.

Parameters:
  • gxPy – GXpy
  • data – 2D numpy data array, must be 2D
  • filename – name of the file
Returns:

GXgrd instance

New in version 9.1.

gc = None
indexWindow(name, x0=0, y0=0, nx=None, ny=None)

Window a grid based on index. :param x0: integer index of the first X point :param y0: integer index of the first Y point :param nx: number of points in x :param ny: number of points in y

New in version 9.1.

static name_parts(name)

Return folder, undecorated file name + ext, file root, ext, decorations.

If extension is not specified, ”.grd” assumed

For example:

>>> import geosoftpy.grd as grd
>>> namep = grd.GXgrd.name_parts("f:/someFolder/name.grd(GRD;TYPE=SHORT)")
>>> print(namep)
('f:/someFolder/','name.grd','name','.grd','(GRD;TYPE=SHORT)')

New in version 9.1.

classmethod new(fileName=None, properties={})

Create a new grid file.

Parameters:
  • gxPy – GX context
  • fileName – name of the grid file, None or ‘’ for a memory grid
  • properties – dictionary of grid properties

New in version 9.1.

classmethod open(fileName, dtype=None, mode=None)

Open an existing grid file.

Parameters:
  • gxPy – GX context
  • fileName – name of the grid file
  • dtype – numpy data type
  • mode

    open mode:

    FILE_READ only read the file, properties cannot be changed
    FILE_READWRITE grid stays the same, but properties may change

New in version 9.1.

properties()

Get the grid properties dictionary :return: properties dictionary

New in version 9.1.

read_rows(ix0=0, iy0=0)
Parameters:
  • ix0
  • iy0
Returns:

New in version 9.1.

save_as(fileName, dtype=None)

Save a grid to a new file. File is overwritten if it exists.

Parameters:
  • fileName – name of the file to save
  • dtype – numpy data type, None to use type of the parent grid
Returns:

GXgrd of saved file

New in version 9.1.

set_properties(properties)

Set grid properties from a properties dict. Settable property keys are:

‘x0’ grid X origin location (default 0.0)
‘y0’ grid Y origin location (0.0)
‘dx’ grid X point separation (1.0)
‘dy’ grid Y point separation (1.0)
‘rot’ grid counter-clockwise rotation angle (0.0)
‘ipj’ coordinate system object (unchanged)

Not all keys need be passed, though best practice it to get the properties from the grid and modify those that need to change and pass the properties back.

Parameters:properties – properties dictionary

New in version 9.1.

write_rows(data, ix0=0, iy0=0, order=1)

Write data to a grid by rows.

Parameters:
  • data – array of data to write
  • ix0 – grid X index of first point
  • iy0 – grid Y index of first point, top index if writing rows top to bottom
  • order – 1: bottom to top; -1: top to bottom

New in version 9.1.

geosoft.gxpy.grd.array_locations(properties, z=0.0)

Create an array of (x,y,z) points for a grid defined by properties :param properties: grid properties :return: array of points, shaped (ny, nx, 3)

New in version 9.1.

geosoft.gxpy.grd.gridBool(g1, g2, joinedGrid, opt=1, size=3, olap=1)
Parameters:
  • g1,g2 – GXgrd of grids to merge
  • new – new output grid, overwritten if it exists
  • opt

    logic to use on overlap points, default 1 (OR):

    0 AND, both grids must have valid value
    1 OR, either grid has a valid value
    2 XOR, same as OR, except overlap is dummied
  • size

    size of the output grid, default is minimum size

    0 minimum size - dummy regions clipped
    1 size to grid 1
    2 size to grid 2
    3 size to maximum including both grids
  • olap

    what to do with overlapping valid points, default uses grid 1

    0 average points
    1 use grid 1
    2 use grid 2
Returns:

GXgrd of the merged output grid

New in version 9.1.

geosoft.gxpy.grd.gridMosaic(mosaic, gridList, typeDecoration='', report=None)

Combine a set of grids into a single grid. Raises an error if the resulting grid is too large.

Parameters:
  • mosaic – name of the output grid, returned. Decorate with ‘(HGD)’ to get an HGD
  • gridList – list of input grid names
  • typeDecoration – decoration for input grids if not default
  • report – string reporting function, report=print to print progress
Returns:

GXgrd

New in version 9.1.