grail.ip.reslib module

Version: 16.2

Table of Contents

Overview

This library provides a set of functions for making working with the reserves dictionary easier (see grail.ip.reserves).

Throughout this module there is a reference to the Reserves Dictionary. The dictionary is returned when working with the grail.ip.reserves module. Specifically it is the dictionary returned by the following two function calls,

hres = reserves.hGetCurResRef()
dres = reserves.dGetRes(hres)

When working with the Reserves Dictionary, in your typical IP script you should also make a call to ordergrades as in,

hres = reserves.hGetCurResRef()
dres = reserves.dGetRes(hres)
reslib.ordergrades(dres)

that ensures the control grade is set and the grade lists between different cuts and areas match in their respective binning within the Reserves Dictionary.

Using reslib Get Functions

Some of the get functions within reslib return reference to the contents of the Reserves Dictionary. What does this mean? This means that if you modify a reference to a Dictionary or List retrieved by a get function, you are in fact modifying the Reserves Dictionary directly. However, if your get function only returns a string, real, or integer value, then do not need to worry about references.

Sometimes modifying the Reserves Dictionary directly is useful and efficient; however, sometimes it will lead to unintentional side-effects. An example of an unintentional side-effect is the illustrated below,

hres = reserves.hGetCurResRef()
dRes = reserves.dGetRes(hRes)

Unordered_Grade_List = reslib.getgradelist(dRes)

print Unordered_Grade_List # (1)

reslib.ordergrades(dRes)

print Unordered_Grade_List # (2)

When you request the unordered grade list via getgradelist, you get a reference to the grade list within the Reserves Dictionary. When your print the grade list at (1) you will see an unordered grade list. After you order the Reserves Dictionary grade list with ordergrades, you will have an ordered grade list. The new ordered grade list in the Reserves Dictionary is the same grade list as the one you referenced with getgradelist. This means that your Unordered_Grade_List in (2) will now be ordered.

If your intention was to get a copy and not a reference to the grade list, then you should use Python's copy module [1]. The above code snippet could be re-written as,

import copy

# ... later ...

hres = reserves.hGetCurResRef()
dRes = reserves.dGetRes(hRes)

Unordered_Grade_List = copy.copy(reslib.getgradelist(dRes))

print Unordered_Grade_List # (1)

reslib.ordergrades(dRes)

print Unordered_Grade_List # (2)

Now your Unordered_Grade_List at step (2) will be the same as the copy of the grade list you got with your call to getgradelist. This is because the Unordered_Grade_List is not a reference to the Reserves Dictionary internal grade list, but a new list onto itself.

In practice, if you intend to quickly read data from the Reserves Dictionary, you do not need to worry about the reference mechanics. If you intend to read and do work with the results, then you need to worry about references with Python's List and Dictionary objects returned by the reslib get functions. If you intend to read/write to the reserves dictionary, then you will need to continue to operate with the same reference to a Python List or Dictionary object. If your get function returns an string, real or integer, then you do not need to worry about references.

Functions

The functions defined in reslib can be broken down into the following broad categories,

  • General Functions

    Functions that are useful for all purpose reserves work with the Reserves Dictionary.

  • Attribute Functions

    Functions that work with the attributes defined within the Reserves Dictionary.

  • Area Functions

    Functions used to work with the Areas within a Reserves Dictionary.

  • Bin (Cutoff) Functions

    Functions used to work with the cutoff bins within the Reserves Dictionary. When you divide a grade into a set of cutoff, the range between cutoffs is considered a bin.

  • Calculation Functions

    Simple functions that perform simple calculations based on the contents of the Reserves Dictionary.

  • Cut Functions

    Functions dedicated to working with the cuts within the Reserves Dictionary.

  • Grade Functions

    Functions dedicated to working with the grades within the Reserves Dictionary.

  • Material Functions

    Functions dedicated to working with the materials within the Reserves Dictionary.

  • Material Set Functions

    Functions that work with material sets within the Reserves Dictionary.

  • ODBC Functions

    Functions relating to the Open Database Connectivity interface with MineSight® Interactive Planner.

  • Path Functions

    Functions relating to pathing information with the active Interactive Planner object.

