用于接收XML格式GCN/TAN通知的匿名VOEvent客户端
项目描述
PyGCN
用于接收XML格式GCN/TAN通知的匿名VOEvent客户端
伽马射线坐标网络/瞬态天文学网络 (GCN/TAN) 是一个分发天文学警报的系统,主要关注高能卫星任务的操作和检测。
GCN/TAN 通过几种交付方法和格式分发通知(即时、机器可读的警报)和报告(人类可读的通讯)。
此软件包实现了一个简单的客户端,它通过自定义TCP/IP VOEvent传输协议 监听VOEvent XML格式的通知。默认情况下,它连接到匿名GCN/TAN服务器之一,因此不需要注册或配置即可开始接收警报。
安装
要安装PyGCN,只需运行
$ pip install --user pygcn
用法
PyGCN提供了一个名为 pygcn-listen
的示例脚本,它将简单地将其接收到的所有VOEvents写入当前目录下的文件。要试用,只需运行
$ pygcn-listen
然后按Control-C退出。
编写自定义GCN处理程序
您也可以编写自己的处理器,为收到的每个GCN执行自定义操作。处理器函数接受两个参数:payload
,GCN的原始内容,以及root
,XML文档的根元素,由lxml.etree
解析。以下是一个基本示例
#!/usr/bin/env python
import gcn
# Define your custom handler here.
def handler(payload, root):
# Get the IVORN, or unique VOEvent ID, and print it.
print(root.attrib['ivorn'])
# Print all of the event attributes.
for param in root.findall('./What/Param'):
name = param.attrib['name']
value = param.attrib['value']
print('{} = {}'.format(name, value))
# Listen for VOEvents until killed with Control-C.
gcn.listen(handler=handler)
过滤
您还可以使用gcn.include_notice_types
或gcn.exclude_notice_types
通过通知类型过滤事件。以下是一个示例
#!/usr/bin/env python
import gcn
# Define your custom handler here.
@gcn.include_notice_types(
gcn.notice_types.FERMI_GBM_FLT_POS, # Fermi GBM localization (flight)
gcn.notice_types.FERMI_GBM_GND_POS, # Fermi GBM localization (ground)
gcn.notice_types.FERMI_GBM_FIN_POS) # Fermi GBM localization (final)
def handler(payload, root):
# Look up right ascension, declination, and error radius fields.
pos2d = root.find('.//{*}Position2D')
ra = float(pos2d.find('.//{*}C1').text)
dec = float(pos2d.find('.//{*}C2').text)
radius = float(pos2d.find('.//{*}Error2Radius').text)
# Print.
print('ra = {:g}, dec={:g}, radius={:g}'.format(ra, dec, radius))
# Listen for VOEvents until killed with Control-C.
gcn.listen(handler=handler)
项目详情
下载文件
下载您平台对应的文件。如果您不确定选择哪一个,请了解更多关于安装包的信息。
源分发
pygcn-1.1.3.tar.gz (30.4 kB 查看哈希值)
构建分发
pygcn-1.1.3-py3-none-any.whl (30.9 kB 查看哈希值)
关闭
pygcn-1.1.3.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | cc74d365e9b53bd909ec7c4c0d36badf327c848f1481909669f099526fde66dc |
|
MD5 | 41caf34d468680d049a6aaca2b5da501 |
|
BLAKE2b-256 | 27e957246fe197bb9478742d601398796224aefe509bc7f00f39c276dfb2be8f |
关闭
pygcn-1.1.3-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 732f4c45242fd5e631a6d302a6174bf3b3c9be91a9f2adaa25f4ffdd21e6a172 |
|
MD5 | 1c12d8f0186ecaaf997262402774467c |
|
BLAKE2b-256 | 8ad2f5b49358dd8b86b3476ba5ba8fdb77632a1a88d11ad799d56a2abbaaf82d |