satcat 0.0.1a4__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.
satcat/__init__.py ADDED
@@ -0,0 +1,6 @@
1
+ from importlib import metadata
2
+
3
+ from .sdk import *
4
+
5
+ __app_name__ = "satcat"
6
+ __version__ = metadata.version(__package__)
satcat/cli/__init__.py ADDED
File without changes
satcat/cli/create.py ADDED
@@ -0,0 +1,246 @@
1
+ from datetime import datetime
2
+ from io import StringIO
3
+ from pathlib import Path
4
+ from typing import List, Optional
5
+
6
+ import shutil
7
+ import typer
8
+
9
+ from satcat.cli.utils import (
10
+ cli_output_model,
11
+ screening_await_cli,
12
+ validate_model_from_input,
13
+ )
14
+
15
+ from satcat.sdk.client import Client
16
+ from satcat.sdk.propagation import models as prop_models
17
+ from satcat.sdk.screening import models as screening_models
18
+
19
+ app = typer.Typer()
20
+
21
+ # Screening
22
+
23
+
24
+ @app.command()
25
+ def ephemeris(
26
+ file: Path,
27
+ file_format: str = typer.Argument(...),
28
+ norad_id: Optional[int] = None,
29
+ comments: Optional[str] = None,
30
+ hbr_m: Optional[float] = None,
31
+ context: Optional[screening_models.EphemerisContext] = None,
32
+ designation: Optional[screening_models.EphemerisDesignation] = None,
33
+ ):
34
+
35
+ with Client() as client:
36
+ resource = client.screening.create_ephemeris(
37
+ file,
38
+ file_format=file_format,
39
+ filename=file.name,
40
+ norad_id=norad_id,
41
+ comments=comments,
42
+ hbr_m=hbr_m,
43
+ context=context,
44
+ designation=designation,
45
+ )
46
+ cli_output_model(resource)
47
+
48
+
49
+ @app.command()
50
+ def ephemeris_from_maneuver_plan(
51
+ scenario_id: str = typer.Option(None, "--scenario-id", "--sid"),
52
+ tradespace_id: str = typer.Option(None, "--tradespace-id", "--tid"),
53
+ plan_id: str = typer.Option(None, "--plan-id", "--pid"),
54
+ designation: Optional[screening_models.EphemerisDesignation] = typer.Option(
55
+ None, "--designation", "--d"
56
+ ),
57
+ ):
58
+
59
+ with Client() as client:
60
+ resource = client.avoidance.create_ephemeris_from_maneuver_plan(
61
+ scenario_id, tradespace_id, plan_id, designation
62
+ )
63
+ cli_output_model(resource)
64
+
65
+
66
+ @app.command()
67
+ def screening(
68
+ primary_ephemeris_file: Optional[Path] = typer.Option(
69
+ None, "--primary-ephemeris-file", "--pef"
70
+ ),
71
+ primary_ephemeris_format: str = typer.Option(
72
+ "AUTOMATIC", "--primary-ephemeris-format", "--pfmt"
73
+ ),
74
+ primary_norad_id: Optional[int] = typer.Option(
75
+ None, "--primary-norad-cat-id", "--pid"
76
+ ),
77
+ primary_ephemeris_ids: Optional[List[str]] = None,
78
+ secondary_ephemeris_ids: Optional[List[str]] = None,
79
+ primary_opm_file: Optional[Path] = typer.Option(None, "--opm"),
80
+ catalog_id: Optional[str] = None,
81
+ threshold_radius_km: float = 15.0,
82
+ threshold_radius_active_km: Optional[float] = None,
83
+ threshold_radius_manned_km: Optional[float] = None,
84
+ threshold_radius_debris_km: Optional[float] = None,
85
+ default_secondary_hbr_m: float = 5.0,
86
+ propagation_start_time: Optional[datetime] = None,
87
+ propagation_duration: Optional[float] = None,
88
+ propagation_timestep: Optional[float] = None,
89
+ launch_window_start: Optional[datetime] = None,
90
+ launch_window_end: Optional[datetime] = None,
91
+ launch_window_cadence_s: Optional[float] = None,
92
+ type: screening_models.ScreeningType = screening_models.ScreeningType.ON_ORBIT,
93
+ auto_archive: bool = False,
94
+ include_primary_vs_primary: bool = False,
95
+ title: Optional[str] = None,
96
+ notes: Optional[str] = None,
97
+ submit: bool = typer.Option(False, "--submit", "-s"),
98
+ use_best_catalog: bool = True,
99
+ use_ephemeris_repository: bool = False,
100
+ wait: bool = typer.Option(
101
+ False,
102
+ "--wait",
103
+ "-w",
104
+ help=(
105
+ "Whether to wait for the screening to complete or return after creating and"
106
+ " submitting the asynchronous screening job."
107
+ ),
108
+ ),
109
+ ):
110
+
111
+ if wait and not submit:
112
+ # Cannot wait without submitting
113
+ submit = True
114
+
115
+ with Client() as client:
116
+ if primary_ephemeris_ids is None:
117
+ primary_ephemeris_ids = []
118
+ if secondary_ephemeris_ids is None:
119
+ secondary_ephemeris_ids = []
120
+ primaries = [
121
+ screening_models.Screenable(ephemeris_id=i) for i in primary_ephemeris_ids
122
+ ]
123
+ secondaries = [
124
+ screening_models.Screenable(ephemeris_id=i) for i in secondary_ephemeris_ids
125
+ ]
126
+
127
+ if primary_opm_file is not None:
128
+ with open(primary_opm_file) as opm_f:
129
+ propagation = client.propagation.create_propagation(opm_file=opm_f)
130
+ primaries.append(screening_models.Screenable(propagation_id=propagation.id))
131
+
132
+ catalog = None
133
+
134
+ if use_best_catalog:
135
+ catalog = client.screening.get_latest_catalog()
136
+ secondaries.append(screening_models.Screenable(catalog_id=catalog.id))
137
+
138
+ elif catalog_id is not None:
139
+ catalog = client.screening.get_catalog(catalog_id)
140
+
141
+ if use_ephemeris_repository:
142
+ secondaries.append(
143
+ screening_models.Screenable(
144
+ ephemeris_group=screening_models.EphemerisGroup.OPERATOR_REPOSITORY
145
+ )
146
+ )
147
+
148
+ if primary_ephemeris_file:
149
+ primary_ephemeris = client.screening.create_ephemeris(
150
+ primary_ephemeris_file,
151
+ file_format=primary_ephemeris_format,
152
+ norad_id=primary_norad_id,
153
+ )
154
+ primaries.append(
155
+ screening_models.Screenable(ephemeris_id=primary_ephemeris.id)
156
+ )
157
+ elif primary_norad_id:
158
+ if catalog:
159
+ primaries.append(
160
+ screening_models.Screenable(
161
+ catalog_id=catalog.id, norad_id=primary_norad_id
162
+ )
163
+ )
164
+ else:
165
+ raise ValueError(
166
+ "primary_norad_id can only be used if"
167
+ "primary_ephemeris_file or catalog_id is set"
168
+ )
169
+
170
+ if title is None:
171
+ now = datetime.now()
172
+ title = f"{now.strftime('%Y-J%j')} - SDK Screening"
173
+
174
+ config = screening_models.ScreeningConfiguration(
175
+ threshold_radius_km=threshold_radius_km,
176
+ threshold_radius_active_km=threshold_radius_active_km,
177
+ threshold_radius_manned_km=threshold_radius_manned_km,
178
+ threshold_radius_debris_km=threshold_radius_debris_km,
179
+ default_secondary_hbr_m=default_secondary_hbr_m,
180
+ submit=submit,
181
+ notes=notes,
182
+ propagation_duration=propagation_duration,
183
+ propagation_start_time=propagation_start_time,
184
+ propagation_timestep=propagation_timestep,
185
+ auto_archive=auto_archive,
186
+ title=title,
187
+ include_primary_vs_primary=include_primary_vs_primary,
188
+ screening_type=type.upper(),
189
+ launch_window_start=launch_window_start,
190
+ launch_window_end=launch_window_end,
191
+ launch_window_cadence_s=launch_window_cadence_s,
192
+ )
193
+
194
+ screening = client.screening.create_screening(
195
+ config,
196
+ primaries=primaries,
197
+ submit=submit,
198
+ secondaries=secondaries,
199
+ )
200
+
201
+ screening = client.screening.get_screening(screening.id)
202
+
203
+ if wait:
204
+ screening = screening_await_cli(client, screening)
205
+
206
+ cli_output_model(screening)
207
+
208
+
209
+ @app.command()
210
+ def propagation(
211
+ opm_file: Optional[Path] = typer.Option(None, "--opm-file", "--opm"),
212
+ submit: bool = typer.Option(False, "--submit", "-s"),
213
+ target_duration_s: Optional[float] = typer.Option(None, "--duration-sec", "-d"),
214
+ timestep_s: Optional[float] = typer.Option(None, "--timestep-sec", "-t"),
215
+ purpose: Optional[str] = typer.Option(None),
216
+ wait: bool = typer.Option(
217
+ False,
218
+ "--wait",
219
+ "-w",
220
+ help=(
221
+ "Whether to wait for the propagation to complete or return after creating"
222
+ " and submitting the asynchronous propagation job."
223
+ ),
224
+ ),
225
+ ):
226
+ configuration = prop_models.PropagationConfiguration(
227
+ timestep=timestep_s, target_duration=target_duration_s, purpose=purpose
228
+ )
229
+
230
+ opm_file_content = StringIO()
231
+ if opm_file is not None:
232
+ with open(opm_file) as f:
233
+ shutil.copyfileobj(f, opm_file_content)
234
+ opm_file_content.seek(0)
235
+ else:
236
+ opm_file_content = None
237
+
238
+ with Client() as client:
239
+ propagation = client.propagation.create_propagation(
240
+ configuration, opm_file=opm_file_content, submit=submit
241
+ )
242
+
243
+ if wait:
244
+ propagation = client.propagation.await_propagation_completion(propagation)
245
+
246
+ cli_output_model(propagation)
satcat/cli/delete.py ADDED
@@ -0,0 +1,10 @@
1
+ import typer
2
+
3
+ from typer import Abort
4
+
5
+ from satcat.cli.utils import cli_output
6
+
7
+ from satcat.sdk.client import Client
8
+
9
+ app = typer.Typer()
10
+
satcat/cli/download.py ADDED
@@ -0,0 +1,47 @@
1
+ from pathlib import Path
2
+
3
+ import typer
4
+
5
+ from satcat.cli.utils import cli_output_model
6
+ from satcat.sdk.client import Client
7
+
8
+ app = typer.Typer()
9
+
10
+
11
+ @app.command()
12
+ def ephemeris(
13
+ resource_id: str,
14
+ file_format: str = typer.Option(
15
+ "OEM", "--file-format", "-f", help="One of OEM, NASA, HDF5, or ORIGINAL"
16
+ ),
17
+ output_file: Path = typer.Option(None, "--output-file", "-o"),
18
+ ):
19
+ """Download an Ephemeris by ID."""
20
+ with Client() as client:
21
+ file_content = client.screening.download_ephemeris(resource_id, file_format)
22
+ if output_file is None:
23
+ typer.echo(file_content.read())
24
+ else:
25
+ with open(output_file, "w+") as outf:
26
+ outf.write(file_content.read())
27
+
28
+
29
+ @app.command()
30
+ def plan(
31
+ scenario_id: str,
32
+ tradespace_id: str,
33
+ plan_id: str,
34
+ file_name: str,
35
+ file_format: str = typer.Option("opm", "--file-format", "-f"),
36
+ output_file: Path = typer.Option(None, "--output-file", "-o"),
37
+ ):
38
+ """Download an Avoidance Maneuver Plan by ID."""
39
+ with Client() as client:
40
+ file_content = client.avoidance.download_maneuver_plan(
41
+ scenario_id, tradespace_id, plan_id, file_format, file_name
42
+ )
43
+ if output_file is None:
44
+ typer.echo(file_content.read())
45
+ else:
46
+ with open(output_file, "w+") as outf:
47
+ outf.write(file_content.read())
satcat/cli/get.py ADDED
@@ -0,0 +1,53 @@
1
+ import typer
2
+
3
+ from satcat.cli.utils import cli_output, cli_output_model
4
+ from satcat.sdk.client import Client
5
+
6
+ app = typer.Typer()
7
+
8
+
9
+ # Screening
10
+
11
+
12
+ @app.command()
13
+ def ephemeris(resource_id: str):
14
+ """Retrieve an Ephemeris by ID."""
15
+ with Client() as client:
16
+ resource = client.screening.get_ephemeris(resource_id)
17
+ cli_output_model(resource)
18
+
19
+
20
+ @app.command()
21
+ def screening(resource_id: str):
22
+ """Retrieve a Screening by ID."""
23
+ with Client() as client:
24
+ resource = client.screening.get_screening(resource_id)
25
+ cli_output_model(resource)
26
+
27
+
28
+ @app.command()
29
+ def catalog(resource_id: str):
30
+ """Retrieve a Catalog by ID."""
31
+ with Client() as client:
32
+ resource = client.screening.get_catalog(resource_id)
33
+ cli_output_model(resource)
34
+
35
+
36
+ @app.command()
37
+ def conjunction_ccsds(screening_id: str, conjunction_id: str):
38
+ """Retrieve a single CCSDS formatted Conjunction by Screening ID."""
39
+ with Client() as client:
40
+ resource = client.screening.get_conjunction_ccsds(screening_id, conjunction_id)
41
+ cli_output(resource)
42
+
43
+
44
+ # Propagation
45
+
46
+
47
+ @app.command()
48
+ def propagation(resource_id: str):
49
+ """Retrieve a Propagation by ID."""
50
+ with Client() as client:
51
+ resource = client.propagation.get_propagation(resource_id)
52
+ cli_output_model(resource)
53
+
satcat/cli/list.py ADDED
@@ -0,0 +1,81 @@
1
+ from typing import Optional
2
+
3
+ import typer
4
+
5
+ from satcat.cli import utils
6
+ from satcat.sdk.client import Client
7
+
8
+ app = typer.Typer()
9
+ count_option = typer.Option(10, "-n", "--count")
10
+
11
+ # Screening
12
+
13
+
14
+ @app.command()
15
+ def ephemerides(count: Optional[int] = count_option, catalog_id: Optional[str] = None):
16
+ with Client() as client:
17
+ if catalog_id:
18
+ resources = client.screening.list_catalog_ephemerides(
19
+ catalog_id, count=count, sort_field='usable_time_end'
20
+ )
21
+ utils.cli_output_list(resources)
22
+ else:
23
+ resources = client.screening.list_ephemerides(count=count)
24
+ utils.cli_output_list(resources)
25
+
26
+
27
+ @app.command()
28
+ def screenings(count: Optional[int] = count_option, show_archived: bool = False):
29
+ with Client() as client:
30
+ resources = client.screening.list_screenings(
31
+ count=count, show_archived=show_archived
32
+ )
33
+ utils.cli_output_list(resources)
34
+
35
+
36
+ @app.command()
37
+ def catalogs(count: Optional[int] = count_option, latest: bool = False):
38
+ with Client() as client:
39
+ resources = client.screening.list_catalogs(count=count, latest=latest)
40
+ utils.cli_output_list(resources)
41
+
42
+
43
+ @app.command()
44
+ def conjunctions(screening_id: str, count: Optional[int] = count_option):
45
+ with Client() as client:
46
+ resources = client.screening.list_conjunctions(
47
+ screening_id=screening_id, count=count
48
+ )
49
+ utils.cli_output_list(resources)
50
+
51
+
52
+ @app.command()
53
+ def screening_primaries(screening_id: str, count: Optional[int] = count_option):
54
+ with Client() as client:
55
+ resources = client.screening.list_screening_primaries(
56
+ screening_id=screening_id, count=count
57
+ )
58
+ utils.cli_output_list(resources)
59
+
60
+
61
+ @app.command()
62
+ def screening_secondaries(screening_id: str, count: Optional[int] = count_option):
63
+ with Client() as client:
64
+ resources = client.screening.list_screening_secondaries(
65
+ screening_id=screening_id, count=count
66
+ )
67
+ utils.cli_output_list(resources)
68
+
69
+
70
+ @app.command()
71
+ def ephemeris_formats():
72
+ with Client() as client:
73
+ resources = client.screening.list_ephemeris_formats()
74
+ utils.cli_output(resources)
75
+
76
+
77
+ @app.command()
78
+ def conjunctions_ccsds(resource_id: str, count: Optional[int] = count_option):
79
+ with Client() as client:
80
+ resources = client.screening.list_conjunctions_ccsds(resource_id, count)
81
+ utils.cli_output(resources)
satcat/cli/main.py ADDED
@@ -0,0 +1,56 @@
1
+ from urllib.parse import urljoin
2
+
3
+ import typer
4
+
5
+ from satcat import __app_name__, __version__
6
+ from satcat.cli.create import app as create_app
7
+ from satcat.cli.delete import app as delete_app
8
+ from satcat.cli.download import app as download_app
9
+ from satcat.cli.get import app as get_app
10
+ from satcat.cli.list import app as list_app
11
+ from satcat.cli.submit import app as submit_app
12
+ from satcat.cli.update import app as update_app
13
+ from satcat.cli.wait import app as await_app
14
+ from satcat.sdk.client import Client
15
+ from satcat.sdk.settings import OutputFormat, settings
16
+
17
+ VERSION = __version__
18
+ SERVICE_NAME = __app_name__
19
+
20
+ app = typer.Typer()
21
+ app.add_typer(await_app, name="await")
22
+ app.add_typer(create_app, name="create")
23
+ app.add_typer(delete_app, name="delete")
24
+ app.add_typer(download_app, name="download")
25
+ app.add_typer(get_app, name="get")
26
+ app.add_typer(list_app, name="list")
27
+ app.add_typer(submit_app, name="submit")
28
+ app.add_typer(update_app, name="update")
29
+
30
+
31
+ @app.command()
32
+ def version():
33
+ typer.echo(f"{SERVICE_NAME} version {VERSION}")
34
+
35
+
36
+ @app.command()
37
+ def health_api():
38
+ with Client() as client:
39
+ res = client.request(urljoin(settings.satcat_rest_api_url, "health"))
40
+ typer.echo(res.text)
41
+
42
+
43
+ @app.callback()
44
+ def main(
45
+ output: OutputFormat = typer.Option(None, "-o", "--output"),
46
+ no_progress: bool = typer.Option(False, "--no-progress"),
47
+ ):
48
+ settings.cli.is_cli = True
49
+ if output is not None:
50
+ settings.cli.output_format = output
51
+
52
+ settings.cli.show_progress = not no_progress
53
+
54
+
55
+ if __name__ == "__main__":
56
+ app()
satcat/cli/submit.py ADDED
@@ -0,0 +1,52 @@
1
+ import typer
2
+ from rich.progress import Progress
3
+
4
+ from satcat.cli.utils import cli_output_model, screening_await_cli
5
+ from satcat.sdk.client import Client
6
+ from satcat.sdk.settings import OutputFormat, settings
7
+
8
+ app = typer.Typer()
9
+
10
+
11
+ @app.command()
12
+ def screening(
13
+ resource_id: str,
14
+ wait: bool = typer.Option(
15
+ False,
16
+ "--wait",
17
+ "-w",
18
+ help=(
19
+ "Whether to wait for the screening to complete or return after creating and"
20
+ " submitting the asynchronous screening job."
21
+ ),
22
+ ),
23
+ ):
24
+ """Submit a Screening by ID."""
25
+
26
+ with Client() as client:
27
+ screening = client.screening.get_screening(resource_id)
28
+ screening = client.screening.submit_screening(screening)
29
+ screening = screening_await_cli(client, screening)
30
+ cli_output_model(screening)
31
+
32
+
33
+ @app.command()
34
+ def propagation(
35
+ resource_id: str,
36
+ wait: bool = typer.Option(
37
+ False,
38
+ "--wait",
39
+ "-w",
40
+ help=(
41
+ "Whether to wait for the screening to complete or return after creating and"
42
+ " submitting the asynchronous screening job."
43
+ ),
44
+ ),
45
+ ):
46
+ """Submit a Propagation by ID."""
47
+ with Client() as client:
48
+ propagation = client.propagation.get_propagation(resource_id)
49
+ resource = client.propagation.submit_propagation(propagation)
50
+ if wait:
51
+ resource = client.propagation.await_propagation_completion(propagation)
52
+ cli_output_model(resource)
satcat/cli/update.py ADDED
@@ -0,0 +1,16 @@
1
+ import json
2
+ from typing import List, Optional
3
+
4
+ import typer
5
+ from typer import Abort
6
+
7
+ from satcat.cli.utils import (
8
+ cli_output,
9
+ cli_output_model,
10
+ validate_model_from_input,
11
+ )
12
+
13
+ from satcat.sdk.client import Client
14
+
15
+ app = typer.Typer()
16
+