def __init__(self, verbose=False): """ :param verbose: """ # initialize Skybot self.skybot = Skybot() self.v = verbose
def getKBOList(self, pgNum, type_of_object='KBO'): with open('PickledPointings.pkl', 'rb') as f: PointingGroups = pickle.load(f) PointingGroups = PointingGroups[pgNum] PointingGroups.drop_duplicates('visit_id',inplace=True) df = PointingGroups allTimes = [] for i in range(len(PointingGroups)): date_obs = df['date_obs'].iloc[i].decode()#[2:-1] time_obj = Time(date_obs, format='iso', scale='utc') allTimes.append(time_obj.jd) allTimes = np.array(allTimes) #timesMask = np.logical_and(allTimes>2458576.714,allTimes<2458577.70862527) times = allTimes ra = PointingGroups['ra'].values dec = PointingGroups['dec'].values i=0 field = (ra[i],dec[i]) epoch = Time(times[i], format='jd') Results = Skybot.cone_search(field, 90*u.arcmin, epoch, location='W84') RA_rate = Results['RA_rate'] DEC_rate = Results['DEC_rate'] pixel = u.arcsec/.26 RA_rate = RA_rate.to(pixel/u.day) DEC_rate = DEC_rate.to(pixel/u.day) totalRate = np.linalg.norm([RA_rate,DEC_rate],axis=0) Type = np.array([classtype[0:3] for classtype in np.array(Results['Type'])]) if type_of_object is not None: KBOList = Results[Type==type_of_object]#['Name','RA','DEC','V','DEC_rate','RA_rate'] else: KBOList = Results return(PointingGroups, KBOList)
def skybot(ra_deg, dec_deg, date, radius, Texp): """ query SkyBoT catalog using astroquery.skybot to search for moving objects parameters: ra_deg, dec_deg, date, Texp, radius: ra_deg, dec_deg: RA and DEC in degrees astropy.units date: date of observation (UTC) Texp: exposure time in astropy.unit radius in arcsecond returns: astropy.table object """ # if present, substitue T by a whitespace if 'T' in date: date=date.replace('T', ' ') field = SkyCoord(ra_deg, dec_deg) epoch = Time(str(date), format='iso') moving_objects_list = Skybot.cone_search(field, radius, epoch, position_error=120*u.arcsecond) # Add RA, DEC at end of exposure moving_objects_list['RA_Tend'] = moving_objects_list['RA'] + moving_objects_list['RA_rate']*Texp moving_objects_list['DEC_Tend'] = moving_objects_list['DEC'] + moving_objects_list['DEC_rate']*Texp # Compute angular distance between Tstart and Tend c1 = SkyCoord(moving_objects_list['RA'], moving_objects_list['DEC'], frame='icrs') c2 = SkyCoord(moving_objects_list['RA_Tend'], moving_objects_list['DEC_Tend'], frame='icrs') sep = c1.separation(c2) moving_objects_list['RADEC_sep'] = sep return moving_objects_list
def cone_search_skybot(image): try: res = Skybot.cone_search(image['skycoord'], rad=SKYMAPPER_FOV, epoch=image['MJD'], location=SKYMAPPER_MPC_CODE, position_error=15 * u.arcsec) except RuntimeError as e: raise e return res
def skybot(ra_deg, dec_deg, date, radius, Texp, position_error=120): """ query SkyBoT catalog using astroquery.skybot to search for moving objects parameters: ra_deg, dec_deg, date, Texp, radius: ra_deg, dec_deg: RA and DEC in degrees astropy.units date: date of observation (astropy.time.Time object) Texp: exposure time in astropy.unit position_error Maximum positional error for targets to be queried (in arcsecond). 120 is the maximum allowed by SkyBot. returns: astropy.table object """ field = SkyCoord(ra_deg, dec_deg) # SkyBot is returning a RuntimeError when no objects are found # So need to use a try except here try: moving_objects_list = Skybot.cone_search( field, radius, date, position_error=position_error * u.arcsecond ) except BaseException: moving_objects_list = None if moving_objects_list is not None: # Add RA, DEC at end of exposure moving_objects_list["RA_Tend"] = ( moving_objects_list["RA"] + moving_objects_list["RA_rate"] * Texp ) moving_objects_list["DEC_Tend"] = ( moving_objects_list["DEC"] + moving_objects_list["DEC_rate"] * Texp ) # Compute angular distance between Tstart and Tend c1 = SkyCoord( moving_objects_list["RA"], moving_objects_list["DEC"], frame="icrs" ) c2 = SkyCoord( moving_objects_list["RA_Tend"], moving_objects_list["DEC_Tend"], frame="icrs", ) sep = c1.separation(c2) moving_objects_list["RADEC_sep"] = sep return moving_objects_list
class IMCCE(object): """Utility to query IMCCE's Skybot service""" def __init__(self, verbose=False): """ :param verbose: """ # initialize Skybot self.skybot = Skybot() self.v = verbose def batch_query(self, queries, n_treads: int = 4): """Run multiple queries in parallel :param queries: :param n_treads: :return: """ n_treads = min(len(queries), n_treads) with ThreadPool(processes=n_treads) as pool: if self.v: return list( tqdm(pool.imap(self.query, queries), total=len(queries))) else: return list(pool.imap(self.query, queries)) def query(self, query: dict, **kwargs): """Query Skybot :param query :param kwargs: :return: """ qid = query.get("id", None) # must be a astropy.coordinates.SkyCoord instance: position = query.get("position") # radius: [arcmin] radius = query.get("radius") * u.arcmin # astropy.time.Time instance: epoch = query.get("epoch") # observatory code, e.g. 'I41' for Palomar: location = query.get("observatory_code", "I41") try: data = self.skybot.cone_search(coo=position, rad=radius, epoch=epoch, location=location) except Exception as e: response = {"status": "error", "message": e} if qid: response["id"] = qid return response response = {"status": "success", "data": data} if qid: response["id"] = qid return response
def query_skybot(img): field = SkyCoord(img.header['ra']*u.deg, img.header['dec']*u.deg) epoch = Time(img.header['date-obs']) objects = Skybot.cone_search(field, 15*u.arcmin, epoch) return objects