Asteroidpy 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.
- asteroidpy/__init__.py +25 -0
- asteroidpy/asteroidpy.py +0 -0
- asteroidpy/configuration.py +277 -0
- asteroidpy/interface.py +645 -0
- asteroidpy/scheduling.py +776 -0
- asteroidpy-0.1.dist-info/METADATA +107 -0
- asteroidpy-0.1.dist-info/RECORD +16 -0
- asteroidpy-0.1.dist-info/WHEEL +5 -0
- asteroidpy-0.1.dist-info/licenses/LICENSE +674 -0
- asteroidpy-0.1.dist-info/top_level.txt +5 -0
- tests/__init__.py +0 -0
- tests/test_configuration.py +230 -0
- tests/test_configuration_corrupted.py +32 -0
- tests/test_configuration_unittest.py +241 -0
- tests/test_configuration_unreadable.py +28 -0
- tests/test_scheduling.py +674 -0
asteroidpy/__init__.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
import asteroidpy.interface as interface
|
|
4
|
+
import configparser
|
|
5
|
+
import cProfile, pstats
|
|
6
|
+
from configparser import ConfigParser
|
|
7
|
+
|
|
8
|
+
import asteroidpy.interface as interface
|
|
9
|
+
|
|
10
|
+
PROFILE = False
|
|
11
|
+
|
|
12
|
+
config: ConfigParser = configparser.ConfigParser()
|
|
13
|
+
|
|
14
|
+
def main() -> None:
|
|
15
|
+
|
|
16
|
+
"""Main function"""
|
|
17
|
+
if PROFILE:
|
|
18
|
+
profiler = cProfile.Profile()
|
|
19
|
+
profiler.enable()
|
|
20
|
+
interface.interface(config)
|
|
21
|
+
profiler.disable()
|
|
22
|
+
stats = pstats.Stats(profiler).sort_stats("ncalls")
|
|
23
|
+
stats.dump_stats("asteroidpy.prof")
|
|
24
|
+
else:
|
|
25
|
+
interface.interface(config)
|
asteroidpy/asteroidpy.py
ADDED
|
File without changes
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
from configparser import ConfigParser
|
|
2
|
+
import os
|
|
3
|
+
from typing import Dict
|
|
4
|
+
from platform import system
|
|
5
|
+
import math
|
|
6
|
+
from platformdirs import user_config_dir, user_config_path
|
|
7
|
+
from astropy.coordinates import Angle
|
|
8
|
+
from astroquery.mpc import MPC
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def save_config(config: ConfigParser) -> None:
|
|
12
|
+
"""Save configurations in config.ini file
|
|
13
|
+
|
|
14
|
+
Parameters
|
|
15
|
+
----------
|
|
16
|
+
config : Configparser
|
|
17
|
+
the Configparser object with configuration option
|
|
18
|
+
|
|
19
|
+
Returns
|
|
20
|
+
-------
|
|
21
|
+
|
|
22
|
+
"""
|
|
23
|
+
# Persist configuration at $HOME/.asteroidpy
|
|
24
|
+
home_dir = os.path.expanduser("~")
|
|
25
|
+
config_path = os.path.join(home_dir, ".asteroidpy")
|
|
26
|
+
with open(config_path, "w", encoding="utf-8") as f:
|
|
27
|
+
config.write(f)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def initialize(config: ConfigParser) -> None:
|
|
31
|
+
"""Initialize Configuration parameters
|
|
32
|
+
|
|
33
|
+
Parameters
|
|
34
|
+
----------
|
|
35
|
+
config : Configparser
|
|
36
|
+
the Configparser object with configuration option
|
|
37
|
+
|
|
38
|
+
Returns
|
|
39
|
+
-------
|
|
40
|
+
|
|
41
|
+
"""
|
|
42
|
+
config['General'] = {'lang': 'en'}
|
|
43
|
+
# ConfigParser stores values as strings; ensure all values are strings
|
|
44
|
+
config['Observatory'] = {
|
|
45
|
+
'place': '',
|
|
46
|
+
'latitude': '0.0',
|
|
47
|
+
'longitude': '0.0',
|
|
48
|
+
'altitude': '0.0',
|
|
49
|
+
'obs_name': '',
|
|
50
|
+
'observer_name': '',
|
|
51
|
+
'mpc_code': 'XXX',
|
|
52
|
+
"east_altitude": '0',
|
|
53
|
+
"nord_altitude": '0',
|
|
54
|
+
"south_altitude": '0',
|
|
55
|
+
"west_altitude": '0',
|
|
56
|
+
}
|
|
57
|
+
print("inizializzato")
|
|
58
|
+
save_config(config)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def load_config(config: ConfigParser) -> None:
|
|
62
|
+
"""Searchs for .asteroidpy. If it's in the folder then it loads all parameter, else it initialize it
|
|
63
|
+
|
|
64
|
+
Parameters
|
|
65
|
+
----------
|
|
66
|
+
config : Configparser
|
|
67
|
+
the Configparser object with configuration option
|
|
68
|
+
|
|
69
|
+
Returns
|
|
70
|
+
-------
|
|
71
|
+
|
|
72
|
+
"""
|
|
73
|
+
# Read configuration from $HOME/.asteroidpy if it exists; otherwise initialize
|
|
74
|
+
home_dir = os.path.expanduser("~")
|
|
75
|
+
config_path = os.path.join(home_dir, ".asteroidpy")
|
|
76
|
+
if os.path.exists(config_path):
|
|
77
|
+
# Attempt to read. If unreadable (permissions) or invalid/empty,
|
|
78
|
+
# fall back to initialize to ensure required sections exist.
|
|
79
|
+
try:
|
|
80
|
+
read_files = config.read(config_path, encoding="utf-8")
|
|
81
|
+
except Exception:
|
|
82
|
+
read_files = []
|
|
83
|
+
|
|
84
|
+
if not read_files or not config.sections():
|
|
85
|
+
initialize(config)
|
|
86
|
+
return
|
|
87
|
+
initialize(config)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def change_language(config: ConfigParser, lang: str) -> None:
|
|
91
|
+
"""Changes language for interface
|
|
92
|
+
|
|
93
|
+
Parameters
|
|
94
|
+
----------
|
|
95
|
+
config : configparser
|
|
96
|
+
the configparser object with configuration options
|
|
97
|
+
lang : string
|
|
98
|
+
the language chosen
|
|
99
|
+
|
|
100
|
+
Returns
|
|
101
|
+
-------
|
|
102
|
+
|
|
103
|
+
"""
|
|
104
|
+
load_config(config)
|
|
105
|
+
config["General"]["lang"] = lang
|
|
106
|
+
save_config(config)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def change_obs_coords(config: ConfigParser, place: str, lat: float, long: float) -> None:
|
|
110
|
+
"""Changes Observatory coordinates
|
|
111
|
+
|
|
112
|
+
Parameters
|
|
113
|
+
----------
|
|
114
|
+
config : Configparser
|
|
115
|
+
the Configparser object with configuration option
|
|
116
|
+
place : string
|
|
117
|
+
Name of Locality
|
|
118
|
+
lat : float
|
|
119
|
+
latitude
|
|
120
|
+
long : float
|
|
121
|
+
longitude
|
|
122
|
+
|
|
123
|
+
Returns
|
|
124
|
+
-------
|
|
125
|
+
|
|
126
|
+
"""
|
|
127
|
+
load_config(config)
|
|
128
|
+
config["Observatory"]["place"] = place
|
|
129
|
+
config["Observatory"]["latitude"] = str(lat)
|
|
130
|
+
config["Observatory"]["longitude"] = str(long)
|
|
131
|
+
save_config(config)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def change_obs_altitude(config: ConfigParser, alt: int) -> None:
|
|
135
|
+
"""Changes Observatory altitude
|
|
136
|
+
|
|
137
|
+
Parameters
|
|
138
|
+
----------
|
|
139
|
+
config : Configparser
|
|
140
|
+
the Configparser object with configuration option
|
|
141
|
+
alt : int
|
|
142
|
+
altitude
|
|
143
|
+
|
|
144
|
+
Returns
|
|
145
|
+
-------
|
|
146
|
+
|
|
147
|
+
"""
|
|
148
|
+
load_config(config)
|
|
149
|
+
config["Observatory"]["altitude"] = str(alt)
|
|
150
|
+
save_config(config)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def change_mpc_code(config: ConfigParser, code: str) -> None:
|
|
154
|
+
"""Changes MPC code
|
|
155
|
+
|
|
156
|
+
Parameters
|
|
157
|
+
----------
|
|
158
|
+
config : Configparser
|
|
159
|
+
the Configparser object with configuration option
|
|
160
|
+
code : string
|
|
161
|
+
MPC Code
|
|
162
|
+
|
|
163
|
+
Returns
|
|
164
|
+
-------
|
|
165
|
+
|
|
166
|
+
"""
|
|
167
|
+
load_config(config)
|
|
168
|
+
config["Observatory"]["mpc_code"] = str(code)
|
|
169
|
+
save_config(config)
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def get_observatory_coordinates(code):
|
|
173
|
+
observatory_location = MPC.get_observatory_location(str(code))
|
|
174
|
+
latitude = math.acos(
|
|
175
|
+
observatory_location[1]
|
|
176
|
+
/ math.sqrt(observatory_location[1] ** 2 + observatory_location[2] ** 2)
|
|
177
|
+
)
|
|
178
|
+
altitude = math.sqrt(
|
|
179
|
+
observatory_location[1] ** 2 + observatory_location[2] ** 2)
|
|
180
|
+
return (
|
|
181
|
+
observatory_location[0].degree,
|
|
182
|
+
math.degrees(latitude),
|
|
183
|
+
altitude,
|
|
184
|
+
observatory_location[3],
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
def change_obs_name(config: ConfigParser, name: str) -> None:
|
|
188
|
+
|
|
189
|
+
"""Changes Observatory name
|
|
190
|
+
|
|
191
|
+
Parameters
|
|
192
|
+
----------
|
|
193
|
+
config : Configparser
|
|
194
|
+
the Configparser object with configuration option
|
|
195
|
+
name : string
|
|
196
|
+
Name of obseratory
|
|
197
|
+
|
|
198
|
+
Returns
|
|
199
|
+
-------
|
|
200
|
+
|
|
201
|
+
"""
|
|
202
|
+
load_config(config)
|
|
203
|
+
config["Observatory"]["obs_name"] = str(name)
|
|
204
|
+
save_config(config)
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def change_observer_name(config: ConfigParser, name: str) -> None:
|
|
208
|
+
"""Changes observer name
|
|
209
|
+
|
|
210
|
+
Parameters
|
|
211
|
+
----------
|
|
212
|
+
config : Configparser
|
|
213
|
+
the Configparser object with configuration option
|
|
214
|
+
name : string
|
|
215
|
+
Name of observer
|
|
216
|
+
|
|
217
|
+
Returns
|
|
218
|
+
-------
|
|
219
|
+
|
|
220
|
+
"""
|
|
221
|
+
load_config(config)
|
|
222
|
+
config["Observatory"]["observer_name"] = str(name)
|
|
223
|
+
save_config(config)
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def print_obs_config(config: ConfigParser, show_sensitive: bool = False) -> None:
|
|
227
|
+
"""Prints Observatory configuration parameters
|
|
228
|
+
|
|
229
|
+
Parameters
|
|
230
|
+
----------
|
|
231
|
+
config : Configparser
|
|
232
|
+
the Configparser object with configuration option
|
|
233
|
+
show_sensitive : bool, optional
|
|
234
|
+
If True, prints sensitive observer location information. Defaults to False (redacted).
|
|
235
|
+
|
|
236
|
+
Returns
|
|
237
|
+
-------
|
|
238
|
+
|
|
239
|
+
"""
|
|
240
|
+
load_config(config)
|
|
241
|
+
if config.has_section("Observatory"):
|
|
242
|
+
if config.has_option("Observatory", "place"):
|
|
243
|
+
print("Località: %s" % config["Observatory"]["place"])
|
|
244
|
+
if config.has_option("Observatory", "latitude"):
|
|
245
|
+
print("Latitudine: %s" % (config["Observatory"]["latitude"] if show_sensitive else "***REDACTED***"))
|
|
246
|
+
if config.has_option("Observatory", "longitude"):
|
|
247
|
+
print("Longitudine: %s" % (config["Observatory"]["longitude"] if show_sensitive else "***REDACTED***"))
|
|
248
|
+
if config.has_option("Observatory", "altitude"):
|
|
249
|
+
print("Altitudine: %s" % (config["Observatory"]["altitude"] if show_sensitive else "***REDACTED***"))
|
|
250
|
+
if config.has_option("Observatory", "observer_name"):
|
|
251
|
+
print("Osservatore: %s" % config["Observatory"]["observer_name"])
|
|
252
|
+
if config.has_option("Observatory", "obs_name"):
|
|
253
|
+
print("Nome Osservatorio: %s" % config["Observatory"]["obs_name"])
|
|
254
|
+
if config.has_option("Observatory", "mpc_code"):
|
|
255
|
+
print("Codice MPC: %s" % config["Observatory"]["mpc_code"])
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
def virtual_horizon_configuration(config: ConfigParser, horizon: Dict[str, str]) -> None:
|
|
259
|
+
"""Change the Virtual horizon configuration
|
|
260
|
+
|
|
261
|
+
Parameters
|
|
262
|
+
----------
|
|
263
|
+
config : Configparser
|
|
264
|
+
the Configparser object with configuration options
|
|
265
|
+
horizon : dictionary of string
|
|
266
|
+
Altitudes for cardinal directions
|
|
267
|
+
|
|
268
|
+
Returns
|
|
269
|
+
-------
|
|
270
|
+
|
|
271
|
+
"""
|
|
272
|
+
load_config(config)
|
|
273
|
+
config["Observatory"]["nord_altitude"] = horizon["nord"]
|
|
274
|
+
config["Observatory"]["south_altitude"] = horizon["south"]
|
|
275
|
+
config["Observatory"]["east_altitude"] = horizon["east"]
|
|
276
|
+
config["Observatory"]["west_altitude"] = horizon["west"]
|
|
277
|
+
save_config(config)
|