Repository navigation
Expand file tree
/
Copy pathbase.py
More file actions
76 lines (57 loc) · 2.09 KB
/
Copy pathbase.py
File metadata and controls
76 lines (57 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from dataclasses import dataclass, fields
from functools import cache
import pyarrow as pa
from skyfield.api import load_constellation_map, position_of_radec
from starplot.mixins import CreateMapMixin, CreateOpticMixin
@cache
def constellation_at():
return load_constellation_map()
@dataclass(slots=True, kw_only=True)
class SkyObject(
CreateMapMixin,
CreateOpticMixin,
):
"""
Base class for sky objects.
All sky object classes inherit from this base class.
"""
ra: float
"""Right Ascension, in degrees (0 to 360)"""
dec: float
"""Declination, in degrees (-90 to 90)"""
constellation_id: str | None = None
"""Three-letter IAU id of the constellation that contains this object"""
healpix_index: int = None
"""[HEALPix](https://en.wikipedia.org/wiki/HEALPix) pixel index of this object's RA/DEC"""
def constellation(self):
"""Returns an instance of the [`Constellation`][starplot.models.Constellation] that contains this object, or `None` if no constellation is found."""
from starplot.models import Constellation
return Constellation.get(iau_id=self.constellation_id)
def populate_constellation_id(self):
"""Populates the constellation_id field based on the location of this object"""
pos = position_of_radec(self.ra / 15, self.dec)
self.constellation_id = constellation_at()(pos).lower()
@classmethod
@cache
def _dir(cls):
return dir(cls)
@classmethod
@cache
def _fields(cls):
return [f.name for f in fields(cls)]
@classmethod
@cache
def _pyarrow_schema(cls):
"""Returns explicit schema"""
return pa.schema(
[
pa.field("ra", pa.float64(), nullable=False),
pa.field("dec", pa.float64(), nullable=False),
pa.field("constellation_id", pa.string()),
pa.field("healpix_index", pa.int64()),
]
)
@dataclass(kw_only=True)
class CatalogObject:
pk: int
"""Primary key of object in catalog. Needs to be unique across all objects in the catalog."""