Gitlab will migrate to a new storage backend starting 0300 UTC on 2020-04-04. We do not anticipate a maintenance window for this migration. Performance may be impacted over the weekend. Thanks for your patience.

Commit aeb04413 authored by Branson Stephens's avatar Branson Stephens

Added comment to EMObservation and modified client to allow Python list arguments.

parent d9c59ad9
......@@ -28,6 +28,21 @@ import netrc
DEFAULT_SERVICE_URL = "https://gracedb.ligo.org/api/"
KNOWN_TEST_HOSTS = ['moe.phys.uwm.edu', 'embb-dev.ligo.caltech.ed', 'simdb.phys.uwm.edu',]
#-----------------------------------------------------------------
# Utilities
# XXX It would be nice to get rid of this if we can.
# It seems that you can pass python lists via the requests package.
# That would make putting our lists into comma-separated strings
# unnecessary.
def cleanListInput(list_arg):
if isinstance(list_arg, float) or isinstance(list_arg, int):
stringified_value = str(list_arg)
return stringified_value
if not isinstance(list_arg, basestring):
stringified_list = ','.join(map(str,list_arg))
return stringified_list
#-----------------------------------------------------------------
# Exception(s)
......@@ -669,15 +684,15 @@ class GraceDb(GsiRest):
return self.get(uri)
def writeEMObservation(self, graceid, group, raList, raWidthList,
decList, decWidthList, startTimeList, durationList):
decList, decWidthList, startTimeList, durationList, comment=None):
"""Write an EM observation entry
Required args: graceid, group, raList, decList, raWidthList,
decWidthList, startTimeList, durationList
The various lists should contain comma-separated values (or
a single value). Start times are in ISO 8601 UTC. Durations
are in seconds.
The various lists arguments should contain Python lists or
comma-separated values (or a single value). Start times are
in ISO 8601 UTC. Durations are in seconds.
(Note that 'group' here is the name of the EM MOU group, not
the LVC data analysis group responsible for the original detection.)
......@@ -688,6 +703,12 @@ class GraceDb(GsiRest):
# NOTE: One could do validation of the various list inputs here
# rather than relying on the server.
# These arguments can consist of a single element, a python
# list, or a string. Transform the list args to csv (unless they
# already are)
raList, raWidthList, decList, decWidthList, startTimeList, durationList = map(
cleanListInput,
[raList, raWidthList, decList, decWidthList, startTimeList, durationList])
template = self.templates['emobservation-list-template']
uri = template.format(graceid=graceid)
......@@ -700,6 +721,7 @@ class GraceDb(GsiRest):
'decWidthList': decWidthList,
'startTimeList': startTimeList,
'durationList': durationList,
'comment': comment,
}
return self.post(uri, body=body)
......
......@@ -2,6 +2,7 @@
import unittest
import random
import os
from datetime import datetime
from ligo.gracedb.rest import GraceDb, GraceDbBasic
......@@ -80,22 +81,31 @@ class TestGracedb(unittest.TestCase):
self.assertTrue('numRows' in logs)
pass
def test_create_embb_log(self):
"""Create an EMBB log entry."""
def test_create_emobservation(self):
"""Create an EM observation entry."""
comment = "Message is {0}".format(random.random())
resp = gracedb.writeEel(eventId, 'Test', 'em.gamma',
'FO', 'TE', comment=comment, instrument='Test')
# Let's put in some made-up values
raList = [1.0,1.0,1.0]
raWidthList = 1.0
decList = [1.0,1.0,1.0]
decWidthList = 1.0
dt = datetime(1900,1,1,1,1,1)
startTimeList = [dt.isoformat() for i in range(3)]
durationList = 1.0
resp = gracedb.writeEMObservation(eventId, 'Test',
raList, raWidthList, decList, decWidthList,
startTimeList, durationList, comment)
self.assertEqual(resp.status, 201)
new_embb_log_uri = resp.getheader('Location')
new_embb_log = resp.json()
self.assertEqual(new_embb_log_uri, new_embb_log['self'])
check_new_embb_log = gracedb.get(new_embb_log_uri).json()
self.assertEqual(check_new_embb_log['comment'], comment)
def test_get_embb_log(self):
"""Retrieve EMBB event log"""
eels = gracedb.eels(eventId).json()
self.assertTrue('numRows' in eels)
new_emobservation_uri = resp.getheader('Location')
new_emobservation = resp.json()
self.assertEqual(new_emobservation_uri, new_emobservation['self'])
check_new_emobservation = gracedb.get(new_emobservation_uri).json()
self.assertEqual(check_new_emobservation['comment'], comment)
def test_get_emobservations(self):
"""Retrieve EM Observation List"""
emos = gracedb.emobservations(eventId).json()
self.assertTrue('numRows' in emos)
def test_upload_large_file(self):
"""Upload a large file. Issue https://bugs.ligo.org/redmine/issues/951"""
......
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