Commit 88e803d5 authored by Brandon Piotrzkowski's avatar Brandon Piotrzkowski

Merge branch 'skymapcomparison' into testraven

parents a21910f9 3a5e3d66
......@@ -237,7 +237,7 @@ def create_external_skymap(ra, dec, error):
return skymap
def write_to_fits(skymap, event):
def write_to_fits(skymap, event, notice_type, notice_date):
"""Write external sky map fits file, populating the
header with relevant info.
......@@ -254,6 +254,16 @@ def write_to_fits(skymap, event):
bytes array of sky map
"""
notice_type_dict = {
'60': 'SWIFT_BAT_GRB_ALERT',
'61': 'SWIFT_BAT_GRB_POSITION',
'110': 'FERMI_GBM_ALERT',
'111': 'FERMI_GBM_FLT_POS',
'112': 'FERMI_GBM_GND_POS',
'115': 'FERMI_GBM_FINAL_POS',
'131': 'FERMI_GBM_SUBTHRESHOLD'
}
gcn_id = event['extra_attributes']['GRB']['trigger_id']
with NamedTemporaryFile(suffix='.fits.gz') as f:
fits.write_sky_map(f.name, skymap,
......@@ -261,6 +271,8 @@ def write_to_fits(skymap, event):
url=event['links']['self'],
instruments=event['pipeline'],
gps_time=event['gpstime'],
notice_type=notice_type_dict[notice_type],
notice_date=notice_date,
creator='gwcelery',
origin='LIGO-VIRGO-KAGRA',
vcs_version=_version.get_versions()['version'],
......@@ -270,7 +282,7 @@ def write_to_fits(skymap, event):
@app.task(shared=False)
def create_upload_external_skymap(event):
def create_upload_external_skymap(event, notice_type, notice_date):
"""Create and upload external sky map using
RA, dec, and error radius information.
......@@ -280,6 +292,7 @@ def create_upload_external_skymap(event):
Dictionary of Swift external event
"""
graceid = event['graceid']
skymap_filename = event['pipeline'].lower() + '_skymap.fits.gz'
......@@ -288,7 +301,7 @@ def create_upload_external_skymap(event):
error = event['extra_attributes']['GRB']['error_radius']
skymap = create_external_skymap(ra, dec, error)
skymap_data = write_to_fits(skymap, event)
skymap_data = write_to_fits(skymap, event, notice_type, notice_date)
message = (
'Mollweide projection of <a href="/api/events/{graceid}/files/'
......
......@@ -122,11 +122,15 @@ def handle_grb_gcn(payload):
end = start + event['extra_attributes']['GRB']['trigger_duration']
detchar.check_vectors(event, event['graceid'], start, end)
external_skymaps.create_upload_external_skymap(event)
notice_type = \
root.find("./What/Param[@name='Packet_Type']").attrib['value']
notice_date = root.find("./Who/Date").text
external_skymaps.create_upload_external_skymap(event, notice_type, notice_date)
if event['pipeline'] == 'Fermi':
external_skymaps.get_upload_external_skymap(graceid)
@lvalert.handler('superevent',
'mdc_superevent',
'external_fermi',
......
......@@ -146,6 +146,7 @@ def test_create_upload_swift_skymap(mock_plot_allsky,
'error_radius': 0}},
'links': {
'self': 'https://gracedb.ligo.org/api/events/E356793'}}
external_skymaps.create_upload_external_skymap(event)
external_skymaps.create_upload_external_skymap(event, '111',
'2020-01-09T01:47:09')
mock_upload.assert_called()
mock_plot_allsky.assert_called_once()
......@@ -9,6 +9,7 @@ from ..tasks import detchar
from . import resource_json
@patch('gwcelery.tasks.external_skymaps.create_upload_external_skymap')
@patch('gwcelery.tasks.external_skymaps.get_upload_external_skymap',
return_value=None)
@patch('gwcelery.tasks.detchar.dqr_json', return_value='dqrjson')
......@@ -21,7 +22,8 @@ from . import resource_json
@patch('gwcelery.tasks.gracedb.create_event')
def test_handle_create_grb_event(mock_create_event, mock_get_event,
mock_upload, mock_json,
mock_get_upload_external_skymap):
mock_get_upload_external_skymap,
mock_create_upload_external_skymap):
text = resource_string(__name__, 'data/fermi_grb_gcn.xml')
external_triggers.handle_grb_gcn(payload=text)
mock_create_event.assert_called_once_with(filecontents=text,
......@@ -49,6 +51,25 @@ def test_handle_create_grb_event(mock_create_event, mock_get_event,
['data_quality'])
]
mock_upload.assert_has_calls(calls, any_order=True)
mock_create_upload_external_skymap.assert_called_once_with(
{'graceid': 'E1',
'gpstime': 1,
'instruments': '',
'pipeline': 'Fermi',
'extra_attributes': {
'GRB': {
'trigger_duration': 1,
'trigger_id': 123,
'ra': 0.0,
'dec': 0.0,
'error_radius': 10.0
}
},
'links': {
'self': 'https://gracedb.ligo.org/events/E356793/'
}
},
'115', '2018-05-24T18:35:45')
@patch('gwcelery.tasks.gracedb.get_events', return_value=[])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment