-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlaunch_identifiers.py
159 lines (137 loc) · 5.72 KB
/
launch_identifiers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import pandas as pd
import requests
from Processing import PastStatus, PastT0s, PastName, PastID
PastT0s = PastT0s.copy()
PastStatus = PastStatus.copy().rename(
columns={"id": "status_id", "abbrev": "status_name"}
)
PastName = PastName.copy()
data = pd.concat(
[PastID, PastT0s, PastStatus[["status_id", "status_name"]], PastName], axis=1
)
year_selected = 1965
days_delta_limit = 1
data_year = data[data.net.dt.year == year_selected].copy().reset_index(drop=True)
def check_special_assignment(identifier_):
if identifier_ == "1966-088A":
return "33da85f3-08a8-4c5f-892d-8b4be3b4fae6"
elif identifier_ == "1966-101A":
return "7ec54e6a-8df8-468c-ad66-b990ab058502"
return
def get_celestrak_data(identifier_):
print(f"Getting data for {identifier_}")
URL = f"https://celestrak.com/satcat/records.php?INTDES={identifier_}"
celestrak_result = requests.get(URL, timeout=360)
if celestrak_result.text == "No SATCAT records found\r\n":
return None, None
else:
celestrak_json = celestrak_result.json()
return celestrak_json[0]["OBJECT_NAME"], celestrak_json[0]["LAUNCH_DATE"]
def cleanup_string(string_):
cleaned_string = ""
for char in string_.lower():
if char.isalpha():
cleaned_string += char
else:
cleaned_string += " "
return cleaned_string
def name_match(string1, string2):
string1 = string1.split("|")[-1]
string2 = string2.split("|")[-1]
string1 = set(cleanup_string(string1).replace("kosmos", "cosmos").split())
string2 = set(cleanup_string(string2).replace("kosmos", "cosmos").split())
common_words = string1 & string2
if not common_words:
return False
for word in common_words:
if len(word) >= 2:
return True
return False
def set_identifier_match(index, identifier_, name_):
print(
f'Found match for {data_year.loc[index, "name"]} ({data_year.loc[index, "status_name"]})'
)
data_year.loc[index, "identifier"] = identifier_
data_year.loc[index, "name_check"] = name_
def set_identifier_none(index):
print(
f'No match for {data_year.loc[index, "name"]} ({data_year.loc[index, "status_name"]})'
)
data_year.loc[index, "identifier"] = None
data_year.loc[index, "name_check"] = None
count = 0
skip_next = False
for i in data_year.index:
count += 1
if skip_next:
skip_next = False
continue
is_special = True
while is_special:
identifier = f'{data_year.loc[i, "net"].strftime("%Y")}-{count:03d}A'
name, date = get_celestrak_data(identifier)
special_case_launch_id = check_special_assignment(identifier)
if special_case_launch_id:
special_index = data_year[data_year.id == special_case_launch_id].index[0]
set_identifier_match(special_index, identifier, name)
count += 1
else:
is_special = False
if date == data_year.loc[i, "net"].strftime("%Y-%m-%d"):
# Check if identifier launch date roughly matches launch date
if data_year.loc[i, "status_id"] == 4:
# If launch failure, make sure name matches
if name_match(name, data_year.loc[i, "name"]):
# Name matches, so failed launch has an identifier
set_identifier_match(i, identifier, name)
else:
# Name does not match, let's check if the next identifier matches the next launch
identifier_2 = (
f'{data_year.loc[i, "net"].strftime("%Y")}-{count + 1:03d}A'
)
name_2, date_2 = get_celestrak_data(identifier_2)
if name_match(
name_2, data_year.loc[i + 1, "name"]
) or date_2 == data_year.loc[i + 1, "net"].strftime("%Y-%m-%d"):
# Next launch matches, so failed launch has an identifier
set_identifier_match(i, identifier, name)
else:
# Next launch does not match, so failed launch does not have an identifier
set_identifier_none(i)
count -= 1
else:
# If launch success, check various things
if name_match(name, data_year.loc[i, "name"]):
# If name matches, assign this identifier to the launch
set_identifier_match(i, identifier, name)
elif (
(i < data_year.tail(1).index.values.item())
and (
data_year.loc[i, "net"].strftime("%Y-%m-%d")
== data_year.loc[i + 1, "net"].strftime("%Y-%m-%d")
)
and name_match(name, data_year.loc[i + 1, "name"])
):
# Next launch on the same day corresponding to the identifier
set_identifier_match(i + 1, identifier, name)
# Check if current launch is for next identifier
identifier_2 = (
f'{data_year.loc[i, "net"].strftime("%Y")}-{(count + 1):03d}A'
)
name_2, date_2 = get_celestrak_data(identifier_2)
if name_match(name_2, data_year.loc[i, "name"]):
# If name matches, assign this identifier to the launch
set_identifier_match(i, identifier_2, name_2)
# Skip next launch
skip_next = True
else:
set_identifier_none(i)
count -= 1
else:
# Assign this identifier to the launch
set_identifier_match(i, identifier, name)
else:
# If launch date does not match, then no identifier for this launch
set_identifier_none(i)
count -= 1
print("Done")