Table of Contents
MineSight® Large Grided Objects (LGO) file access. This module allows for manipulation of surfaces in pre-existing LGO files.
The general order operations are:
- Open the LGO file
- Open the surface
- Read a row
- Set values in row
- Write row
Note
Buffers are flushed and files are closed after the objects are out of scope.
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
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.
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
All examples are difference calculations using various methods.
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))
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)
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()
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.
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")
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()
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")
The surface in the LGO file. Surface objects are only created using the Lgo.open_surface function.
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]
Returns the elevation level of the location in the LGO surface as a float.
Sets the elevation level of the location in the LGO surface.
A Python None can be used for the value to set to undefined.
Sets the name of the surface.
Returns a Row object of the row in the surface.
Sets the Row in the surface.
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)
Gets an elevation level at the given index.
Sets an elevation level at the given index.