snad-space / ztf-viewer

ZTF data releases light curve viewer
http://ztf.snad.space
MIT License
14 stars 2 forks source link

Handling Skybot exceptions when searching for asteroids #379

Open AIofHuman opened 5 months ago

AIofHuman commented 5 months ago

If the Skybot does not find a solar system object in the specified search area (Skybot.cone_search), it throws an exception such as RuntimeError. For other exceptions (incorrect data or lack of Internet), the type of exceptions is the same, only the text of the messages differs. It is necessary to differ between object "not found" events and "service error" events. Possible solution:

try:
    results = Skybot.cone_search(field, 0.0041667*u.deg, earthed_time, location='I41')
    return len(results) > 0, results[0]['Name']
except Exception as e:
    if len(e.args)>0 and e.args[0][0:22]=='No solar system object':
        return False, 'No object'
    else:
        print(f'Exception {e.args[0]}')     
        return False, 'Service error'