llama.files.lvc_skymap.utils module

Utilities for working with LVC skymaps

class llama.files.lvc_skymap.utils.SkymapFilename(string)

Bases: str

A skymap filename on GraceDB with built-in parsing of skymap file along with convenience methods used for selecting and canonicalizing skymap filenames.

property basename

Remove the filename extension and just get the base name. Since this base name corresponds to the information contained in the skymap (vs. the format of that information, given by SkymapFilename.extension), this should be a good indicator of the contents of the skymap.

>>> skymap = SkymapFilename("bayestar.multiorder.fits")
>>> skymap.basename
'bayestar'
>>> skymap0 = SkymapFilename("bayestar.multiorder.fits,0")
>>> skymap0.basename
'bayestar'
canonicalize(graceid, canonical_date=None)

Return the canonicalized filename (including version information) for this skymap filename for the given graceid at the given date (instance of datetime.datetime or None to use the current time). If this filename already contains a version, just return self. Queries GraceDB to resolve this information. Raises a ligo.gracedb.rest.HTTPError if a GraceDB query fails to connect.

For this event, a second version (v1) of bayestar.fits was created at 2019-05-10 04:03:40 UTC; canonicalizing at an earlier date should return v0 (the original) while a later date should return v1 (the update):

>>> from dateutil.parser import parse
>>> skymap = SkymapFilename("bayestar.fits")
>>> skymap.canonicalize("S190510g", parse("2019-05-10 04:03:30 UTC"))
'bayestar.fits,0'
>>> skymap.canonicalize("S190510g", parse("2019-05-10 04:03:50 UTC"))
'bayestar.fits,1'

If the skymap name was already canonicalized, then the original value will be returned:

>>> canonical = SkymapFilename("bayestar.fits,0")
>>> canonical == canonical.canonicalize("foo")
True

If the file does not exist at the requested time, then the version should be assumed to be the zeroth version (since this will be the first available version):

>>> nonexistent = SkymapFilename("bayestar.fits")
>>> unix0 = datetime.datetime.fromtimestamp(0)
>>> nonexistent.canonicalize("S190510g", unix0)
'bayestar.fits,0'
property extension

The file extension, drawn from SKYMAP_FILE_EXTENSIONS.

>>> skymap = SkymapFilename("bayestar.multiorder.fits")
>>> skymap.extension
'.multiorder.fits'
>>> skymap0 = SkymapFilename("bayestar.multiorder.fits,0")
>>> skymap0.extension
'.multiorder.fits'
property filename

The filename of this skymap, including the file extension, with the version number removed.

>>> skymap = SkymapFilename("bayestar.multiorder.fits")
>>> skymap.filename
'bayestar.multiorder.fits'
>>> skymap0 = SkymapFilename("bayestar.multiorder.fits,0")
>>> skymap.filename
'bayestar.multiorder.fits'
property version

The version of this skymap filename as an integer (since many versions of the same filename can be uploaded). Returns None if not specified.

>>> skymap = SkymapFilename("bayestar.multiorder.fits")
>>> skymap.version == None
True
>>> skymap0 = SkymapFilename("bayestar.multiorder.fits,0")
>>> skymap0.version
0
llama.files.lvc_skymap.utils.available_skymaps(graceid)

Get a list of available skymap logs in ascending order of creation time from GraceDB for a given graceid.

llama.files.lvc_skymap.utils.skymap_filenames(filenames)

Return only filenames from filenames that could be skymap filenames.