Skip to content

Make magnetization direction required in public reduction_to_pole#684

Open
gaoflow wants to merge 1 commit into
fatiando:mainfrom
gaoflow:fix/rtp-magnetization-required
Open

Make magnetization direction required in public reduction_to_pole#684
gaoflow wants to merge 1 commit into
fatiando:mainfrom
gaoflow:fix/rtp-magnetization-required

Conversation

@gaoflow
Copy link
Copy Markdown

@gaoflow gaoflow commented Jun 1, 2026

Completes #661 (which fixes #440).

Problem

#661 made the magnetization inclination/declination required in reduction_to_pole_kernel and removed the code that filled in defaults when they were None. However, the public reduction_to_pole function in _transformations.py was missed — it still declared:

magnetization_inclination=None,
magnetization_declination=None,

and passed those straight into the now-strict kernel. So the documented default usage (omitting the magnetization direction, as the docstring still described) crashes deep inside the kernel:

>>> hm.reduction_to_pole(grid, inclination, declination)
TypeError: loop of ufunc does not support argument 0 of type NoneType which has no callable radians method

This is exactly the silent "induced-only magnetization" foot-gun that @leouieda wanted to remove in #440 — except now it is a crash with a confusing message rather than a clear, explicit requirement.

Fix

Complete #661 on the public function:

  • Make magnetization_inclination / magnetization_declination required arguments (remove the =None defaults).
  • Drop the stale "If None … will be set equal to the inclination/declination" docstring text, mirroring the kernel docstring updated in Make the magnetization direction required in RTP #661.

Omitting the magnetization direction now raises a clear error at call time:

TypeError: reduction_to_pole() missing 2 required positional arguments:
'magnetization_inclination' and 'magnetization_declination'

Verification

  • All existing reduction_to_pole tests and gallery/user-guide examples already pass the magnetization angles explicitly (updated in Make the magnetization direction required in RTP #661), so they are unaffected.
  • Added a regression test (test_reduction_to_pole_magnetization_required) asserting the arguments are required; it fails on main (the old cryptic TypeError message does not name the argument) and passes with this change.
  • test/test_transformations.py + test/test_filters.py: 61 passed. ruff check / ruff format --check clean.

PR fatiando#661 (fixing fatiando#440) made the magnetization inclination/declination
required in the reduction_to_pole_kernel and removed the code that filled
in defaults when they were None. However, the public reduction_to_pole
function was missed: it still declared magnetization_inclination=None and
magnetization_declination=None and passed those straight to the kernel.

As a result, the documented default usage
reduction_to_pole(grid, inclination, declination) (omitting the
magnetization direction) crashed deep inside the kernel with a cryptic
'np.radians(None)' TypeError instead of the intended behaviour of
requiring the user to be explicit about the magnetization direction.

Complete fatiando#661 on the public function: make the magnetization arguments
required and drop the stale 'If None ...' docstring text (mirroring the
kernel). Omitting them now raises a clear 'missing required argument'
error at call time. Add a regression test.

Relevant issues/PRs: fatiando#440, fatiando#661
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Source magnetization direction should not be optional in reduction to the pole

1 participant