Extract information from a pesummary file

Alongside the data that is stored in a core pesummary metafile (see the core docs), the gw pesummary metafile stores additional information, for example the PSD and calibration data.

Extracting skymap statistics

If a ligo.skymap skymap was successfully produced when the metafile was created, the skymap statistics (sky localisation at 90% confidence, localization volume at 90% confidence etc.) are stored in the metadata. These can be extracted by running:

>>> ind = data.labels.index("EXP1")
>>> kwargs = data.extra_kwargs[ind]["other"]
>>> print(kwargs["area90"])
'1234.0'

Extracting strain data

If passed from the command line, the gravitational wave strain data used during the analysis is also stored in the PESummary metafile. You can extract it by running:

>>> strain_data = data.gwdata
>>> IFOs = strain_data.detectors
>>> strain = strain_data[IFOs[0]]

Here strain_data is a pesummary.gw.file.strain.StrainDataDict object and strain is a pesummary.gw.file.strain.StrainData object. For details about these objects see the <Strain Data in PESummary tutorial.

Loading the calibration envelope for a specific run

If passed from the command line, the calibration envelope that was used during the analysis is also stored in the PESummary metafile. You can extract it for a specific run by running:

>>> calibration_data = data.priors["calibration"]["EXP1"]
>>> IFOs = calibration_data.detectors
>>> IFO = IFOs[0]
>>> frequency = calibration_data[IFO].frequencies
>>> median_mag = calibration_data[IFO].magnitude
>>> mag_lower = calibration_data[IFO].magnitude_lower

For more details see the Calibration class tutorial.

Loading the psd for a specific run

If passed from the command line, the psds that were used during the analysis are also stored in the PESummary metafile. You can extract it for a specific analysis by running:

>>> psd = data.psd["EXP1"]
>>> print(type(psd))
<class 'pesummary.gw.file.psd.PSDDict'>
>>> IFOs = psd.detectors
>>> IFO = IFOs[0]
>>> frequency = psd[IFO].frequencies
>>> strains = psd[IFO].strains

For more details see the PSD class tutorial.

Converting file format

As well as converting to same file formats as described in the core docs, the gw package also allows for you to convert to a lalinference .hdf5 or a lalinference .dat file. This can be done by using the following:

>>> data.to_lalinference(outdir="./")
>>> data.to_lalinference(outdir="./", dat=True)

Loading all data for a specific run without PESummary

Of course, you do not have to use PESummary to load in the data from a PESummary metafile. The core JSON and h5py python libraries can be used. The PESummary file has the following data structure:

label                               Group
    -> posterior_samples            Dataset
    -> config_file                  Group
        -> [section]                Group
            -> key                  Dataset
    -> priors                       Group
        -> calibration              Group
            -> IFO                  Dataset
        -> samples                  Dataset
    -> injection_data               Dataset
    -> meta_data                    Group
        -> meta_data                Group
            -> gracedb              Group
                -> id               Dataset
                ->                  Dataset
            ->                      Dataset
        -> sampler                  Group
            ->                      Dataset
    -> version                      Dataset
    -> approximant                  Dataset
    -> calibration_envelope         Group
        -> IFO                      Dataset
    -> psds                         Group
        -> IFO                      Dataset
    -> skymap                       Group
        -> data                     Dataset
        -> meta_data                Group
            ->                      Dataset

label2                              Group
    -> posterior_samples            Dataset
    -> config_file                  Group
        -> [section]                Group
            -> key                  Dataset
    -> priors                       Group
        -> calibration              Group
            -> IFO                  Dataset
    -> injection_data               Dataset
    -> meta_data                    Group
        -> meta_data                Group
            -> gracedb              Group
                -> id               Dataset
                ->                  Dataset
            ->                      Dataset
        -> sampler                  Group
            ->                      Dataset
    -> version                      Dataset
    -> approximant                  Dataset
    -> calibration_envelope         Group
        -> IFO                      Dataset
    -> psds                         Group
        -> IFO                      Dataset
    -> skymap                       Group
        -> data                     Dataset
        -> meta_data                Group
            ->                      Dataset

...

version                             Group
    -> environment                  Dataset
    -> packages                     Dataset
    -> pesummary                    Dataset

history
    -> gps_creation_time            Dataset
    -> creator                      Dataset
    ->                              Dataset