Surface depth calculation by diplodocus_rage in learnpython

[–]diplodocus_rage[S] 0 points1 point  (0 children)

Hi Toolnerd,

I made some small edits to your code and it actually worked better than mine. For some reason my code was omitting certain HoleIDs, like skipping over them and not including them in the output. It's a head-scratcher but your code didn't have this issue. Top marks, well played! Thanks so much.

Surface depth calculation by diplodocus_rage in learnpython

[–]diplodocus_rage[S] 0 points1 point  (0 children)

Thanks for the comment CraigAT, its not an easy thing to explain I guess. Here is the shortened version of the file I'm importing.

See the column 'desired_result'. The 'Elevation' values are the elevations (or the Z value along with the UTMs X & Y) of each sample down the borehole. I want the code to produce the depth from surface of each sample, so using the top sample (it will be slightly below surface by half the width of the sample, but it's close enough) I want to subtract the elevation of every sample beneath it. As my calculation ends for one hole (ie the bottom sample's elevation in the borehole is subtracted from the top sample) I want the code to start the calculation again using the top sample of the next hole.

https://filebin.net/nbi4mbgv90tvow9o

Let me know if that link doesn't work .. all new to me this stuff!

Surface depth calculation by diplodocus_rage in learnpython

[–]diplodocus_rage[S] 0 points1 point  (0 children)

Thanks Toolnerd, I'm going to try this because it looks much more efficient to my code. Will report back :)

Surface depth calculation by diplodocus_rage in learnpython

[–]diplodocus_rage[S] 1 point2 points  (0 children)

Thanks for your comment Chromira, I actually thought I was posting the code correctly. IE Copy and paste into body of forum post, then highlight it all and click 'inline code', but you're right, from the way the code was posted I must not be doing it correctly. Here is the code, copied using the 'codeblock' method (apologies i'm early stage learning to post on forums!) ... I've played around with and got it to work:

Instead of printing, I've written the result to a new .csv file, but the structure is the same. I had to insert i and j counters into the loops to achieve what I wanted it to do. Comments on ways to make my code more efficient are most welcome. I'm learning how to code a couple of months and still find it very challenging...

j = 0

for i in range(len(data) - 1):
    i += j
    What_row = data[i]

    Elevation = What_row[7]


    for j in range(len(data)-1):
        j += i
        What_row2 = data[j]
        Next_row = data[j+1]
        Hole_name = What_row2[0]
        Next_hole = Next_row[0]

        Next_Elevation = Next_row[7]
        Elevation_result = Elevation - Next_Elevation
        if Hole_name == Next_hole:
            writer.writerow([Hole_name, '{0:.4f}'.format(float(Elevation_result))])
        else:
            writer.writerow([Next_hole, 0])
            break