<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Gather precovery imaging
This notebook shows how to get precovery imaging for objects found with KBMOD. Once we have an object
identified we can record the observations we used in MPC format and use the following tools to search
other telescope data for possible images where the object may be present to help orbit determination.
Precovery Classes
Here we describe the methods we have for identifying precovery images
Step1:  Create Query URL from MPC formatted file
In the notebook orbit_fitting_demo.ipynb we show how to use the ephem_utils.py code in KBMOD to create a file with the observations for an identified object in KBMOD and turn it into an MPC formatted file. The file created in that demo is saved here as kbmod_mpc.dat. We will use that file to show how the precovery interface works.
Step2:  Query service via URL
The formatted URL above will work in a browser to return results. But we have the query_ssois function that will pull down the results and provide them in a pandas dataframe all in one go.
Step3:  Create direct data download link
It's possible to take the URLs for the data provided in results_df['MetaData'] and turn them directly into a download link clickable from here in the notebook.
Step4:  Compare KBMOD data to available data
<ASSISTANT_TASK:>
Python Code:
from precovery_utils import ssoisPrecovery
Explanation: Gather precovery imaging
This notebook shows how to get precovery imaging for objects found with KBMOD. Once we have an object
identified we can record the observations we used in MPC format and use the following tools to search
other telescope data for possible images where the object may be present to help orbit determination.
Precovery Classes
Here we describe the methods we have for identifying precovery images:
Solar System Object Imaging Search (SSOIS)
Currently our precovery_utils only has a class to use the SSOIS service
from the Canadian Astronomy Data Centre and described in Gwyn, Hill and Kavelaars (2012).
End of explanation
ssois_query = ssoisPrecovery()
query_url = ssois_query.format_search_by_arc_url('kbmod_mpc.dat')
print(query_url)
Explanation: Create Query URL from MPC formatted file
In the notebook orbit_fitting_demo.ipynb we show how to use the ephem_utils.py code in KBMOD to create a file with the observations for an identified object in KBMOD and turn it into an MPC formatted file. The file created in that demo is saved here as kbmod_mpc.dat. We will use that file to show how the precovery interface works.
End of explanation
results_df = ssois_query.query_ssois(query_url)
results_df.head()
Explanation: Query service via URL
The formatted URL above will work in a browser to return results. But we have the query_ssois function that will pull down the results and provide them in a pandas dataframe all in one go.
End of explanation
from IPython.display import HTML
image_data_link = results_df["MetaData"].iloc[-1]
HTML('<a href="{}">{}</a>'.format(image_data_link, image_data_link))
Explanation: Create direct data download link
It's possible to take the URLs for the data provided in results_df['MetaData'] and turn them directly into a download link clickable from here in the notebook.
End of explanation
%pylab inline
from ephem_utils import mpc_reader
kbmod_observations = mpc_reader('kbmod_mpc.dat')
scatter(kbmod_observations.ra.deg, kbmod_observations.dec.deg, marker='x', s=200, c='r', label='KBMOD Observations', zorder=10)
plt.legend()
scatter(results_df['Object_RA'], results_df['Object_Dec'], c=results_df['MJD'])
cbar = plt.colorbar()
plt.xlabel('RA')
plt.ylabel('Dec')
cbar.set_label('MJD')
Explanation: Compare KBMOD data to available data
End of explanation
<END_TASK>