Interacting with ligo.skymap

If ligo.skymap is installed in your environment and a skymap can be successfully produced, pesummary will store the skymap data in the pesummary metafile when the summarypages executable is run. A fits file is also produced and can be downloaded directly from the webpages. For details about how to install the ligo.skymap package, see the ligo.skymap documentation. Below we will go through how this data can be extracted and a skymap produced. We will also explain how a fits file can be produced and added to an existing pesummary metafile is a skymap is not already present.

A ligo.skymap skymap is produced automatically with the summarypages executable if the ligo.skymap package is installed. The fits file can then be downloaded directly from the webpages, or accessed from the meta file itself. To produce a skymap from the probability array stored in the meta file, we may run,

>>> from import read
>>> f = read('posterior_samples.h5')
>>> label = f.labels[0]
>>> fig = f.skymap[label].plot(contour=[50, 90])
>>> fig.savefig('skymap.png')

If more than one skymap is stored in the meta file, a comparison plot can be produced by running,

>>> from import read
>>> f = read('posterior_samples.h5')
>>> labels = f.labels[:2]
>>> fig = f.skymap.plot(
...     colors=["k", "r"], contour=[90], show_probability_map=labels[0],
...     labels=labels
... )
>>> fig.savefig('skymap_comparison.png')

If, however, the skymap data is not stored in the meta file, a skymap can be produced by following the instructions below.

Generating a fits file with the ligo.skymap executables

Here we will go through step by step how to generate a skymap with the ligo.skymap package when you have a PESummary metafile. If, you wish to produce the skymap without running the summarypages executable, this can be done by following the instructions below.

If your metafile has a single analysis stored, a skymap can be generated with ease:

$ ligo-skymap-from-samples --enable-multiresolution \
                           --samples posterior_samples.h5 \
                           --outdir ./

If your metafile has more than one analysis stored, you will need to select which analysis you wish to use. This may be done with the –path command line executable,

$ ligo-skymap-from-samples --enable-multiresolution \
                           --samples posterior_samples.h5 \
                           --outdir ./ \
                           --path analysis_one/posterior_samples

where –path should be {label}/posterior_samples.

Appending a fits file to an existing metafile

A ligo.skymap fits file may be added to an existing pesummary metafile with the summarymodify executable. An example command line is below which demonstrates how to add the contents of the fits file located at ./skymap.fits to the posterior_samples.h5 file for the analysis with label analysis_one:

$ summarymodify --webdir ./ \
                --store_skymap analysis_one:./skymap.fits \
                --samples posterior_samples.h5

Generating a skymap

A skymap can be produced easily when the pesummary file has been read in using the pesummary package. For details about how to read in a pesummary file with the pesummary package, see Reading in a pesummary metafile,

 1from import fetch_open_samples
 2import matplotlib.pyplot as plt
 3import requests
 4import time
 6TESTING = True
 9def generate_skymap(samples, **kwargs):
10    """Generate a skymap from a SamplesDict object
12    Parameters
13    ----------
14    samples: pesummary.utils.samples_dict.SamplesDict
15        samples you wish to generate a skymap for
16    **kwargs: dict, optional
17        all additional kwargs are passed to the `.plot()` method
18    """
19    return samples.plot(type="skymap", **kwargs)
22f = fetch_open_samples(
23    "GW190814", catalog="GWTC-2", unpack=True, path="GW190814.h5"
25label = f.labels[0]
27# If the pesummary file has the skymap data already
28# stored in the metafile, we may directly use the plot
29# function
31    skymap = f.skymap[label]
32    fig = skymap.plot()
34except (KeyError, AttributeError):
35    print("No skymap data stored in the metafile")
37# Otherwise, we may produce a skymap on the fly using
38# the posterior samples already stored. This may take
39# some time
40posterior_samples = f.samples_dict[label]
42    import multiprocessing
44    p = multiprocessing.Process(target=generate_skymap, args=(posterior_samples,))
45    p.start()
46    # Only let the skymap generation run for 120s
47    time.sleep(120)
48    p.terminate()
49    p.join()
51    fig = posterior_samples.plot(type="skymap")