General Functions

Functions that are useful for all purpose reserves work with the Reserves Dictionary.

get_cuts_except_current(dRes)

New in version 4.70

Scans through dRes and returns a list of cut dictionaries for all the cuts, except the current cut.

get_current_cut_idx(dRes):

New in version 4.70

Returns the current cut within the dRes. If there is no current cut it will return -1.

is_current_cut(dRes):

New in version 4.70

Returns True if there is a current cut. This is the same as checking that get_current_cut_idx does not return -1.

getcontrolgrade(dRes[, areaidx])

Returns the controlling grade, if an area index is not specified it is assumed that there is only one area.

Note

The results of this function call are undefined if reslib.ordergrades has not be called prior to calling this function.

getreslibversion()
Returns the version for the reslib module.
getunitsflag(dRes)

Returns 0 if the metric, 1 if imperial. The value is based on the value of the flag stored within the Interactive Plan database only, not the units used for you MineSight® 3D project.

The grail.ms3d.project module provides details about the MineSight® 3D project and its units.

getplanname(dRes)
Returns the plan name.
olddict(dRes)
Returns 1 if old style dictionary else returns None.
ordergrades(dRes)

Sets control grade and ensures grade lists are in proper order. In a typical IP script, this will be your third function call,

hres = reserves.hGetCurResRef()
dres = reserves.dGetRes(hres)
reslib.ordergrades(dres)
ordergradescut(res)
For internal usage only.
ordergradesitems(glist)
For internal use only.
preprints(msg[, fname])

Default file writing logger.

Will append a messages, msg, to the the file, fname, or if desired, another filename. Default file name is scripterr.txt.

Attribute Functions

attrexists(cut, attributeName)

Returns a one if custom attribute exists otherwise returns none. Takes a cut and the custom attribute name as an argument.

Takes a cut and the custom attributeName as an argument.

getcustomattr(cut, attrname)

Returns custom attribute value if it exists in the given cut. The attrname is case sensitive. The cut should be a cut dictionary as retrieved from dRes. For example, to print all custom attribute for all cuts given dRes you would do the following,

for cut in dRes['cuts']:
   
print reslib.attr_value(cut, 'MyCustomAttr')
getcustomattrname(dRes, index)
Returns custom attribute name given dRes and attribute index.
getnumcustomattr(dRes)
Returns number of custom attributes given Reserves Dictionary, dRes.

Area Functions

getnumareas(dRes)
Return number of areas in plan.
getarea(dRes, cut)
Returns reference to an area for a given Reserves Dictionary and cut. See also Using reslib Get Functions.
getdefarea(dRes)
Returns a default reference to an area for a given Reserves Dictionary, dRes. See also Using reslib Get Functions.
getareabyindex(dRes, index)
Returns a reference to an area given the Reserves Dictionary, dRes, and the area index. See also Using reslib Get Functions.
getareaindexfrommatsetname(dRes, materialname)
Returns an area index for a materialname within the Reserves Dictionary, dRes.

Bin (Cutoff) Functions

Functions used to work with the cutoff bins within the Reserves Dictionary. When you divide a grade into a set of cutoff, the range between cutoffs is considered a bin.

