joferkington / mplstereonet

Stereonets for matplotlib
MIT License
189 stars 66 forks source link

Adding kinematic analysis module #36

Closed regine709 closed 4 years ago

regine709 commented 4 years ago

Hi Joe,

Please consider adding this - this is a module to do kinematic analysis for rock slope stability. Three modes of rock block failures can be analyzed, i.e. planar sliding, wedge sliding and flexural toppling. You can use the module to generate plots below: basic

And you can check which joints/intersections are in the potential failure zones, and highlight / count them: check

Scripts to produce the plots above and sample data are added in the examples folder. There are other examples to show how to control the plot styles, and how to use a single combined plot to analyze the three failure modes.

But please note that for this module, I import a package called Shapely to do the geometry manipulation, such as splitting polygons. Since this package is not previously included in mplstereonet, I don't know whether you will prefer this.

I use mplstereonet occasionally at work, and I really appreciate it. I think it would be great if we can also do kinematic analysis with mplstereonet. I'm rather new to python packages and Git. If you have any comments or suggestions, please let me know.

Thanks, Regine

joferkington commented 4 years ago

Hi @regine709 - This is a really nice implementation! Thanks a ton for the PR! I really appreciate that you took the time to do this and the documentation and examples are fantastic.

A couple very minor requests:

  1. apparent_dip and azimuth_diff should probably go in analysis.py, as they're generally useful for other types of analysis as well.
  2. mplstereonet still supports python 2.x as well as 3.x, so the classes should explicitly inherit from object (won't matter yet for what you have, but if a @property/etc is added, it'll silently fail to work in 2.x unless the class inherits from object).
  3. If you don't mind, it would be nice to add a couple of tests to the tests directory for the core calculations. The examples will semi-automatically be used as "golden file" image-based tests, but it's still very useful to have simpler unit tests that check the functionality from a theoretical/mathematical standpoint. I'd be happy to add some after the PR is merged, but the tests are best written by someone more familiar with the exact analysis than I am. They don't have to be exhaustive -- a few simple test cases are more than enough.
  4. It's often useful for plotting methods (plot_kinematic) to return the artists they create so that those can be customized later. Would it make sense to return a dict of the artists that plot_kinematic adds instead of the axes instance? (E.g. see plt.boxplot and a few other matplotlib methods for examples of plotting methods that return a dict of artists.) On the other hand, if that seems too cumbersome, feel free to ignore.

I'm also more than happy to merge this as-is if you're running short on time. It's an excellent PR.

regine709 commented 4 years ago

Hi @joferkington ,

Thanks a lot for your interest and suggestions. I agree with your points, especially point (4) - return a dict of the artists for plot_kinematic - does sound more flexible for users. Great, I'll revise these. I'm still learning how tests work, so that may take sometime.

joferkington commented 4 years ago

Thanks a ton for the added tests and changes @regine709! (And my apologies for not noticing them earlier.)

I really appreciate all the work you put into this!

regine709 commented 4 years ago

@joferkington Thanks for merging the PR. Actually I was just about to write a message about the new commits, but was distracted by an issue about the tests - which I just posted in #37 #