CelestialSurveyor
63 строки · 2.3 Кб
1from astropy import units as u
2from astropy.coordinates import SkyCoord
3from astropy.wcs import WCS
4
5
6class KnownObject:
7"""
8Represents a known astronomical object.
9
10Attributes:
11name (str): The name of the object.
12coordinates (SkyCoord): The celestial coordinates of the object.
13magnitude (str): The visual magnitude of the object.
14_wcs (WCS): The World Coordinate System information of the object.
15__pixel_coordinates (None or array-like): The pixel coordinates of the object.
16"""
17def __init__(self, properties: dict, wcs: WCS=None):
18self.name = properties["Object name"]
19self.coordinates = SkyCoord(
20ra=properties["Astrometric RA (hh:mm:ss)"].replace("'", "").replace('"', ''),
21dec=properties["Astrometric Dec (dd mm'ss\")"].replace("'", " ").replace('"', ''),
22unit=(u.hourangle, u.deg)
23)
24self.magnitude = properties["Visual magnitude (V)"]
25self._wcs = wcs
26self.__pixel_coordinates = None
27
28def __str__(self):
29return f"{self.name}:{self.magnitude}"
30
31@property
32def wcs(self) -> WCS:
33"""World Coordinate System information of the object"""
34return self._wcs
35
36@wcs.setter
37def wcs(self, value: WCS):
38self._wcs = value
39
40@property
41def pixel_coordinates(self) -> tuple:
42"""Pixel coordinates of the object on the image calculated from the World Coordinate System information"""
43if not isinstance(self._wcs, WCS):
44raise ValueError("WCS is not specified or is not an instance of class WCS")
45return self.wcs.world_to_pixel(self.coordinates) if self.__pixel_coordinates is None \
46else self.__pixel_coordinates
47
48
49if __name__ == '__main__':
50params = {
51"Object name": "(2021 RP107)",
52"Astrometric RA (hh:mm:ss)": "03:14:38",
53"Astrometric Dec (dd mm'ss\")": "+31 41'05\"",
54"Dist. from center RA (\")": "-8.E3",
55"Dist. from center Dec (\")": "956.",
56"Dist. from center Norm (\")": "8268.",
57"Visual magnitude (V)": "19.9",
58"RA rate (\"/h)": "-4.002E+01",
59"Dec rate (\"/h)": "8.931E+00",
60"Est. error RA (\")": "2735.",
61"Est. error Dec (\")": "2735."
62}
63print(KnownObject(params))
64