getbingrade(dRes, bin, gradename)
Returns a grade for a given bin and gradename within the Reserves Dictionary, dRes.
getbingradematset(dRes, materialset, bin, gradename)
Returns a grade for a bin within a materialset with the given gradename, within the Reserves Dictionary, dRes.
getbingradematseti(dRes, materialset, bin, gradename, gidx)
Returns a grade for a bin within a materialset with the given gradename and gradeiindex within the Reserves Dictionary, dRes.
getbingradeperiod(dRes, period, bin, gradename)
Returns a grade for a gradename within a given period and :a`bin` within the Reserves Dictionary, dRes.
getbintonsmatset(dRes, materialset, bin)
Returns the total tons for a given materialset and bin index for the Reserves Dictionary, dRes. This is the tons as reported across all periods.
getbintonsperiodmatset(dRes, period, materialset, bin)
Returns the tons for a period and materialset with the given bin index within the Reserves Dictionary, dRes.
getbinvol(dRes, bin)
Returns the volume for a given bin within the Reserves Dictionary, dRes.
getbinvolmatset(dRes, materialset, bin)
Returns the volume for a materialset's :a`bin` within the Reserves Dictionary, dRes.
getbinvolperiod(dRes, period, bin)
Returns the volume for a given period and bin index within the Reserves Dictionary, dRes.
getbinvolperiodmatset(dRes, period, materialset, bin)
Returns the volume for a given period, materialset and bin index within the Reserves Dictionary, dRes.
getmaxbinsbycut(dRes, cut)
Returns the maximum number of bins represented across all the materials for a given cut within the Reserves Dictionary, dRes.
getnumbinsbycut(dRes, cut)
Returns the number of bins for the cut within the Reserves Dictionary, dRes.
getnumbinsbymaterial(dRes, area, materialset, material)
Return number of bins for a material within materialset inside a given area as defined by the Reserves Dictionary, dRes.
getnumbinsmaterial(dRes, materialindex [, areaindex])

Returns the number of bins for a materialindex. The areaindex will default to 0.

Note

That this only works if your IP plan only has one material set.

getnumbins(dRes[, areaidx])

Returns the number of bins within the Reserves Dictionary, dRes, for the areaindex. The areaindex defaults to 0.

Note

That this only works if your IP plan only has one material set.

getnumbinsmaterialbycut(dRes, cut, materialindex [, areaindex])
Returns the number of bins given the Reserves Dictionary, dRes, for the cut, materialindex, and optional areaindex. The area index defaults to 0.

Calculation Functions

Simple functions that perform simple calculations based on the contents of the Reserves Dictionary.

gettonscutbin(cut, bin)
Returns the tons given a cut and bin.
getvolcutbin(cut, bin)
Returns the volume given a cut and bin.

Cut Functions

getcutcontrolgrade(dRes, cut)
Returns control grade given a cut.
getcutgradematerialbin(cut, gname, matname, bin)
Return the grade for a cut given the materials and grade name and bin number.
getcutgradematerialbini(cut, gidx, matname, bin)
Return the grade for a cut given the materials and grade name and bin number.
getcutmaterialnumblocks(cut, matname, bin)
Returns the number of blocks given material and bin number. See also Using reslib Get Functions
getcuttons(cut)
Returns the total tons for a given cut.
getcuttonsmaterial(dRes, cut, matname)
Return the total tons for a cut with the given material name, matname.
getcuttonsmaterialbin(cut, matname, bin)
Return the tons for a cut given the materials name and bin number.
getcutvolmaterial(dRes, cut, matname)
Return the total volume for a cut for a material given the material name.
getcutvolmaterialbin(cut, matname, bin)
Return the volume for a cut given the materials name and bin number.
getcutvolume(cut)
Returns total volume for a given cut.
get_cut_segid(cut)

New in version 4.70

Returns the segment id for the given cut. This ID can be used with the plan ID to look back into the MSPD. A currently active, new cut, will not have a segement id until that cut is saved to the MSPD.

get_cut_geominfo(cut)

New in version 4.70

Returns the field "Geom Info" field for a given cut. This is also known as "geometry creation info", or "geomcreation".

Grade Functions

getgrade(gname, res)
Return grade given reserve dictionary and grade name.
getgradei(gidx, res)
Return grade given reserve dictionary and grade index.
getgradelist(dRes[, areaidx])

Return list of grade dictionaries, which includes name, and accumulation flag. See also Using reslib Get Functions.

Note

You are working with a reference to the grade list within the Reserves Dictionary. If you intend to operate with a entirely new structure use Python's copy module instead [1].

