Example #1
0
 def test_ordering_param(self, simple_populated_db):
     """Just a sanity check that ordering syntax is correct"""
     dbinf = simple_populated_db
     all_ivorns = apiv1.list_ivorn(order=apiv1.OrderValues.id)
     all_ivorns_rev_order = apiv1.list_ivorn(order=apiv1.OrderValues.id_desc)
     assert all_ivorns == dbinf.inserted_ivorns
     assert all_ivorns_rev_order == all_ivorns[::-1]
Example #2
0
    def test_synopsis(self, simple_populated_db):
        """Check synopsis wrapper function, helper class."""
        dbinf = simple_populated_db

        # Try an packet with references
        ivorns_w_refs = apiv1.list_ivorn(filters={apiv1.FilterKeys.ref_any: True}, order=apiv1.OrderValues.id)
        s = Synopsis(apiv1.packet_synopsis(ivorns_w_refs[0]))
        assert s.references
        assert len(s.sky_events) == 0

        # Now try a non-existent ivorn:
        with pytest.raises(requests.HTTPError):
            apiv1.packet_synopsis("ivo://foo/bar")

        # Now try a packet with co-ords
        sb_ivorn = swift_bat_grb_655721.attrib["ivorn"]
        assert sb_ivorn in dbinf.inserted_ivorns
        s = Synopsis(apiv1.packet_synopsis(sb_ivorn))
        assert s.coords
        assert len(s.coords) == 1
        skyevent = s.sky_events[0]
        c_pkt = vp.pull_astro_coords(swift_bat_grb_655721)
        assert skyevent.position.ra.value == c_pkt.ra
        assert skyevent.position.dec.value == c_pkt.dec
        assert skyevent.position_error.value == c_pkt.err
Example #3
0
    def test_list_pagination(self, simple_populated_db, reset_globals_to_defaults):
        """
        Sanity check that pagination params passed correctly to wrapper func.

        (NB wrapper tested independently elsewhere).
        """
        vr.default_list_n_max = 30
        vr.default_pagesize = 5
        dbinf = simple_populated_db
        count = apiv1.count()
        assert count > vr.default_list_n_max
        ivorns = apiv1.list_ivorn()
        assert len(ivorns) == vr.default_list_n_max
        # This time we override the max:
        ivorns = apiv1.list_ivorn(n_max=0)
        assert len(ivorns) == dbinf.n_inserts
Example #4
0
def get_asassn(ndays, ref_date):
    start_date = ref_date - datetime.timedelta(days=ndays)
    obs_filters = {
        FilterKeys.role: 'observation',
        FilterKeys.authored_since: start_date,
        FilterKeys.authored_until: ref_date,
        FilterKeys.ivorn_contains: 'ASASSN',
        }
    asassn_ivorns = apiv1.list_ivorn(filters=obs_filters)
    asassn_events  = {}
    for ivorn in asassn_ivorns:
        raw_xml = apiv1.packet_xml(ivorn)
        root = lxml.etree.fromstring(raw_xml)
        
        for param in root.findall('./What/Group/Param'):
            if param.attrib['name'] == 'id_other':
                name = param.attrib['value']
                name = name.replace('= ', '')
                break
            if param.attrib['name'] == 'id_assasn':
                name = param.attrib['value']
                break
        
        isot = root.findall('./WhereWhen/ObsDataLocation/ObservationLocation/AstroCoords/'
                        'Time/TimeInstant/ISOTime')[0].text
        ra = root.findall('./WhereWhen/ObsDataLocation/ObservationLocation/AstroCoords/'
                        'Position2D/Value2/C1')[0].text
        dec = root.findall('./WhereWhen/ObsDataLocation/ObservationLocation/AstroCoords/'
                        'Position2D/Value2/C2')[0].text
                
        asassn_events[name] = {'isot': isot,
                            'ra': ra,
                            'dec': dec}
    return asassn_events
