spherapy 0.2.0__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.
- spherapy/__init__.py +93 -0
- spherapy/__main__.py +17 -0
- spherapy/_version.py +34 -0
- spherapy/data/TLEs/25544.tle +153378 -0
- spherapy/orbit.py +874 -0
- spherapy/timespan.py +436 -0
- spherapy/updater.py +91 -0
- spherapy/util/__init__.py +0 -0
- spherapy/util/celestrak.py +87 -0
- spherapy/util/constants.py +38 -0
- spherapy/util/credentials.py +131 -0
- spherapy/util/elements_u.py +70 -0
- spherapy/util/epoch_u.py +149 -0
- spherapy/util/exceptions.py +7 -0
- spherapy/util/orbital_u.py +72 -0
- spherapy/util/spacetrack.py +272 -0
- spherapy-0.2.0.dist-info/METADATA +211 -0
- spherapy-0.2.0.dist-info/RECORD +22 -0
- spherapy-0.2.0.dist-info/WHEEL +5 -0
- spherapy-0.2.0.dist-info/entry_points.txt +3 -0
- spherapy-0.2.0.dist-info/licenses/LICENSE.md +19 -0
- spherapy-0.2.0.dist-info/top_level.txt +1 -0
spherapy/__init__.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import configparser
|
|
2
|
+
from importlib import metadata, resources
|
|
3
|
+
import os
|
|
4
|
+
import pathlib
|
|
5
|
+
|
|
6
|
+
import platformdirs
|
|
7
|
+
|
|
8
|
+
from spherapy.util import credentials
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _creatPackagedTLEListing() -> None|dict[int,pathlib.Path]:
|
|
12
|
+
packaged_tles = {}
|
|
13
|
+
package_file_listing = metadata.files('spherapy')
|
|
14
|
+
package_dir = resources.files('spherapy')
|
|
15
|
+
if package_file_listing is not None and len(package_file_listing) > 0:
|
|
16
|
+
for path in package_file_listing:
|
|
17
|
+
if 'TLEs' in path.parts:
|
|
18
|
+
try:
|
|
19
|
+
tle_id = int(path.stem)
|
|
20
|
+
except ValueError:
|
|
21
|
+
print("Can't import packaged TLEs, skipping...") #noqa: T201
|
|
22
|
+
return None
|
|
23
|
+
traversable = package_dir.joinpath(f"{path.relative_to('spherapy')}")
|
|
24
|
+
resource_path = pathlib.Path(f'{traversable}')
|
|
25
|
+
packaged_tles[tle_id] = resource_path
|
|
26
|
+
return packaged_tles
|
|
27
|
+
|
|
28
|
+
service_name = "spherapy"
|
|
29
|
+
service_author = "MSL"
|
|
30
|
+
|
|
31
|
+
try:
|
|
32
|
+
__version__ = metadata.version(service_name)
|
|
33
|
+
except metadata.PackageNotFoundError:
|
|
34
|
+
print(f'Version of {service_name} is uknown') #noqa: T201
|
|
35
|
+
__version__ = "x.x.x"
|
|
36
|
+
|
|
37
|
+
config_dir_str = os.getenv('SPHERAPY_CONFIG_DIR')
|
|
38
|
+
if config_dir_str is None:
|
|
39
|
+
use_config_file = False
|
|
40
|
+
config_dir = pathlib.Path(platformdirs.user_config_dir(appname=service_name,
|
|
41
|
+
version=__version__,
|
|
42
|
+
ensure_exists=True))
|
|
43
|
+
else:
|
|
44
|
+
use_config_file = True
|
|
45
|
+
config_dir = pathlib.Path(config_dir_str)
|
|
46
|
+
|
|
47
|
+
# will load a config even if not using
|
|
48
|
+
config = configparser.ConfigParser()
|
|
49
|
+
read_files = config.read(config_dir.joinpath('spherapy.conf'))
|
|
50
|
+
|
|
51
|
+
if use_config_file and len(read_files) == 0:
|
|
52
|
+
raise configparser.Error(f"Couldn't find spherapy.conf at {config_dir}")
|
|
53
|
+
|
|
54
|
+
# Locate dir to store TLE files
|
|
55
|
+
if not use_config_file:
|
|
56
|
+
# use default user directories
|
|
57
|
+
_data_dir = pathlib.Path(platformdirs.user_data_dir(appname=service_name, ensure_exists=True))
|
|
58
|
+
tle_dir = _data_dir.joinpath('TLEs')
|
|
59
|
+
else:
|
|
60
|
+
# use the config file
|
|
61
|
+
_TLE_dir_str = config['paths'].get('TLE_path')
|
|
62
|
+
|
|
63
|
+
if _TLE_dir_str is None:
|
|
64
|
+
raise ValueError("Config file has not TLE_path")
|
|
65
|
+
|
|
66
|
+
_temp_dir = pathlib.Path(_TLE_dir_str)
|
|
67
|
+
if _TLE_dir_str == '':
|
|
68
|
+
# TLE dir not set in config file
|
|
69
|
+
_data_dir = pathlib.Path(platformdirs.user_data_dir(appname=service_name,
|
|
70
|
+
ensure_exists=True))
|
|
71
|
+
tle_dir = _data_dir.joinpath('TLEs')
|
|
72
|
+
elif _temp_dir.is_absolute():
|
|
73
|
+
tle_dir = _temp_dir
|
|
74
|
+
else: # noqa: PLR5501
|
|
75
|
+
# _temp_dir is relative
|
|
76
|
+
if config_dir.is_dir():
|
|
77
|
+
tle_dir = config_dir.joinpath(_TLE_dir_str)
|
|
78
|
+
else:
|
|
79
|
+
tle_dir = config_dir.parent.joinpath(_TLE_dir_str)
|
|
80
|
+
|
|
81
|
+
tle_dir.mkdir(parents=True, exist_ok=True)
|
|
82
|
+
|
|
83
|
+
# Load credentials
|
|
84
|
+
|
|
85
|
+
spacetrack_credentials:dict[str,str|None] = {'user':None, 'passwd':None}
|
|
86
|
+
# load spacetrack_credentials from the relevant source
|
|
87
|
+
if not use_config_file:
|
|
88
|
+
credentials._reloadCredentials() # noqa: SLF001
|
|
89
|
+
else:
|
|
90
|
+
credentials._reloadCredentials(config) # noqa: SLF001
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
packaged_TLEs = _creatPackagedTLEListing() #noqa: N816
|
spherapy/__main__.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""Command line scripts for spherapy.
|
|
2
|
+
|
|
3
|
+
Contains:
|
|
4
|
+
- create_credentials (spherapy-create-credentials)
|
|
5
|
+
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from spherapy import credentials
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def create_credentials():
|
|
12
|
+
"""Helper script to call create credentials function."""
|
|
13
|
+
credentials.createCredentials()
|
|
14
|
+
|
|
15
|
+
def clear_credentials():
|
|
16
|
+
"""Helper script to call clear credentials function."""
|
|
17
|
+
credentials.clearCredentials()
|
spherapy/_version.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# file generated by setuptools-scm
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
|
|
4
|
+
__all__ = [
|
|
5
|
+
"__version__",
|
|
6
|
+
"__version_tuple__",
|
|
7
|
+
"version",
|
|
8
|
+
"version_tuple",
|
|
9
|
+
"__commit_id__",
|
|
10
|
+
"commit_id",
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
TYPE_CHECKING = False
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from typing import Tuple
|
|
16
|
+
from typing import Union
|
|
17
|
+
|
|
18
|
+
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
|
19
|
+
COMMIT_ID = Union[str, None]
|
|
20
|
+
else:
|
|
21
|
+
VERSION_TUPLE = object
|
|
22
|
+
COMMIT_ID = object
|
|
23
|
+
|
|
24
|
+
version: str
|
|
25
|
+
__version__: str
|
|
26
|
+
__version_tuple__: VERSION_TUPLE
|
|
27
|
+
version_tuple: VERSION_TUPLE
|
|
28
|
+
commit_id: COMMIT_ID
|
|
29
|
+
__commit_id__: COMMIT_ID
|
|
30
|
+
|
|
31
|
+
__version__ = version = '0.2.0'
|
|
32
|
+
__version_tuple__ = version_tuple = (0, 2, 0)
|
|
33
|
+
|
|
34
|
+
__commit_id__ = commit_id = None
|