def build_filter_library(): if not file_existing_and_readable(os.path.join(get_speclite_filter_path(),'filter_lib.yml')): print ('Downloading optical filters. This will take a while.\n') if internet_connection_is_active(): filter_dict={} filter_dict = download_SVO_filters(filter_dict) filter_dict = download_grond(filter_dict) # Ok, finally, we want to keep track of the SVO filters we have # so we will save this to a YAML file for future reference with open(os.path.join(get_speclite_filter_path(),'filter_lib.yml'), 'w') as f: yaml.safe_dump(filter_dict, f, default_flow_style=False) return True else: print ("You do not have the 3ML filter library and you do not have an active internet connection.") print ("Please connect to the internet to use the 3ML filter library.") print ("pyspeclite filter library is still available.") return False else: return True
def build_filter_library(): if not file_existing_and_readable(os.path.join(get_speclite_filter_path(),'filter_lib.yml')): print ('Downloading optical filters. This will take a while.\n') if internet_connection_is_active(): filter_dict={} filter_dict = download_SVO_filters(filter_dict) filter_dict = download_grond(filter_dict) # Ok, finally, we want to keep track of the SVO filters we have # so we will save this to a YAML file for future reference with open(os.path.join(get_speclite_filter_path(),'filter_lib.yml'), 'w') as f: yaml.safe_dump(filter_dict, f, default_flow_style=False) return True else: print ("You do not have the 3ML filter library and you do not have an active internet connection.") print ("Please connect to the internet to use the 3ML filter library.") print ("pyspeclite filter library is still available.") return False else: return True
def cone_search(self, ra, dec, radius): """ Searches for sources in a cone of given radius and center :param ra: decimal degrees, R.A. of the center of the cone :param dec: decimal degrees, Dec. of the center of the cone :param radius: radius in degrees :return: a table with the list of sources """ skycoord = SkyCoord(ra=ra * u.degree, dec=dec * u.degree, frame='icrs') # First check that we have an active internet connection if not internet_connection_is_active(): # pragma: no cover raise ConeSearchFailed("It looks like you don't have an active internet connection. Cannot continue.") with warnings.catch_warnings(): #Ignore all warnings, which are many from the conesearch module warnings.simplefilter('ignore') try: votable = conesearch.conesearch(skycoord, radius, catalog_db=self.catalog, verb=3, verbose=True, cache=False) except VOSError as exc: # Pragma: no cover # Download failed raise ConeSearchFailed("Cone search failed. Reason: %s" % exc.message) else: # Download successful table = votable.to_table() self._last_query_results = table.to_pandas().set_index('name').sort_values("Search_Offset") out = self.apply_format(table) #This is needed to avoid strange errors del votable del table # Save coordinates of center of cone search self._ra = ra self._dec = dec # Make a DataFrame with the name of the source as index return out
def compute_fermi_relative_mission_times(trigger_time): """ If the user has the requests library, this function looks online to the HEASARC xtime utility and computes other mission times relative to the input MET :param trigger_time: a fermi MET :return: mission time in a python dictionary """ mission_dict = collections.OrderedDict() if trigger_time == 0: return None # Complements to Volodymyr Savchenko xtime_url = "https://heasarc.gsfc.nasa.gov/cgi-bin/Tools/xTime/xTime.pl" pattern = """<tr>.*?<th scope=row><label for="(.*?)">(.*?)</label></th>.*?<td align=center>.*?</td>.*?<td>(.*?)</td>.*?</tr>""" args = dict( time_in_sf=trigger_time, timesys_in="u", timesys_out="u", apply_clock_offset="yes") if internet_connection_is_active(): content = requests.get(xtime_url, params=args).content mission_info = re.findall(pattern, content, re.S) mission_dict['UTC'] = mission_info[0][-1] mission_dict[mission_info[7][1]] = mission_info[7][2] # LIGO mission_dict[mission_info[8][1]] = mission_info[8][2] # NUSTAR mission_dict[mission_info[12][1]] = mission_info[12][2] # RXTE mission_dict[mission_info[16][1]] = mission_info[16][2] # SUZAKU mission_dict[mission_info[20][1]] = mission_info[20][2] # SWIFT mission_dict[mission_info[24][1]] = mission_info[24][2] # CHANDRA return mission_dict else: return None
def compute_fermi_relative_mission_times(trigger_time): """ If the user has the requests library, this function looks online to the HEASARC xtime utility and computes other mission times relative to the input MET :param trigger_time: a fermi MET :return: mission time in a python dictionary """ mission_dict = collections.OrderedDict() if trigger_time == 0: return None # Complements to Volodymyr Savchenko xtime_url = "https://heasarc.gsfc.nasa.gov/cgi-bin/Tools/xTime/xTime.pl" pattern = """<tr>.*?<th scope=row><label for="(.*?)">(.*?)</label></th>.*?<td align=center>.*?</td>.*?<td>(.*?)</td>.*?</tr>""" args = dict( time_in_sf=trigger_time, timesys_in="u", timesys_out="u", apply_clock_offset="yes", ) if internet_connection_is_active(): content = requests.get(xtime_url, params=args).content mission_info = re.findall(pattern, content, re.S) mission_dict["UTC"] = mission_info[0][-1] mission_dict[mission_info[7][1]] = mission_info[7][2] # LIGO mission_dict[mission_info[8][1]] = mission_info[8][2] # NUSTAR mission_dict[mission_info[12][1]] = mission_info[12][2] # RXTE mission_dict[mission_info[16][1]] = mission_info[16][2] # SUZAKU mission_dict[mission_info[20][1]] = mission_info[20][2] # SWIFT mission_dict[mission_info[24][1]] = mission_info[24][2] # CHANDRA return mission_dict else: return None
import shutil import pytest from threeML import * from threeML.io.network import internet_connection_is_active from threeML.exceptions.custom_exceptions import TriggerDoesNotExist skip_if_internet_is_not_available = pytest.mark.skipif( not internet_connection_is_active(), reason="No active internet connection") @skip_if_internet_is_not_available @pytest.mark.xfail def test_download_GBM_data(): # test good trigger names good_triggers = ['080916009', 'bn080916009', 'GRB080916009'] which_detector = 'n1' for i, trigger in enumerate(good_triggers): temp_dir = '_download_temp' dl_info = download_GBM_trigger_data(trigger_name=trigger, detectors=[which_detector], destination_directory=temp_dir) assert os.path.exists(dl_info[which_detector]['rsp']) assert os.path.exists(dl_info[which_detector]['tte'])
import pytest from threeML import * from threeML.io.network import internet_connection_is_active skip_if_internet_is_not_available = pytest.mark.skipif(not internet_connection_is_active(), reason="No active internet connection") @skip_if_internet_is_not_available #@pytest.mark.xfail def test_gbm_catalog(): gbm_catalog = FermiGBMBurstCatalog() _ = gbm_catalog.cone_search(0.0, 0.0, 5.0) assert gbm_catalog.ra_center == 0.0 assert gbm_catalog.dec_center == 0.0 gbm_catalog.search_around_source('Crab', 5.0) models = ['band','comp','plaw','sbpl'] intervals = ['peak','fluence'] for model in models: for interval in intervals: _ = gbm_catalog.get_model(model=model,interval=interval) gbm_catalog.query('t90 >2')
import shutil import pytest from threeML import * from threeML.io.network import internet_connection_is_active from threeML.exceptions.custom_exceptions import TriggerDoesNotExist skip_if_internet_is_not_available = pytest.mark.skipif(not internet_connection_is_active(), reason="No active internet connection") @skip_if_internet_is_not_available @pytest.mark.xfail def test_download_LAT_data(): # Crab ra = 83.6331 dec = 22.0199 tstart = '2010-01-01 00:00:00' tstop = '2010-01-02 00:00:00' temp_dir = '_download_temp' ft1, ft2 = download_LAT_data(ra, dec, 20.0, tstart, tstop, time_type='Gregorian', destination_directory=temp_dir) assert os.path.exists(ft1) assert os.path.exists(ft2)
def cone_search(self, ra, dec, radius): """ Searches for sources in a cone of given radius and center :param ra: decimal degrees, R.A. of the center of the cone :param dec: decimal degrees, Dec. of the center of the cone :param radius: radius in degrees :return: a table with the list of sources """ skycoord = SkyCoord(ra=ra * u.degree, dec=dec * u.degree, frame="icrs") # First check that we have an active internet connection if not internet_connection_is_active(): # pragma: no cover raise ConeSearchFailed( "It looks like you don't have an active internet connection. Cannot continue." ) with warnings.catch_warnings(): # Ignore all warnings, which are many from the conesearch module warnings.simplefilter("ignore") try: votable = conesearch.conesearch( skycoord, radius, catalog_db=self.catalog, verb=3, verbose=True, cache=False, ) except VOSError as exc: # Pragma: no cover # Download failed raise ConeSearchFailed("Cone search failed. Reason: %s" % exc.message) else: # Download successful table = votable # Workaround to comply with newer versions of astroquery if isinstance(votable, astropy.io.votable.tree.Table): table = votable.to_table() if table is None: log.error("Your search returned nothing") return None table.convert_bytestring_to_unicode() pandas_df = (table.to_pandas().set_index("name").sort_values( "Search_Offset")) str_df = pandas_df.select_dtypes([object]) if astropy_old: str_df = str_df.stack().str.decode("utf-8").unstack() for col in str_df: pandas_df[col] = str_df[col] if astropy_old: new_index = [x.decode("utf-8") for x in pandas_df.index] pandas_df.index = new_index self._last_query_results = pandas_df out = self.apply_format(table) # This is needed to avoid strange errors del votable del table # Save coordinates of center of cone search self._ra = ra self._dec = dec # Make a DataFrame with the name of the source as index return out
import shutil import os import pytest from threeML import * from threeML.exceptions.custom_exceptions import TriggerDoesNotExist from threeML.io.network import internet_connection_is_active skip_if_internet_is_not_available = pytest.mark.skipif( not internet_connection_is_active(), reason="No active internet connection" ) try: import GtApp except ImportError: has_Fermi = False else: has_Fermi = True # This defines a decorator which can be applied to single tests to # skip them if the condition is not met skip_if_LAT_is_not_available = pytest.mark.skipif(not has_Fermi, reason="Fermi Science Tools not installed", )
def cone_search(self, ra, dec, radius): """ Searches for sources in a cone of given radius and center :param ra: decimal degrees, R.A. of the center of the cone :param dec: decimal degrees, Dec. of the center of the cone :param radius: radius in degrees :return: a table with the list of sources """ skycoord = SkyCoord(ra=ra * u.degree, dec=dec * u.degree, frame='icrs') # First check that we have an active internet connection if not internet_connection_is_active(): # pragma: no cover raise ConeSearchFailed( "It looks like you don't have an active internet connection. Cannot continue." ) with warnings.catch_warnings(): #Ignore all warnings, which are many from the conesearch module warnings.simplefilter('ignore') try: votable = conesearch.conesearch(skycoord, radius, catalog_db=self.catalog, verb=3, verbose=True, cache=False) except VOSError as exc: # Pragma: no cover # Download failed raise ConeSearchFailed("Cone search failed. Reason: %s" % exc.message) else: # Download successful table = votable.to_table() self._last_query_results = table.to_pandas().set_index( 'name').sort_values("Search_Offset") out = self.apply_format(table) #This is needed to avoid strange errors del votable del table # Save coordinates of center of cone search self._ra = ra self._dec = dec # Make a DataFrame with the name of the source as index return out