Skip to content

Commit

Permalink
build: use new unxt api (#85)
Browse files Browse the repository at this point in the history
* build: use new unxt api
* fix: type hint

Signed-off-by: nstarman <[email protected]>
  • Loading branch information
nstarman authored Apr 2, 2024
1 parent 9ecceaa commit c39db99
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
19 changes: 14 additions & 5 deletions src/coordinax/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,18 +583,21 @@ def to_units(self, units: Any) -> "AbstractVectorBase":
usys = unitsystem(units)
return replace(
self,
**{k: v.to(usys[v.unit.physical_type]) for k, v in dataclass_items(self)},
**{
k: v.to_units(usys[v.unit.physical_type])
for k, v in dataclass_items(self)
},
)

@dispatch
def to_units(
self, units: Mapping[u.PhysicalType | str, Unit], /
self, units: Mapping[u.PhysicalType | str, Unit | str], /
) -> "AbstractVectorBase":
"""Convert the vector to the given units.
Parameters
----------
units : Mapping[PhysicalType | str, Unit]
units : Mapping[PhysicalType | str, Unit | str]
The units to convert to according to the physical type of the
components.
Expand Down Expand Up @@ -628,7 +631,10 @@ def to_units(
# Convert to the given units
return replace(
self,
**{k: v.to(units_[v.unit.physical_type]) for k, v in dataclass_items(self)},
**{
k: v.to_units(units_[v.unit.physical_type])
for k, v in dataclass_items(self)
},
)

@dispatch
Expand Down Expand Up @@ -678,7 +684,10 @@ def to_units(

return replace(
self,
**{k: v.to(units_[v.unit.physical_type]) for k, v in dataclass_items(self)},
**{
k: v.to_units(units_[v.unit.physical_type])
for k, v in dataclass_items(self)
},
)

# ===============================================================
Expand Down
2 changes: 1 addition & 1 deletion src/coordinax/operators/_galilean/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class GalileanOperator(AbstractCompositeOperator, AbstractGalileanOperator):
t=Quantity[PhysicalType('time')](value=f32[], unit=Unit("kpc s / km")),
q=Cartesian3DVector( ... )
)
>>> new.t.to("Gyr").value.round(2)
>>> new.t.to_units("Gyr").value.round(2)
Array(2.5, dtype=float32)
>>> new.q.x
Quantity['length'](Array(3.5567803, dtype=float32), unit='kpc')
Expand Down
2 changes: 1 addition & 1 deletion src/coordinax/operators/_galilean/rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def converter(x: Any) -> Array:
if isinstance(x, GalileanRotationOperator):
out = x.rotation
elif isinstance(x, Quantity):
out = x.to_value("")
out = x.to_units_value("")
else:
out = x
return jnp.asarray(out)
Expand Down
2 changes: 1 addition & 1 deletion src/coordinax/operators/_galilean/translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def __call__(self: "GalileanTranslationOperator", x: FourVector, /) -> FourVecto
>>> new.x
Quantity['length'](Array(2., dtype=float32), unit='kpc')
>>> new.t.to("Gyr")
>>> new.t.to_units("Gyr")
Quantity['time'](Array(0.99999994, dtype=float32), unit='Gyr')
"""
Expand Down
8 changes: 4 additions & 4 deletions tests/test_d3.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def test_neg_compare_apy(

# # Try finding the poles
# if hasattr(vector, "theta"):
# sel = (vector.theta.to_value("deg") != 0) & (
# vector.theta.to_value("deg") != 180
# sel = (vector.theta.to_units_value("deg") != 0) & (
# vector.theta.to_units_value("deg") != 180
# )
# else:
# sel = slice(None)
Expand All @@ -49,8 +49,8 @@ def test_neg_compare_apy(
# for c in vecsel.components:
# unit = getattr(apyvecsel, c).unit
# assert np.allclose(
# getattr(vecsel, c).to_value(unit),
# getattr(apyvecsel, c).to_value(unit),
# getattr(vecsel, c).to_units_value(unit),
# getattr(apyvecsel, c).to_units_value(unit),
# atol=5e-7,
# )

Expand Down

0 comments on commit c39db99

Please sign in to comment.