Skip to content

Commit f365097

Browse files
authored
Merge pull request #1814 from esdc-esac-esa-int/feat-XXX-download-epic-metadata
Download epic metadata
2 parents ccdc465 + d6cec4f commit f365097

File tree

4 files changed

+150
-1
lines changed

4 files changed

+150
-1
lines changed

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ gaia
119119
- Improved code to handle bit data type. [#1784]
120120
- Prepared code to handle new datalink products. [#1784]
121121

122+
esa.xmm_newton
123+
^^^^^^^^^^^^^^
124+
125+
- Added new function to download EPIC sources metadate. [#1814]
122126

123127
0.4.1 (2020-06-19)
124128
==================

astroquery/esa/xmm_newton/core.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
from . import conf
2424
from astropy import log
25+
from astropy.coordinates import SkyCoord
2526

2627

2728
__all__ = ['XMMNewton', 'XMMNewtonClass']
@@ -433,5 +434,78 @@ def get_epic_images(self, filename, *, band=[], instrument=[],
433434

434435
return ret
435436

437+
def get_epic_metadata(self, *, target_name=None,
438+
coordinates=None, radius=None):
439+
"""Downloads the European Photon Imaging Camera (EPIC)
440+
metadata from a given target
441+
442+
Parameters
443+
----------
444+
target_name : string, optional, default None
445+
The name of the target
446+
coordinates : `~astropy.coordinates.SkyCoord`, optinal, default None
447+
The coordinates of the target in a SkyCoord object
448+
radius : float, optional, default None
449+
The radius to query the target in degrees
450+
451+
Returns
452+
-------
453+
epic_source, cat_4xmm, stack_4xmm, slew_source : `~astropy.table.Table` objects
454+
Tables containing the metadata of the target
455+
"""
456+
if not target_name and not coordinates:
457+
raise Exception("Input parameters needed, "
458+
"please provide the name "
459+
"or the coordinates of the target")
460+
461+
epic_source = {"table": "xsa.v_epic_source",
462+
"column": "epic_source_equatorial_spoint"}
463+
cat_4xmm = {"table": "xsa.v_epic_source_cat",
464+
"column": "epic_source_cat_equatorial_spoint"}
465+
stack_4xmm = {"table": "xsa.v_epic_xmm_stack_cat",
466+
"column": "epic_stack_cat_equatorial_spoint"}
467+
slew_source = {"table": "xsa.v_slew_source_cat",
468+
"column": "slew_source_cat_equatorial_spoint"}
469+
470+
cols = "*"
471+
472+
c = coordinates
473+
if not coordinates:
474+
c = SkyCoord.from_name(target_name, parse=True)
475+
476+
if type(c) is not SkyCoord:
477+
raise Exception("The coordinates must be an "
478+
"astroquery.coordinates.SkyCoord object")
479+
if not radius:
480+
radius = 0.1
481+
482+
query_fmt = ("select {} from {} "
483+
"where 1=contains({}, circle('ICRS', {}, {}, {}));")
484+
epic_source_table = self.query_xsa_tap(query_fmt.format(cols,
485+
epic_source["table"],
486+
epic_source["column"],
487+
c.ra.degree,
488+
c.dec.degree,
489+
radius))
490+
cat_4xmm_table = self.query_xsa_tap(query_fmt.format(cols,
491+
cat_4xmm["table"],
492+
cat_4xmm["column"],
493+
c.ra.degree,
494+
c.dec.degree,
495+
radius))
496+
stack_4xmm_table = self.query_xsa_tap(query_fmt.format(cols,
497+
stack_4xmm["table"],
498+
stack_4xmm["column"],
499+
c.ra.degree,
500+
c.dec.degree,
501+
radius))
502+
slew_source_table = self.query_xsa_tap(query_fmt.format(cols,
503+
slew_source["table"],
504+
slew_source["column"],
505+
c.ra.degree,
506+
c.dec.degree,
507+
radius))
508+
return epic_source_table, cat_4xmm_table, stack_4xmm_table, slew_source_table
509+
436510

437511
XMMNewton = XMMNewtonClass()

astroquery/esa/xmm_newton/tests/test_xmm_newton.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
import os
1717
import errno
1818
import shutil
19+
from astropy.coordinates import SkyCoord
20+
from astropy.utils.diff import report_diff_values
21+
from astroquery.utils.tap.core import TapPlus
22+
1923
from ..core import XMMNewtonClass
2024
from ..tests.dummy_tap_handler import DummyXMMNewtonTapHandler
2125

@@ -295,3 +299,47 @@ def test_get_epic_images(self):
295299
for ob_name in self._files:
296300
shutil.rmtree(ob_name)
297301
os.remove(_tarname)
302+
303+
@pytest.mark.remote_data
304+
def test_get_epic_metadata(self):
305+
tap_url = "http://nxsadev.esac.esa.int/tap-server/tap/"
306+
target_name = "4XMM J122934.7+015657"
307+
radius = 0.01
308+
epic_source_table = "xsa.v_epic_source"
309+
epic_source_column = "epic_source_equatorial_spoint"
310+
cat_4xmm_table = "xsa.v_epic_source_cat"
311+
cat_4xmm_column = "epic_source_cat_equatorial_spoint"
312+
stack_4xmm_table = "xsa.v_epic_xmm_stack_cat"
313+
stack_4xmm_column = "epic_stack_cat_equatorial_spoint"
314+
slew_source_table = "xsa.v_slew_source_cat"
315+
slew_source_column = "slew_source_cat_equatorial_spoint"
316+
xsa = XMMNewtonClass(TapPlus(url=tap_url))
317+
epic_source, cat_4xmm, stack_4xmm, slew_source = xsa.get_epic_metadata(target_name=target_name,
318+
radius=radius)
319+
c = SkyCoord.from_name(target_name, parse=True)
320+
query = ("select * from {} "
321+
"where 1=contains({}, circle('ICRS', {}, {}, {}));")
322+
table = xsa.query_xsa_tap(query.format(epic_source_table,
323+
epic_source_column,
324+
c.ra.degree,
325+
c.dec.degree,
326+
radius))
327+
assert report_diff_values(epic_source, table)
328+
table = xsa.query_xsa_tap(query.format(cat_4xmm_table,
329+
cat_4xmm_column,
330+
c.ra.degree,
331+
c.dec.degree,
332+
radius))
333+
assert report_diff_values(cat_4xmm, table)
334+
table = xsa.query_xsa_tap(query.format(stack_4xmm_table,
335+
stack_4xmm_column,
336+
c.ra.degree,
337+
c.dec.degree,
338+
radius))
339+
assert report_diff_values(stack_4xmm, table)
340+
table = xsa.query_xsa_tap(query.format(slew_source_table,
341+
slew_source_column,
342+
c.ra.degree,
343+
c.dec.degree,
344+
radius))
345+
assert report_diff_values(slew_source, table)

docs/esa/xmm_newton.rst

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,30 @@ This will show the column details of the table 'v_all_observations' in XSA TAP s
133133
>>> XMMNewton.get_epic_images('tarfile.tar', band=[1,2], instrument=['M1'])
134134
{1: {'M1': '/home/dev/esa/0405320501/pps/P0405320501M1S002IMAGE_1000.FTZ'}, 2: {'M1': '/home/dev/esa/0405320501/pps/P0405320501M1S002IMAGE_2000.FTZ'}}
135135
136-
This will extract the European Photon Imaging Camera (EPIC) images within the specified TAR file, bands, and instruments. It will also return a dictionary containing the paths to the extracted files.
136+
This will extract the European Photon Imaging Camera (EPIC) images within the specified TAR file, bands, and instruments. It will also return a dictionary containing the paths to the extracted files.
137+
138+
------------------------------------------------------------------------------
139+
7. Getting the European Photon Imaging Camera (EPIC) metadata from the XSA TAP
140+
------------------------------------------------------------------------------
141+
142+
This function retrieves the EPIC metadata from a given target.
143+
144+
The target must be defined with either a source name or a `~astropy.coordinates.SkyCoord` object.
145+
146+
The EPIC metadata can be found in four tables in the XSA TAP:
147+
148+
- xsa.v_epic_source
149+
- xsa.v_epic_source_cat
150+
- xsa.v_epic_xmm_stack_cat
151+
- xsa.v_slew_source_cat
152+
153+
.. code-block:: python
154+
155+
>>> from astroquery.esa.xmm_newton import XMMNewton
156+
>>>
157+
>>> epic_source, cat_4xmm, stack_4xmm, slew_source = XMMNewton.get_epic_metadata(target_name="4XMM J122934.7+015657")
158+
159+
This will return the metadata within the four TAP tables in four `~astropy.table.Table` for the given target.
137160

138161
Reference/API
139162
=============

0 commit comments

Comments
 (0)