fatiando / harmonica

Forward modeling, inversion, and processing gravity and magnetic data
https://www.fatiando.org/harmonica
BSD 3-Clause "New" or "Revised" License
211 stars 69 forks source link

Add computation of gravitational tensor components for point sources #288

Closed santisoler closed 2 years ago

santisoler commented 2 years ago

Add new kernel functions to compute gravity tensor components generated by point sources. Add test functions for the new feature: check that the diagonal elements satisfy the Laplace equation, compare all components against finite difference computations from the gravity acceleration. Add test class for checking the symmetry of tensor components. Refactor old test functions for point gravity: merge some functions into single ones through pytest parametrizations. Avoid using "gradient" for specifying the gravity acceleration vector: the "gravity gradient" is usually used to refer to the tensor.

Reminders:

santisoler commented 2 years ago

@leouieda I finally found a very good opportunity to add a test class! The tests for tensor components symmetry has a few different cases that were hard to cover with just a few pytest parameters. So I decided it would be better to define a class for it, with different methods for each one of these cases. Let me know what do you think.

santisoler commented 2 years ago

I had never used a class for this before. Is the advantage only being able to hold values as attributes? Not complaining, just curious

Neither do I. I saw that xarray uses classes in their tests, mostly to group and keep tests organized and use inheritance to avoid repeating themselves. I thought that here this new class would work in that sense: group all tensor symmetry related fixtures, parameters and functions (methods now) under the same structure. I think the current scheme improves readability. Pytest parametrizations are nice to avoid repetition and buggy for loops inside test functions, but for some multi parameters cases, they fell short and create harder to read code.

To finish this PR I would: