fatiando / harmonica

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

Change the shape of the magnetization in magnetic forward functions #446

Closed santisoler closed 7 months ago

santisoler commented 7 months ago

The problem

Currently, the magnetization argument in prism_magnetic and the magnetic_moments argument in dipole_magnetic expect a 2d array where each row corresponds to the magnetization or magnetic moment vector for each prism or dipole, respectively.

For example, if we have 5 dipoles, the magnetic_moments should be:

magnetic_moments = np.array(
    [
        [1.9, 2.3, 4.5],
        [0.2, -2.1, 5.7],
        [0.2, -2.1, 5.7],
        [-2.3, 7.8, 9.2],
        [0.1, 2.7, 2.1],
    ]
)

This introduces some inconsistencies. For example, passing arrays to the hm.magnetic_angles_to_vec would return a tuple of three arrays, one for each component of the magnetization/magnetic field. So in order to obtain magnetic moments from inclination, declination and amplitude, we would need to transpose those.

Moreover, the current 2d array is not in agreement how we treat coordinates in Harmonica: they are usually a tuple with easting, northing and upward arrays.

The solution

We should change the expected inputs of these functions so they take magnetization and magnetic_moments as a tuple with three 1-d arrays. Following the previous example, they should be:

magnetic_moments = (
    np.array([1.9, 0.2, 0.2, -2.3 0.1]),
    np.array([2.3, -2.1, -2.1, 7.8, 2.7]),
    np.array([4.5, 5.7, 5.7, 9.2, 2.1]),
)

This change was discussed in Fatiando Meeting of 2024-01-04

Are you willing to help implement and maintain this feature?

Yes, but anyone that wants to tackle it is more than welcome!

We should work on this before the next release, so we don't release the new magnetic functions with an interface that will be deprecated.