Skip to content

Commit

Permalink
Merge c726e97 into b56a56a
Browse files Browse the repository at this point in the history
  • Loading branch information
cdeil committed May 11, 2015
2 parents b56a56a + c726e97 commit 959201c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 14 deletions.
59 changes: 48 additions & 11 deletions gammapy/datasets/catalogs.py
Expand Up @@ -4,14 +4,17 @@

from __future__ import (absolute_import, division, print_function,
unicode_literals)
from astropy.table import Table
import numpy as np
from astropy.utils.data import download_file
from astropy.coordinates import Angle
from astropy.table import Table, Column
from ..datasets import get_path

__all__ = ['load_catalog_atnf',
'load_catalog_hess_galactic',
# 'load_catalog_hgps',
'load_catalog_green',
# 'load_catalog_snrcat',
'load_catalog_snrcat',
'load_catalog_tevcat',
]

Expand Down Expand Up @@ -116,25 +119,59 @@ def load_catalog_tevcat():
filename = get_path('catalogs/tevcat.fits.gz', location='remote')
return Table.read(filename)

# TODO: implement properly
def load_catalog_snrcat():

def load_catalog_snrcat(cache=True):
"""Load SNRcat supernova remnant catalog.
`SNRcat <http://www.physics.umanitoba.ca/snr/SNRcat/>`__
is a census of high-energy observations of Galactic supernova remnants.
Unfortunately the SNRCat information is not available in electronic format.
This function obtains the CSV table from
http://www.physics.umanitoba.ca/snr/SNRcat/SNRdownload.php?table=SNR
and adds some useful columns.
Note that this only represents a subset of the information available in SNRCat,
to get at the rest (e.g. observations and papers) we would have to scrape their
web pages.
This is a dump of http://www.physics.umanitoba.ca/snr/SNRcat/SNRlist.php?textonly from 2015-02-08.
It doesn't contain position and extension columns and is really a HTML page with lots of hidden stuff that
would have to be scraped, i.e. we can't be simply ``requests.get`` the latest version from there ... sigh.
I've contacted them and they might provide a useful version of their catalog in the future ...
Parameters
----------
cache : bool, optional
Whether to use the cache
Returns
-------
catalog : `~astropy.table.Table`
Source catalog
"""
filename = get_path('catalogs/SNRCat.csv', location='remote')
return Table.read(filename, format='ascii.csv')
url = 'http://www.physics.umanitoba.ca/snr/SNRcat/SNRdownload.php?table=SNR'
filename = download_file(url, cache=cache)

# Note: currently the first line contains this comment, which we skip via `header_start=1`
# This file was downloaded on 2015-05-11T03:00:55 CDT from http://www.physics.umanitoba.ca/snr/SNRcat
table = Table.read(filename, format='ascii.csv', header_start=1, delimiter=';')

# Fix the columns to have common column names and add unit info
table.rename_column('G', 'Source_Name')
table.rename_column('G_lon', 'GLON')
table['GLON'].unit = 'deg'
table.rename_column('G_lat', 'GLAT')
table['GLAT'].unit = 'deg'
table.rename_column('J', 'Source_JName')

ra = Angle(table['J_ra'], unit='hour').deg
dec = Angle(table['J_dec'], unit='deg').deg
index = table.index_column('J_dec') + 1
table.add_column(Column(ra, name='RAJ2000', unit='deg'), index=index)
table.add_column(Column(dec, name='DEJ2000', unit='deg'), index=index)

distance = np.mean([table['distance_min'], table['distance_max']], axis=0)
index = table.index_column('distance_max') + 1
table.add_column(Column(distance, name='distance', unit='kpc'), index=index)

# TODO: make age, distance and size columns quantities with units

# TODO: parse size_radio and size_X to get float columns

return table

6 changes: 3 additions & 3 deletions gammapy/datasets/tests/test_catalogs.py
Expand Up @@ -24,11 +24,11 @@ def test_load_catalog_green():
assert len(catalog) == 294


# TODO: activate test when available
@remote_data
def _test_load_catalog_snrcat():
def test_load_catalog_snrcat():
catalog = datasets.load_catalog_snrcat()
assert len(catalog) == 338
assert len(catalog) > 300
assert set(['Source_Name', 'RAJ2000']).issubset(catalog.colnames)


@remote_data
Expand Down

0 comments on commit 959201c

Please sign in to comment.