Skip to content

Commit

Permalink
✨ feat(frames): new function frame_of
Browse files Browse the repository at this point in the history
  • Loading branch information
nstarman committed Jan 13, 2025
1 parent 7bbb7f3 commit abff519
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/coordinax/_src/frames/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
"NoFrame",
"TransformedReferenceFrame",
"frame_transform_op",
"frame_of",
# Coordinate
"AbstractCoordinate",
"Coordinate",
]

from .api import frame_transform_op
from .api import frame_of, frame_transform_op
from .base import AbstractReferenceFrame
from .coordinate import AbstractCoordinate, Coordinate
from .errors import FrameTransformError
Expand Down
5 changes: 5 additions & 0 deletions src/coordinax/_src/frames/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ def frame_transform_op(
/,
) -> Any:
"""Make a frame transform."""


@dispatch.abstract
def frame_of(obj: Any, /) -> Any:
"""Get the frame of an object."""
19 changes: 19 additions & 0 deletions src/coordinax/_src/frames/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,22 @@ def from_(
raise TypeError(msg)

return obj


# ---------------------------
# Frame API


@dispatch
def frame_of(obj: AbstractReferenceFrame, /) -> AbstractReferenceFrame:
"""Get the frame of an `coordinax.frames.AbstractReferenceFrame`.
Examples
--------
>>> import coordinax.frames as cxf
>>> frame = cxf.ICRS()
>>> frame_of(frame) is frame
True
"""
return obj
17 changes: 17 additions & 0 deletions src/coordinax/_src/frames/coordinate.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,23 @@ def __str__(self) -> str:
return f"{type(self).__name__}(\n{str_fs}\n)"


@dispatch
def frame_of(obj: AbstractCoordinate) -> AbstractReferenceFrame:
"""Return the frame of the coordinate.
Examples
--------
>>> import coordinax as cx
>>> coord = cx.Coordinate(cx.CartesianPos3D.from_([1, 2, 3], "kpc"),
... cx.frames.ICRS())
>>> cx.frame_of(coord)
ICRS()

Check failure on line 137 in src/coordinax/_src/frames/coordinate.py

View workflow job for this annotation

GitHub Actions / Check Oldest Dependencies (3.11, ubuntu-latest)

coordinate.py line=136 column=1

Check failure on line 137 in src/coordinax/_src/frames/coordinate.py

View workflow job for this annotation

GitHub Actions / Check Python 3.11 on ubuntu-latest

coordinate.py line=136 column=1

Check failure on line 137 in src/coordinax/_src/frames/coordinate.py

View workflow job for this annotation

GitHub Actions / Check Python 3.11 on macos-latest

coordinate.py line=136 column=1

Check failure on line 137 in src/coordinax/_src/frames/coordinate.py

View workflow job for this annotation

GitHub Actions / Check Python 3.12 on ubuntu-latest

coordinate.py line=136 column=1

Check failure on line 137 in src/coordinax/_src/frames/coordinate.py

View workflow job for this annotation

GitHub Actions / Check Python 3.12 on macos-latest

coordinate.py line=136 column=1

Check failure on line 137 in src/coordinax/_src/frames/coordinate.py

View workflow job for this annotation

GitHub Actions / Check Python 3.13 on ubuntu-latest

coordinate.py line=136 column=1

Check failure on line 137 in src/coordinax/_src/frames/coordinate.py

View workflow job for this annotation

GitHub Actions / Check Python 3.13 on macos-latest

coordinate.py line=136 column=1
"""
return obj.frame


##############################################################################


Expand Down
2 changes: 2 additions & 0 deletions src/coordinax/frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"NoFrame",
"TransformedReferenceFrame",
"frame_transform_op",
"frame_of",
# Coordinates
"AbstractCoordinate",
"Coordinate",
Expand All @@ -65,6 +66,7 @@
FrameTransformError,
NoFrame,
TransformedReferenceFrame,
frame_of,
frame_transform_op,
)

Expand Down

0 comments on commit abff519

Please sign in to comment.