alerce_xmatch
API to cross the information of astronomical catalogs with your local catalog or a pandas DataFrame with the astronomical position (ra, dec).
Installation
Dependencies
This libraries are specify in the requirements.txt
file:
certifi==2019.3.9
numpy==1.16.4
pandas==0.24.2
python-dateutil==2.8.0
pytz==2019.1
six==1.12.0
websocket-client==0.56.0
Pip installation
pip[3] install alerce_xmatch
Manual installation
Clone this repo, by executing:
git clone https://github.com/alercebroker/xmatch_client.git
Then, change the current directory to this repo (generally by using cd xmatch_client
) and execute:
python[3] setup.py install
Usage
Import lib
The library is called alerce_xmatch
. To import to your current script (or jupyter notebook) use:
import alerce_xmatch
The class and method available are:
from alerce_xmatch import Catalog, crossmatch, OutputCols, TargetCatalogs
Description
To crossmatch and create a Catalog
Catalogs object has a DataFrame with the astronomical position (in [ra, dec] format) and optionally an id (generally called oid) and more useful attributes. Also, it has an optional name. To create a Catalog object use:
my_catalog = Catalog(df=df, name=name)
# By default df=None, and name="input_catalog"
With this catalog you can get the cross information by using the method:
my_catalog.crossmatch(<target>, output=OutputCols.BOTH, radec=True)
The <target>
parameter are available by importing alerce_xmatch.TargetCatalogs
and the possibilities are:
from alerce_xmatch import TargetCatalogs
# Available catalogs
TargetCatalogs.GAIA
TargetCatalogs.ASASSN
TargetCatalogs.CRTSNORTH
TargetCatalogs.CRTSSOUTH
TargetCatalogs.LINEAR
TargetCatalogs.TNS
TargetCatalogs.ZTF
The other optional parameters are:
Output columns:
The parameter output
, define the columns on the output DataFrame of the resulting Catalog. This option are OutputCols
as follow:
from alerce_xmatch import OutputCols
OutputCols.BOTH # Show all the resilting columns
OutputCols.TARGET # Show the columns of the target catalog (Gaia, Asassn, ZTF, etc...)
OutputCols.SOURCE # Show the columns of your catalog
Show ra, dec coordinates
By default radec
is True
, which implies that the output DataFrame has the [ra, dec] position. You can hide this attribute (and lose it) setting radec
to False
.
To crossmatch a DataFrame
If you want to get and provide just the DataFrame with your info, use the crossmatch method provided as follow:
import pandas as pd
from alerce_xmatch import crossmatch, TargetCatalogs, OutputCols
source_catalog = pd.DataFrame(<your data>)
result = crossmatch(source_catalog, TargetCatalogs.ZTF, output=OutputCols.BOTH, radec=True)
Here, the example target catalog is ZTF, and the optional parameters are used with its default value.
The output type, given a DataFrame, it is a pandas DataFrame. This static method can be used identically providing a Catalog as the source_catalog
and the output type will be a Catalog object.