Using Curl with GraceDB [public]

How upload footprints for the bulletin board

The following program builds the cirl commands that you can use to communicate with the LIGO-Virgo event database, GraceDB. You should already be able to log in and get a password, then put that in your .netrc file as in the example below, and then you can upload the coordinates of your observations.

# Upload observation footprints to !GraceDB/EMBB bulletin board
# Questions, write roy.williams@ligo,org

# with a line similar to this
#    machine gracedb.ligo.org login albert.einstein@LIGO.ORG password JKJKJKJkjkjkjkj1223
# You can get the password from 
#    https://gracedb.ligo.org/gracedb/options/manage_password

import os
# This translates for urls, ' ' -> %20 and ',' -> $2C etc
from urllib import quote   

def upload_to_embb(grace_id, report, base_url='https://gracedb.ligo.org/gracedb'):

# grace_id : the identifier of the event to which this report is to be added
# report   : the information we want to upload to that event's bulletin board, as dictionary
# here we can set defaults to simplify things
    datum_list = []   # strings like 'key=value'
    for (key,val) in report.items():
        s = key + '=' + quote(str(val))
        datum_list.append(s)
# form a curl command
    first_part = 'curl --request POST --insecure --netrc --data '
# this part is list of "key=value" delimited by ampersand
    data_part = '"' + '&'.join(datum_list) + '" '   
    url_part = base_url + '/apibasic/events/' + grace_id + '/emobservation/'
    command = first_part + data_part + url_part   # concatenation of strings
    print command
# run the command
    os.system(command)

#### Here is an example #################
if __name__ == '__main__':
    grace_id = 'M158044'        # identifier for the event this report concerns

# report the observations
    report = {
    'group'       :'CRTS',      # the MOU group responsible
    'comment'     :'hello my friend',     # the human-made part of the report
    'raList'      :'123.0,124.0,125.0',   # a list of RA of centers of footprints (degrees)
    'decList'     :'10.0,11.0,13.0',      # a list of Dec of centers of footprints (degrees)
    'startTimeList' :'"2015-05-31T12:45:00","2015-05-31T12:49:00","2015-05-31T12:53:00"',  # list of beginnings of exposures, UTC
    'raWidthList' :'10.0',       # list (or one for all) of footprint widths in RA (degrees)
    'decWidthList':'10.0',       # list (or one for all) of footprint widths in Dec (degrees)
    'durationList':'20.0',       # list (or one for all) of exposure times in sec
    }
    upload_to_embb(grace_id, report)

-- RoyWilliams - 20 Apr 2015
Topic revision: r7 - 2018-05-29, adminuser
Warning: Can't find topic LV_EM.WebLeftBarExample

This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding GW-Astronomy wiki? Send feedback