Sample script for filtering the MPCORB file

This commit is contained in:
Brandon Rhodes 2020-07-07 21:05:24 -04:00
parent 5f655a517e
commit 8a0a60fd6a
2 changed files with 34 additions and 0 deletions

4
ci/MPCORB.excerpt.DAT Normal file
View File

@ -0,0 +1,4 @@
00001 3.4 0.15 K205V 162.68631 73.73161 80.28698 10.58862 0.0775571 0.21406009 2.7676569 0 MPO492748 6751 115 1801-2019 0.60 M-v 30h Williams 0000 (1) Ceres 20190915
00002 4.2 0.15 K205V 144.97567 310.20237 173.02474 34.83293 0.2299723 0.21334458 2.7738415 0 MPO530953 8031 109 1821-2019 0.58 M-v 28h MPCW 0000 (2) Pallas 20190812
00003 5.2 0.15 K205V 125.43538 248.06618 169.85146 12.99105 0.2569364 0.22612869 2.6682853 0 MPO530953 7023 106 1821-2020 0.59 M-v 38h MPCW 0000 (3) Juno 20200204
00004 3.0 0.15 K205V 204.32771 150.87484 103.80908 7.14190 0.0885158 0.27150657 2.3620141 0 MPO530953 6964 102 1821-2020 0.60 M-p 18h MPCW 0000 (4) Vesta 20200203

View File

@ -0,0 +1,30 @@
# mpc_make_excerpt.py
"""Search the MPCORB file for minor planets, given their packed designations."""
import argparse
import re
import sys
import zlib
from skyfield.api import load
from skyfield.data import mpc
def main(argv):
parser = argparse.ArgumentParser(description='Grep MPCORB.DAT.gz')
parser.add_argument('designations', nargs='+', help='packed designations'
' of the minor planets whose orbits you need')
args = parser.parse_args(argv)
designations = [re.escape(d.encode('ascii')) for d in args.designations]
pattern = rb'^((?:%s) .*\n)' % rb'|'.join(designations)
r = re.compile(pattern, re.M)
data = load.open(mpc.MPCORB_URL).read()
data = zlib.decompress(data, wbits = zlib.MAX_WBITS | 16)
lines = r.findall(data)
sys.stdout.buffer.write(b''.join(lines))
if __name__ == '__main__':
main(sys.argv[1:])