alerce xmatch服务的客户端
alerce-xmatch的Python项目详细描述
alerce_xmatch
用于将天文目录信息与本地目录或熊猫数据帧与天文位置(ra,dec)交叉的api。
安装
依赖性
这些库在requirements.txt
文件中指定:
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安装
pip install alerce_xmatch
手动安装
通过执行以下操作克隆此回购:
git clone https://github.com/alercebroker/xmatch_client.git
然后,将当前目录更改为此repo(通常使用cd xmatch_client
),并执行:
python setup.py install
用法
导入lib
这个库称为alerce_xmatch
。要导入到当前脚本(或jupyter笔记本),请使用:
importalerce_xmatch
可用的类和方法是:
fromalerce_xmatchimportCatalog,crossmatch,OutputCols,TargetCatalogs
说明
交叉匹配并创建目录
catalogs对象有一个带有天文位置(格式为[ra,dec])和可选id(通常称为oid)的数据帧和更有用的属性。此外,它还有一个可选名称。要创建目录对象,请使用:
my_catalog=Catalog(df=df,name=name)# By default df=None, and name="input_catalog"
使用此目录,您可以使用以下方法获取交叉信息:
my_catalog.crossmatch(<target>,output=OutputCols.BOTH,radec=True)
通过导入alerce_xmatch.TargetCatalogs
可以使用<target>
参数,其可能性为:
fromalerce_xmatchimportTargetCatalogs# Available catalogsTargetCatalogs.GAIATargetCatalogs.ASASSNTargetCatalogs.CRTSNORTHTargetCatalogs.CRTSSOUTHTargetCatalogs.LINEARTargetCatalogs.TNSTargetCatalogs.ZTF
其他可选参数是:
输出列:
参数output
,定义结果目录的输出数据帧上的列。这个选项是OutputCols
,如下所示:
fromalerce_xmatchimportOutputColsOutputCols.BOTH# Show all the resilting columnsOutputCols.TARGET# Show the columns of the target catalog (Gaia, Asassn, ZTF, etc...)OutputCols.SOURCE# Show the columns of your catalog
显示RA,DEC坐标
默认情况下radec
是True
,这意味着输出数据帧具有[ra,dec]位置。可以隐藏此属性(并将其丢失)将radec
设置为False
。
交叉匹配数据帧
如果您只想获取并提供包含信息的数据帧,请使用下面提供的crossmatch方法:
importpandasaspdfromalerce_xmatchimportcrossmatch,TargetCatalogs,OutputColssource_catalog=pd.DataFrame(<yourdata>)result=crossmatch(source_catalog,TargetCatalogs.ZTF,output=OutputCols.BOTH,radec=True)
这里,示例目标目录是ztf,可选参数与其默认值一起使用。
输出类型,给定一个数据帧,它是一个pandas数据帧。这个静态方法可以像source_catalog
一样提供一个目录,并且输出类型将是一个目录对象。