Improve interface of forward models in Harmonica? #90
santisoler
started this conversation in
Polls
Replies: 3 comments 2 replies
-
I like the current simplicity of the API. Creating functions for each component seems like it would bloat the API and documentation. I see how passing string parameters may be non-ideal, but at least it is simple to look at a single forward modeling function in the documentation. |
Beta Was this translation helpful? Give feedback.
1 reply
-
I like the current design, haha. |
Beta Was this translation helpful? Give feedback.
1 reply
-
Yes I agree with the above and think the simplicity of the current docs is more important than having auto-completion. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
TL;DR (too long, didn't read)
I opened a poll to make a community-based decision on the design of the forward modelling functions in Harmonica.
The idea is to avoid passing the desired fields as strings (like we currently do):
but create separate functions for each available field, like:
Complete the poll and optionally add a comment if you have any good ideas! We want to hear them!
The problem
Hi everyone! All across the Fatiando project we have to make design decisions every time we implement a new feature. These design decisions can be divided in two big categories:
The first one is related to the computational power house, how the computations are efficiently carried out and how their implementations are testable, extendable and maintainable. Since users aren't expected to directly interact with these pieces of code, we have a high flexibility for changes: while ensuring that the public functions and classes recreate the previous results, we can safely refactor the underlying code for speed gain, extensibility and maintainability.
The second set of decisions are harder to make. When we write public functions and classes we expect users to interact with them, so there are a few things that we have to consider while doing so: how easy it is to use it, how clear is the documentation, what's the scope of this function or class, etc. But also we have to consider that users will get used to using these interfaces, so pushing changes to them cannot be arbitrarily done.
In Harmonica we have implemented forward modelling functions since almost we started moving the old Fatiando code into it. In this new design every forward modelling function in available directly from
harmonica
, instead of having them living inside submodules like in the oldfatiando
. For example, if we want to compute the downward gravity acceleration of rectangular prisms we can run the following:In this design we have a single function to compute any gravity field generated by prisms: the field that the user wants to compute must be passed as a string to the
field
. This reduces the amounts of functions and condenses every possible gravity field into a single function call. But this comes with a cost: we need to pass the desired field as a string. This imposes some challenges:prism_gravity
function, so you have to read it every time you want to remember exactly which string should you pass so you don't find yourself in the situation described in the previous item.Possible solution
Considering these drawbacks I thought this might be a good opportunity to change that design decision. Instead of passing the field as a string I think we could create separate forward modelling functions for each component. For example, for the downward component of the acceleration of the prism it could be something like:
While the gravitational potential and the two other components of the acceleration could be functions named:
We could also use this design for tensor components:
And also for the magnetic fields of prisms (see https://github.com/fatiando/harmonica#366 for a draft implementation of these):
Since this decision would impact most Harmonica users I thought this might be a good opportunity to include them in this design decision. I left a poll for you to put your thoughts on it, but I would like to encourage you to comment on this discussion and give more detailed thoughts.
6 votes ·
Beta Was this translation helpful? Give feedback.
All reactions