getgradename(dRes, i[, areaidx])
Returns a grade name given an index into the reserves dictionary. The area index is optional.
getgradeperiod(dRes, period, gradename)
Return grade for period given Reserves Dictionary and grade name.
getgradeperiodmatset(dRes, period, materialset, gradename)
Return grade for period given Reserves Dictionary and grade name.
getgradeperiodmatseti(dRes, period, materialset, gradename, gidx)
Return grade for period given Reserves Dictionary and grade name.
getgradeplan(dRes, gradename)
Return grade for plan given Reserves Dictionary and grade name.
getgradeplanmatset(dRes, materialset, gradename)
Return grade for plan given Reserves Dictionary and grade name.
getgradeplanmatseti(dRes, materialset, gname, gidx)
Return grade for plan given Reserves Dictionary and grade name.
getgrades(dRes[, areaidx])
Returns a list of grade dictionaries. If no area index specified, there is assumed to be only 1. See also Using reslib Get Functions.
getnumgrades(dRes[, areaidx])
Return number of grades, area index is optional.
getnumgradescut(cut)
Returns number of grades for a given cut.
isgradeaccum(dRes, grade[, areaindex])
Returns 1 if the grade is an accumulated grade; otherwise, returns 0.
isgradethick(dRes, grade[, areaindexi])

Returns 1 if the accumulation are performed with the special thickness case.

The thickness case is a special case on how to average. In MineSight® Interactive Planner we can sum up our grades in two ways,

  1. We can do a weighted average based on the specific gravity. For example with copper grades.
  2. We can do a straight accumulation. For example with dollar values of barrels of oil.

Thickness is the exception to the above to methods. If one wants to the know the average thickness of a the cut, you can not sum and you can not do a weighted average based on the specific gravity. You have to do a weighted average based on how many blocks were considered. In other words, how much area the average considers.

Material Functions

getmat(dRes, matsetname, matname)
Return material given materialset name and material name. See also Using reslib Get Functions.
getmatreserves(cut, matname)
Returns reserves structure given a cut structure and material name. See also Using reslib Get Functions.
getmaterial(dRes, material)
Return material given Reserves Dictionary and material name only works with single material set. See also Using reslib Get Functions.
getmaterialbycut(dRes, cut, material[, areaindex])
Return material given Reserves Dictionary and material name. The areaindex defaults to 0. See also Using reslib Get Functions.
getmaterials(dRes[, areaidx])
Return default material given Reserves Dictionary only works with single material set. See also Using reslib Get Functions.
getmaterialsbycut(dRes, cut[, areaidx])
Return material given Reserves Dictionary and a cut, which gives you the material set. See also Using reslib Get Functions.
getmaterialsetbycut(dRes, cut)
Returns the materialset for the given cut only works for the new dictionary structure.
getnummaterialsbycut(dRes, cut)
Return number of materials given Reserve Dictionary and a cut, which gives you the material set.

Material Set Functions

getmaterialsetbyindex(dRes, areaindex, materialsetindex)
Return material set given area and materialset index. See also Using reslib Get Functions.
getmatsetindexfromcut(dRes, cut[, areaidx])
Return index to a material set, given a cut. See also Using reslib Get Functions.
getmatsets(dRes[, areaidx])
Return the materials sets dictionary given Reserves Dictionary. See also Using reslib Get Functions.
getnummaterialsets(dRes, areaindex)
Return number of material sets given area index.
getnummatsets(dRes)
Return number of material sets Reserve Dictionary.
matincut(material, cut)
Return reserves for a given cut and material. See also Using reslib Get Functions.

ODBC Functions

Functions related to the Open Database Connectivity (ODBC) interface.

db_odbc_str(dRes)

This returns a string for use with the python odbc module. It can be used to open a connection to a database with a properly defined ODBC name.

As an example, this function will convert the following result of a call to db_odbc_connection_str,

