grail.data.lgomodule module

Version: 16.2

Table of Contents

Summary

MineSight® Large Grided Objects (LGO) file access. This module allows for manipulation of surfaces in pre-existing LGO files.

The general order operations are:

  1. Open the LGO file
  2. Open the surface
  3. Read a row
  4. Set values in row
  5. Write row

Note

Buffers are flushed and files are closed after the objects are out of scope.

Terms and Definitions

During a discussion of LGO's there are several terms that need defining.

LGO
MineSight® Large Grided Objects that contains surfaces.
Surface
An entry in the LGO file that contains rows.
Row
An array of elevation levels in a surface

Undefined Values

All elevation levels that are undefined will return a Python None value. Any elevation level to be set as undefined, Python None will be used. The Surface get_value and the Row get methods allow for overwriting the undefined value via the optional undefined keyword.

Accessing LGO Data

LGO files contain surfaces that contains rows that contains values. Each surface in the LGO file has a unique name.

LGO files are accessed using the lgomodule

from grail.data import lgomodule
lgo = lgomodule.open("test.lgo","w")

Each Lgo contains direction vectors for the plane of orientation via get_xvector and get_yvector methods. is_inverted returns True when the elevation is inverted. As well as the size of the data points via get_xsize and get_ysize and the number of columns and rows via get_row_count and get_col_count .

The surface in the LGO is accessed by the unique name.

surface = lgo.open_surface("mysurface")

The name of the Surface can be accessed using get_name . Setting the name via set_name will only allow unique names to the Lgo .

Each Surface contains rows that can be accessed by three methods.

Directly:

value = surface.get_value(5, 5)
value = value + 1
surface.set_value(5, 5, value)

Via the Row object:

row = surface.get_row(5)
row[5] = row[5] + 1
surface.set_row(5, row)

Or via the Row object using a sequence:

row = surface[5]
row[5] = row[5] + 1
surface[5] = row

Examples of LGO Access

All examples are difference calculations using various methods.

Direct Method

This method can result in slower access if the values are not transverse by row then columns. The Row method forces this construct. If only a small number of values in each row are needed, this is the preferred method.

from grail.data import lgomodule
lgo = lgomodule.open("test.lgo","w")
surf1 = lgo.open_surface("surf1", True)
surf2 = lgo.open_surface("surf2", True)
surf3 = lgo.open_surface("surf3")
for y in range(lgo.get_row_count()):
    
for x in range(lgo.get_col_count()):
        
val1 = surf1.get_value(x, y)
        
val2 = surf2.get_value(x, y)
        
if val1 == None or val2 == None:
            
surf3.set_value(x, y, None)
        
else:
            
surf3.set_value(x, y, abs(val1 - val2))

Row Method

This is the preferred method for this type of calculation.

from grail.data import lgomodule
lgo = lgomodule.open("test.lgo","w")
surf1 = lgo.open_surface("surf1", True)
surf2 = lgo.open_surface("surf2", True)
surf3 = lgo.open_surface("surf3")
row3 = lgomodule.Row(lgo.get_col_count())
for y in range(lgo.get_row_count()):
    
row1 = surf1.get_row(y)
    
row2 = surf2.get_row(y)
    
for x in range(lgo.get_col_count()):
        
val1 = row1[x]
        
val2 = row2[x]
        
if val1 == None or val2 == None:
            
row3[x] = None
        
else:
            
row3[x] = abs(val1 - val2)
    
surf3.set_row(y, row3)

Row Method with Sequences

This is the same as above but more short hand.

from grail.data import lgomodule
lgo = lgomodule.open("test.lgo","w")
surf1 = lgo.open_surface("surf1", True)
surf2 = lgo.open_surface("surf2", True)
surf3 = lgo.open_surface("surf3")
row3 = lgomodule.Row(lgo.get_col_count())
for y in range(len(surf1)):
    
row1 = surf1[y]
    
row2 = surf2[y]
    
for x in range(len(row1)):
        
val1 = row1[x]
        
val2 = row2[x]
        
if val1 == None or val2 == None:
            
row3[x] = None
        
else:
            
row3[x] = abs(val1 - val2)
    
surf3 = row3

Sequences can also be used to list the surfaces in the LGO file when the name is not known or when a process needs to be performed on each Surface.

