MCPcopy Create free account
hub / github.com/Tong89/smartNode / _parse_tle_text

Function _parse_tle_text

backend/physics/tle_source.py:155–194  ·  view source on GitHub ↗

解析 3 行格式的 TLE 文本(名称行 + 第一行 + 第二行)。 支持: - 标准 3LE(每组三行) - 2LE(无名称行,每组两行,名称设为 catnr) - 自动跳过空行与注释行(# 开头) 返回 (name, line1, line2, epoch) 列表,epoch 从 TLE line1 解析。

(text: str)

Source from the content-addressed store, hash-verified

153
154
155def _parse_tle_text(text: str) -> List[TleEntry]:
156 """解析 3 行格式的 TLE 文本(名称行 + 第一行 + 第二行)。
157
158 支持:
159 - 标准 3LE(每组三行)
160 - 2LE(无名称行,每组两行,名称设为 catnr)
161 - 自动跳过空行与注释行(# 开头)
162
163 返回 (name, line1, line2, epoch) 列表,epoch 从 TLE line1 解析。
164 """
165 lines = [ln.rstrip() for ln in text.splitlines() if ln.strip() and not ln.startswith("#")]
166 entries: List[TleEntry] = []
167 i = 0
168 while i < len(lines):
169 # 检测是否为 TLE 行(以 '1 ' 或 '2 ' 开头的68-69字符行)
170 if (
171 i + 1 < len(lines)
172 and lines[i].startswith("1 ")
173 and lines[i + 1].startswith("2 ")
174 ):
175 # 2LE 格式(前面没有名称行)
176 line1, line2 = lines[i], lines[i + 1]
177 name = line1[2:7].strip() # CATNR 作为名称
178 epoch = _epoch_from_line1(line1)
179 entries.append((name, line1, line2, epoch))
180 i += 2
181 elif (
182 i + 2 < len(lines)
183 and lines[i + 1].startswith("1 ")
184 and lines[i + 2].startswith("2 ")
185 ):
186 # 3LE 格式(名称 + 两行根数)
187 name = lines[i].strip()
188 line1, line2 = lines[i + 1], lines[i + 2]
189 epoch = _epoch_from_line1(line1)
190 entries.append((name, line1, line2, epoch))
191 i += 3
192 else:
193 i += 1
194 return entries
195
196
197def _epoch_from_line1(line1: str) -> str:

Callers 3

_write_cacheFunction · 0.85
fetch_groupFunction · 0.85
fetch_by_catnrFunction · 0.85

Calls 2

_epoch_from_line1Function · 0.85
appendMethod · 0.80

Tested by

no test coverage detected