0
Completed

3D block estimation script runs into exception when filters return no source sample points or blocks

Nikolay Karakashov 9 years ago in Scripting updated by Pavel Yakovlev (Moderator (RUS)) 9 years ago 5
I've set up a nested loop script to perform some simple IDW estimations, whereby the script uses the same basic Formset and uses variables in place of the ore body filter and the source assay data.

The input lab data is located in a DAT file, where the records are coded using a 'Body Code', for example BL1, BL2 etc.
The source and destination blocks use the same blank block model, which gets updated as the estimations run through. Empty blocks are also coded for each ore body using the same notation.

The formset runs one set of estimations for each ore body and the filters vary twice (two ore types), then a second pass using a larger search ellipse is performed for a total of 4 looped formsets.

For the purposes of this topic I will only show one looped formset as they're all essentially the same and run one after another. I have confirmed that they perform exactly as expected, but I run into an Exception every now and then and seem to have narrowed it to ore bodies where there are either no blocks matching the ore body number (for example I had no block for ore body CS16) or no matching samples, which is expected for some filter conditions.

When I manually run an estimation using the problematic settings for the filters the estimation runs through just fine, it simply doesn't write anything to the block model, so I'm not sure why the script won't perform it? short of inserting a 'dummy' sample point for each ore body I'm out of ideas how to proceed. We have 165 ore bodies, so that's 660 separate estimations (used to do it with keyboard scripting before Python)!

Here is the exception in the script output window, line 157 is highlighted in bold below:

"
File ALL_MMS_Estimates.DAT exists. Update? [Yes]
<class 'Exception'>: File ALL_MMS_Estimates.DAT exists. Update? [Yes]
: File "<string>", line 157, in <module>


>>>
"When the script is running smoothly I simply get :
"File ALL_MMS_Estimates.DAT exists. Update? [Yes]"
over and over

Here is one loop-through sample. Ignore the nested If-Else statements at the bottom, the scirpt breaks down even when they're taken away

Status = 1
Prospect = "BL"
totBody = 10
curBody = 1
while Status <= 1:

while curBody <= totBody:

Dbfilter_Obm3dIdw_FormSet1_Nested2= MMpy.FormSet("DBFILTER","15.0.1.545")

DataGrid3 = MMpy.DataGrid(4,1)

DataGrid3.set_column_info(0,1,4)

DataGrid3.set_column_info(1,2,6)

DataGrid3.set_column_info(2,3,-1)

DataGrid3.set_column_info(3,4,14)

DataGrid3.set_row(0, ["Body Code","0",Prospect+str(curBody),""])

DataGrid3.set_row(1, ["Ore Code","0","SB",""])

Dbfilter_Obm3dIdw_FormSet1_Nested2.set_field("GRID",DataGrid3.serialise())

Dbfilter_Obm3dIdw_FormSet1_Nested2.set_field("NEGATE","0")

Dbfilter_Obm3dIdw_FormSet1_Nested2.set_field("COMBINE_EQ","0")

Dbfilter_Obm3dIdw_FormSet1_Nested2.set_field("OR","0")

Dbfilter_Obm3dIdw_FormSet1_Nested2.set_field("AND","1")

Dbfilter_Obm3dIdw_FormSet1_Nested2.set_field("DBFLT_EQ","1")

Dbfilter_Obm3dIdw_FormSet1_Nested2.set_field("FTYPE","0")

Dbfilter_Obm3dIdw_FormSet1_Nested2.set_field("FILE","Block Modelling\\3D assays 29Nov")



SearchEllipse_Obm3dIdw_FormSet1_Nested1= MMpy.FormSet("SEARCH_ELLIPSE","15.0.1.545")

SearchEllipse_Obm3dIdw_FormSet1_Nested1.set_field("DIPDIR","65.000")

SearchEllipse_Obm3dIdw_FormSet1_Nested1.set_field("SENSE","0")

SearchEllipse_Obm3dIdw_FormSet1_Nested1.set_field("ROT_BOOL","0")

SearchEllipse_Obm3dIdw_FormSet1_Nested1.set_field("3AXES_BOOL","0")