Example #5
0
def get_fermi(ndays, ref_date):
    start_date = ref_date - datetime.timedelta(days=ndays)
    obs_filters = {
        FilterKeys.role: 'observation',
        FilterKeys.authored_since: start_date,
        FilterKeys.authored_until: ref_date,
        FilterKeys.stream: 'nasa.gsfc.gcn/Fermi',
        FilterKeys.ivorn_contains: 'GBM_Fin_Pos',
        }
    fermi_ivorns = apiv1.list_ivorn(filters=obs_filters)
    fermi_events = {}
    for ivorn in fermi_ivorns:
        raw_xml = apiv1.packet_xml(ivorn)
        root = lxml.etree.fromstring(raw_xml)
        
        for param in root.findall('./What/Param'):
            if param.attrib['name'] == 'TrigID':
                name = 'FermiGBM-' + param.attrib['value']
                break
        
        isot = root.findall('./WhereWhen/ObsDataLocation/ObservationLocation/AstroCoords/'
                        'Time/TimeInstant/ISOTime')[0].text
        ra = root.findall('./WhereWhen/ObsDataLocation/ObservationLocation/AstroCoords/'
                        'Position2D/Value2/C1')[0].text
        dec = root.findall('./WhereWhen/ObsDataLocation/ObservationLocation/AstroCoords/'
                        'Position2D/Value2/C2')[0].text
                
        fermi_events[name] = {'isot': isot,
                            'ra': ra,
                            'dec': dec}
    return fermi_events
Example #6
0
    def test_xml_retrieval(self, simple_populated_db):
        dbinf = simple_populated_db
        all_ivorns = apiv1.list_ivorn(order=apiv1.OrderValues.id)
        xml = apiv1.packet_xml(all_ivorns[-1])
        assert xml == vp.dumps(dbinf.insert_packets[-1])

        # Now try a non-existent ivorn:
        with pytest.raises(requests.HTTPError):
            apiv1.packet_xml("ivo://foo/bar")
Example #7
0
def get_swift(ndays, ref_date):
    start_date = ref_date - datetime.timedelta(days=ndays)
    obs_filters = {
        FilterKeys.role: 'observation',
        FilterKeys.authored_since: start_date,
        FilterKeys.authored_until: ref_date,
        FilterKeys.stream: 'nasa.gsfc.gcn/SWIFT',
        FilterKeys.ivorn_contains: 'BAT_GRB_Pos',
        }
    swift_ivorns = apiv1.list_ivorn(filters=obs_filters)
    prog = ['A', 'B','C','D','E','F','G','H']
    swift_events = {}
    for ivorn in swift_ivorns:
        raw_xml = apiv1.packet_xml(ivorn)
        root = lxml.etree.fromstring(raw_xml)
        
        name = root.findall('./Why/Inference/Name')[0].text
        name = name.replace(' ', '')
        for key in swift_events.keys():
            if name in key:
                name = name + prog[(prog == key[-1]) + 1]
                break
        if name[-1] not in prog:
            name = name + prog[0]
            
        if 'null' in name:
            continue
        
        isot = root.findall('./WhereWhen/ObsDataLocation/ObservationLocation/AstroCoords/'
                        'Time/TimeInstant/ISOTime')[0].text
        ra = root.findall('./WhereWhen/ObsDataLocation/ObservationLocation/AstroCoords/'
                        'Position2D/Value2/C1')[0].text
        dec = root.findall('./WhereWhen/ObsDataLocation/ObservationLocation/AstroCoords/'
                        'Position2D/Value2/C2')[0].text
                
        swift_events[name] = {'isot': isot,
                              'ra': ra,
                              'dec': dec}

    return swift_events
import voeventdb.remote.apiv1 as apiv1
from astropy.coordinates import Angle, SkyCoord

# Define a search cone
cone_centre = SkyCoord(ra=149, dec=51, unit='deg')
cone_radius = Angle(3, unit='deg')

# Define a filter-set
my_filters = {
    apiv1.FilterKeys.cone: (cone_centre, cone_radius),
    apiv1.FilterKeys.ivorn_contains: 'BAT_GRB',
    apiv1.FilterKeys.role: 'observation',
}

# See how many results match our filter-set
n_results = apiv1.count(filters=my_filters)

# List all IVORNs for matching VOEvents, oldest first
matching_ivorns = apiv1.list_ivorn(
    filters=my_filters,
    order=apiv1.OrderValues.author_datetime,
)
# Fetch the raw XML for the first listed VOEvent
xml_content = apiv1.packet_xml(matching_ivorns[0])