Crashing script in for loop

Geoff Elson 8 years ago in Scripting updated 8 years ago 7

I am trying to calculate the distance between each composite xyz and the nearest composite xyz from a different drillhole but my script is crashing.

I have changed the range upper limit to 10, 100 and 700 and it works but when I go to record_count MM crashes. Any advice would be helpful.

Thanks Geoff.

Image 934

Посмотрите, нет ли в файле пустых строк.

No blanks, that was something I looked into. Thanks.

Hi Geoff,

How many rows do you have in your file? If the number is too large, it is possible that MM doesn't respond when the script in process. I also have few comments about your script:

  1. Using for loop is not so fast, so for large number of iteration it can take much time. Another way to implement the loop is to use generator - it's a bit faster, but anyway takes much time for many points. See nearest1.py
  2. Operations such as power (**) are also not so fast.
  3. The most efficient way to find a distance to the nearest point is to use external modules and functions such as numpy and scipy. It is much faster but requires a lot of RAM, this is why we need to delete objects when script is done. See nearest2.py

Both scripts have a function to generate a temporary file for testing. Try to implement one of this approaches (the first one is a clear Python, so you don't need to install anything) and tell me whether it works or MM still crashes.

Pavel, thanks for your expert advice. As you may have guessed I am beginner and couldn't quite manage implementing a more elegant array approach.

I can learn a lot from your code, thanks for providing.

Hi Geoff,

The Paired Samples function on the Stats menu in Micromine might help you measure distances more easily/efficiently. You can enter the assay file as file 1 and file 2 but then you'll have to use some form of database query or python script to remove pairs where the hole-ids are the same and to get the closest match.

Thanks Rupert, but I got around to Pavel's code with a bit a prep and got the script working.

The modification I made was first using "at change increment" in the composite file followed by "replicated" to make temporary numeric drill hole codes so the script would only look at other drill holes and it is easier with the get_num only.

Any way the results are exactly what I need. Can't say thank you enough, I now have a new tool in my toolbox.