Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement RoI Interactions with Points #395

Closed
wants to merge 29 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2aa3df5
Create RoI base skeleton
willGraham01 Jan 27, 2025
5ce2a33
Write 1D and 2D ROI classes
willGraham01 Jan 27, 2025
588df0b
Write some basic instantiation tests
willGraham01 Jan 27, 2025
b69cc71
Pre-commit lint
willGraham01 Jan 27, 2025
19798e5
Fix polygon boundary attributes, return our wrappers instead
willGraham01 Jan 27, 2025
33031e8
Write methods for automating broadcasts across space dimension of xar…
willGraham01 Jan 28, 2025
7169beb
Fix mypy typing
willGraham01 Jan 28, 2025
8f3d5e8
Ignore mypy typehint bugs (it can't cope with additional kwargs being…
willGraham01 Jan 28, 2025
b637037
Fix classmethods not being extendable
willGraham01 Jan 29, 2025
2efe064
Preserve wrapped function docstrings
willGraham01 Jan 29, 2025
3743860
Will is learning markdown != rst
willGraham01 Jan 29, 2025
c0e4a14
Use xr.apply_ufunc
willGraham01 Jan 30, 2025
3eff3d3
Tidy some docstring explanations
willGraham01 Jan 30, 2025
066fafe
Will still doesn't know rst
willGraham01 Jan 30, 2025
fa28685
Allow make_broadcastable to preserve old function call behaviour
willGraham01 Jan 30, 2025
85e9d99
Merge branch 'wgraham-broadcasting-decorator' into wgraham-roi-is-inside
willGraham01 Jan 31, 2025
47148dc
Write in_inside method for determining if points are included in regi…
willGraham01 Jan 29, 2025
8da0835
SonarQ analysis recommendations
willGraham01 Jan 29, 2025
021abba
More informative name
willGraham01 Jan 29, 2025
62bee38
Missed an unused variable
willGraham01 Jan 29, 2025
28494ac
Update test that used default values
willGraham01 Jan 29, 2025
4bcb925
Docstring linting
willGraham01 Jan 31, 2025
ec460ad
Write in_inside method for determining if points are included in regi…
willGraham01 Jan 29, 2025
a715ef0
nearest point to template, but want to preserve original methods
willGraham01 Jan 30, 2025
a023fe8
Write test for nearest_point_to
willGraham01 Jan 30, 2025
4bda7ef
Write distance_to method
willGraham01 Jan 30, 2025
b773ce1
Add tests for distance_to method
willGraham01 Jan 30, 2025
a41e468
Write vector_to method
willGraham01 Jan 30, 2025
114cffe
Remove file that reappeared during rebase
willGraham01 Jan 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Allow make_broadcastable to preserve old function call behaviour
willGraham01 committed Jan 31, 2025
commit fa28685575b9b69b447ae6d42e90befd3acbb9a2
10 changes: 9 additions & 1 deletion movement/utils/broadcasting.py
Original file line number Diff line number Diff line change
@@ -174,7 +174,9 @@ def make_broadcastable( # noqa: C901
where the ``self`` argument is present only if ``f`` was a class method.
``fr`` applies ``f`` along the ``broadcast_dimension`` of ``data``.
The ``\*args`` and ``\*\*kwargs`` match those passed to ``f``, and retain
the same interpretations and effects on the result.
the same interpretations and effects on the result. If ``data`` provided to
``fr`` is not an ``xarray.DataArray``, it will fall back on the behaviour
of ``f`` (and ignore the ``broadcast_dimension`` argument).
See the docstring of ``make_broadcastable_inner`` in the source code for a
more explicit explanation of the returned decorator.
@@ -268,6 +270,9 @@ def inner_clsmethod( # type: ignore[valid-type]
broadcast_dimension: str = "space",
**kwargs: KeywordArgs.kwargs,
) -> xr.DataArray:
# Preserve original functionality
if not isinstance(data, xr.DataArray):
return f(self, data, *args, **kwargs)
return apply_along_da_axis(
lambda input_1D: f(self, input_1D, *args, **kwargs),
data,
@@ -297,6 +302,9 @@ def inner( # type: ignore[valid-type]
broadcast_dimension: str = "space",
**kwargs: KeywordArgs.kwargs,
) -> xr.DataArray:
# Preserve original functionality
if not isinstance(data, xr.DataArray):
return f(data, *args, **kwargs)
return apply_along_da_axis(
lambda input_1D: f(input_1D, *args, **kwargs),
data,
22 changes: 22 additions & 0 deletions tests/test_unit/test_make_broadcastable.py
Original file line number Diff line number Diff line change
@@ -241,3 +241,25 @@ def two_to_some(xy_pair) -> np.ndarray:
else:
assert d in mock_dataset.dims
assert len(output[d]) == len(mock_dataset[d])


def test_retain_underlying_function() -> None:
value_for_arg = 5.0
value_for_kwarg = 7.0
value_for_simple_input = [0.0, 1.0, 2.0]

def simple_function(input_1D, arg, kwarg=3.0):
return arg * sum(input_1D) + kwarg

@make_broadcastable()
def simple_function_broadcastable(input_1D, arg, kwarg=3.0):
return simple_function(input_1D, arg, kwarg=kwarg)

result_from_broadcastable = simple_function_broadcastable(
value_for_simple_input, value_for_arg, kwarg=value_for_kwarg
)
result_from_original = simple_function(
value_for_simple_input, value_for_arg, kwarg=value_for_kwarg
)
assert isinstance(result_from_broadcastable, float)
assert np.isclose(result_from_broadcastable, result_from_original)