Skip to content

Add linearity tests for forward models #293

Closed

Description

@santisoler

Description of the desired feature:

Our forward models for the different geometries (points, prisms, tesseroids) allow to take multiple bodies as inputs, returning a single array as the resulting field generated by every one of these bodies on the computation points.
One of the properties of these forward models is their linearity: the resulting field for all the bodies should be equal to the sum of the individual fields.
Although this property is easily readable from the code, it might be wise to add functions that actually test them.
We could add test_linearity functions for each geometry that compares the resulting field of passing a set of bodies to the resulting field of computing the fields of each one separately and then sum them up.

Through pytests.mark.parametrize we could write a single function per geometry, adding the field as a parameter.
For example:

@pytest.mark.parametrize("field", ("potential", "g_z", ...))
def test_linearity(field):
    """
    Test linearity of the forward model
    """
    ...

Are you willing to help implement and maintain this feature? Yes, but I would love to help anyone motivated to tackle it. 💪🏼

Activity

  1. added
    enhancement
    good first issue
    on Dec 3, 2021
  2. manduinca commented on Jul 15, 2026

    @manduinca
    Contributor

    Hi! I'd like to work on this one.

    My plan is to add a parametrized test_linearity for each geometry (point sources, prisms and tesseroids), comparing the field produced by the full set of bodies against the sum of the fields of each body computed separately, with field as the parametrize argument as suggested above. I'd place them in the existing per-geometry modules (test_point_gravity.py, test_prism.py, test_tesseroid.py).

    Two quick questions before I start:

    1. Would you prefer a single PR covering all geometries, or one per geometry to keep reviews small?
    2. Should the magnetic forward models (prism_magnetic, dipole) be covered too, or do we keep this scoped to gravity?
  3. santisoler commented on Jul 22, 2026

    @santisoler
    MemberAuthor

    Hi @manduinca! Thanks for offering help with this, it's much appreciated!

    Your idea sounds good: splitting the tests for each geometry and them parametrize by field sounds right. It would be nice to include linearity tests for both gravity and magnetic fields. I think including all of them in a single PR should be enough. I suspect it won't be too large, so feel free to open a single one.

    Thanks again, and let me know if you need any help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions