maptek.vulcan.block_model
This class allows access to the block model structures within Vulcan.
To download all the example scripts on this page, click Python Block Model Example Scripts.
Block model template script
The follow script is a template showing the basic requirements needed to create a block model using Python. This script will serve as an example of several function calls.
# Filename: bm_blockmodel_template.py # Purpose: Create a new regular block model. # Returns: regular block model. from maptek import vulcan # Step 1: Create a block model object. bm_name = 'example.bmf' with vulcan.block_model(bm_name) as bm: # Step 2: Define variables that will hold the model parameters. # These hold the model extents and number of blocks in the # x, y, and z directions. xbegin, ybegin, zbegin = 0, 0, 0 xend, yend, zend = 50, 50, 50 x_num_block, y_num_block, z_num_block = 5, 5, 5 # Step 3: Create a block model. # At this stage, only the extents and number of blocks will be set. No # actual blocks are created yet. Note that this will clear any information # about the previous block model the object referred to. bm.create_regular(bm_name, xbegin, ybegin, zbegin, xend, yend, zend, x_num_block, y_num_block, z_num_block) # Step 4: Add variables to block model. # args : (name, type, default, description) bm.add_variable('class', 'integer', '-99', '1, 2, or 3') bm.add_variable('cu', 'float', '-99.0', 'copper') bm.add_variable('au', 'double', '-99.0', 'gold') bm.add_variable('byte', 'byte', '0', 'byte') bm.add_variable('geocod', 'short', '-99', 'flag') bm.add_variable('lith', 'name', 'none', 'geology') # Step 5: Move the origin of the block model to the desired location. # When a block model is initially created, it is set at a location of # (0.0, 0.0, 0.0). bm.translate(77900.0, 4350.0, -320.0) # enter xyz translation distances # Step 6: Set the rotation parameters. # For this example, we want a bearing of 62 degrees. To get that, we have # to subtract standard Vulcan 90 degrees. Using mod 360 constrains the # answer within 360 degrees. bearing = (62 - 90) % 360 dip = 0 plunge = 0 bm.rotate(dip, plunge, bearing) # Step 7: Set the block length. xlen = int(xend/x_num_block) # 50/5 = 10 ylen = int(yend/y_num_block) # 50/5 = 10 zlen = int(zend/z_num_block) # 50/5 = 10 # Step 8: Add blocks to the model. Note that blocks are added in model # space NOT world space. Each block is defined from the lower left of the # 3D cube to the upper right of the 3D cube. for i in range(0, xend, xlen): for j in range(0, yend, ylen): for k in range(0, zend, zlen): # calc the min/max block xmin = i ymin = j zmin = k xmax = i + xlen ymax = j + ylen zmax = k + zlen # add block to block model bm.add_block(xmin, ymin, zmin, xmax, ymax, zmax) # Step 9: Index block model, then verify results. verify_index = bm.index_model() if verify_index == 0: print("Block model has been indexed.") else: print("Block model has not been indexed.")
Navigating through a block model
Python treats block models in a way similar to working with a database. Each block can be thought of as representing a record, and the variables found within that block represent a field within that record.
To create or edit a block model, you will need to iterate through the model in a manner that allows you access to each block. The following navigational functions are ways of moving through a block model:
rewind(self) -> int - 0 if successful, 1 otherwise.
eof(self) -> bool
next(self) -> int - 0 if successful, 1 otherwise.
get_position(self) -> float - the current record position.
set_position(self, pos) -> int - 0 if successful, 1 otherwise.
The rewind()
function sets the position within the model to the beginning.
The eof()
function sets the position to the end of the model.
The next()
function advances the position by one record (or block).
The set_position()
and get_position()
functions are used when you know the block and need to reference it again later. For example, using some sort of operation in which you need to review the entire model, then go back.
# Filename: bm_get_position.py # Purpose: Get the current record position. # Returns: float - the current record position. from maptek import vulcan blockmodel = 'example.bmf' # input block model with vulcan.block_model(blockmodel) as bm: # open the block model assert bm.is_open(), 'f"{blockmodel} is not open."' bm.rewind() # Move to the first record. while not bm.eof(): index = bm.get_position() # Get current record position = block index print(f'{index = }') bm.next() # Move to the next record.
However, the navigational functions can be superseded by just iterating.
for block in block_model: # Do something
Is the same as the older:
while not block_model.eof(): # Do something block_model.next() # If this is forgotten or missed it will loop forever
add_block(self, x0, y0, z0, x1, y1, z1) -> int
Add a new block to the model.
Note: The block location is not validated upon adding. The block should be sized equal to a parent or sub block size and should be inserted at a location that correctly aligns to those coordinates. This function should only be used where no blocks exist (such as deleted blocks). Also, note that a newly created block will overlap existing blocks if blocks already exists at the location.
Parameters
Note: This function uses block coordinates as the input arguments, not real-world coordinates.
x0 : float
- The X coordinate of the lower extent of the block.
y0 : float
- The Y coordinate of the lower extent of the block.
z0 : float
- The Z coordinate of the lower extent of the block.
x1 : float
- The X coordinate of the upper extent of the block.
y1 : float
- The Y coordinate of the upper extent of the block.
z1 : float
- The Z coordinate of the upper extent of the block.
Returns
Integer
- 0 if successful, 1 otherwise.
Raises PermissionError
if the block model is open in read only mode.
# Filename: bm_add_block.py # Purpose: Add a new block to the model. # Returns: integer, 0 if successful, 1 otherwise. from maptek import vulcan blockmodel = 'example.bmf' # input block model with vulcan.block_model(blockmodel, 'w') as bm: # open the block model assert bm.is_open(), 'f"{blockmodel} is not open."' x0 = 0.0 # X coordinate of the lower extent of the block. y0 = 0.0 # Y coordinate of the lower extent of the block. z0 = 0.0 # Z coordinate of the lower extent of the block. x1 = 10.0 # X coordinate of the upper extent of the block. y1 = 10.0 # Y coordinate of the upper extent of the block. z1 = 10.0 # Z coordinate of the upper extent of the block. state = bm.add_block(x0, y0, z0, x1, y1, z1) print(f'{state = }') # verify: 0 if successful, 1 otherwise.
add_variable(self, *args, **kwargs) -> int
Add a variable to a block model.
Parameters
name : str
- Variable name
type : str
- Variable type (name, byte, short, integer, float, double)
default : str
- Default variable value
description : str
- Variable description
Returns
Integer
- 0 = success, Non-zero = failure
# Filename: bm_add_variable.py # Purpose: Add a variable to a block model. # Returns: Integer: 0 = success, Non-zero = failure. from maptek import vulcan blockmodel = 'demo_vein.bmf' # input block model with vulcan.block_model(blockmodel) as bm: # open the block model assert bm.is_open(), 'f"{blockmodel} is not open."' name, type, default, description = 'au', 'double', '-99.0', 'oz per ton' if not bm.is_field(name): # check if already variable exists validate = bm.add_variable(name, type, default, description) assert validate == 0, 'Error: Failed to create variable' print(f"{name = } successfully added.") else: print(f"{name = } already exists.")
block_extent(self) -> list
Get the extent of the currently selected block.
Returns
list[float]
- For most models, this will be in the form of
[Xmin, Ymin, Zmin, Xmax, Ymax, Zmax]
where the min
values are the coordinates of the lower extent, and the max
values are the coordinates of the upper extent.
For HARP models, the corner offsets will also be shown.
# Filename: bm_block_extent.py # Purpose: Get the extent of the currently selected block. # Returns: List from maptek import vulcan blockmodel = 'example.bmf' # input block model with vulcan.block_model(blockmodel) as bm: # open the block model assert bm.is_open(), 'f"{blockmodel} is not open."' # get single block extent bm.set_position(1) # select block using index s_ext = bm.block_extent() # get block extent print(s_ext) # print results # iterate through block model to get all block extents for block in bm: index = bm.get_position() # get block index ext = bm.block_extent() # get block extent print(f'{index} : {ext}') # print results
close(self) -> int
Close the block model file.
Returns
Integer
- 0 if successful, 1 otherwise.
# Filename: bm_close.py # Purpose: Close a block model. # Returns: Integer from maptek import vulcan blockmodel = 'demo_vein.bmf' # input block model bm = vulcan.block_model(blockmodel) # open the block model if bm: print(f'{blockmodel} successfully opened.') state = bm.close() # close block model print(state) # print result of close: 0 if successful, 1 otherwise
create_irregular(self, name, x0, y0, z0, x1, y1, z1, nx, ny, nz, sub_nx, sub_ny, sub_nz) -> int
Create a new irregular block model optionally with a sub schema.
Note: This will clear any information about the previous block model the object referred to.
Parameters
name : str
- The file path for the new block model.
x0 : float
- The minimum X coordinate of the model extent.
y0 : float
- The minimum Y coordinate of the model extent.
z0 : float
- The minimum Z coordinate of the model extent.
x1 : float
- The maximum X coordinate of the model extent.
y1 : float
- The maximum Y coordinate of the model extent.
z1 : float
- The maximum Z coordinate of the model extent.
nx : int
- The number of blocks in the X direction for the main schema.
ny : int
- The number of blocks in the Y direction for the main schema.
nz : int
- The number of blocks in the Z direction for the main schema.
sub_nx : int
- The number of blocks in the X direction for the sub schema.
sub_ny : int
- The number of blocks in the Y direction for the sub schema.
sub_nz : int
- The number of blocks in the Z direction for the sub schema.
Returns
Integer
- 0 if successful, 1 otherwise.
# Filename: bm_create_irregular.py # Purpose: Create a new regular block model. # Returns: Integer - 0 if successful, 1 otherwise. from maptek import vulcan # Step 1: Create a block model object. name = 'example.bmf' with vulcan.block_model(name) as bm: # Step 2: Define variables that will hold the model parameters. # These hold the model extents and number of blocks in the # x, y, and z directions. xbegin, ybegin, zbegin = 0, 0, 0 # minimum coordinate of model extent xend, yend, zend = 50, 50, 50 # maximum coordinate of model extent p_nx, p_ny, p_nz = 10, 10, 10 # number of blocks in the main schema sub_nx, sub_ny, sub_nz = 5, 5, 5 # number of blocks in the sub schema # Step 3: Create a block model. # At this stage, only the extents and number of blocks will be set. No # actual blocks are created yet. Note that this will clear any information # about the previous block model the object referred to. bm.create_irregular(name, xbegin, ybegin, zbegin, xend, yend, zend, p_nx, p_ny, p_nz, sub_nx, sub_ny, sub_nz) # Step 4: Add variables to block model. # args : (name, type, default, description) bm.add_variable('class', 'integer', '-99', '1, 2, or 3') bm.add_variable('cu', 'float', '-99.0', 'copper') bm.add_variable('au', 'double', '-99.0', 'gold') bm.add_variable('byte', 'byte', '0', 'byte') bm.add_variable('geocod', 'short', '-99', 'flag') bm.add_variable('lith', 'name', 'none', 'geology') # Step 5: Move the origin of the block model to the desired location. # When a block model is initially created, it is set at a location of # (0.0, 0.0, 0.0). bm.translate(77900.0, 4350.0, -320.0) # enter xyz translation distances # Step 6: Set the rotation parameters. # For this example, we want a bearing of 62 degrees. To get that, we have # to subtract standard Vulcan 90 degrees. Using mod 360 constrains the # answer within 360 degrees. x = 62 # (62 - 90) % 360 y = 25 z = 0 bm.rotate(x, y, z) # Step 7: Set the block length. xlen = int(xend / p_nx) # 50/5 = 10 ylen = int(yend / p_ny) # 50/5 = 10 zlen = int(zend / p_nz) # 50/5 = 10 # Step 8: Add blocks to the model. Note that blocks are added in model # space NOT world space. Each block is defined from the lower left of the # 3D cube to the upper right of the 3D cube. for i in range(0, xend, xlen): for j in range(0, yend, ylen): for k in range(0, zend, zlen): # calc the min/max block xmin = i ymin = j zmin = k xmax = i + xlen ymax = j + ylen zmax = k + zlen # add block to block model bm.add_block(xmin, ymin, zmin, xmax, ymax, zmax) # Step 9: Index block model, then verify results. verify_index = bm.index_model() if verify_index == 0: print("Block model has been indexed.") else: print("Block model has not been indexed.")
create_regular(self, name, x0, y0, z0, x1, y1, z1, nx, ny, nz) -> int
Create a new regular block model.
Note: This will clear any information about the previous block model the object referred to.
Parameters
name : str
- The file path for the new block model.
x0 : float
- The minimum X coordinate of the model extent.
y0 : float
- The minimum Y coordinate of the model extent.
z0 : float
- The minimum Z coordinate of the model extent.
x1 : float
- The maximum X coordinate of the model extent.
y1 : float
- The maximum Y coordinate of the model extent.
z1 : float
- The maximum Z coordinate of the model extent.
nx : int
- The number of blocks in the X direction.
ny : int
- The number of blocks in the Y direction.
nz : int
- The number of blocks in the Z direction.
Returns:
Integer
- 0 if successful, 1 otherwise.
For example code see Block model template script.
create_strat(self, name, x0, y0, z0, x1, y1, z1, nx, ny) -> int
Create a new stratigraphic block model.
Note: This will clear any information about the previous block model the object referred to.
Parameters
name : str
- The file path for the new block model.
x0 : float
- The minimum X coordinate of the model extent.
y0 : float
- The minimum Y coordinate of the model extent.
z0 : float
- The minimum Z coordinate of the model extent.
x1 : float
- The maximum X coordinate of the model extent.
y1 : float
- The maximum Y coordinate of the model extent.
z1 : float
- The maximum Z coordinate of the model extent.
nx : int
- The number of blocks in the X direction.
ny : int
- The number of blocks in the Y direction.
Returns:
Integer
- 0 if successful, 1 otherwise.
# Filename: bm_create_strat.py # Purpose: Create a stratigraphic block model. # Returns: Integer - 0 if successful, 1 if not. from maptek import vulcan # Step 1: Create a block model object. with vulcan.block_model() as bm: # Step 2: Define variables that will hold the model parameters. # These hold the model extents and number of blocks in the # x and y directions. x0, y0, z0 = 0, 0, 0 x1, y1, z1 = 50, 50, 5 nx, ny = 5, 5 # Step 3: Create a stratigraphic block model. # At this stage, only the extents and number of blocks will be set. No # actual blocks are created yet. Note that this will clear any information # about the previous block model the object referred to. bm.create_strat('example_strat.bmf', x0, y0, z0, x1, y1, z1, nx, ny) # Step 4: Add variables to block model. # args : (name, type, default, description) bm.add_variable('class', 'integer', '-99', '1=measured, 2=indicated, 3=infered') bm.add_variable('ore', 'float', '-99', 'coal') bm.add_variable('lith', 'name', 'none', 'geology') # Step 5: Move the origin of the block model to the desired location. # When a block model is initially created, it is set at a location of # (0.0, 0.0, 0.0). bm.translate(77900.0, 4350.0, -320.0) # enter xyz translation distances # Step 6: Set the rotation parameters. # For this example, we want a bearing of 62 degrees. To get that, we have # to subtract standard Vulcan 90 degrees. Using mod 360 constrains the # answer within 360 degrees. bearing = (62 - 90) % 360 dip = 0 plunge = 0 bm.rotate(dip, plunge, bearing) # Step 7: Set the block length. xlen = int(x1/nx) # 50/5 = 10 ylen = int(y1/ny) # 50/5 = 10 zlen = 5 # Step 8: Add blocks to the model. Note that blocks are added in model # space NOT world space. Each block is defined from the lower left of the # 3D cube to the upper right of the 3D cube. for i in range(0, x1, xlen): for j in range(0, y1, ylen): for k in range(0, z1, zlen): # calc the min/max block xmin = i ymin = j zmin = k xmax = i + xlen ymax = j + ylen zmax = k + zlen # add block to block model bm.add_block(xmin, ymin, zmin, xmax, ymax, zmax) # Step 9: Index block model, then verify results. verify_index = bm.index_model() if verify_index == 0: print("Block model has been indexed.") else: print("Block model has not been indexed.")
creation_date(self) -> string
Check when the block model was created.
Returns
String
- The date of the block model creation.
# Filename: bm_creation_date.py # Purpose: Get the block model creation date. # Returns: String from maptek import vulcan blockmodel = 'example.bmf' # input block model with vulcan.block_model(blockmodel) as bm: # open the block model cr_date = bm.creation_date() # get the creation date print(f"Creation date: {cr_date}")
delete_variable(self, name) -> int
Remove a variable from the block model.
Parameters
name : str
- The name of the variable to delete.
Returns
Integer
- 0 if successful, 1 otherwise.
# Filename: bm_delete_variable.py # Purpose: Remove a variable from the block model. # Returns: Integer - 0 if successful, 1 if not. from maptek import vulcan blockmodel = 'example.bmf' # input block model del_var = 'lith' # variable to delete with vulcan.block_model(blockmodel) as bm: # open the block model assert bm.is_field(del_var), f'Variable does not exist.' var = bm.delete_variable('lith') # delete variable print(f'{var = }')
description(self) -> string
Get the description of the block model.
Note: The description is set by using Block > Manipulation > Edit Description.
Returns
String
- The description.
# Filename: bm_description.py # Purpose: Get the description of the block model. # Returns: String - the description. from maptek import vulcan blockmodel = 'example.bmf' # input block model with vulcan.block_model(blockmodel) as bm: # open the block model descript = bm.description() print(f'{descript = }')
field_default(self, name) -> float
Get the default value of a numeric variable.
Parameters
name : str
- The variable name to get the default value for.
Returns
float
- The default float value of the variable.
# Filename: bm_field_default.py # Purpose: Get the default value of a numeric variable. # Returns: Float from maptek import vulcan blockmodel = 'demo_vein.bmf' # input block model with vulcan.block_model(blockmodel) as bm: # get list of all numeric variables vars = bm.field_list_numbers() # iterate through list of variables to get default values for var in vars: default_val = bm.field_default(var) # get default value print(f"Variable: {var} Default value: {default_val}")
field_default_string(self, name) -> string
Get the default value of a string variable.
Parameters
name : str
- The variable name to get the default value for.
Returns
String
- The default string value of the variable.
# Filename: bm_field_default_string.py # Purpose: Get the default value of a string variable. # Returns: String from maptek import vulcan blockmodel = 'demo_vein.bmf' # input block model with vulcan.block_model(blockmodel) as bm: # get list of all string variables vars = bm.field_list_strings() # iterate through list of variables to get default values for var in vars: default_val = bm.field_default_string(var) # get default value print(f"Variable: {var} Default value: {default_val}")
field_description(self, name) -> string
Get the description of a variable.
Parameters
name : str
- The variable name to get the description for.
Returns:
String
- The description of the variable.
# Filename: bm_field_description.py # Purpose: Get the description of a block model variable. # Returns: String from maptek import vulcan blockmodel = 'demo_vein.bmf' # input block model with vulcan.block_model(blockmodel) as bm: # open the blockmodel # get list of all numeric variables vars = bm.field_list() # iterate through variable list for var in vars: descript = bm.field_description(var) # get variable description print(f'{var = :<15} {descript = }')
field_index(self, name) -> int
Get the index of a given variable in the block model.
Note: This function is an older version of get_variable_index()
(shown below). It is kept in place to accommodate older scripts. However, newer scripts should use the get_variable_index()
function instead.
Parameters
name : str
- The variable to get the index for.
Returns
Integer
- The index of the given variable.
# Filename: bm_field_index.py # Purpose: Get the index of a block model variable. # Returns: Integer from maptek import vulcan blockmodel = 'demo_vein.bmf' # input block model with vulcan.block_model(blockmodel) as bm: # open the blockmodel vars = bm.field_list() # get list of all variables # iterate through variable list for var in vars: field_ind = bm.field_index(var) # get the index of the variable print(f'{var = :<15} {var_index = }')
field_list(self) -> list
Get the list of variables for the block model.
Returns
list[str]
- The list of variable names.
# Filename: bm_field_list.py # Purpose: Create list of the variables from a block model. # Returns: List from maptek import vulcan blockmodel = 'demo_vein.bmf' # input block model with vulcan.block_model(blockmodel) as bm: # open the blockmodel list_of_vars = bm.field_list() # Get the list of variables for var in list_of_vars: print(var)
field_list_numbers(self) -> list
Get the list of numeric variables for the block model.
Returns
list[str]
- The list of numeric variable names.
# Filename: bm_field_list_numbers.py # Purpose: Create list of all numeric variables from a block model. # Returns: List from maptek import vulcan blockmodel = 'demo_vein.bmf' # input block model with vulcan.block_model(blockmodel) as bm: # open the blockmodel number_vars = bm.field_list_numbers() # get the list of numeric variables for var in number_vars: print(var)
field_list_strings(self) -> list
Get the list of string variables for the block model.
Returns
list[str]
- The list of string variable names.
# Filename: bm_field_list_numbers.py # Purpose: Create list of all string variables from a block model. # Returns: List from maptek import vulcan blockmodel = 'demo_vein.bmf' # input block model with vulcan.block_model(blockmodel) as bm: # open the blockmodel string_vars = bm.field_list_strings() # get the list of numeric variables for var in string_vars: print(var)
field_predefined(self, name) -> int
Check if a variable is a predefined field.
Parameters
name : str
- The variable to check.
Returns
Integer
- 1 if the variable is predefined, 0 otherwise.
# Filename: bm_field_predefined.py # Purpose: Check if a variable is a predefined field. # Returns: Integer - 1 if the variable is predefined, 0 otherwise. from maptek import vulcan blockmodel = 'example.bmf' # input block model with vulcan.block_model(blockmodel) as bm: # get list of all variables vars = bm.field_list() # iterate through list of variables for var in vars: val = bm.field_predefined(var) # check if a variable is a predefined if val == 1: print(f"Variable: {var} - Predefined") elif val == 0: print(f"Variable: {var} - User defined")
field_type(self, name) -> string
Get the type of a field.
Parameters
name : str
- The variable to get the type of.
Returns
String
- The type of the variable. Possible valid return values (subject to change) are:
[float, double, integer, byte, name, short, sfloat, int64, bit
]
Note: '***'
is returned if the variable doesn't exist.
# Filename: bm_field_type.py # Purpose: Get the variable type of input variable. # Returns: String from maptek import vulcan blockmodel = 'demo_vein.bmf' # input block model with vulcan.block_model(blockmodel) as bm: # open the blockmodel list_of_vars = bm.field_list() # Get the list of variables for var in list_of_vars: var_type = bm.field_type(var) # get the variable type print(f'Variable: {var} Type: {var_type}')
find_world_xyz(self, x, y, z) -> int
Find a block at given real world coordinates and set the record position.
Parameters
x : float
- The X coordinate to look for the block.
y : float
- The Y coordinate to look for the block.
z : float
- The Z coordinate to look for the block.
Returns
Integer
- 0 if successful, 1 otherwise.
# Filename: bm_find_world_xyz.py # Purpose: Find a block at given real world coordinates and set the record position. # Returns: Integer - 0 if successful, 1 otherwise. from maptek import vulcan blockmodel = 'example.bmf' # input block model with vulcan.block_model(blockmodel) as bm: # open the block model assert bm.is_open(), 'f"{blockmodel} is not open."' state = bm.find_world_xyz(78000.0, 4500.0, -300.0) # locate block print(state)
find_world_xyz_seam(self, p, seam) -> int find_world_xyz_seam(self, x, y, z, seam) -> int
Find the seam at given real world coordinates.
Parameters
x : float
- The X coordinate to look for the seam.
y : float
- The Y coordinate to look for the seam.
p : list
- point.
seam : str
- The name of the seam.
Returns
Integer
- 0 if successful, 1 otherwise.
code coming soon
find_xyz(self, x, y, z) -> int
Find a block at given model coordinates and set the record position.
Parameters
x : float
- The X coordinate to look for the block.
y : float
- The Y coordinate to look for the block.
z : float
- The Z coordinate to look for the block.
Returns
Integer
- 0 if successful, 1 otherwise.
# Filename: bm_find_xyz.py # Purpose: Find a block at given block coordinates and set the record position. # Returns: Integer - 0 if successful, 1 otherwise. from maptek import vulcan blockmodel = 'example.bmf' # input block model with vulcan.block_model(blockmodel) as bm: # open the block model assert bm.is_open(), 'f"{blockmodel} is not open."' state = bm.find_xyz(20.0, 20.0, 20.0) # locate block print(f'{state = }') b_coord = bm.to_world(20.0, 20.0, 20.0) print(f'{b_coord = }')
find_xyz_seam(self, p, seam) -> int find_xyz_seam(self, x, y, z, seam) -> int
Find the seam at given model coordinates.
Parameters
x : float
- The X coordinate to look for the seam.
y : float
- The Y coordinate to look for the seam.
p : list
- point.
seam : str
- The name of the seam.
Returns
Integer
- 0 if successful, 1 otherwise.
code coming soon
get(self, name) -> float get(self, k) -> float
Get the numeric value of a variable, either by name or by index.
Parameters
name : str
- The name of the variable to get the value of.
k : int
- The index of the variable to get the value of.
Returns
float
- The value of the variable.
# Filename: bm_get.py # Purpose: Get the value of a numeric block model variable. # Returns: Float from maptek import vulcan blockmodel = 'demo_vein.bmf' # input block model input_var = 'au_id' # input variable with vulcan.block_model(blockmodel) as bm: # open the block model assert bm.is_open(), 'f"{blockmodel} is not open."' # create lists to hold values value_by_name = [] value_by_index = [] # method 1: get values using variable name for block in bm: # iterate through block model nval = bm.get(input_var) # get value using name value_by_name.append(nval) # add to list # method 2: get values using variable index for block in bm: # iterate through block model index = bm.get_variable_index(input_var) # get the index of the variable ival = bm.get(index) # get value using index value_by_index.append(ival) # add to list # print values of each list side by side to show they are identical for index, (by_name, by_index) in enumerate(zip(value_by_name, value_by_index)): print(f'{index = :<8} {by_name = :<8} {by_index = }')
get_data( self, var, sel=None) -> numpy.array
Gets the values of a set of blocks, or all blocks if no selection is provided.
Parameters
variable : (str)
- Variable to get data from.
sel : list[int]
- List of block indices to get from such as the return from block_model.get_matches()
.
Returns
numpy.array()
- NumPy array of all values for the specified variable.
Tip: It can be helpful to use this function with the get_data()
function.
# Filename: bm_get_matches.py # Purpose: Get the blocks that match the given match arguments. # Returns: numpy.ndarray[Int64] - The indexes of the matched blocks. from maptek import vulcan blockmodel = 'example.bmf' # input block model with vulcan.block_model(blockmodel) as bm: # open the block model assert bm.is_open(), 'blockmodel is not open.' matches = bm.get_matches('''-C "rocktype eqs 'oxide'"''') data = bm.get_data('au', matches) # get variable information print(data)
get_grid( self, var ) -> numpy.array
Returns a 3D i/j/k grid of block model values for a regular block model.
Parameters
var : str
- Variable name to get data for.
Returns
numpy.array
- 3D numpy array with block values in i/j/k or x/y/z order
code coming soon
get_matches(self, match_string) -> numpy.ndarray[Int64]
Get the blocks that match the given match arguments.
Parameters
selection : str
The selection criteria string.
Options | Descriptions |
---|---|
-v <variable> [value] |
Mask with variable. |
-t <triangulation> |
Bounding triangulation. Blocks with centroids inside the triangulation will be selected. The -X option may be applied to select based on block extents. |
-n <top surface> |
Top bounding surface triangulation. |
-u <lower surface> |
Lower bounding surface triangulation. |
-B <triangulation> |
Use single bounding surface |
-Z |
Project down Z axis. Requires -B. |
-O |
Select blocks outside the solid only. |
-bm <xl, xt, yl, yt, zl, zt> |
Define the bounding extents using block model coordinates. When using this switch, you will need to specify the minimum and maximum X, Y and Z coordinates. Blocks having extents that are inside, or intersect these extents are selected. |
-bw <xl, xt, yl, yt, zl, zt> |
Define the bounding extents using real world coordinates. When using this switch, you will need to specify the minimum and maximum X, Y and Z coordinates. Blocks having centroids that are inside the extents are selected. The -X option may be used to reproduce the extents intersection type selection of -bm. |
-s <mx, my, mz> |
Sub-block dimensions. |
-p <a, b, c, d> |
Include planed blocks. |
-C <condition> |
Use conditional expression. |
-r <offset> |
Provide a plane offset buffer. |
-X |
Use proportional volumes against solid. This modifies the block selection to include blocks that intersect the selecting volume. |
-T |
Use selection file with triangulations. |
-S |
Reverse block selection |
Returns
numpy.ndarray[Int64]
- The indexes of the matched blocks.
Tip: It can be helpful to use this function with the get_data()
function.
# Filename: bm_get_matches.py # Purpose: Get the blocks that match the given match arguments. # Returns: numpy.ndarray[Int64] - The indexes of the matched blocks. from maptek import vulcan blockmodel = 'example.bmf' # input block model with vulcan.block_model(blockmodel) as bm: # open the block model assert bm.is_open(), 'blockmodel is not open.' matches = bm.get_matches('''-C "rocktype eqs 'oxide'"''') data = bm.get_data('au', matches) # get variable information print(data)
get_matches_extent(self, match_string) -> tuple[numpy.ndarray]
Get a list of NumPy arrays containing the block IDs and extents of each block selected in the match.
Parameters
match_string : str
- The match arguments.
Returns
tuple[numpy.ndarray]
- The extents of the matched blocks, in the form
tuple[[id], [Xmin], [Xmax], [Ymin], [Ymax], [Zmin], [Zmax]]
That is, a tuple of 7 NumPy arrays, where the first array is the list of IDs, the second is the list of minimum X values, etc.
Raises SyntaxError
code coming soon
get_multiple(self, fields) -> list
Get the values of a list of numeric variables.
Parameters
fields
- List of numeric variables
# Filename: bm_get_multiple.py # Purpose: Get the values of a list of numeric variables. # Returns: List. from maptek import vulcan blockmodel = 'demo_vein.bmf' # input block model input_vars = ['au_id', 'au_ok', 'au_nn'] # input variables with vulcan.block_model(blockmodel) as bm: # open the block model assert bm.is_open(), 'f"{blockmodel} is not open."' # iterate through block model for block in bm: vals = bm.get_multiple(input_vars) # get value using name print(f'{vals}')
get_multiple_string(self, fields) -> list
Get the values of a list of string variables.
Parameters
fields
- List of string variables
# Filename: bm_get_multiple_string.py # Purpose: Get the values of a list of string variables. # Returns: List. from maptek import vulcan blockmodel = 'demo_vein.bmf' # input block model input_vars = ['class', 'flag', 'geology', 'ore_zone'] # input variables with vulcan.block_model(blockmodel) as bm: # open the block model assert bm.is_open(), 'f"{blockmodel} is not open."' # iterate through block model for block in bm: vals = bm.get_multiple_string(input_vars) # get value using name print(f'{vals}')
get_pandas( self, vars=None, select=None ) -> pandas.DataFrame
Gets block model data as a pandas.DataFrame.
Parameters
vars : list[str], default = None
- Variable list to get from model. Defaults to all variables if None
select : str, default = None
- Selection string to use.
Returns
pandas.DataFrame
code coming soon
get_pandas_extent( self, vars=None, select=None ) -> pandas.DataFrame
Gets all matches within an extent.
Parameters
vars : list[str], default=None
- Variable list to get from model. All variables if None
select : str, default=None
- Selection string to use.
Returns
pandas.DataFrame
- Block model within the match extent.
code coming soon
get_regular_indices(self) -> numpy.ndarray[Int64]
Get the indices of a regular block model, in i/j/k order.
Returns
numpy.ndarray[Int64]
- The indices of the blocks.
Raises
TypeError
if the block model is not a regular block model.
code coming soon
get_string(self, name) -> string get_string(self, k) -> string
Get the string value of a variable, either by name or by index.
Parameters
name : str
- The name of the variable to get the value of.
k : int
- The index of the variable to get the value of.
Returns
String
- The value of the variable.
# Filename: bm_get.py # Purpose: Get the value of a numeric block model variable. # Returns: Float from maptek import vulcan blockmodel = 'demo_vein.bmf' # input block model input_var = 'au_id' # input variable with vulcan.block_model(blockmodel) as bm: # open the block model assert bm.is_open(), 'f"{blockmodel} is not open."' # create lists to hold values value_by_name = [] value_by_index = [] # method 1: get values using variable name for block in bm: # iterate through block model nval = bm.get_string(input_var) # get value using name value_by_name.append(nval) # add to list # method 2: get values using variable index for block in bm: # iterate through block model index = bm.get_variable_index(input_var) # get the index of the variable ival = bm.get_string(index) # get value using index value_by_index.append(ival) # add to list # print values of each list side by side to show they are identical for i, (n_value, i_value) in enumerate(zip(value_by_name, value_by_index)): print(f'Index {i}: {i_value} Name value: {n_value}')
get_translation_values(self, field_name) -> list
Get the translation values for a field.
This provides the mapping from the values as integers (indices) to string values. Using get_string() will translate the value for a single block to its correpsonding string, where as this function allows bulk-translation of the underlying values.
This is especially useful for large models, where calling get_data_string() may use large amounts of memory. By getting the data out as an integer rather than a string, much less memory is required.
For example, you can call get_data_int64()
to load all the values then map the values it returns to the translation values for their strings.
>>> selection = bm.get_matches()
>>> var = 'region'
>>> numeric_values = bm.get_data_int64(var, selection)
>>> translation_values = bm.get_translation_values(var)
>>> print(numeric_values, translation_values)
>>> for value in numeric_values:
>>> print(translation_values[value])
Another usage would be to count the occurrence of each string without ever needing to translate the data.
>>> selection = bm.get_matches()
>>> var = 'region'
>>> translation_values = bm.get_translation_values(var)
>>> counter = collections.Counter(bm.get_data_int64(var, selection))
>>> for key, value in counter.items():
>>> print(translation_values[key], value)
Parameters
field_name : str
- The field to get the translation values for.
Returns
list[str]
- The translation values.
code coming soon
get_variable_index(self, name) -> int
Get the index of a variable.
Parameters
name : str
- The variable to get the index of.
Returns
Integer
- The index of the variable.
# Filename: bm_get_variable_index.py # Purpose: Get the index of a variable. # Returns: Integer. from maptek import vulcan blockmodel = 'demo_vein.bmf' # input block model input_var = 'geology' # input variable with vulcan.block_model(blockmodel) as bm: # open the block model assert bm.is_open(), 'f"{blockmodel} is not open."' value = bm.get_variable_index(input_var) # get variable index number print(value) # print results
index_model(self) -> int
Build the index for the block model.
Returns
Integer
- 0 if successful, 1 otherwise.
code coming soon
is_field(self, field) -> bool
Check if the given variable exists on the block model.
Parameters
field : str
- The variable to check for existence.
Returns
bool
- True if the variable exists, False otherwise.
# Filename: bm_is_field.py # Purpose: Verify that the input variable exists. # Returns: Bool. from maptek import vulcan blockmodel = 'demo_vein.bmf' # input block model input_var = 'geology' # input variable with vulcan.block_model(blockmodel) as bm: # open the block model assert bm.is_open(), 'f"{blockmodel} is not open."' # verify variable exists; True = yes, False = no value = bm.is_field(input_var) print(value) # print results
is_indexed(self) -> int
Check whether the block model is indexed.
Returns
Integer
- 1 if the model is indexed, 0 otherwise.
# Filename: bm_is_indexed.py # Purpose: Check if the model is indexed. # Returns: '1' if yes, '0' if no. from maptek import vulcan blockmodel = 'demo_vein.bmf' # input block model with vulcan.block_model(blockmodel) as bm: # open the block model assert bm.is_open(), 'f"{blockmodel} is not open."' verify_index = bm.is_indexed() # check if the block model is indexed print(f"{verify_index}")
is_number(self, field) -> bool
Check if the given variable exists as a numeric variable in the block model.
Parameters
field : str
- The variable to check exists and is numeric.
Returns
bool
- True if the variable exists and is numeric, False otherwise.
# Filename: bm_is_field.py # Purpose: Check if variable type is numeric. # Returns: Bool. from maptek import vulcan blockmodel = 'demo_vein.bmf' # input block model input_var = 'geology' # input variable with vulcan.block_model(blockmodel) as bm: # open the block model assert bm.is_open(), 'f"{blockmodel} is not open."' # check if variable type is numeric; True = yes, False = no value = bm.is_number(input_var) print(value) # print results
is_open(self) -> bool
Check if given block model is open.
Returns
bool
- True if the variable exists and is numeric, False otherwise.
code coming soon
is_regular(self) -> bool
Check if the model is a regular model.
Returns
bool
- True if the model is a regular model, False if the model is irregular.
# Filename: bm_is_regular.py # Purpose: Check if a block model is regularised. # Returns: Bool. from maptek import vulcan blockmodel = 'demo_vein.bmf' # input block model with vulcan.block_model(blockmodel) as bm: # open the block model assert bm.is_open(), 'f"{blockmodel} is not open."' # Check if a block model is regularised. True = yes, False = no value = bm.is_regular() print(value) # print results
is_string(self, field) -> bool
Check if the given variable exists as a string variable on the block model.
Parameters
field : str
- The variable to check exists is a string variable.
Returns
bool
- True if the field exists and is a string field, False otherwise.
# Filename: bm_is_string.py # Purpose: Check if variable type is string. # Returns: Bool. from maptek import vulcan blockmodel = 'demo_vein.bmf' # input block model input_var = 'geology' # input variable with vulcan.block_model(blockmodel) as bm: # open the block model assert bm.is_open(), 'f"{blockmodel} is not open."' # check if variable type is string; True = yes, False = no value = bm.is_string(input_var) print(value) # print results
is_tb_model(self) -> bool
Check if the model is an extended format model.
Note: All new models are extended (TB) models.
Returns
bool
- True if the model is an extended (TB) model, False otherwise.
# Filename: bm_is_tb_model.py # Purpose: Check if a block model is an extended model. # Returns: Bool. from maptek import vulcan blockmodel = 'demo_vein.bmf' # input block model with vulcan.block_model(blockmodel) as bm: # open the block model assert bm.is_open(), 'f"{blockmodel} is not open."' # Check if a block model is an extended model. True = yes, False = no value = bm.is_tb_model() print(value) # print results
match_extent(self) -> list
Get the extent of the current match selection.
Returns
list[float]
code coming soon
match_volume(self) -> float
Calculates the volume of the current match selection.
Returns
float
- The calculated volume.
code coming soon
model_extent(self) -> list
Returns
list[float]
- In the form [Xmin, Ymin, Zmin, Xmax, Ymax, Zmax] where the min values are the coordinates of the lower extent, and the max values are the coordinates of the upper extent.
# Filename: bm_model_extent.py # Purpose: Get the extent of the model. # Returns: List. from maptek import vulcan blockmodel = 'demo_vein.bmf' # input block model with vulcan.block_model(blockmodel) as bm: # open the block model assert bm.is_open(), 'f"{blockmodel} is not open."' bm_extents = bm.model_extent() # create list of model extents print(bm_extents) # print results
model_n_schemas(self) -> int
Get the number of schemas associated with the model.
Returns
Integer
- The number of schemas.
# Filename: bm_model_n_schemas.py # Purpose: Get the number of schemas used in block model. # Returns: Integer. from maptek import vulcan blockmodel = 'demo_vein.bmf' # input block model with vulcan.block_model(blockmodel) as bm: # open the block model assert bm.is_open(), 'f"{blockmodel} is not open."' bm_num_schemas = bm.model_n_schemas() # get number of schemas used print(bm_num_schemas) # print results
model_orientation(self) -> list
Get the orientation of the model.
Returns
list[float]
- The amount of rotation (in degrees) for each axis, in the form [X, Y, Z]
# Filename: bm_model_orientation.py # Purpose: Create list showing bearing, dip, and plunge of a block model. # Returns: List. from maptek import vulcan blockmodel = 'demo_vein.bmf' # input block model with vulcan.block_model(blockmodel) as bm: # open the block model assert bm.is_open(), 'f"{blockmodel} is not open."' orientation = bm.model_orientation() # get the orientation print(f"bearing, dip, plunge = {orientation}")
model_origin(self) -> list
Get the origin of the model.
Returns
list[float]
- The origin coordinates, in the form [X, Y, Z]
# Filename: bm_model_origin.py # Purpose: Create list of block model origin [x,y,z] # Returns: List. from maptek import vulcan blockmodel = 'demo_vein.bmf' # input block model with vulcan.block_model(blockmodel) as bm: # open the block model assert bm.is_open(), 'f"{blockmodel} is not open."' origin = bm.model_origin() # get the origin print(f"origin x, y, z = {origin}")
model_schema_extent(self, k) -> list
Get the extent of a schema within the model.
Parameters
k : int
- The index of the schema to get the extent of.
Returns
list[float]
- In the form [Xmin, Ymin, Zmin, Xmax, Ymax, Zmax] where the min values are the coordinates of the lower extent, and the max values are the coordinates of the upper extent.
# Filename: bm_model_schema_extent.py # Purpose: Create list of schema extents. # Returns: List. from maptek import vulcan blockmodel = 'demo_vein.bmf' # input block model with vulcan.block_model(blockmodel) as bm: # open the block model p_extent = bm.model_schema_extent(0) # get the extent for parent blocks sub_extent = bm.model_schema_extent(1) # get the extent for sub blocks print(f"parent block extent = {p_extent}") print(f"sub block extent = {sub_extent}")
model_schema_dimensions(self, k) -> list
Get the dimensions of a schema within the model.
Parameters
k : int
- The index of the schema to get the dimensions of.
Returns
list[float]
- The dimensions of the schema, in the form [X, Y, Z]
code coming soon
model_schema_size(self, k) -> list
Get the size of a schema within the model.
Parameters
k : int
- The index of the schema to get the size of.
Returns
list[float]
- The size of the schema, in the form
[Xmin, Ymin, Zmin, Xmax, Ymax, Zmax]
# Filename: bm_model_schema_size.py # Purpose: Create list of schema size. # Returns: List. from maptek import vulcan blockmodel = 'demo_vein.bmf' # input block model with vulcan.block_model(blockmodel) as bm: # open the block model io stream pb_size = bm.model_schema_size(0) # get the extent for parent blocks sub_size = bm.model_schema_size(1) # get the extent for parent blocks print(f"list order: [x size, y size, z size, x max, y max, z max]") print(f"parent block size: {pb_size}") print(f"sub block size: {sub_size}")
modified_date(self) -> string
Check when the block model was last modified.
Returns
String
- The date of the last modification.
# Filename: bm_modified_date.py # Purpose: Get the most recent modification date of a block model. # Returns: String. from maptek import vulcan blockmodel = 'demo_vein.bmf' # input block model with vulcan.block_model(blockmodel) as bm: # open the block model io stream last_modified = bm.modified_date() # get the modification date print(f"{last_modified}")
move_block(self, x0, y0, z0, x1, y1, z1) ->
Move the block at the current record to the given coordinates.
Note: The 'current record' is that pointed to using rewind()
and next()
.
Parameters
x0 : float
- The X coordinate for the new lower extent of the block.
y0 : float
- The Y coordinate for the new lower extent of the block.
z0 : float
- The Z coordinate for the new lower extent of the block.
x1 : float
- The X coordinate for the new upper extent of the block.
y1 : float
- The Y coordinate for the new upper extent of the block.
z1 : float
- The Z coordinate for the new upper extent of the block.
Returns
Integer
- 0 if successful, 1 otherwise.
Raises PermissionError
if the block model is open in read only mode.
code coming soon
n_blocks(self) -> int
Get the number of blocks in the model.
Returns
Integer
- The number of blocks.
# Filename: bm_n_blocks.py # Purpose: Get the number of blocks in a block model. # Returns: Integer. from maptek import vulcan blockmodel = 'demo_vein.bmf' # input block model with vulcan.block_model(blockmodel) as bm: # open the block model io stream num_blocks = bm.n_blocks() # get the number of blocks print(f"{num_blocks}")
pop_select(self) ->
code coming soon
put(self, *args) ->
code coming soon
put_data( self, var, data, sel=None) ->
code coming soon
put_data_double(self, name, n1, n0) ->
code coming soon
put_data_float(self, name, n1, n0) ->
code coming soon
put_data_string(self, var, data, sel=None) ->
code coming soon
put_data_string_list(self, name, data, n0) ->
code coming soon
put_grid( self, var, data) -> put_grid(self, name, data) ->
code coming soon
put_pandas( self, dataframe, vars=None ) ->
code coming soon
put_string(self, *args) ->
code coming soon
rotate(self, x, y, z) ->
code coming soon
scale(self, x, y, z) ->
code coming soon
select(self, selection) -> int
Specify block selection criteria for a block model.
Each instance of using this function will overwrite any previous selection on the same level.
Parameters
selection : str
The selection criteria string.
Options | Descriptions |
---|---|
-v <variable> [value] |
Mask with variable. |
-t <triangulation> |
Bounding triangulation. Blocks with centroids inside the triangulation will be selected. The -X option may be applied to select based on block extents. |
-n <top surface> |
Top bounding surface triangulation. |
-u <lower surface> |
Lower bounding surface triangulation. |
-B <triangulation> |
Use single bounding surface |
-Z |
Project down Z axis. Requires -B. |
-O |
Select blocks outside the solid only. |
-bm <xl, xt, yl, yt, zl, zt> |
Define the bounding extents using block model coordinates. When using this switch, you will need to specify the minimum and maximum X, Y and Z coordinates. Blocks having extents that are inside, or intersect these extents are selected. |
-bw <xl, xt, yl, yt, zl, zt> |
Define the bounding extents using real world coordinates. When using this switch, you will need to specify the minimum and maximum X, Y and Z coordinates. Blocks having centroids that are inside the extents are selected. The -X option may be used to reproduce the extents intersection type selection of -bm. |
-s <mx, my, mz> |
Sub-block dimensions. |
-p <a, b, c, d> |
Include planed blocks. |
-C <condition> |
Use conditional expression. |
-r <offset> |
Provide a plane offset buffer. |
-X |
Use proportional volumes against solid. This modifies the block selection to include blocks that intersect the selecting volume. |
-T |
Use selection file with triangulations. |
-S |
Reverse block selection |
Returns
Integer
- 0 if successful, 1 otherwise.
# Filename: bm_select.py # Purpose: Specify block selection criteria for a block model. # Returns: Integer (0 if successful, 1 otherwise.) from maptek import vulcan blockmodel = 'demo_vein.bmf' # input block model input_var = 'flag' # use this variable # open the block model with vulcan.block_model(blockmodel) as bm: assert bm.is_open(), 'f"{blockmodel} is not open."' # select all blocks within vein solid bm.select('-t TQ1.00t') # select initial solid for block in bm: # iterate through selected blocks bm.put(input_var, 'ore') # flag as ore
select_xy_seam(self, x, y, seam) ->
code coming soon
set_model_orientation(self, a1, a2, a3) ->
code coming soon
set_model_origin(self, x0, y0, z0) ->
code coming soon
to_model(self, *args) ->
to_model(self, x, y, z) -> double_list
to_model(self, p) -> Point_type
Convert a set of real world coordinates to model coordinates.
Parameters
x
- The X coordinate to convert as float.
y
- The Y coordinate to convert as float.
z
- The Z coordinate to convert as float.
p
- point object.
Returns
list[float]
- The converted coordinates, in the form [X, Y, Z].
# Filename: bm_to_model.py # Purpose: Convert a set of real world coordinates to model coordinates. # Returns: list[float] The converted coordinates in the form [X, Y, Z]. from maptek import vulcan blockmodel = 'example.bmf' # input block model with vulcan.block_model(blockmodel) as bm: # open block model mod_coords = bm.to_model(77920.0, 4370.0, 0.0) # get model coordinates print(mod_coords)
to_world(self, *args) ->
code coming soon
translate(self, x, y, z) ->
code coming soon
write(self) ->
code coming soon