GraceDbHelper

GraceDbHelper(group)

Bases: object

Source code in gw/lts/utils/gracedb_helper.py
11
12
13
14
def __init__(self, group):
    self.group = group
    service_url = f"https://{self.group}/api/"
    self.client = GraceDb(service_url=service_url)

query_file

query_file(graceid, filename, outpath=None, tag=None)

Download a file from given GraceDb event. Optionally write out the file to disk. Return the file.

Source code in gw/lts/utils/gracedb_helper.py
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def query_file(self, graceid, filename, outpath=None, tag=None):
    """
    Download a file from given GraceDb event.
    Optionally write out the file to disk.
    Return the file.
    """
    try:
        response = self.client.files(graceid, filename)
        if response.status == http.client.OK:
            if outpath:
                outfile = os.path.join(outpath, f"{tag}-{graceid}.fits")
                with open(outfile, "wb") as f:
                    f.write(response.read())
    except HTTPError:
        response = None

    return response