Skip to content

Commit

Permalink
feat: distance modulus
Browse files Browse the repository at this point in the history
Signed-off-by: nstarman <nstarman@users.noreply.github.com>
  • Loading branch information
nstarman committed Jul 8, 2024
1 parent 2977ff0 commit 08febd1
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions src/unxt/_quantity/distance.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# pylint: disable=import-error, no-member, unsubscriptable-object
# b/c it doesn't understand dataclass fields

__all__ = ["AbstractDistance", "Distance", "Parallax"]
__all__ = ["AbstractDistance", "Distance", "Parallax", "DistanceModulus"]

from abc import abstractmethod
from dataclasses import KW_ONLY
Expand Down Expand Up @@ -143,7 +143,35 @@ def parallax(self) -> "Parallax":
@property
def distance_modulus(self) -> Quantity:
"""The distance modulus."""
return self.distance.distance_modulus # TODO: shortcut
return self.distance.distance_modulus # TODO: specific shortcut

Check warning on line 146 in src/unxt/_quantity/distance.py

View check run for this annotation

Codecov / codecov/patch

src/unxt/_quantity/distance.py#L146

Added line #L146 was not covered by tests


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


class DistanceModulus(AbstractDistance):
"""Distance modulus quantity."""

def __check_init__(self) -> None:
"""Check the initialization."""
if self.unit != u.mag:
msg = "Distance modulus must have units of magnitude."
raise ValueError(msg)

Check warning on line 159 in src/unxt/_quantity/distance.py

View check run for this annotation

Codecov / codecov/patch

src/unxt/_quantity/distance.py#L157-L159

Added lines #L157 - L159 were not covered by tests

@property
def distance(self) -> Distance:
"""The distance."""
return Distance(10 ** (self.value / 5 + 1), "pc")

Check warning on line 164 in src/unxt/_quantity/distance.py

View check run for this annotation

Codecov / codecov/patch

src/unxt/_quantity/distance.py#L164

Added line #L164 was not covered by tests

@property
def parallax(self) -> Parallax:
"""The parallax."""
return self.distance.parallax # TODO: specific shortcut

Check warning on line 169 in src/unxt/_quantity/distance.py

View check run for this annotation

Codecov / codecov/patch

src/unxt/_quantity/distance.py#L169

Added line #L169 was not covered by tests

@property
def distance_modulus(self) -> "DistanceModulus":
"""The distance modulus."""
return self

Check warning on line 174 in src/unxt/_quantity/distance.py

View check run for this annotation

Codecov / codecov/patch

src/unxt/_quantity/distance.py#L174

Added line #L174 was not covered by tests


# ============================================================================
Expand All @@ -159,6 +187,19 @@ def constructor(
return cls(xp.asarray(d.value, dtype=dtype), d.unit)


@Distance.constructor._f.register # type: ignore[no-redef] # noqa: SLF001
def constructor(
cls: type[Distance],
value: DistanceModulus | Quantity["mag"],
/,
*,
dtype: Any = None,
) -> Distance:
"""Construct a `Distance` from a mag through the dist mod."""
d = 10 ** (value.to_units_value("mag") / 5 + 1)
return cls(xp.asarray(d, dtype=dtype), "pc")

Check warning on line 200 in src/unxt/_quantity/distance.py

View check run for this annotation

Codecov / codecov/patch

src/unxt/_quantity/distance.py#L199-L200

Added lines #L199 - L200 were not covered by tests


@Parallax.constructor._f.register # type: ignore[no-redef] # noqa: SLF001
def constructor(
cls: type[Parallax], value: Distance | Quantity["length"], /, *, dtype: Any = None
Expand Down

0 comments on commit 08febd1

Please sign in to comment.