def query_region_maps(self, position, radius, missions=__ALL_STRING, get_query_payload=False, cache=True): """ This method queries a chosen region for all available maps and returns a TableList with all the found maps metadata for the chosen missions and region. Parameters ---------- position : str or `astropy.coordinates` object Can either be a string of the location, eg 'M51', or the coordinates of the object. radius : str or `~astropy.units.Quantity` The radius of a region. missions : string or list, optional Can be either a specific mission or a list of missions (all mission names are found in list_missions()) or 'all' to search in all missions. Defaults to 'all'. get_query_payload : bool, optional When set to True the method returns the HTTP request parameters. Defaults to False. cache : bool, optional When set to True the method will use a cache located at .astropy/astroquery/cache. Defaults to True. Returns ------- table_list : `~astroquery.utils.TableList` Each mission returns a `~astropy.table.Table` with the metadata and observations available for the chosen missions and region. It is structured in a TableList like this: TableList with 8 tables: '0:HERSCHEL' with 8 column(s) and 25 row(s) '1:HST' with 8 column(s) and 735 row(s) Examples -------- query_region_maps("m101", "14'", "all") import astropy.units as u query_region_maps("265.05, 69.0", 14*u.arcmin, "Herschel") query_region_maps("265.05, 69.0", ["Herschel", "HST"]) """ sanitized_position = self._sanitize_input_position(position) sanitized_radius = self._sanitize_input_radius(radius) sanitized_missions = self._sanitize_input_mission(missions) query_result = {} sesame_database.set('simbad') coordinates = commons.parse_coordinates(sanitized_position) self._store_query_result_maps(query_result, sanitized_missions, coordinates, sanitized_radius, get_query_payload, cache) if (get_query_payload): return query_result return commons.TableList(query_result)
def test_database_specify(name, db_dict): # First check that at least some sesame mirror is up for url in sesame_url.get(): if urllib.request.urlopen(url).getcode() == 200: break else: pytest.skip("All SESAME mirrors appear to be down, skipping " "test_name_resolve.py:test_database_specify()...") for db in db_dict.keys(): with sesame_database.set(db): icrs = SkyCoord.from_name(name) time.sleep(1)
def test_database_specify(name, db_dict): # First check that at least some sesame mirror is up for url in sesame_url.get(): if urllib.request.urlopen(url).getcode() == 200: break else: pytest.skip("All SESAME mirrors appear to be down, skipping " "test_name_resolve.py:test_database_specify()...") for db in db_dict.keys(): with sesame_database.set(db): icrs = SkyCoord.from_name(name) time.sleep(1)
def query_region_catalogs(self, position, radius, catalogs=__ALL_STRING, row_limit=DEFAULT_ROW_LIMIT, get_query_payload=False, cache=True): """ This method queries a chosen region for all available catalogs and returns a TableList with all the found catalogs metadata for the chosen missions and region. Parameters ---------- position : str or `astropy.coordinates` object Can either be a string of the location, eg 'M51', or the coordinates of the object. radius : str or `~astropy.units.Quantity` The radius of a region. catalogs : string or list, optional Can be either a specific catalog or a list of catalogs (all catalog names are found in list_catalogs()) or 'all' to search in all catalogs. Defaults to 'all'. row_limit : int, optional Determines how many rows that will be fetched from the database for each mission. Can be -1 to select maximum (currently 100 000). Defaults to 10000. get_query_payload : bool, optional When set to True the method returns the HTTP request parameters. Defaults to False. cache : bool, optional When set to True the method will use a cache located at .astropy/astroquery/cache. Defaults to True. Returns ------- table_list : `~astroquery.utils.TableList` Each mission returns a `~astropy.table.Table` with the metadata of the catalogs available for the chosen mission and region. It is structured in a TableList like this: TableList with 8 tables: '0:Gaia DR1 TGA' with 8 column(s) and 25 row(s) '1:HSC' with 8 column(s) and 75 row(s) Examples -------- query_region_catalogs("m101", "14'", "all") import astropy.units as u query_region_catalogs("265.05, 69.0", 14*u.arcmin, "Gaia DR1 TGA") query_region_catalogs("265.05, 69.0", 14*u.arcmin, ["Gaia DR1 TGA", "HSC"]) """ sanitized_position = self._sanitize_input_position(position) sanitized_radius = self._sanitize_input_radius(radius) sanitized_catalogs = self._sanitize_input_catalogs(catalogs) sanitized_row_limit = self._sanitize_input_row_limit(row_limit) sesame_database.set('simbad') coordinates = commons.parse_coordinates(sanitized_position) query_result = {} self._store_query_result_catalogs(query_result, sanitized_catalogs, coordinates, sanitized_radius, sanitized_row_limit, get_query_payload, cache) if (get_query_payload): return query_result return commons.TableList(query_result)
def query_region_catalogs(self, position, radius, catalogs=__ALL_STRING, row_limit=DEFAULT_ROW_LIMIT, get_query_payload=False, cache=True): """ This method queries a chosen region for all available catalogs and returns a TableList with all the found catalogs metadata for the chosen missions and region. Parameters ---------- position : str or `astropy.coordinates` object Can either be a string of the location, eg 'M51', or the coordinates of the object. radius : str or `~astropy.units.Quantity` The radius of a region. catalogs : string or list, optional Can be either a specific catalog or a list of catalogs (all catalog names are found in list_catalogs()) or 'all' to search in all catalogs. Defaults to 'all'. row_limit : int, optional Determines how many rows that will be fetched from the database for each mission. Can be -1 to select maximum (currently 100 000). Defaults to 10000. get_query_payload : bool, optional When set to True the method returns the HTTP request parameters. Defaults to False. cache : bool, optional When set to True the method will use a cache located at .astropy/astroquery/cache. Defaults to True. Returns ------- table_list : `~astroquery.utils.TableList` Each mission returns a `~astropy.table.Table` with the metadata of the catalogs available for the chosen mission and region. It is structured in a TableList like this: TableList with 8 tables: '0:Gaia DR1 TGA' with 8 column(s) and 25 row(s) '1:HSC' with 8 column(s) and 75 row(s) Examples -------- query_region_catalogs("m101", "14'", "all") import astropy.units as u query_region_catalogs("265.05, 69.0", 14*u.arcmin, "Gaia DR1 TGA") query_region_catalogs("265.05, 69.0", 14*u.arcmin, ["Gaia DR1 TGA", "HSC"]) """ sanitized_position = self._sanitize_input_position(position) sanitized_radius = self._sanitize_input_radius(radius) sanitized_catalogs = self._sanitize_input_catalogs(catalogs) sanitized_row_limit = self._sanitize_input_row_limit(row_limit) sesame_database.set('simbad') coordinates = commons.parse_coordinates(sanitized_position) query_result = {} self._store_query_result_catalogs(query_result, sanitized_catalogs, coordinates, sanitized_radius, sanitized_row_limit, get_query_payload, cache) if (get_query_payload): return query_result return commons.TableList(query_result)
def query_region(self, objectname, match_tol=1.0, obj_radius=1.0, bycoord=False): ''' Fetch remote data from NED and SIMBAD matching coordinates and build table. ''' # Create custom query objects. customSimbad = Simbad() customNed = Ned() # Log SIMBAD votable (changeable) fields. logging.debug("SIMBAD votable fields") logging.debug(customSimbad.get_votable_fields()) customSimbad.remove_votable_fields('coordinates') # customSimbad.add_votable_fields("otype(3)", "ra(d)", "dec(d)") customSimbad.add_votable_fields("otype", "ra(d)", "dec(d)") # Download object data from both SIMBAD and NED. logging.info( "Querying SIMBAD and NED for region {}".format(objectname)) if bycoord: try: objectcoords = SkyCoord(objectname) except (ValueError, u.UnitsError): logging.info("Invalid coordinates.") return else: # Resolve the object name into sky coordinate using NED # ensures that NED and SIMBAD searches are using the same position sesame_database.set('ned') try: objectcoords = get_icrs_coordinates(objectname) except NameResolveError: logging.info("Name resolution failed.") return logging.info("Name resolved to coordinates {}".format(objectcoords)) # SIMBAD logging.info("SIMBAD is currently being queried...") try: with warnings.catch_warnings( ): # suppress warnings generated by SIMBAD query warnings.simplefilter("ignore") simbad_table = customSimbad.query_region(objectcoords, radius=obj_radius * u.arcmin) # workaround. If SIMBAD query finds nothing, returns None but we want a zero-length table if type(simbad_table) is not Table: logging.debug("No SIMBAD objects") simbad_table = Table(data=None, names=DataController.simbad_table_cols, dtype=DataController.simbad_table_dtypes, masked=True) logging.info("SUCCESS: SIMBAD Data retrieved.") except Timeout: logging.debug("SIMBAD timeout error") return # NED logging.info("NED is currently being queried...") for attempt in range( 3): # sometimes NED times out, so try a couple of times Ned.TIMEOUT = (attempt + 1) * DataController.ned_timeout_default try: ned_table = Ned.query_region(objectcoords, radius=obj_radius * u.arcmin) logging.info("SUCCESS: NED Data retrieved.") except RequestException: logging.debug("NED problem, retrying") else: # if attempt successful break out of loop, no need to try again break else: # closes for loop: executes only if all attempts fail logging.debug("NED query failed") return # Save some query stats. self.stats.query_name = objectname self.stats.sim_count = len(simbad_table) self.stats.ned_count = len(ned_table) # process tables ned_table = self.reformat_table( ned_table, keepcolsifpresent=[ 'Object Name', # cover NED changing names of cols 'RA(deg)', 'RA', 'DEC(deg)', 'DEC', 'Type' ], old_name='Object Name', new_name='Name_N', old_type='Type', new_type='Type_N') logging.info("Reformatting tables.") simbad_table = self.reformat_table( simbad_table, keepcolsifpresent=["MAIN_ID", "RA_d", "DEC_d", "OTYPE"], old_name='MAIN_ID', new_name='Name_S', old_type='OTYPE', new_type='Type_S') logging.info("Building sky coordinates.") # Build SkyCoord from appropriate ned and simbad col's with matching units ned_coo = SkyCoord(ra=ned_table['RA(deg)'], dec=ned_table['DEC(deg)']) sim_coo = SkyCoord(ra=simbad_table['RA_d'], dec=simbad_table['DEC_d']) logging.info("Finding object matches.") # Find object matches if len(ned_coo) > 0 and len(sim_coo) > 0: matched_ned, matched_sim, ned_only, sim_only = self.symmetric_match_sky_coords_v2( ned_coo, sim_coo, match_tol * u.arcsec) else: matched_ned = [] matched_sim = [] ned_only = [] sim_only = [] logging.debug("") logging.debug("Matched NED rows:") logging.debug(ned_table[matched_ned]) logging.debug("Matched SIMBAD rows:") logging.debug(simbad_table[matched_sim]) logging.debug("") self.stats.overlap_count = len(matched_ned) # Explore results logging.debug("Matched NED:") logging.debug(matched_ned) logging.debug("Matched SIMBAD") logging.debug(matched_sim) logging.debug("NED ONLY") logging.debug(ned_only) logging.debug("SIMBAD ONLY") logging.debug(sim_only) # Generate the matched table and save the result. logging.info("Building combined table.") matched_table = hstack( [ned_table[matched_ned], simbad_table[matched_sim]], join_type='outer', metadata_conflicts='silent') # Hide the metadata warning. self.combined_table = matched_table