Skip to content

GEOPY-2880: Allow EM receiver orientations to be defined as 2D array (per location) - #171

Merged
domfournier merged 3 commits into
developfrom
GEOPY-2880
Aug 24, 2026
Merged

domfournier merged 3 commits into
developfrom
GEOPY-2880

Conversation

@domfournier

@domfournier domfournier commented Aug 19, 2026 •

Copy link
Copy Markdown

GEOPY-2880 - Allow EM receiver orientations to be defined as 2D array (per location)

Copilot AI lite review requested due to automatic review settings August 19, 2026 21:16
@github-actions github-actions Bot changed the title GEOPY-2880 GEOPY-2880: Allow EM receiver orientations to be defined as 2D array (per location) Aug 19, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enables EM receiver orientations to be provided per-location by extending the validate_direction utility to accept 2D arrays and normalize them row-wise.

Changes:

  • Expand validate_direction to accept either a single direction vector or a per-location matrix of direction vectors.
  • Normalize 2D orientation inputs along the last axis.
Suppressed comments (2)

simpeg/utils/code_utils.py:1225

  • The validate_direction docstring still describes obj/return value as a single (dim,) vector, but the implementation now accepts and returns an (n, dim) array (per-location/per-receiver orientations). Updating the docstring will prevent API confusion.
    obj = validate_ndarray_with_shape(

simpeg/utils/code_utils.py:1234

  • This change alters validate_direction semantics (2D inputs are now valid and should be normalized row-wise). The existing unit tests currently assert that a 2D input like [[1, 2, 3]] raises, and there are no tests covering the new (n, dim) behavior (including normalization and error cases like wrong second dimension). Please update/add tests accordingly to lock in the new contract.
    obj = validate_ndarray_with_shape(
        property_name, obj, shape=[(dim,), ("*", 3)], dtype=float
    )

    # Normalize the orientation
    # do this to make a copy of the input
    if obj.ndim > 1:
        return obj / np.linalg.norm(obj, axis=-1)[:, None]
    else:
        return obj / np.linalg.norm(obj)

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread simpeg/utils/code_utils.py
domfournier and others added 2 commits August 19, 2026 14:33
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Comment on lines +1225 to +1234
obj = validate_ndarray_with_shape(
property_name, obj, shape=[(dim,), ("*", dim)], dtype=float
)

# Normalize the orientation
# do this to make a copy of the input
obj = obj / np.linalg.norm(obj)
return obj
if obj.ndim > 1:
return obj / np.linalg.norm(obj, axis=-1)[:, None]
else:
return obj / np.linalg.norm(obj)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this caused a regression - test_direction_validation now fails as [[1, 2, 3]] no longer raises ValueError

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have long abandonned maintaining the tests on simpeg side.

@domfournier
domfournier merged commit ccb3af6 into develop Aug 24, 2026
13 checks passed
@domfournier
domfournier deleted the GEOPY-2880 branch August 24, 2026 17:44
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.

3 participants