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

feat: parse to_units with unitsystem #77

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Changes from all commits
Commits
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
9 changes: 5 additions & 4 deletions src/coordinax/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from plum import dispatch

import quaxed.array_api as xp
from unxt import Quantity, UnitSystem
from unxt import Quantity, unitsystem

from ._utils import classproperty, dataclass_items, dataclass_values, full_shaped
from coordinax._typing import Unit
Expand Down Expand Up @@ -521,7 +521,7 @@ def components(cls) -> tuple[str, ...]:
return tuple(f.name for f in fields(cls))

@property
def units(self) -> Mapping[str, u.Unit]:
def units(self) -> Mapping[str, Unit]:
"""Get the units of the vector's components."""
return MappingProxyType({k: v.unit for k, v in dataclass_items(self)})

Expand Down Expand Up @@ -554,7 +554,7 @@ def represent_as(self, target: type[BT], /, *args: Any, **kwargs: Any) -> BT:
raise NotImplementedError

@dispatch
def to_units(self, units: UnitSystem) -> "AbstractVectorBase":
def to_units(self, units: Any) -> "AbstractVectorBase":
"""Convert the vector to the given units.

Parameters
Expand All @@ -580,9 +580,10 @@ def to_units(self, units: UnitSystem) -> "AbstractVectorBase":
)

"""
usys = unitsystem(units)
return replace(
self,
**{k: v.to(units[v.unit.physical_type]) for k, v in dataclass_items(self)},
**{k: v.to(usys[v.unit.physical_type]) for k, v in dataclass_items(self)},
)

@dispatch
Expand Down
Loading