Created
March 19, 2018 07:39
-
-
Save astronasutarou/3a0ab492a07011e3e9b026628085a336 to your computer and use it in GitHub Desktop.
throw a request to MPChecker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#-*- coding: utf-8 -*- | |
from argparse import ArgumentParser as ap | |
from astropy.time import Time | |
from astropy.coordinates import Longitude, Latitude | |
from pprint import pprint | |
from pyquery import PyQuery | |
import astropy.units as u | |
import requests, sys | |
mpc_url=u'https://www.minorplanetcenter.net/cgi-bin/mpcheck.cgi' | |
if __name__ == '__main__': | |
for i, arg in enumerate(sys.argv): | |
if (arg[0] == '-') and arg[1].isdigit(): sys.argv[i] = ' ' + arg | |
parser = ap(description=u'test script to use MPChecker') | |
parser.add_argument('ra', type=str, help=u'right ascension') | |
parser.add_argument('dec', type=str, help=u'declination') | |
parser.add_argument('-d', '--date', dest='date', type=Time, | |
default=Time.now(), help=u'observation date') | |
parser.add_argument('-r', dest='radius', default=25.0, | |
help=u'search radius in arcmin') | |
parser.add_argument('-m', dest='limmag', default=20.0, | |
help=u'limiting magnitude in the V-band') | |
args = parser.parse_args() | |
try: | |
args.ra = Longitude(args.ra) | |
except: | |
args.ra = Longitude(args.ra, unit=u.hour) | |
try: | |
args.dec = Latitude(args.dec) | |
except: | |
args.dec = Latitude(args.dec, unit=u.degree) | |
fday = args.date.datetime.day \ | |
+ args.date.datetime.hour/24.0 \ | |
+ args.date.datetime.minute/24.0/60.0 \ | |
+ args.date.datetime.second/24.0/60.0/60.0 | |
params = dict( | |
## datetime | |
# year: year of observation | |
# month: month of observation | |
# day: fractional day of observation | |
year=args.date.datetime.year, | |
month=args.date.datetime.month, | |
day=fday, | |
## search settings | |
# ra: right ascension | |
# decl: declination | |
# radius: search radius in arcmin | |
# limit: limiting magnitude | |
ra=str(args.ra.to_string( | |
sep=' ',unit=u.hour,pad=True,precision=2)), | |
decl=str(args.dec.to_string( | |
sep=' ',unit=u.deg,pad=True,precision=1,alwayssign=False)), | |
radius=args.radius, | |
limit=args.limmag, | |
## misc settings | |
which='pos', # query by position | |
type='p', # plain HTML page | |
oc='381', # observatory code 381: Tokyo-Kiso | |
pdes='u', # unpacked designations | |
mot='h', # motion per hour | |
tmot='s', # separate motions | |
needed='f', # all objects | |
ps='n', # not used? | |
sort='r', # sort by RA | |
TextArea='' # remain to be empty | |
) | |
r = requests.post(mpc_url, data=params) | |
pq = PyQuery(r.text) | |
pre_text = pq('pre').html() | |
if pre_text is None: | |
print('no object detected') | |
else: | |
objects = pre_text.rstrip().split('\n') | |
for n, line in enumerate(objects): | |
if n<4: continue # skip header lines | |
print(line.rstrip()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment