-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to discard thin prisms of a layer when forward modelling #373
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mdtanker for opening this PR! This is looking great!
I left a few little comments below, nothing too big. I think the only thing that we would like to improve before merging this are the tests. We are currently testing if the gravity fields of two layers (one that have discarded thin prisms and one that doesn't) generate the same gravity field. This test makes sense, but we are not actually testing if discarding prisms based on thickness actually works: assume that the function has a bug and it doesn't discard any prism, the gravity field would still be exactly the same and all tests will pass, but the bug will still be there.
Would you like to write an extra test that checks just the private _discard_thin_prisms
function? Basically it should build a set of prisms with different thicknesses and a set of densities (would be better if they all have different densities), pass them to the _discard_thin_prisms
function and check if the output doesn't contain the thin prisms and the density values are the correct ones: the ones that correspond with the thick prisms.
The advantage of writing private functions in a modular way is that it's way easier to test them independently of the higher level code that uses them. This is usually known as unit testing where we test the smallest units of our codebase independently of the rest.
Co-authored-by: Santiago Soler <[email protected]>
Co-authored-by: Santiago Soler <[email protected]>
Co-authored-by: Santiago Soler <[email protected]>
@santisoler thanks for reviewing so fast! Good catch with adding that additional test. I'm having trouble using the Also, I noticed most of the other functions in |
Hi @mdtanker!
When you are trying to import with
when you run The good thing is that you can always import private stuff, but you need to provide the whole route to them. In this case you can import the from ..forward.prism_layer import _discard_thin_prisms
I'm glad you bring this question. While doing object-oriented designs is usually tempting to add a new method to the class, even if it's a private one. But this instinct can lead to bugs or even to repeat code that could be broadly used throughout the project in the future. Every time you need to decide if some function should be a method or a function ask yourself: is this function actually needing some attribute of the class? In this particular case the By contrast, every other method of the prism layer is actually reading some attributes from result = layer.prism_layer.gravity(coordinates, field) or with a dedicated function? result = prism_layer_gravity(coordinates, layer, field) Probably not the discussion for this PR, but I just wanted to mention it since behind our designs we are always taking these types of decisions. |
@santisoler thanks for the help. I've added a separate test to check that Thanks for the explanation on methods vs. functions! Very helpful to have that explained. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mdtanker for adding that test! I left a few comments below, mainly about the docstrings. After those are fixed I think this should be ready to be merged.
Co-authored-by: Santiago Soler <[email protected]>
Thanks for those suggestions. I've added them, and a few other minor changes. Happy for you to merge whenever 👍 |
Thanks @mdtanker! I think this is ready to be merged! 🚀 |
Add a new
thickness_threshold
parameter to theprism_layer.gravity()
methodthat allows the user to ignore prisms below a certain thickness. This is
implemented within a new
_discard_thin_prisms()
, function which is similar tothe
_discard_null_prisms()
function. Add tests that check whether thecalculated gravity is the same from manually removing prisms and removing
prisms based on a threshold, and whether providing no threshold still produces
the correct gravity.
I've added a parameter
thickness_threshold
to theprism_layer.gravity()
function which allows the user to ignore prisms below a certain thickness. This is implemented within a new function_discard_thin_prisms()
, which is similar to the function_discard_null_prisms()
here.I've also added a test that checks:
whether the calculated gravity is the same from manually removing prisms and removing prisms based on a threshold
whether providing no threshold still produces the correct gravity.
This shouldn't affect performance if no threshold is supplied since the discard is skipped if
thickness_threshold is None
.I'm not sure what the performance hit is when a threshold is supplied.
Relevant issues/PRs:
Fixes #371