Skip to content

Commit 243f695

Browse files
jespinosaarbsipocz
authored andcommitted
JWSTPCR-133: query by target name method, tests and docs created
1 parent d7384e3 commit 243f695

11 files changed

+1345
-9
lines changed

astroquery/jwst/core.py

Lines changed: 138 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@
1616
"""
1717
from astroquery.utils.tap import TapPlus
1818
from astroquery.utils import commons
19+
from astroquery.simbad import Simbad
20+
from astroquery.vizier import Vizier
21+
from astroquery.ned import Ned
1922
from astropy import units
2023
from astropy.units import Quantity
24+
from astropy.coordinates import SkyCoord
25+
from astropy import log
2126

2227
from datetime import datetime
2328
import os
@@ -27,6 +32,7 @@
2732
import shutil
2833
import gzip
2934

35+
3036
from . import conf
3137
from .data_access import JwstDataHandler
3238

@@ -53,6 +59,7 @@ class JwstClass(object):
5359
PLANE_DATAPRODUCT_TYPES = ['image', 'cube', 'measurements', 'spectrum']
5460
ARTIFACT_PRODUCT_TYPES = ['info', 'thumbnail', 'auxiliary', 'science', 'preview']
5561
INSTRUMENT_NAMES = ['NIRISS', 'NIRSPEC', 'NIRCAM', 'MIRI', 'FGS']
62+
TARGET_RESOLVERS = ['ALL', 'SIMBAD', 'NED', 'VIZIER']
5663

5764
def __init__(self, tap_plus_handler=None, data_handler=None):
5865
if tap_plus_handler is None:
@@ -435,7 +442,7 @@ def query_region_async(self, coordinate, radius=None,
435442
coordinate : astropy.coordinates, mandatory
436443
coordinates center point
437444
radius : astropy.units, required if no 'width' nor 'height' are provided
438-
radius
445+
radius (deg)
439446
width : astropy.units, required if no 'radius' is provided
440447
box width
441448
height : astropy.units, required if no 'radius' is provided
@@ -716,7 +723,7 @@ def cone_search_async(self, coordinate, radius=None,
716723
flag to show all available columns in the output. Default behaviour is to show the most
717724
representative columns only
718725
background : bool, optional, default 'False'
719-
when the job is executed in asynchronous mode, this flag specifies
726+
when the job is executed in asynchronous mode, this flag specifies
720727
whether the execution will wait until results are available
721728
output_file : str, optional, default None
722729
file name where the results are saved if dumpToFile is True.
@@ -752,6 +759,135 @@ def cone_search_async(self, coordinate, radius=None,
752759
verbose=verbose,
753760
dump_to_file=dump_to_file)
754761

762+
def query_by_target_name(self, target_name, target_resolver="ALL",
763+
radius=None,
764+
width=None,
765+
height=None,
766+
observation_id=None,
767+
cal_level="Top",
768+
prod_type=None,
769+
instrument_name=None,
770+
filter_name=None,
771+
proposal_id=None,
772+
only_public=False,
773+
show_all_columns=False,
774+
async_job=False,
775+
verbose=False):
776+
"""Launches a job
777+
TAP & TAP+
778+
779+
Parameters
780+
----------
781+
target_name : str, mandatory
782+
name of the target that will be used as center point
783+
target_resolver : str, optional, default ALL
784+
resolver used to associate the target name with its coordinates.
785+
The ALL option evaluates a "SIMBAD then NED then VIZIER"
786+
approach. Options are: ALL, SIMBAD, NED, VIZIER.
787+
radius : astropy.units, required if no 'width' nor 'height' are
788+
provided.
789+
radius (deg)
790+
width : astropy.units, required if no 'radius' is provided
791+
box width
792+
height : astropy.units, required if no 'radius' is provided
793+
box height
794+
observation_id : str, optional, default None
795+
get the observation given by its ID.
796+
cal_level : object, optional, default 'Top'
797+
get the planes with the given calibration level. Options are:
798+
'Top': str, only the planes with the highest calibration level
799+
1,2,3: int, the given calibration level
800+
prod_type : str, optional, default None
801+
get the observations providing the given product type. Options are:
802+
'image','cube','measurements','spectrum': str, only results of the
803+
given product type
804+
instrument_name : str, optional, default None
805+
get the observations corresponding to the given instrument name.
806+
Options are:
807+
'NIRISS', 'NIRSPEC', 'NIRCAM', 'MIRI', 'FGS': str, only results
808+
of the given instrument
809+
filter_name : str, optional, default None
810+
get the observations made with the given filter.
811+
proposal_id : str, optional, default None
812+
get the observations from the given proposal ID.
813+
only_public : bool, optional, default 'False'
814+
flag to show only metadata corresponding to public observations
815+
show_all_columns : bool, optional, default 'False'
816+
flag to show all available columns in the output. Default behaviour
817+
is to show the most
818+
representative columns only
819+
async_job : bool, optional, default 'False'
820+
executes the query (job) in asynchronous/synchronous mode (default
821+
synchronous)
822+
verbose : bool, optional, default 'False'
823+
flag to display information about the process
824+
825+
Returns
826+
-------
827+
The job results (astropy.table).
828+
"""
829+
coordinates = self.resolve_target_coordinates(target_name,
830+
target_resolver)
831+
if async_job:
832+
return self.query_region_async(coordinates, radius, width, height,
833+
observation_id=observation_id,
834+
cal_level=cal_level,
835+
prod_type=prod_type,
836+
instrument_name=instrument_name,
837+
filter_name=filter_name,
838+
proposal_id=proposal_id,
839+
only_public=only_public,
840+
show_all_columns=show_all_columns,
841+
verbose=verbose)
842+
else:
843+
return self.query_region(coordinates, radius, width, height,
844+
observation_id=observation_id,
845+
cal_level=cal_level,
846+
prod_type=prod_type,
847+
instrument_name=instrument_name,
848+
filter_name=filter_name,
849+
proposal_id=proposal_id,
850+
only_public=only_public,
851+
show_all_columns=show_all_columns,
852+
verbose=verbose)
853+
854+
def resolve_target_coordinates(self, target_name, target_resolver):
855+
if target_resolver not in self.TARGET_RESOLVERS:
856+
raise ValueError('This target resolver is not allowed')
857+
858+
result_table = None
859+
if target_resolver == 'ALL' or target_resolver == 'SIMBAD':
860+
try:
861+
result_table = Simbad.query_object(target_name)
862+
return SkyCoord('{} {}'.format(result_table['RA'][0],
863+
result_table['DEC'][0]),
864+
unit=(units.hourangle,
865+
units.deg), frame='icrs')
866+
except Exception:
867+
log.info('SIMBAD could not resolve this target')
868+
if target_resolver == 'ALL' or target_resolver == 'NED':
869+
try:
870+
result_table = Ned.query_object(target_name)
871+
return SkyCoord(result_table['RA'][0],
872+
result_table['DEC'][0],
873+
unit='deg', frame='fk5')
874+
except Exception:
875+
log.info('NED could not resolve this target')
876+
if target_resolver == 'ALL' or target_resolver == 'VIZIER':
877+
try:
878+
result_table = Vizier.query_object(target_name,
879+
catalog='II/336/apass9')[0]
880+
# Sorted to use the record with the least uncertainty
881+
result_table.sort(['e_RAJ2000', 'e_DEJ2000'])
882+
return SkyCoord(result_table['RAJ2000'][0],
883+
result_table['DEJ2000'][0],
884+
unit='deg', frame='fk5')
885+
except Exception:
886+
log.info('VIZIER could not resolve this target')
887+
if result_table is None:
888+
raise ValueError('This target name cannot be determined with'
889+
' this resolver: {}'.format(target_resolver))
890+
755891
def remove_jobs(self, jobs_list, verbose=False):
756892
"""Removes the specified jobs
757893
TAP+
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Produced with astropy.io.votable version 4.0.1.post1
3+
http://www.astropy.org/ -->
4+
<VOTABLE version="1.4" xmlns="http://www.ivoa.net/xml/VOTable/v1.4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.ivoa.net/xml/VOTable/v1.4">
5+
<RESOURCE type="results">
6+
<TABLE ID="NED_MainTable" name="Main Information Table for MESSIER 001">
7+
<DESCRIPTION>
8+
Main information about object (Cone Search results)
9+
</DESCRIPTION>
10+
<FIELD ID="No." datatype="int" name="No." ucd="meta.number" width="4">
11+
<DESCRIPTION>
12+
A sequential object number applicable to this list only.
13+
</DESCRIPTION>
14+
</FIELD>
15+
<FIELD ID="Object_Name" arraysize="30" datatype="char" name="Object Name" ucd="meta.id;meta.main" width="30">
16+
<DESCRIPTION>
17+
NED preferred name for the object
18+
</DESCRIPTION>
19+
</FIELD>
20+
<FIELD ID="RA" datatype="double" name="RA" ucd="pos.eq.ra;meta.main" unit="degrees" width="10">
21+
<DESCRIPTION>
22+
Right Ascension in degrees (Equatorial J2000.0)
23+
</DESCRIPTION>
24+
</FIELD>
25+
<FIELD ID="DEC" datatype="double" name="DEC" ucd="pos.eq.dec;meta.main" unit="degrees" width="10">
26+
<DESCRIPTION>
27+
Declination in degrees (Equatorial J2000.0)
28+
</DESCRIPTION>
29+
</FIELD>
30+
<FIELD ID="Type" arraysize="*" datatype="char" name="Type" ucd="src.class" width="10">
31+
<DESCRIPTION>
32+
NED's Preferred Object Type: G,GPair,GTrpl,GGroup,GClstr,QSO,AbLS
33+
,RadioS,IrS,EmLS,UvES,XrayS,SN
34+
</DESCRIPTION>
35+
</FIELD>
36+
<FIELD ID="Velocity" datatype="double" name="Velocity" ucd="src.veloc.hc" unit="km.s-1" width="10">
37+
<DESCRIPTION>
38+
Velocity in km/sec, based on known heliocentric redshift
39+
</DESCRIPTION>
40+
</FIELD>
41+
<FIELD ID="Redshift" datatype="double" name="Redshift" ucd="src.redshift" width="10">
42+
<DESCRIPTION>
43+
Heliocentric redshift for the object, if it exists in NED
44+
</DESCRIPTION>
45+
</FIELD>
46+
<FIELD ID="Redshift_Flag" arraysize="*" datatype="char" name="Redshift Flag" ucd="meta.code;src.redshift" width="5">
47+
<DESCRIPTION>
48+
Quality flag for known heliocentric redshift
49+
</DESCRIPTION>
50+
</FIELD>
51+
<FIELD ID="Magnitude_and_Filter" arraysize="*" datatype="char" name="Magnitude and Filter" ucd="meta.code;src.magnitude" width="5">
52+
<DESCRIPTION>
53+
NED's Basic Data magnitude and filter, generally in an optical
54+
band.
55+
</DESCRIPTION>
56+
</FIELD>
57+
<FIELD ID="Separation" datatype="double" name="Separation" ucd="pos.distance" unit="arcmin" width="10">
58+
<DESCRIPTION>
59+
Angular separation of the object coordinates and the search
60+
coordinate.
61+
</DESCRIPTION>
62+
</FIELD>
63+
<FIELD ID="References" datatype="int" name="References" ucd="meta.bib;meta.number" width="5">
64+
<DESCRIPTION>
65+
Number of literature references in NED
66+
</DESCRIPTION>
67+
</FIELD>
68+
<FIELD ID="Notes" datatype="int" name="Notes" ucd="meta.note;meta.number" width="5">
69+
<DESCRIPTION>
70+
Number of catalog notes in NED
71+
</DESCRIPTION>
72+
</FIELD>
73+
<FIELD ID="Photometry_Points" datatype="int" name="Photometry Points" ucd="phot;meta.number" width="5">
74+
<DESCRIPTION>
75+
Number of photometric data points stored by NED for the object
76+
</DESCRIPTION>
77+
</FIELD>
78+
<FIELD ID="Positions" datatype="int" name="Positions" ucd="pos;meta.number" width="5">
79+
<DESCRIPTION>
80+
Number of position data points stored by NED for the object
81+
</DESCRIPTION>
82+
</FIELD>
83+
<FIELD ID="Redshift_Points" datatype="int" name="Redshift Points" ucd="src.redshift;meta.number" width="5">
84+
<DESCRIPTION>
85+
Number of redshift data points stored by NED for the object.
86+
</DESCRIPTION>
87+
</FIELD>
88+
<FIELD ID="Diameter_Points" datatype="int" name="Diameter Points" ucd="phys.size.diameter;meta.number" width="5">
89+
<DESCRIPTION>
90+
Number of diameter data points stored by NED for the object.
91+
</DESCRIPTION>
92+
</FIELD>
93+
<FIELD ID="Associations" datatype="int" name="Associations" ucd="meta.id.assoc;meta.number" width="5">
94+
<DESCRIPTION>
95+
Number of NED associations for the object.
96+
</DESCRIPTION>
97+
</FIELD>
98+
<DATA>
99+
<TABLEDATA>
100+
<TR>
101+
<TD>1</TD>
102+
<TD>MESSIER 001</TD>
103+
<TD> 83.63321</TD>
104+
<TD> 22.01446</TD>
105+
<TD>SNR</TD>
106+
<TD/>
107+
<TD/>
108+
<TD/>
109+
<TD/>
110+
<TD/>
111+
<TD>136</TD>
112+
<TD>2</TD>
113+
<TD>61</TD>
114+
<TD>18</TD>
115+
<TD>0</TD>
116+
<TD>2</TD>
117+
<TD>0</TD>
118+
</TR>
119+
</TABLEDATA>
120+
</DATA>
121+
</TABLE>
122+
</RESOURCE>
123+
</VOTABLE>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SELECT DISTANCE(POINT('ICRS',target_ra,target_dec), POINT('ICRS',83.63321000000002,22.01446)) AS dist, observationid, calibrationlevel, public, dataproducttype, instrument_name, energy_bandpassname, target_name, target_ra, target_dec, position_bounds_center, position_bounds_spoly FROM jwst.main WHERE CONTAINS( POINT('ICRS',target_ra,target_dec), CIRCLE('ICRS',83.63321000000002,22.01446, 5.0))=1 AND max_cal_level=calibrationlevel ORDER BY dist ASC
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Produced with astropy.io.votable version 4.0.1.post1
3+
http://www.astropy.org/ -->
4+
<VOTABLE version="1.4" xmlns="http://www.ivoa.net/xml/VOTable/v1.4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.ivoa.net/xml/VOTable/v1.4">
5+
<RESOURCE type="results">
6+
<TABLE ID="SimbadScript" name="default">
7+
<DESCRIPTION>
8+
Simbad script executed on 2020.04.27CEST17:47:25
9+
</DESCRIPTION>
10+
<FIELD ID="MAIN_ID" arraysize="*" datatype="char" name="MAIN_ID" ucd="meta.id;meta.main" width="22">
11+
<DESCRIPTION>
12+
Main identifier for an object
13+
</DESCRIPTION>
14+
<LINK href="http://simbad.u-strasbg.fr/simbad/sim-id?Ident=${MAIN_ID}&amp;NbIdent=1" value="${MAIN_ID}"/>
15+
</FIELD>
16+
<FIELD ID="RA" arraysize="13" datatype="unicodeChar" name="RA" precision="8" ucd="pos.eq.ra;meta.main" unit="&quot;h:m:s&quot;" width="13">
17+
<DESCRIPTION>
18+
Right ascension
19+
</DESCRIPTION>
20+
</FIELD>
21+
<FIELD ID="DEC" arraysize="13" datatype="unicodeChar" name="DEC" precision="8" ucd="pos.eq.dec;meta.main" unit="&quot;d:m:s&quot;" width="13">
22+
<DESCRIPTION>
23+
Declination
24+
</DESCRIPTION>
25+
</FIELD>
26+
<FIELD ID="RA_PREC" datatype="short" name="RA_PREC" width="2">
27+
<DESCRIPTION>
28+
Right ascension precision
29+
</DESCRIPTION>
30+
</FIELD>
31+
<FIELD ID="DEC_PREC" datatype="short" name="DEC_PREC" width="2">
32+
<DESCRIPTION>
33+
Declination precision
34+
</DESCRIPTION>
35+
</FIELD>
36+
<FIELD ID="COO_ERR_MAJA" datatype="float" name="COO_ERR_MAJA" precision="3" ucd="phys.angSize.smajAxis;pos.errorEllipse;pos.eq" unit="mas" width="6">
37+
<DESCRIPTION>
38+
Coordinate error major axis
39+
</DESCRIPTION>
40+
</FIELD>
41+
<FIELD ID="COO_ERR_MINA" datatype="float" name="COO_ERR_MINA" precision="3" ucd="phys.angSize.sminAxis;pos.errorEllipse;pos.eq" unit="mas" width="6">
42+
<DESCRIPTION>
43+
Coordinate error minor axis
44+
</DESCRIPTION>
45+
</FIELD>
46+
<FIELD ID="COO_ERR_ANGLE" datatype="short" name="COO_ERR_ANGLE" ucd="pos.posAng;pos.errorEllipse;pos.eq" unit="deg" width="3">
47+
<DESCRIPTION>
48+
Coordinate error angle
49+
</DESCRIPTION>
50+
</FIELD>
51+
<FIELD ID="COO_QUAL" arraysize="1" datatype="unicodeChar" name="COO_QUAL" ucd="meta.code.qual;pos.eq" width="1">
52+
<DESCRIPTION>
53+
Coordinate quality
54+
</DESCRIPTION>
55+
</FIELD>
56+
<FIELD ID="COO_WAVELENGTH" arraysize="1" datatype="unicodeChar" name="COO_WAVELENGTH" ucd="instr.bandpass;pos.eq" width="1">
57+
<DESCRIPTION>
58+
Wavelength class for the origin of the coordinates (R,I,V,U,X,G)
59+
</DESCRIPTION>
60+
</FIELD>
61+
<FIELD ID="COO_BIBCODE" arraysize="*" datatype="char" name="COO_BIBCODE" ucd="meta.bib.bibcode;pos.eq" width="19">
62+
<DESCRIPTION>
63+
Coordinate reference
64+
</DESCRIPTION>
65+
</FIELD>
66+
<DATA>
67+
<TABLEDATA>
68+
<TR>
69+
<TD>M 1</TD>
70+
<TD>05 34 31.94</TD>
71+
<TD>+22 00 52.2</TD>
72+
<TD>6</TD>
73+
<TD>6</TD>
74+
<TD/>
75+
<TD/>
76+
<TD>0</TD>
77+
<TD>C</TD>
78+
<TD>R</TD>
79+
<TD>2011A&amp;A...533A..10L</TD>
80+
</TR>
81+
</TABLEDATA>
82+
</DATA>
83+
</TABLE>
84+
</RESOURCE>
85+
</VOTABLE>

0 commit comments

Comments
 (0)