geotechTools mapData (kdTree)
Complex workflows can be shortened to a few lines of high-level Python

geotechTools mapData (kdTree)

Introducing the Python geotechTools last week (and the repository on GitHub), the example did little more than robustly read and filter the data, plus a simple plot. In the article about using Python, not Excel, I previously introduced the kdTree library in scipy.spatial. This extraordinarily efficient and robust tool enables mapping of millions of points to their closest counterpart in another dataset in seconds. Sounds very useful?

By adding kdTree to the class xyzData() as a method to map data, very complex workflows can be shortened to a few lines of high-level Python.

Article content
Python code using xyzData() class to map columns from a separate csv file
Article content
Points from random_colour.csv containing colour information (left), resulting values in SampleDataset (right)
Article content
FIle random_colour.csv

mapData()

This method operates on either

  • an np.array of shape (N, 4) with rows of [x,y,z,c], where c will be mapped into a new column with the index stored in newIndex; or

  • an xyzData class object with all columns mapped and their indices added

Article content
mapData()
Article content
iPython: showing new (mapped) columns in f.index

extractArrayN4()

In case there is a need to extract a single column out of xyzData, this method becomes useful. It returns an np.array of shape (N, 4) compatible with the above. A nice example on how compact the code can become with numpy:

Article content
extractArrayN4()

If you think this is cool, please do hit 'like' or leave a comment 😉

I've added a Jupyter notebook with this code (mapData_geotechTools.ipynb) to the GitHub repository as the main for the project, geotechTools.py, usually reflects the latest example - https://github.com/SMArndt/geotechTools/blob/main/mapData_geotechTools.ipynb

Thanks for sharing Stephan. I've been using the value transfer function within Gem4D for this task. Great to know of this method within Python. Thanks!

To view or add a comment, sign in

More articles by Stephan ARNDT

  • EAGCG Recap: IUCM & Abaqus

    This year's EAGCG workshop was spectacular. There was an extensive line-up of speakers and sponsors, about 145…

  • Slope Stability (Part 3): Pore Pressure

    Why is pore pressure important for slope stability? Part 1 of the Slope Stability articles outlined the importance of…

    7 Comments
  • Slope Stability - Shear Strength Reduction Method (Part 2)

    "It has always been done this way" The five monkeys experiment. I doubt there's reliable information to confirm this…

    4 Comments
  • Slope Stability - Shear Strength Reduction Method (Part 1)

    Ok, up front: There's nothing new here; you'll have to wait for Part 2. There, I intend to present some challenging…

    9 Comments
  • Monkeys on Typewriters

    AI will take your job - AI will make it easier until it does - AI in Python and C++ using Copilot - AI does not know…

    7 Comments
  • Principal Stress Transformations

    In this article, we're going off on a tangent from the theme of block models, kdTrees and grid data in the GitHub…

    6 Comments
  • Don't stress, use Python

    Any discussion about in-situ stress for an underground mine can turn into a heated argument quickly - just from my…

    2 Comments
  • Python gridData in geotechTools

    Traditionally, there are endless applications for arranging points in a regular grid. In practical terms, this means we…

    2 Comments
  • Python geotechTools on GitHub

    So, you're still using Excel for geotech data. Here are some examples of using Python and libraries like Numpy to…

    37 Comments
  • 2024: Are you still using Excel (for Geotech data)?

    Spoiler alert … for most of you, the answer is probably ‘yes’. A recent poll in Mining Geomechanics showed these…

    18 Comments

Explore content categories