This example just prints the name of the surfaces in the LGO file.

from grail.data import lgomodule
lgo = lgomodule.open("test.lgo","r")
for surface in lgo:
    
print surface.get_name()

Classes

There are three classes defined within this Module.

Lgo
Defines the LGO file.
Surface
Defines the surface in the LGO file.
Row
Defines the row of values in the surface.

Lgo Class

Lgo

The Lgo class is created only by the lgomodule.open(file, method) function.

An example would be,

from grail.data import lgomodule
lgo = lgomodule.open("test.lgo", "w")
Arguments:
file : string
Path to the LGO file to open.
method : string
'r' for read only access. 'w' for read and write access.
Throws:
IOError
When there is a file access error.
Sequences:

The use of the Lgo object as a sequence will return each Surface in the LGO.

Example,

from grail.data import lgomodule
lgo = lgomodule.open("test.lgo","r")
for surface in lgo:
    
print surface.get_name()
open_surface(name[,onlyexisting=False])

Opens a surface in the LGO file.

An example would be,

from grail.data import lgomodule
lgo = lgomodule.open("test.lgo", "w")
surf = lgo.open_surface("mysurface")
Arguments:
name : string
The name of the surface in the file.
onlyexsting : boolean
Do not create a surface. Default: create.
Throws:
IOError
When a surface cannot be created or does not exist (when onlyexisting=True).
get_origin()
Returns the origin of the LGO as a point.
get_xvector()
Returns the vector of the x-axis as a point.
get_yvector()
Returns the vector of the y-axis as a point.
get_xsize()
Returns the size of the columns as a float.
get_ysize()
Returns the size of the rows as a float.
get_row_count()
Returns the number of rows in the LGO surfaces.
get_col_count()
Returns the number of columns in the LGO surfaces.
is_inverted()
Returns True when the elevation vector is negative.

Surface Class

Surface

The surface in the LGO file. Surface objects are only created using the Lgo.open_surface function.

Sequences:

The use of the Surface object as a sequence will return/set each Row in the surface.

Example,

from grail.data import lgomodule
lgo = lgomodule.open("test.lgo","r")
surface = lgo.open_surface("test")
for row in surface:
    
print row[5]
get_value(col,row[,undefined=None])

Returns the elevation level of the location in the LGO surface as a float.

Arguments:
col : integer
The column number of the location.
row : integer
The row number of the location.
undefined : any
The value to return when undefined. Default: Python None.
Throws:
IndexError
When the given column and row is out of range.
set_value(col,row,value)

Sets the elevation level of the location in the LGO surface.

A Python None can be used for the value to set to undefined.

Arguments:
col : integer
The column number of the location.
row : integer
The row number of the location.
value : float
The value to set the elevation to. This can be a Python None.
Throws:
IndexError
When the given column and row is out of range.
IOError
When the LGO file is read only.
get_name()
Returns the name of the surface as a string.
set_name(name)

Sets the name of the surface.

Arguments:
name : string
The name to use.
Throws:
ValueError
When the string is empty.
IOError
When the LGO file is read only.
RuntimeError
When the surface name is associated with another surface.
get_row(index)

Returns a Row object of the row in the surface.

Arguments:
index : integer
The row number of the Row in the surface to return.
Throws:
IndexError
When the row number is out of range.
set_row(index,row)

Sets the Row in the surface.

Arguments:
index : integer
The row number of the Row in the surface to set.
row : Row
The Row object to get the row from.
Throws:
IOError
When the LGO file is read only.

Row Class

Row(size)

An array of fixed size with elevation values that can be undefined. A Row object can be made independent of a surface. A newly created Row object will have all values as undefined.

Example,

from gial.data import lgomodule
row = lgomodule.Row(50)
Arguments:
size : integer
The size of the array to make.
Sequences:
The Row object will return/set each elevation level with Python None as the undefined value.
get(index[,undefined=None])

Gets an elevation level at the given index.

Arguments:
index : integer
The location to get the value from.
undefined
The value to return when undefined. Default: Python None.
Throws:
IndexError
When index is out of range.
set(index,value)

Sets an elevation level at the given index.

Arguments:
index : integer
The location to set the value.
value : float
The value to set. Python None can be used for undefined.
Throws:
IndexError
When index is out of range.