SearchEllipse_Obm3dIdw_FormSet1_Nested1.set_field("PLUNGE_BOOL","1")

SearchEllipse_Obm3dIdw_FormSet1_Nested1.set_field("PITCH_BOOL","0")

SearchEllipse_Obm3dIdw_FormSet1_Nested1.set_field("PITCH","0.000")

SearchEllipse_Obm3dIdw_FormSet1_Nested1.set_field("DIP","80.000")

SearchEllipse_Obm3dIdw_FormSet1_Nested1.set_field("SPHERIC_BOOL","0")

SearchEllipse_Obm3dIdw_FormSet1_Nested1.set_field("2D","0")

SearchEllipse_Obm3dIdw_FormSet1_Nested1.set_field("MIN_POINTS","8")

SearchEllipse_Obm3dIdw_FormSet1_Nested1.set_field("MAX_POINTS","24")

SearchEllipse_Obm3dIdw_FormSet1_Nested1.set_field("SECTORS","0")

SearchEllipse_Obm3dIdw_FormSet1_Nested1.set_field("PLUNGE3","10.000")

SearchEllipse_Obm3dIdw_FormSet1_Nested1.set_field("AZIMUTH3","-115.000")

SearchEllipse_Obm3dIdw_FormSet1_Nested1.set_field("PLUNGE2","80.000")

SearchEllipse_Obm3dIdw_FormSet1_Nested1.set_field("AZIMUTH2","65.000")

SearchEllipse_Obm3dIdw_FormSet1_Nested1.set_field("STRIKE","335.000")

SearchEllipse_Obm3dIdw_FormSet1_Nested1.set_field("FACTOR3","25")

SearchEllipse_Obm3dIdw_FormSet1_Nested1.set_field("FACTOR2","25")

SearchEllipse_Obm3dIdw_FormSet1_Nested1.set_field("ROTATION","-80.000")

SearchEllipse_Obm3dIdw_FormSet1_Nested1.set_field("FACTOR1","150")

SearchEllipse_Obm3dIdw_FormSet1_Nested1.set_field("PLUNGE1","0.000")

SearchEllipse_Obm3dIdw_FormSet1_Nested1.set_field("AZIMUTH1","335.000")

SearchEllipse_Obm3dIdw_FormSet1_Nested1.set_field("ELLIPSE_BOOL","1")

SearchEllipse_Obm3dIdw_FormSet1_Nested1.set_field("RADIUS","1")



Dbfilter_Obm3dIdw_FormSet1_Nested0= MMpy.FormSet("DBFILTER","15.0.1.545")

DataGrid2 = MMpy.DataGrid(4,1)

DataGrid2.set_column_info(0,1,4)

DataGrid2.set_column_info(1,2,6)

DataGrid2.set_column_info(2,3,-1)

DataGrid2.set_column_info(3,4,14)

DataGrid2.set_row(0, ["Body Code","0",Prospect+str(curBody),""])

DataGrid2.set_row(1, ["Ore Code","0","SB",""])

Dbfilter_Obm3dIdw_FormSet1_Nested0.set_field("GRID",DataGrid2.serialise())

Dbfilter_Obm3dIdw_FormSet1_Nested0.set_field("NEGATE","0")

Dbfilter_Obm3dIdw_FormSet1_Nested0.set_field("COMBINE_EQ","0")

Dbfilter_Obm3dIdw_FormSet1_Nested0.set_field("OR","0")

Dbfilter_Obm3dIdw_FormSet1_Nested0.set_field("AND","1")

Dbfilter_Obm3dIdw_FormSet1_Nested0.set_field("DBFLT_EQ","1")

Dbfilter_Obm3dIdw_FormSet1_Nested0.set_field("FTYPE","0")

Dbfilter_Obm3dIdw_FormSet1_Nested0.set_field("FILE","Block Modelling\\3D assays 29Nov")



Obm3dIdw_FormSet1= MMpy.FormSet("OBM3D_IDW","15.0.1.545")

Obm3dIdw_FormSet1.set_field("FLTBOOL","0")

Obm3dIdw_FormSet1.set_field("STR_FTYPE","0")

Obm3dIdw_FormSet1.set_field("STR_BOOL","1")

