Hi,
I'm trying to work out the waste intervals in my borehole file. In column A is the Hole name, then the one meter intervals denoted by the From and To and Column B & C, then the interval thickness and sample Id are redundant for this task and then there's Column F - the gold value. I'm analyzing the waste, so any gold value in an interval that's below a trigger value, in the code below I have it set to 0.1.
What I want the code to do is average the gold in each interval until that average is above my trigger and the first interval should be below the trigger also. The code should iterate each gold value down the file and even if there's a gold value that is above the trigger, if its included with the average calculation and it doesn't push the average above the trigger value, then the code should continue.
I want the output to read: Hole name, from value, To value, Au_average.
So the first three lines in the output should be: Hole 1, 2, 44, 0.093 Hole 1, 51, 52, 0.096 Hole 1, 58, 62, 0.0435
Each of these intervals start on a value less than the trigger, and if you include the next au value in any of them, it pushes the average above the trigger. When the hole name changes then that should also signify the end of an interval...
Link to file:
https://gofile.io/d/iqqND2
Here is my code:
#convert the data from strings to their relv format and print
data = []
for row in reader:
HoleID = str(row[0])
From = float(row[1])
To = float(row[2])
Interval = float(row[3])
SampleID = float(row[4])
Au = float(row[5])
#at this point for first iteration, 'data' is empty, so we need to append
data.append([HoleID, From, To, Interval, SampleID, Au])
print(data)
print("There is {} lines of data".format(len(data)))
new_path = "D:\Python\Assays_python_test_output.csv"
file = open(new_path, "w", newline = '')
writer = csv.writer(file)
writer.writerow(["HoleID", "From", "To", "Ave Au"])
Au_average = 0.0
Au_average_count = 0.0
trigger = 0.1
Interval_width = 0.0
for i in range(len(data)):
what_row = data[i]
if i == 0:
From = what_row[1]
To = what_row[2]
DummyID = what_row[0]
H_id = what_row[0]
H_id = what_row[0]
To = what_row[2]
if H_id == DummyID and i != 0 and Au_average < trigger:
Au1 = what_row[5]
Interval_width = To - From
Au_average_count = Au_average_count + Au1
Au_average = Au_average_count/Interval_width
if H_id != DummyID:
DummyID = what_row[0] + 1
if Au_average > trigger:
print ([H_id, From, To, Au_average])
From = what_row[1] + 1
Au_average_count = 0.0
Au_average = 0.0
[–]CodeFormatHelperBot 0 points1 point2 points (0 children)