CelestialSurveyor

Форк
0
/
data_classes.py 
163 строки · 6.0 Кб
1
import numpy as np
2

3
from astropy.coordinates import SkyCoord
4
from astropy.wcs import WCS
5
from dataclasses import dataclass
6
from datetime import datetime
7
from decimal import Decimal
8
from typing import Optional
9

10

11
@dataclass
12
class SolveData:
13
    """
14
    Class representing data required for plate solving of an image which is present in FITS or XISF header.
15

16
    Attributes:
17
        sky_coord (SkyCoord): The sky coordinates of image center.
18
        pixel_scale (Decimal): The pixel scale.
19
    """
20
    sky_coord: SkyCoord
21
    pixel_scale: Decimal
22

23
    def __post_init__(self):
24
        """
25
        Ensure the pixel scale is of Decimal type.
26
        """
27
        if not isinstance(self.pixel_scale, Decimal):
28
            raise TypeError("Pixel scale must be a Decimal object.")
29
        if not isinstance(self.sky_coord, SkyCoord):
30
            raise TypeError("Sky coordinates must be a SkyCoord object.")
31

32
    def __repr__(self):
33
        return f"SolveData(sky_coord={self.sky_coord}, pixel_scale={self.pixel_scale})"
34

35
    def __str__(self):
36
        return f"SolveData: Sky Coordinate: {self.sky_coord}, Pixel Scale: {self.pixel_scale}"
37

38

39
@dataclass
40
class SiteLocation:
41
    """
42
    Class to represent a site's geographical location.
43

44
    Attributes:
45
        lat (Decimal): The latitude of the site in decimal degrees.
46
        long (Decimal): The longitude of the site in decimal degrees.
47
    """
48
    lat: Decimal
49
    long: Decimal
50

51
    def __post_init__(self):
52
        """
53
        Ensure the lat and long are of Decimal type.
54
        """
55
        if not isinstance(self.lat, Decimal):
56
            raise TypeError("Latitude must be a Decimal object.")
57
        if not isinstance(self.long, Decimal):
58
            raise TypeError("Longitude must be a Decimal object.")
59

60
    def __repr__(self):
61
        return f"SiteLocation(lat={self.lat}, long={self.long})"
62

63
    def __str__(self):
64
        return f"SiteLocation: Latitude: {self.lat}, Longitude: {self.long}"
65

66

67
@dataclass
68
class Header:
69
    """
70
    Class to represent the header information of an image.
71

72
    Attributes:
73
        file_name (str): The name of the image file.
74
        exposure (Decimal): The exposure time of the image.
75
        timestamp (datetime): The timestamp of the image.
76
        site_location (SiteLocation): The geographical location of the site.
77
        solve_data (SolveData) [Optional]: The data required for plate solving of the image.
78
        wcs (WCS) [Optional]: WCS data - plate solve result.
79
    """
80
    file_name: str
81
    exposure: Decimal
82
    timestamp: datetime
83
    site_location: SiteLocation
84
    solve_data: Optional[SolveData] = None
85
    wcs: Optional[WCS] = None
86

87
    def __post_init__(self):
88
        """
89
        Perform type-checking on the attributes of the Header class to ensure correct data types.
90
        """
91
        if not isinstance(self.file_name, str):
92
            raise TypeError("File name must be a string.")
93

94
        if not isinstance(self.exposure, Decimal):
95
            raise TypeError("Exposure must be a Decimal object.")
96

97
        if not isinstance(self.timestamp, datetime):
98
            raise TypeError("Timestamp must be a datetime.datetime object.")
99

100
        if not isinstance(self.exposure, Decimal):
101
            raise TypeError("Exposure must be a Decimal object.")
102

103
        if not isinstance(self.site_location, SiteLocation):
104
            raise TypeError("Site location must be a SiteLocation object.")
105

106
        if not isinstance(self.solve_data, SolveData) and self.solve_data is not None:
107
            raise TypeError("Solve data must be a SolveData object or None.")
108

109
        if not isinstance(self.wcs, WCS) and self.wcs is not None:
110
            raise TypeError("WCS data must be a WCS object or None.")
111

112
    def __repr__(self):
113
        return (f"Header(file_name={self.file_name}, exposure={self.exposure}, timestamp={self.timestamp}, "
114
                f"site_location={self.site_location}, solve_data={self.solve_data}, wcs={self.wcs})")
115

116
    def __str__(self):
117
        return (f"Header: File Name: {self.file_name}, Exposure: {self.exposure}, Timestamp: {self.timestamp}, "
118
                f"Site Location: {self.site_location}, Solve Data: {self.solve_data}, WCS: {self.wcs}")
119

120

121
@dataclass
122
class SharedMemoryParams:
123
    """
124
    Data class representing parameters for shared memory file.
125
    Shared memory file is used to spread image data across multiple processes.
126

127
    Attributes:
128
        shm_name (str): The name of the shared memory.
129
        shm_size (int): The size of the shared memory.
130
        shm_shape (Tuple): The shape of the shared memory.
131
        shm_dtype (np.dtype): The data type of the shared memory.
132
        y_slice (slice): The y slice of the original image. Defaults to slice(None, None).
133
        x_slice (slice): The x slice of the original image. Defaults to slice(None, None).
134
    """
135
    shm_name: str
136
    shm_size: int
137
    shm_shape: tuple
138
    shm_dtype: np.dtype
139
    y_slice: slice = slice(None, None)
140
    x_slice: slice = slice(None, None)
141

142
    def __post_init__(self):
143
        if not isinstance(self.shm_name, str):
144
            raise TypeError("Shared memory name must be a string.")
145
        if not isinstance(self.shm_size, int):
146
            raise TypeError("Shared memory size must be an integer.")
147
        if not isinstance(self.shm_shape, tuple):
148
            raise TypeError("Shared memory shape must be a tuple.")
149
        if not isinstance(self.y_slice, slice):
150
            raise TypeError("Y slice must be a slice.")
151
        if not isinstance(self.x_slice, slice):
152
            raise TypeError("X slice must be a slice.")
153

154

155

156
    def __repr__(self):
157
        return (f"SharedMemoryParams(shm_name={self.shm_name}, shm_size={self.shm_size}, shm_shape={self.shm_shape}, "
158
                f"shm_dtype={self.shm_dtype}, y_slice={self.y_slice}, x_slice={self.x_slice})")
159

160
    def __str__(self):
161
        return (f"SharedMemoryParams: Shared Memory Name: {self.shm_name}, Shared Memory Size: {self.shm_size}, "
162
                f"Shared Memory Shape: {self.shm_shape}, Shared Memory Data Type: {self.shm_dtype}, "
163
                f"Y Slice: {self.y_slice}, X Slice: {self.x_slice}")
164

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.