Obm3dIdw_FormSet1.set_field("OUTL_BOOL","0")

Obm3dIdw_FormSet1.set_field("TYPE","0")

Obm3dIdw_FormSet1.set_field("TEMPLATE_BOOL","0")

Obm3dIdw_FormSet1.set_field("USE_DATASEARCH","0")

Obm3dIdw_FormSet1.set_field("ANGLES","0")

Obm3dIdw_FormSet1.set_field("ROTATION","1")

Obm3dIdw_FormSet1.set_field("MAX_RL","524")

Obm3dIdw_FormSet1.set_field("BCOUNT_RL","8")

Obm3dIdw_FormSet1.set_field("BS_RL","10")

Obm3dIdw_FormSet1.set_field("MIN_RL","454")

Obm3dIdw_FormSet1.set_field("OBM3I_OBM_RL_FLD","MRL")

Obm3dIdw_FormSet1.set_field("MAX_NORTH","6674625")

Obm3dIdw_FormSet1.set_field("BCOUNT_NORTH","10")

Obm3dIdw_FormSet1.set_field("BS_NORTH","25")

Obm3dIdw_FormSet1.set_field("MIN_NORTH","6674400")

Obm3dIdw_FormSet1.set_field("OBM3I_OBM_N_FLD","NORTH")

Obm3dIdw_FormSet1.set_field("MAX_EAST","789370")

Obm3dIdw_FormSet1.set_field("BCOUNT_EAST","3")

Obm3dIdw_FormSet1.set_field("BS_EAST","25")

Obm3dIdw_FormSet1.set_field("MIN_EAST","789320")

Obm3dIdw_FormSet1.set_field("OBM3I_OBM_E_FLD","EAST")

Obm3dIdw_FormSet1.set_field("EXTENTS","0")

Obm3dIdw_FormSet1.set_field("WEIGHTS","0")

DataGrid0 = MMpy.DataGrid(1,1)

DataGrid0.set_column_info(0,0,4)

DataGrid0.set_row(0, ["Fe_pct"])

DataGrid0.set_row(1, ["S_pct"])

DataGrid0.set_row(2, ["P_pct"])

DataGrid0.set_row(3, ["SiO2_pct"])

DataGrid0.set_row(4, ["Al2O3_pct"])

Obm3dIdw_FormSet1.set_field("OBM_FIELDS_GRID",DataGrid0.serialise())

DataGrid1 = MMpy.DataGrid(5,1)

DataGrid1.set_column_info(0,0,4)

DataGrid1.set_column_info(1,1,6)

DataGrid1.set_column_info(2,2,-1)

DataGrid1.set_column_info(3,3,-1)

DataGrid1.set_column_info(4,4,-1)

DataGrid1.set_row(0, ["Run count","0","2","0","1"])

Obm3dIdw_FormSet1.set_field("EXTRA_FIELDS_GRID",DataGrid1.serialise())

Obm3dIdw_FormSet1.set_field("AUDIT_BOOL","0")

Obm3dIdw_FormSet1.set_field("SECTORS","0")

Obm3dIdw_FormSet1.set_field("CLOSEST_DISTANCE","0")

Obm3dIdw_FormSet1.set_field("AVERAGE_DISTANCE","1")

Obm3dIdw_FormSet1.set_field("REPORT","0")

Obm3dIdw_FormSet1.set_field("ROTATION_FIELD","rot")

Obm3dIdw_FormSet1.set_field("PLUNGE_FIELD","dip")

Obm3dIdw_FormSet1.set_field("AZIMUTH_FIELD","Str")

Obm3dIdw_FormSet1.set_field("SEARCH_BOOL","1")

Obm3dIdw_FormSet1.set_field("MAX_COUNT_PER_REFERENCE","8")

Obm3dIdw_FormSet1.set_field("REPORT_FILE","BLOCK WEIGHTING", MMpy.append_flag.none) #Change to MMpy.append_flag.report to append report result

Obm3dIdw_FormSet1.set_field("ONLY","1")

Obm3dIdw_FormSet1.set_field("CNT","1")

Obm3dIdw_FormSet1.set_field("FROM_FILE","1")

