1616"""
1717from astroquery .utils .tap import TapPlus
1818from astroquery .utils import commons
19+ from astroquery .simbad import Simbad
20+ from astroquery .vizier import Vizier
21+ from astroquery .ned import Ned
1922from astropy import units
2023from astropy .units import Quantity
24+ from astropy .coordinates import SkyCoord
25+ from astropy import log
2126
2227from datetime import datetime
2328import os
2732import shutil
2833import gzip
2934
35+
3036from . import conf
3137from .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+
0 commit comments