harv 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- harv/__init__.py +64 -0
- harv/_version.py +24 -0
- harv/custom_types.py +91 -0
- harv/data/__init__.py +28 -0
- harv/data/containers.py +351 -0
- harv/data/datasets.py +334 -0
- harv/data/helpers.py +182 -0
- harv/distributions.py +81 -0
- harv/io.py +70 -0
- harv/kepler/__init__.py +38 -0
- harv/kepler/body.py +267 -0
- harv/kepler/constants.py +8 -0
- harv/kepler/masses.py +197 -0
- harv/kepler/nbody_system.py +156 -0
- harv/kepler/orbits.py +505 -0
- harv/kepler/orientation.py +283 -0
- harv/models/__init__.py +40 -0
- harv/models/_helpers.py +121 -0
- harv/models/astrometry.py +162 -0
- harv/models/component.py +980 -0
- harv/models/extensions/__init__.py +16 -0
- harv/models/extensions/base.py +142 -0
- harv/models/extensions/gp.py +136 -0
- harv/models/extensions/jitter.py +65 -0
- harv/models/extensions/multi_survey.py +76 -0
- harv/models/extensions/trend.py +107 -0
- harv/models/joint.py +1408 -0
- harv/models/parameterizations/__init__.py +19 -0
- harv/models/parameterizations/_base.py +103 -0
- harv/models/parameterizations/gaia.py +702 -0
- harv/models/parameterizations/rv.py +309 -0
- harv/models/priors/__init__.py +15 -0
- harv/models/priors/custom_priors.py +255 -0
- harv/models/priors/defaults.py +131 -0
- harv/models/priors/helpers.py +169 -0
- harv/models/priors/prior.py +178 -0
- harv/models/rv.py +135 -0
- harv/plot.py +1265 -0
- harv/samplers/__init__.py +24 -0
- harv/samplers/base.py +81 -0
- harv/samplers/conversion.py +209 -0
- harv/samplers/numpyro.py +1076 -0
- harv/samplers/rejection.py +691 -0
- harv/samplers/samples.py +1583 -0
- harv/simulate/__init__.py +14 -0
- harv/simulate/astrometry.py +332 -0
- harv/simulate/rv.py +311 -0
- harv/simulate/scanlaw.py +124 -0
- harv-0.0.1.dist-info/METADATA +206 -0
- harv-0.0.1.dist-info/RECORD +52 -0
- harv-0.0.1.dist-info/WHEEL +4 -0
- harv-0.0.1.dist-info/licenses/LICENSE +21 -0
harv/__init__.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""harv: Tools for inferring Keplerian orbital parameters.
|
|
2
|
+
|
|
3
|
+
A JAX-based package for modeling binary-star and star-exoplanet systems with time series
|
|
4
|
+
data, such as Gaia DR4 epoch astrometry and radial velocities. The package is units
|
|
5
|
+
aware via unxt, supports probabilistic modeling with numpyro, and provides flexible
|
|
6
|
+
Keplerian orbit frameworks for single and multi-body systems.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
# TODO: need to figure out what is available at top level. Gut feeling is we leave
|
|
10
|
+
# harv.io things as harv.io.load_sampler and harv.plot.plot_rv, and Abstract classes
|
|
11
|
+
# should be under harv.models, but what should be accessible at top level?
|
|
12
|
+
__all__ = (
|
|
13
|
+
# Data containers
|
|
14
|
+
"GaiaAstrometryData",
|
|
15
|
+
"RVData",
|
|
16
|
+
"SourceData",
|
|
17
|
+
# Distributions
|
|
18
|
+
"QD",
|
|
19
|
+
"QuantityDistribution",
|
|
20
|
+
# Models API
|
|
21
|
+
"GaiaAstrometryModel",
|
|
22
|
+
"JointModel",
|
|
23
|
+
"ParamInfo",
|
|
24
|
+
"RVModel",
|
|
25
|
+
# Samplers
|
|
26
|
+
"AbstractSampler",
|
|
27
|
+
"NumpyroSampler",
|
|
28
|
+
"HarvPrior",
|
|
29
|
+
"RejectionSampler",
|
|
30
|
+
"Samples",
|
|
31
|
+
# Modules:
|
|
32
|
+
"data",
|
|
33
|
+
"plot",
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
from harv.data import GaiaAstrometryData, RVData, SourceData
|
|
37
|
+
from harv.distributions import QD, QuantityDistribution
|
|
38
|
+
from harv.models.extensions import (
|
|
39
|
+
AbstractExtension,
|
|
40
|
+
GP,
|
|
41
|
+
Jitter,
|
|
42
|
+
MultiSurveyOffset,
|
|
43
|
+
ParamInfo,
|
|
44
|
+
MonomialTrend,
|
|
45
|
+
)
|
|
46
|
+
from harv.models import (
|
|
47
|
+
AbstractComponentModel,
|
|
48
|
+
AbstractParameterization,
|
|
49
|
+
EcoswEsinwRV,
|
|
50
|
+
GaiaAstrometryModel,
|
|
51
|
+
JointModel,
|
|
52
|
+
RVModel,
|
|
53
|
+
StandardGaiaAstrometry,
|
|
54
|
+
StandardRV,
|
|
55
|
+
HarvPrior,
|
|
56
|
+
)
|
|
57
|
+
from harv.samplers import (
|
|
58
|
+
AbstractSampler,
|
|
59
|
+
NumpyroSampler,
|
|
60
|
+
RejectionSampler,
|
|
61
|
+
Samples,
|
|
62
|
+
)
|
|
63
|
+
from harv import data
|
|
64
|
+
from harv import plot
|
harv/_version.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# file generated by vcs-versioning
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"__version__",
|
|
7
|
+
"__version_tuple__",
|
|
8
|
+
"version",
|
|
9
|
+
"version_tuple",
|
|
10
|
+
"__commit_id__",
|
|
11
|
+
"commit_id",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
version: str
|
|
15
|
+
__version__: str
|
|
16
|
+
__version_tuple__: tuple[int | str, ...]
|
|
17
|
+
version_tuple: tuple[int | str, ...]
|
|
18
|
+
commit_id: str | None
|
|
19
|
+
__commit_id__: str | None
|
|
20
|
+
|
|
21
|
+
__version__ = version = '0.0.1'
|
|
22
|
+
__version_tuple__ = version_tuple = (0, 0, 1)
|
|
23
|
+
|
|
24
|
+
__commit_id__ = commit_id = None
|
harv/custom_types.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"""Custom types used in harv."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, Literal
|
|
4
|
+
|
|
5
|
+
import jax
|
|
6
|
+
import numpy as np
|
|
7
|
+
from jaxtyping import Float, Int, Real
|
|
8
|
+
from unxt import AbstractQuantity, Q
|
|
9
|
+
from unxt.quantity import AllowValue, ustrip
|
|
10
|
+
|
|
11
|
+
Angle = Literal["angle"]
|
|
12
|
+
AngularSpeed = Literal["angular_speed"]
|
|
13
|
+
Length = Literal["length"]
|
|
14
|
+
Mass = Literal["mass"]
|
|
15
|
+
Speed = Literal["speed"]
|
|
16
|
+
Time = Literal["time"]
|
|
17
|
+
Dimless = Literal["dimensionless"]
|
|
18
|
+
|
|
19
|
+
QAngle = Q["angle"]
|
|
20
|
+
QAngularSpeed = Q["angular_speed"]
|
|
21
|
+
QDimless = Q["dimensionless"]
|
|
22
|
+
QLength = Q["length"]
|
|
23
|
+
QMass = Q["mass"]
|
|
24
|
+
QSpeed = Q["speed"]
|
|
25
|
+
QTime = Q["time"]
|
|
26
|
+
|
|
27
|
+
ScalarQAngle = Real[Q["angle"], ""]
|
|
28
|
+
ScalarQAngularSpeed = Real[Q["angular_speed"], ""]
|
|
29
|
+
ScalarQDimless = Real[Q["dimensionless"], ""]
|
|
30
|
+
ScalarQLength = Real[Q["length"], ""]
|
|
31
|
+
ScalarQMass = Real[Q["mass"], ""]
|
|
32
|
+
ScalarQSpeed = Real[Q["speed"], ""]
|
|
33
|
+
ScalarQTime = Real[Q["time"], ""]
|
|
34
|
+
ScalarQAny = Real[AbstractQuantity, ""]
|
|
35
|
+
|
|
36
|
+
NAngle = Real[Q["angle"], "n"]
|
|
37
|
+
NDimless = Real[Q["dimensionless"], "n"]
|
|
38
|
+
NTime = Real[Q["time"], "n"]
|
|
39
|
+
NVelocity = Real[Q["speed"], "n"]
|
|
40
|
+
NFloatArray = Float[jax.Array, "n"]
|
|
41
|
+
NIntArray = Int[jax.Array, "n"]
|
|
42
|
+
NQAny = Real[AbstractQuantity, ""]
|
|
43
|
+
|
|
44
|
+
Vec3QLength = Real[Q["length"], "3"]
|
|
45
|
+
Vec3QSpeed = Real[Q["speed"], "3"]
|
|
46
|
+
|
|
47
|
+
BatchVec3QLength = Real[Q["length"], "3 *batch"]
|
|
48
|
+
BatchVec3QSpeed = Real[Q["speed"], "3 *batch"]
|
|
49
|
+
|
|
50
|
+
BatchQAngle = Real[Q["angle"], "*batch"]
|
|
51
|
+
BatchQAngularSpeed = Real[Q["angular_speed"], "*batch"]
|
|
52
|
+
BatchQDimless = Real[Q["dimensionless"], "*batch"]
|
|
53
|
+
BatchQLength = Real[Q["length"], "*batch"]
|
|
54
|
+
BatchQMass = Real[Q["mass"], "*batch"]
|
|
55
|
+
BatchQSpeed = Real[Q["speed"], "*batch"]
|
|
56
|
+
BatchQTime = Real[Q["time"], "*batch"]
|
|
57
|
+
BatchFloat = Float[jax.Array, "*batch"] | BatchQDimless
|
|
58
|
+
BatchQAny = Real[AbstractQuantity, "*batch"]
|
|
59
|
+
|
|
60
|
+
# Set of all Batch-level Quantity types that carry physical dimensions.
|
|
61
|
+
# Used by AbstractParameters.__init_subclass__ to auto-detect which fields
|
|
62
|
+
# require a QDistribution prior.
|
|
63
|
+
DIMENSIONED_BATCH_TYPES: frozenset[Any] = frozenset(
|
|
64
|
+
{
|
|
65
|
+
BatchQAngle,
|
|
66
|
+
BatchQAngularSpeed,
|
|
67
|
+
BatchQLength,
|
|
68
|
+
BatchQSpeed,
|
|
69
|
+
BatchQTime,
|
|
70
|
+
}
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
ScalarFloat = Float[jax.Array, ""] | np.floating[Any] | float | int | ScalarQDimless
|
|
74
|
+
|
|
75
|
+
# Like ScalarFloat but shape-agnostic (a strict superset): plain Python/NumPy
|
|
76
|
+
# scalars, JAX arrays of any rank, or dimensionless Quantities of any rank.
|
|
77
|
+
# Use for shape-agnostic building blocks that broadcast over scalar or batched
|
|
78
|
+
# inputs (see docs/spec.md, "Shared building blocks").
|
|
79
|
+
BatchFloatLike = (
|
|
80
|
+
Float[jax.Array, "*batch"] | np.floating[Any] | float | int | BatchQDimless
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def float_converter(x: ScalarFloat) -> Float[jax.Array, ""]:
|
|
85
|
+
"""Converter for dimensionless scalar float fields.
|
|
86
|
+
|
|
87
|
+
Strips units from a dimensionless quantity or passes through plain scalars,
|
|
88
|
+
always producing a 0-d JAX array. Use as an ``eqx.field`` converter wherever
|
|
89
|
+
a dimensionless scalar is stored internally as a plain JAX float.
|
|
90
|
+
"""
|
|
91
|
+
return ustrip(AllowValue, "", x)
|
harv/data/__init__.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""Data classes for representing time series data.
|
|
2
|
+
|
|
3
|
+
TODO: we could add support for metadata for the data type classes below.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
__all__ = (
|
|
7
|
+
"AbstractAstrometryData",
|
|
8
|
+
"AbstractData",
|
|
9
|
+
"DatasetType",
|
|
10
|
+
"GaiaAstrometryData",
|
|
11
|
+
# "AbsoluteAstrometryData",
|
|
12
|
+
"InputData",
|
|
13
|
+
"RVData",
|
|
14
|
+
"SourceData",
|
|
15
|
+
"SystemData",
|
|
16
|
+
"build_indicator_matrix",
|
|
17
|
+
"stack_datasets",
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
from .containers import InputData, SourceData, SystemData
|
|
21
|
+
from .datasets import (
|
|
22
|
+
AbstractAstrometryData,
|
|
23
|
+
AbstractData,
|
|
24
|
+
DatasetType,
|
|
25
|
+
GaiaAstrometryData,
|
|
26
|
+
RVData,
|
|
27
|
+
)
|
|
28
|
+
from .helpers import build_indicator_matrix, stack_datasets
|
harv/data/containers.py
ADDED
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
"""Dataset containers for multi-component and multi-instrument data."""
|
|
2
|
+
|
|
3
|
+
__all__ = (
|
|
4
|
+
"AbstractDatasetContainer",
|
|
5
|
+
"DatasetType",
|
|
6
|
+
"InputData",
|
|
7
|
+
"SourceData",
|
|
8
|
+
"SystemData",
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
from collections.abc import Iterator
|
|
12
|
+
from typing import Any, TypeVar, cast
|
|
13
|
+
|
|
14
|
+
import equinox as eqx
|
|
15
|
+
import jax
|
|
16
|
+
|
|
17
|
+
from harv.custom_types import ScalarQTime
|
|
18
|
+
from harv.data.datasets import (
|
|
19
|
+
AbstractAstrometryData,
|
|
20
|
+
AbstractData,
|
|
21
|
+
DatasetType,
|
|
22
|
+
RVData,
|
|
23
|
+
)
|
|
24
|
+
from harv.data.helpers import (
|
|
25
|
+
_synchronize_t_refs,
|
|
26
|
+
build_indicator_matrix,
|
|
27
|
+
stack_datasets,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
_DT = TypeVar("_DT", bound=DatasetType)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class AbstractDatasetContainer(eqx.Module):
|
|
34
|
+
"""Base class providing a dict-like interface over named datasets.
|
|
35
|
+
|
|
36
|
+
Subclasses (SystemData, SourceData) share this common interface but carry different
|
|
37
|
+
semantic meaning.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
_datasets: dict[str, DatasetType]
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
def t_ref(self) -> ScalarQTime | None:
|
|
44
|
+
"""Reference epoch shared by all contained datasets.
|
|
45
|
+
|
|
46
|
+
Guaranteed to be consistent across components because every concrete
|
|
47
|
+
subclass calls :func:`~harv.data.helpers._synchronize_t_refs` in its
|
|
48
|
+
``__init__``.
|
|
49
|
+
"""
|
|
50
|
+
return next(iter(self._datasets.values())).t_ref
|
|
51
|
+
|
|
52
|
+
def __getitem__(self, name: str) -> DatasetType:
|
|
53
|
+
return self._datasets[name]
|
|
54
|
+
|
|
55
|
+
def __contains__(self, name: str) -> bool:
|
|
56
|
+
return name in self._datasets
|
|
57
|
+
|
|
58
|
+
def __len__(self) -> int:
|
|
59
|
+
return len(self._datasets)
|
|
60
|
+
|
|
61
|
+
def keys(self) -> Iterator[str]:
|
|
62
|
+
"""Dataset/component names."""
|
|
63
|
+
return iter(self._datasets.keys())
|
|
64
|
+
|
|
65
|
+
def values(self) -> Iterator[DatasetType]:
|
|
66
|
+
"""Dataset/component values."""
|
|
67
|
+
return iter(self._datasets.values())
|
|
68
|
+
|
|
69
|
+
def items(self) -> Iterator[tuple[str, DatasetType]]:
|
|
70
|
+
"""(name, dataset) pairs."""
|
|
71
|
+
return iter(self._datasets.items())
|
|
72
|
+
|
|
73
|
+
def get_datasets_by_type(self, data_type: type[_DT]) -> dict[str, _DT]:
|
|
74
|
+
"""Get all datasets/components of a specific data type.
|
|
75
|
+
|
|
76
|
+
Parameters
|
|
77
|
+
----------
|
|
78
|
+
data_type
|
|
79
|
+
Concrete data class (e.g. RVData, GaiaAstrometryData) to filter by.
|
|
80
|
+
|
|
81
|
+
Examples
|
|
82
|
+
--------
|
|
83
|
+
>>> from harv.data.datasets import RVData, GaiaAstrometryData
|
|
84
|
+
>>> from harv.data.containers import SourceData
|
|
85
|
+
>>> source_data = SourceData( # doctest: +SKIP
|
|
86
|
+
... keck_rv=RVData(...),
|
|
87
|
+
... gaia=GaiaAstrometryData(...),
|
|
88
|
+
... )
|
|
89
|
+
>>> source_data.get_datasets_by_type(RVData) # doctest: +SKIP
|
|
90
|
+
{'keck_rv': RVData(...)}
|
|
91
|
+
>>> source_data.get_datasets_by_type(GaiaAstrometryData) # doctest: +SKIP
|
|
92
|
+
{'gaia': GaiaAstrometryData(...)}
|
|
93
|
+
"""
|
|
94
|
+
return {k: v for k, v in self._datasets.items() if isinstance(v, data_type)}
|
|
95
|
+
|
|
96
|
+
def _require_datasets_by_type(self, data_type: type[_DT]) -> dict[str, _DT]:
|
|
97
|
+
"""Like get_datasets_by_type but raises if no datasets of the requested type."""
|
|
98
|
+
datasets = self.get_datasets_by_type(data_type)
|
|
99
|
+
if not datasets:
|
|
100
|
+
msg = f"No datasets of type {data_type.__name__} found"
|
|
101
|
+
raise ValueError(msg)
|
|
102
|
+
return datasets
|
|
103
|
+
|
|
104
|
+
def stacked_by_type(self, data_type: type[_DT]) -> _DT:
|
|
105
|
+
"""Stack all datasets of the requested type.
|
|
106
|
+
|
|
107
|
+
Parameters
|
|
108
|
+
----------
|
|
109
|
+
data_type
|
|
110
|
+
Concrete data class (e.g. RVData, GaiaAstrometryData) to filter by before
|
|
111
|
+
stacking.
|
|
112
|
+
|
|
113
|
+
Examples
|
|
114
|
+
--------
|
|
115
|
+
>>> from harv.data.datasets import RVData, GaiaAstrometryData
|
|
116
|
+
>>> from harv.data.containers import SourceData
|
|
117
|
+
>>> source_data = SourceData( # doctest: +SKIP
|
|
118
|
+
... keck_rv=RVData(...),
|
|
119
|
+
... wiyn_rv=RVData(...),
|
|
120
|
+
... gaia=GaiaAstrometryData(...),
|
|
121
|
+
... )
|
|
122
|
+
>>> source_data.stacked_by_type(RVData) # doctest: +SKIP
|
|
123
|
+
RVData(...)
|
|
124
|
+
"""
|
|
125
|
+
return stack_datasets(self._require_datasets_by_type(data_type))
|
|
126
|
+
|
|
127
|
+
def indicator_data_by_type(
|
|
128
|
+
self,
|
|
129
|
+
data_type: type[_DT],
|
|
130
|
+
reference: str,
|
|
131
|
+
) -> tuple[_DT, jax.Array | None, tuple[str, ...] | None]:
|
|
132
|
+
"""Return stacked data and indicator flags for one dataset type.
|
|
133
|
+
|
|
134
|
+
This is a convenience wrapper around get_datasets_by_type +
|
|
135
|
+
build_indicator_matrix for use in extensions that need to build a kernel matrix
|
|
136
|
+
across multiple datasets of the same type (e.g. multiple RV instruments).
|
|
137
|
+
|
|
138
|
+
Parameters
|
|
139
|
+
----------
|
|
140
|
+
data_type
|
|
141
|
+
Concrete data class (e.g. RVData, GaiaAstrometryData) to filter by before
|
|
142
|
+
stacking.
|
|
143
|
+
reference
|
|
144
|
+
Name of the reference dataset to use for time coordinates and metadata. Must
|
|
145
|
+
be one of the keys in the returned dict from
|
|
146
|
+
get_datasets_by_type(data_type).
|
|
147
|
+
"""
|
|
148
|
+
datasets = self._require_datasets_by_type(data_type)
|
|
149
|
+
stacked, indicator, names = build_indicator_matrix(datasets, reference)
|
|
150
|
+
return stacked, indicator, names
|
|
151
|
+
|
|
152
|
+
def plot(
|
|
153
|
+
self,
|
|
154
|
+
ax: Any = None,
|
|
155
|
+
*,
|
|
156
|
+
add_legend: bool = True,
|
|
157
|
+
color_cycler: Any = None,
|
|
158
|
+
**kwargs: Any,
|
|
159
|
+
) -> Any:
|
|
160
|
+
"""Plot all contained datasets on the same axes.
|
|
161
|
+
|
|
162
|
+
Dispatches to each dataset's ``.plot()`` method, drawing all components onto a
|
|
163
|
+
single axes panel with a legend showing the names. Each dataset is assigned a
|
|
164
|
+
distinct color from ``color_cycler`` (or the current ``axes.prop_cycle`` when
|
|
165
|
+
not specified).
|
|
166
|
+
|
|
167
|
+
This base implementation does not check that the contained datasets share a
|
|
168
|
+
concrete type; concrete subclasses are responsible for any preconditions
|
|
169
|
+
(:class:`SystemData` enforces homogeneity at construction; :class:`SourceData`
|
|
170
|
+
validates at call time).
|
|
171
|
+
|
|
172
|
+
Parameters
|
|
173
|
+
----------
|
|
174
|
+
ax
|
|
175
|
+
The :class:`matplotlib.axes.Axes` instance to draw on. If ``None``, a new
|
|
176
|
+
figure is created.
|
|
177
|
+
add_legend
|
|
178
|
+
Whether to add a legend labelled by component name. Default: ``True``.
|
|
179
|
+
color_cycler
|
|
180
|
+
A ``cycler.Cycler`` whose ``"color"`` key supplies per-component colors.
|
|
181
|
+
When ``None`` (default), colors are taken from the current
|
|
182
|
+
``axes.prop_cycle`` rcParam.
|
|
183
|
+
**kwargs
|
|
184
|
+
Forwarded to each component's ``.plot()`` method. A ``color``
|
|
185
|
+
keyword here overrides the cycler for all components.
|
|
186
|
+
|
|
187
|
+
Returns
|
|
188
|
+
-------
|
|
189
|
+
The :class:`matplotlib.axes.Axes` instance.
|
|
190
|
+
|
|
191
|
+
Examples
|
|
192
|
+
--------
|
|
193
|
+
>>> import matplotlib.pyplot as plt
|
|
194
|
+
>>> from unxt import Q
|
|
195
|
+
>>> from harv import RVData
|
|
196
|
+
>>> from harv.data.containers import SystemData
|
|
197
|
+
>>> sys_data = SystemData(
|
|
198
|
+
... primary=RVData(
|
|
199
|
+
... time=Q([0.0, 50.0], "day"),
|
|
200
|
+
... rv=Q([10.0, -10.0], "km/s"),
|
|
201
|
+
... rv_err=Q([0.5, 0.5], "km/s"),
|
|
202
|
+
... ),
|
|
203
|
+
... secondary=RVData(
|
|
204
|
+
... time=Q([0.0, 50.0], "day"),
|
|
205
|
+
... rv=Q([-10.0, 10.0], "km/s"),
|
|
206
|
+
... rv_err=Q([0.5, 0.5], "km/s"),
|
|
207
|
+
... ),
|
|
208
|
+
... )
|
|
209
|
+
>>> ax = sys_data.plot()
|
|
210
|
+
>>> plt.close("all")
|
|
211
|
+
"""
|
|
212
|
+
import matplotlib.pyplot as plt # noqa: PLC0415
|
|
213
|
+
|
|
214
|
+
if ax is None:
|
|
215
|
+
_, ax = plt.subplots()
|
|
216
|
+
|
|
217
|
+
if "color" not in kwargs:
|
|
218
|
+
if color_cycler is not None:
|
|
219
|
+
colors = list(color_cycler.by_key()["color"])
|
|
220
|
+
else:
|
|
221
|
+
colors = plt.rcParams["axes.prop_cycle"].by_key()["color"]
|
|
222
|
+
else:
|
|
223
|
+
colors = None
|
|
224
|
+
|
|
225
|
+
for i, (name, ds) in enumerate(self._datasets.items()):
|
|
226
|
+
per_ds: dict[str, Any] = {}
|
|
227
|
+
if colors is not None:
|
|
228
|
+
per_ds["color"] = colors[i % len(colors)]
|
|
229
|
+
ds.plot( # ty: ignore[unresolved-attribute]
|
|
230
|
+
ax=ax, add_labels=(i == 0), label=name, **per_ds, **kwargs
|
|
231
|
+
)
|
|
232
|
+
|
|
233
|
+
if add_legend:
|
|
234
|
+
ax.legend()
|
|
235
|
+
|
|
236
|
+
return ax
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
class SystemData(AbstractDatasetContainer):
|
|
240
|
+
"""Container for a multi-component system.
|
|
241
|
+
|
|
242
|
+
Each named component holds the same concrete data class representing observations of
|
|
243
|
+
a distinct physical body or photocenter in a gravitationally bound system.
|
|
244
|
+
"""
|
|
245
|
+
|
|
246
|
+
_dataset_type: type[AbstractData] = eqx.field(static=True)
|
|
247
|
+
|
|
248
|
+
def __init__(self, **datasets: DatasetType) -> None:
|
|
249
|
+
if not datasets:
|
|
250
|
+
raise ValueError("At least one component must be provided")
|
|
251
|
+
|
|
252
|
+
type_map: dict[str, str] = {}
|
|
253
|
+
for name, ds in datasets.items():
|
|
254
|
+
if not isinstance(ds, AbstractData):
|
|
255
|
+
raise TypeError(
|
|
256
|
+
f"Component '{name}' must be an AbstractData subclass "
|
|
257
|
+
f"(RVData, GaiaAstrometryData, ...), got {type(ds).__name__}"
|
|
258
|
+
)
|
|
259
|
+
type_map[name] = type(ds).__name__
|
|
260
|
+
|
|
261
|
+
dataset_types = {type(ds) for ds in datasets.values()}
|
|
262
|
+
if len(dataset_types) != 1:
|
|
263
|
+
msg = (
|
|
264
|
+
"SystemData requires all component datasets to have the same "
|
|
265
|
+
f"concrete data class; got {type_map}"
|
|
266
|
+
)
|
|
267
|
+
raise TypeError(msg)
|
|
268
|
+
|
|
269
|
+
datasets = cast(
|
|
270
|
+
"dict[str, DatasetType]",
|
|
271
|
+
_synchronize_t_refs(cast("dict[str, AbstractData]", datasets)),
|
|
272
|
+
)
|
|
273
|
+
self._datasets = datasets
|
|
274
|
+
self._dataset_type = next(iter(dataset_types))
|
|
275
|
+
|
|
276
|
+
@property
|
|
277
|
+
def dataset_type(self) -> type[AbstractData]:
|
|
278
|
+
"""Concrete dataset class shared by all components."""
|
|
279
|
+
return self._dataset_type
|
|
280
|
+
|
|
281
|
+
def stacked(self) -> DatasetType:
|
|
282
|
+
"""Stack all component datasets."""
|
|
283
|
+
return stack_datasets(self._datasets)
|
|
284
|
+
|
|
285
|
+
def indicator_data(
|
|
286
|
+
self,
|
|
287
|
+
reference: str,
|
|
288
|
+
) -> tuple[DatasetType, jax.Array | None, tuple[str, ...] | None]:
|
|
289
|
+
"""Return stacked data and component-indicator flags."""
|
|
290
|
+
return build_indicator_matrix(self._datasets, reference)
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
class SourceData(AbstractDatasetContainer):
|
|
294
|
+
"""Container for multiple named datasets for a single source.
|
|
295
|
+
|
|
296
|
+
Accepts arbitrary named datasets via keyword arguments. Names are user-defined and
|
|
297
|
+
can be anything (e.g., gaia, keck_rv, hst_imaging).
|
|
298
|
+
"""
|
|
299
|
+
|
|
300
|
+
def __init__(self, **datasets: DatasetType) -> None:
|
|
301
|
+
if not datasets:
|
|
302
|
+
raise ValueError("At least one dataset must be provided")
|
|
303
|
+
for name, ds in datasets.items():
|
|
304
|
+
if not isinstance(ds, AbstractData):
|
|
305
|
+
raise TypeError(
|
|
306
|
+
f"Dataset '{name}' must be AbstractAstrometryData or "
|
|
307
|
+
f"RVData, got {type(ds).__name__}"
|
|
308
|
+
)
|
|
309
|
+
datasets = cast(
|
|
310
|
+
"dict[str, DatasetType]",
|
|
311
|
+
_synchronize_t_refs(cast("dict[str, AbstractData]", datasets)),
|
|
312
|
+
)
|
|
313
|
+
object.__setattr__(self, "_datasets", datasets)
|
|
314
|
+
|
|
315
|
+
def _n_astrometry(self) -> int:
|
|
316
|
+
"""Number of astrometric datasets."""
|
|
317
|
+
return len(self.get_datasets_by_type(AbstractAstrometryData))
|
|
318
|
+
|
|
319
|
+
def _n_rv(self) -> int:
|
|
320
|
+
"""Number of radial velocity datasets."""
|
|
321
|
+
return len(self.get_datasets_by_type(RVData))
|
|
322
|
+
|
|
323
|
+
def plot(self, *args: Any, **kwargs: Any) -> Any:
|
|
324
|
+
"""Plot all datasets on a single axes.
|
|
325
|
+
|
|
326
|
+
Only valid when every contained dataset shares the same concrete type;
|
|
327
|
+
plotting heterogeneous types (e.g. RV in km/s and astrometry in mas) on a
|
|
328
|
+
single axes would overlay incompatible y-axes. Use
|
|
329
|
+
:meth:`get_datasets_by_type` to filter to a single type first when needed.
|
|
330
|
+
|
|
331
|
+
Parameters mirror :meth:`.AbstractDatasetContainer.plot`.
|
|
332
|
+
|
|
333
|
+
Raises
|
|
334
|
+
------
|
|
335
|
+
TypeError
|
|
336
|
+
If the contained datasets are not all of the same concrete type.
|
|
337
|
+
"""
|
|
338
|
+
types = {type(ds) for ds in self._datasets.values()}
|
|
339
|
+
if len(types) > 1:
|
|
340
|
+
type_map = {n: type(d).__name__ for n, d in self._datasets.items()}
|
|
341
|
+
raise TypeError(
|
|
342
|
+
"SourceData.plot() requires all datasets to share the same concrete "
|
|
343
|
+
f"type; got {type_map}. Use .get_datasets_by_type(<DataClass>) to "
|
|
344
|
+
"select one type, then plot the resulting datasets individually."
|
|
345
|
+
)
|
|
346
|
+
return super().plot(*args, **kwargs)
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
# Type alias for any top-level input accepted by the sampler and likelihoods.
|
|
350
|
+
# Use this instead of AbstractData in signatures that also accept SourceData.
|
|
351
|
+
InputData = AbstractData | AbstractDatasetContainer
|