('ODBC;DSN=test;DBQ=C:\\tmp\\projects\\IPSingleOrePercent\\'
 
'attrib_database\\test.mdb;DriverId=25;FIL=MS Access;'
 
MaxBufferSize=2048;PageTimeout=5;')

to the following value for use in the python odbc module,

test//

notice, that if there was a username and password you would have gotten the following,

test/username/password

See the warning in db_odbc_obj for issues regarding using the python odbc module directly.

db_odbc_obj(dRes)

This returns the results of calling the python odbc module with the db_odbc_str function. The odbc Object returned can let you make queries against the underlying database.

import pprint
from grail.ip import reslib

sql = "SELECT OBJECTID FROM GEOMOBJECT"
odbc = reslib.db_odbc_obj(dRes)

cursor = odbc.cursor()
cursor.execute(sql)
resultList = cursor.fetchall()

print "Results of SQL Query: " + sql
pprint.pprint(resultList)

where the resulting message window would have something like this,

Results of SQL Query: SELECT OBJECTID FROM GEOMOBJECT
[('test-2007',),
 
('test_plan',),
 
('test-2007_OPENIP',),
 
('test-2007_BLASTVECS',)]

Warning

Extreme caution should be taken when using this Database connection and issuing SQL statements against the DB. By circumnavigating the standard interfaces you are risking corrupting your data. Furthermore, we can not guarantee that the underlying definitions will remain consistent from release to release.

db_odbc_connection_str(dRes)

Returns the connection string used for the current database.

Deprecated alias getODBCconnection since v4.00.

db_query(dRes)

Returns the query used for the currently active view into the database. The active view is defined by open 'plan'. Specifically this returns the contents of the WHERE clause within a SQL SELECT statement. For instance, with the following SQL statement,

SELECT * FROM GEOMOBJECT WHERE OBJECTID = "PLAN23"

this function would return "OBJECTID = 'PLAN23'".

Deprecated alias getODBCquery since v4.00.

Path Functions

Functions used to returning pathing information for a given Interactive Plan. All paths are returned as absolute paths.

getplanfilepath(dRes)
Returns the absolute path to the Interactive Planner MineSight® Resource file.
getmodelpath(dRes[, area])

Alias: get_model_path starting in 4.60.

Returns the absolute path to the model for the given area index. Default area index is 0. The model path will only have a value if the area type is a AREATYPE_MODEL. See get_area_type for more details.

getpcfpath(dRes[, area])

Alias: get_pcf_path starting in 4.60.

Returns the absolute path to the Project Control File (PCF) for a given area. Default area index is 0.

get_area_type(dRes[,area])

New in version 4.60.

Returns the either AREATYPE_DH or AREATYPE_MODEL depending on what type of model is used for the underlying area. A AREATYPE_DH corresponds to drillhole data, and the AREATYPE_MODEL corresponds to modeling data. The default area is 0.

get_dh_survey_path(dRes[,area])

New in version 4.60.

Returns the absolute path for the survey file if the area type for area is AREATYPE_DH (drillhole). See get_area_type for more details. If the area is not a drillhole area, this will return a blank string. The default area is 0. Call get_survey_type, to get its file number in the MineSight(r) system.

get_dh_assay_path(dRes[,area])

New in version 4.60.

Returns the absolute path for the assay file if the area type for area is AREATYPE_DH (drillhole). See get_area_type for more details.If the area is not a drillhole area, this will return a blank string. The default area is 0. Call get_survey_type, to get its file number in the MineSight(r) system.

get_dh_survey_type(dRes[,area])

New in version 4.60.

Returns the file number in the MineSight(r) system as an integer for the survey file define for the area. If the area is not a drillhole area, this will return 0. The default area is 0.

get_dh_assay_type(dRes[,area])

New in version 4.60.

Returns the file number in the MineSight(r) system as an integer for the assay file define for the area. If the area is not a drillhole area, this will return 0. The default area is 0.

Constants

AREATYPE_DH
New in version 4.60. When querying get_area_type it will return this if the area is a drill hole type.
AREATYPE_MODEL:
New in version 4.60. When querying get_area_type it will return this if the area is a model type.
AREATYPE_TORQUE:
New in version 6.10. When querying get_area_type it will return this if the area is a MSTorque drill hole type.

Reference

[1](1, 2) "copy -- Shallow and deep copy operations". 21 December 2001. 6 June 2005. <http://www.python.org/doc/2.2/lib/module-copy.html>