Obm3dIdw_FormSet1.set_field("P_OBM_RL_FLD","RL")

Obm3dIdw_FormSet1.set_field("P_OBM_N_FLD","NORTH")

Obm3dIdw_FormSet1.set_field("P_OBM_E_FLD","EAST")

Obm3dIdw_FormSet1.set_field("BM_FILTER","1")

Obm3dIdw_FormSet1.set_field("BM_FLTNO",Dbfilter_Obm3dIdw_FormSet1_Nested0)

Obm3dIdw_FormSet1.set_field("BM_FTYPE","0")

Obm3dIdw_FormSet1.set_field("BM_FILE","Block Modelling\\ALL_MMS_Estimates")

Obm3dIdw_FormSet1.set_field("COUNT","Count_field")

Obm3dIdw_FormSet1.set_field("COUNTREF","Hole_ID")

Obm3dIdw_FormSet1.set_field("XX","0")

Obm3dIdw_FormSet1.set_field("BLANK_MISSING","0")

Obm3dIdw_FormSet1.set_field("CHAR_MISSING","0")

Obm3dIdw_FormSet1.set_field("INDEX","0")

Obm3dIdw_FormSet1.set_field("STDEV","0")

Obm3dIdw_FormSet1.set_field("NUMS","1")

Obm3dIdw_FormSet1.set_field("POWER","2")

Obm3dIdw_FormSet1.set_field("SEARCH",SearchEllipse_Obm3dIdw_FormSet1_Nested1)

Obm3dIdw_FormSet1.set_field("METHOD","0")

Obm3dIdw_FormSet1.set_field("OUT_FTYPE","0")

Obm3dIdw_FormSet1.set_field("OUT_FILE","Block Modelling\\ALL_MMS_Estimates")

Obm3dIdw_FormSet1.set_field("OUTLINE_BOOL","0")

Obm3dIdw_FormSet1.set_field("OBM3I_FLTNO",Dbfilter_Obm3dIdw_FormSet1_Nested2)

Obm3dIdw_FormSet1.set_field("OBM3I_FILTER","1")

Obm3dIdw_FormSet1.set_field("OBM3I_FTYPE","0")

Obm3dIdw_FormSet1.set_field("OBM3I_FILE","Block Modelling\\3D assays 29Nov")



Obm3dIdw_FormSet1.run()



curBody = curBody + 1

curBody = 1

Status = Status + 1

if Status == 2:

Prospect = "BN"

totBody = 8

else:

if Status == 3:

Prospect = "BS"

totBody = 6

else:

if Status == 4:

Prospect = "CC"

totBody = 18

else:

if Status == 5:

Prospect = "CN"

totBody = 14

else:

if Status == 6:

Prospect = "CS"

totBody = 22

else:

if Status == 7:

Prospect = "CW"

totBody = 37

else:

if Status == 8:

Prospect = "DD"

totBody = 8

else:

if Status == 9:

Prospect = "SC"

totBody = 25

else:

if Status == 10:

Prospect = "SN"

totBody = 18

else:

if Status == 11:

Prospect = "SS"

totBody = 24
Under review
Hi Nikolay,

If I understand what you are doing, you are running the same process in a loop and there might be occurrence of this process that doesn't have valid data, but you don't care and just want to move on to the next one.

The best solution for you might be to use python exceptions mechanism (https://docs.python.org/3.3/tutorial/errors.html#h...

Because we are throwing an exception, you can catch it and handle how your program is suppose to react:

In your case :

try:
  Obm3dIdw_FormSet1.run()
except:
  continue # continue the loop

Might be the way to go.

Hope this helps !
Yes that's exactly right. Pasting the Exception bypass works great, I just had to add another counter increase in the exception case, before continue (which ironically doesn't continue, but goes back to the start of the loop) in order to avoid an infinite loop:

try:   

	Obm3dIdw_FormSet1.run() 

except:   

	curBody = curBody + 1
	continue # continue the loop
Thanks!
If I have many ore bodies and different search radiuses I always use macro to complete it. Never used Scripting. Is this mkre funcional or what? Which is better? I use MM 2011.
+1
Python scripting was added in MM 2013, so macro is the only way to solve the task in MM 2011.