def __init__(self, coord, radius, mission, **kwargs): surveycoord.SurveyCoord.__init__(self, coord, radius, **kwargs) # self.survey = None self.mission = mission # Instantiate astroquery object self.heasarc = Heasarc()
def get_obsid_list_from_heasarc(cache_file='heasarc.hdf5'): try: heasarc = Heasarc() all_nustar_obs = heasarc.query_object( '*', 'numaster', resultmax=100000, fields='OBSID,TIME,END_TIME,NAME,OBSERVATION_MODE,OBS_TYPE') except Exception: return Table({ 'TIME': [0], 'TIME_END': [0], 'MET': [0], 'NAME': [""], 'OBSERVATION_MODE': [""], 'OBS_TYPE': [""], 'OBSID': [""] }) all_nustar_obs = all_nustar_obs[all_nustar_obs["TIME"] > 0] for field in 'OBSID,NAME,OBSERVATION_MODE,OBS_TYPE'.split(','): all_nustar_obs[field] = [om.strip() for om in all_nustar_obs[field]] mjds = Time(np.array(all_nustar_obs['TIME']), format='mjd') mjd_ends = Time(np.array(all_nustar_obs['END_TIME']), format='mjd') # all_nustar_obs = all_nustar_obs[all_nustar_obs["OBSERVATION_MODE"] == 'SCIENCE'] all_nustar_obs['MET'] = np.array(all_nustar_obs['TIME'] - NUSTAR_MJDREF) * 86400 all_nustar_obs['DATE'] = mjds.fits all_nustar_obs['DATE-END'] = mjd_ends.fits return all_nustar_obs
def GetObservationList(source_name, mission): try: logging.debug('Querying Heasarc {} for source {}'.format(mission, source_name)) obs_list = h.query_object(source_name, mission=mission, fields='All', resultmax=3000) return obs_list except: logging.debug('Failed to get {} observation list'.format(mission)) return None
def get_precise_position(source): heasarc = Heasarc() try: result_table = heasarc.query_object( source, mission='atnfpulsar', fields=f'RA,DEC') pos = result_table[0] ra, dec = pos['RA'] * u.deg, pos['DEC'] * u.deg coords = SkyCoord(ra, dec, frame='icrs') except (ValueError, TypeError): log.warning("Not found in ATNF; searching Simbad") result_table = Simbad.query_object(source) pos = result_table[0] ra, dec = pos['RA'], pos['DEC'] coords = SkyCoord(ra, dec, frame='icrs', unit=(u.hourangle, u.deg)) log.info(f"Precise position: {ra}, {dec}") return coords
class HEASARC_Survey(surveycoord.SurveyCoord): """ Class to handle queries on the HEASARC survey. Uses `astroquery` for searching the Heasarc SQL database. Args: coord (SkyCoord): Coordiante for surveying around radius (Angle): Search radius around the coordinate mission (str): Mission served by HEASAR for the data searches """ def __init__(self, coord, radius, mission, **kwargs): surveycoord.SurveyCoord.__init__(self, coord, radius, **kwargs) # self.survey = None self.mission = mission # Instantiate astroquery object self.heasarc = Heasarc() def get_catalog(self): """ Grab a catalog of sources around the input coordinate to the search radius Returns: astropy.table.Table: Catalog of sources returned """ try: catalog = self.heasarc.query_region(self.coord, mission=self.mission, radius=self.radius) except (ValueError, TypeError): # No table found self.catalog = Table() else: # Clean if len(catalog) != 0: catalog.rename_column("RA", "ra") catalog.rename_column("DEC", "dec") for key in ['ra', 'dec']: catalog[key].unit = units.deg # Sort self.catalog = catalog_utils.sort_by_separation(catalog, self.coord, radec=('ra', 'dec')) else: self.catalog = catalog # Add meta, etc. self.catalog.meta['radius'] = self.radius self.catalog.meta['survey'] = self.survey # Validate self.validate_catalog() # Return return self.catalog
""" Methods related to fussing with a catalog""" import numpy as np import pdb from astropy.coordinates import SkyCoord from astropy import units # Import check try: from astroquery.heasarc import Heasarc #from astroquery.xmatch import XMatch except ImportError: print("Warning: You need to install astroquery to use the survey tools...") else: # Instantiate heasarc = Heasarc() def clean_heasarc(catalog): """ Insure RA/DEC are ra/dec in the Table Table is modified in place Args: catalog (astropy.table.Table): Catalog generated by astroquery """ # RA/DEC catalog.rename_column("RA", "ra") catalog.rename_column("DEC", "dec")
def test_has_input_products(self, instrument, logger=None): print('--> start has input_products') RA = instrument.get_par_by_name('RA').value DEC = instrument.get_par_by_name('DEC').value radius = instrument.get_par_by_name('radius').value scw_list = instrument.get_par_by_name('scw_list').value use_max_pointings = instrument.get_par_by_name('max_pointings').value osa_version = instrument.get_par_by_name('osa_version').value query_out = QueryOutput() message = '' debug_message = '' has_input_products_message = '' prod_list = [] if scw_list is not None and scw_list != []: prod_list = scw_list else: T1_iso = instrument.get_par_by_name('T1')._astropy_time.isot T2_iso = instrument.get_par_by_name('T2')._astropy_time.isot print('input', RA, DEC, T1_iso, T2_iso) if self._test_products_with_astroquery: # note that this just might introduce discrepancy, since it is not the exact workflow used by the backend from astroquery.heasarc import Heasarc import astroquery heasarc = Heasarc() with astroquery.heasarc.Conf.server.set_temp( 'https://www.isdc.unige.ch/browse/w3query.pl'): T_i = heasarc.query_region( SkyCoord(RA, DEC, unit="deg"), mission='integral_rev3_scw', resultmax=1000000, # all ppo radius="200 deg", cache=False, time=T1_iso.replace("T", " ") + " .. " + T2_iso.replace("T", " "), fields='All') else: target = "ReportScWList" modules = ['git://rangequery/staging-1-3'] scwlist_assumption = OsaDispatcher.get_scwlist_assumption( None, T1_iso, T2_iso, RA, DEC, radius, use_max_pointings) assume = [ "rangequery.ReportScWList(input_scwlist=%s)" % scwlist_assumption[0], scwlist_assumption[1] ] remote = dc.RemoteDDA(self.data_server_url, self.data_server_cache) try: product = remote.query(target=target, modules=modules, assume=assume, sync=True) #DONE query_out.set_done(message=message, debug_message=str(debug_message)) prod_list = getattr(product, 'scwidlist', None) if prod_list is None: raise RuntimeError(f"product.prod_list is None") if len(prod_list) < 1: run_query_message = 'scwlist empty' debug_message = '' query_out.set_failed('test has input prods', message=run_query_message, logger=logger, job_status='failed', e_message=run_query_message, debug_message='') raise DDAException(message='scwlist empty', debug_message='') except dc.WorkerException as e: run_query_message = 'WorkerException' debug_message = self.get_exceptions_message(e) # FAILED query_out.set_failed('test has input prods', message='has input_products=%s' % run_query_message, logger=logger, excep=e, job_status='failed', e_message=run_query_message, debug_message=debug_message) raise DDAException('WorkerException', debug_message) except dc.AnalysisException as e: run_query_message = 'AnalysisException' debug_message = self.get_exceptions_message(e) query_out.set_failed('test has input prods', message='run query message=%s' % run_query_message, logger=logger, excep=e, job_status='failed', e_message=run_query_message, debug_message=debug_message) raise DDAException(message=run_query_message, debug_message=debug_message) except Exception as e: run_query_message = 'DDAUnknownException in test has input prods: ' + repr( e) query_out.set_failed('test has input prods ', message='run query message=%s' % run_query_message, logger=logger, excep=e, job_status='failed', e_message=run_query_message, debug_message='') raise DDAUnknownException() return query_out, prod_list
from astroquery.vizier import Vizier import pandas as pd import time class ULX(): '''This class is used to for the creation of ULX objects ''' def __init__(self, name, ra, dec, host, ulx_num, candidate): self.name = name self.ra = ra self.dec = dec self.host = host self.ulx_num = ulx_num self.candidate = candidate h = Heasarc() v = Vizier() v.ROW_LIMIT = -1 # ============================================================================= # Useful Commands ''' table.show_in_browser(jsviewer=True) h_mission_list = h.query_mission_list() ''' # ============================================================================= cxogsgsrc #'cxogsrc','xmmmaster',
def query_master_catalogue(source_name): h = Heasarc() catalogue = h.query_object(source_name, mission='xmmmaster') return catalogue