Source code for frb.surveys.tns_util

""" Created by Yuxin Dong """
from astropy import units as u
from astropy.coordinates import SkyCoord 
import requests
import json
from collections import OrderedDict


# For searches 

# ID of your Bot:
YOUR_BOT_ID=111031

# name of your Bot:
YOUR_BOT_NAME="Avon"

# API key of your Bot:
api_key="fc32024eaf71cad9e5b3880c833e8b83c676996f"




[docs] def parse_coord(ra, dec): if (not (is_number(ra) and is_number(dec)) and (':' not in ra and ':' not in dec)): error = 'ERROR: cannot interpret: {ra} {dec}' print(error.format(ra=ra, dec=dec)) return(None) if (':' in str(ra) and ':' in str(dec)): # Input RA/DEC are sexagesimal unit = (u.hourangle, u.deg) else: unit = (u.deg, u.deg) try: coord = SkyCoord(ra, dec, frame='icrs', unit=unit) return(coord) except ValueError: error = 'ERROR: Cannot parse coordinates: {ra} {dec}' print(error.format(ra=ra,dec=dec)) return(None)
[docs] def is_number(num): try: num = float(num) except ValueError: return(False) return(True)
### sarching for matching transients using TNS API and a specified radius ### # function for changing data to json format
[docs] def format_to_json(source): # change data to json format and return parsed = json.loads(source) result = parsed['data'] #print(result) result = parsed['data']['reply'] return result
# function for search obj from tutorial