PSD class

pesummary handles PSD data through a custom PSD class. This PSD class is inherited from the numpy.ndarray class. Multiple PSDs are stored in the PSDDict class.

Initializing the PSD class

The PSD class is initialized with an 2d array containing the frequency and strain data,

>>> from pesummary.gw.file.psd import PSD
>>> import numpy as np
>>> frequencies = [0, 0.125, 0.25]
>>> strains = [0.25, 0.25, 0.25]
>>> psd_data = np.vstack([frequencies, strains]).T
>>> psd = PSD(psd_data)

Alternatively, a file containing the psd can be read in with,

>>> filename = "./IFO0_psd.dat"
>>> psd = PSD.read(filename)

Using the PSD object

The PSD object allows for you to save the stored PSD data with ease. This can be done with the following:

>>> psd.save_to_file("new_psd.dat", delimiter="\t")

Initializing the PSDDict class

The PSDDict class is initialized with a dictionary of 2d array’s containing the frequency and strain data for each detector you are interested in,

>>> from pesummary.gw.file.psd import PSDDict
>>> psd_data = {
...     "H1": [[0.00000e+00, 2.50000e-01],
...            [1.25000e-01, 2.50000e-01],
...            [2.50000e-01, 2.50000e-01]],
...     "V1": [[0.00000e+00, 2.50000e-01],
...            [1.25000e-01, 2.50000e-01],
...            [2.50000e-01, 2.50000e-01]]
... }
>>> psd_dict = PSDDict(psd_data)

The data for each detector is stored as a PSD object:

>>> type(psd_dict["H1"])
<class 'pesummary.gw.file.psd.PSD'>

If you have multiple psds stored in multiple files, you can simply run the following,

>>> psd_H1 = PSD.read("IFO0_psd.dat")
>>> psd_V1 = PSD.read("IFO2_psd.dat")
>>> psd_data = {"H1": psd_H1, "V1": psd_V1}
>>> psd_dict = PSDDict(psd_data)

Using the PSDDict object

The PSDDict object has extra helper functions and properties to make it easier for you to extract the information stored within. For example, you can list the detectors stored with,

>>> psd_dict.detectors
['H1', 'V1']

Or you can simply plot all stored PSDs on a single axis,

>>> psd_dict.plot()

The frequency and strain data for a specific IFO can also be extracted with,

>>> psd_dict["H1"].frequencies
array([0.   , 0.125, 0.25 ])
>>> psd_dict["H1"].strains
array([0.25, 0.25, 0.25])

pesummary.gw.file.psd.PSD

class pesummary.gw.file.psd.PSD(input_array)[source]

Class to handle PSD data

interpolate(low_freq_cutoff, delta_f)[source]

Interpolate PSD to a new delta_f

Parameters:
  • low_freq_cutoff (float) – Frequencies below this value are set to zero.

  • delta_f (float, optional) – Frequency resolution of the frequency series in Hertz.

classmethod read(path_to_file, **kwargs)[source]

Read in a file and initialize the PSD class

Parameters:
  • path_to_file (str) – the path to the file you wish to load

  • **kwargs (dict) – all kwargs are passed to the read methods

static read_from_dat(path_to_file, IFO=None, **kwargs)[source]

Read in a dat file and return a numpy array containing the data

Parameters:
  • path_to_file (str) – the path to the file you wish to load

  • **kwargs (dict) – all kwargs are passed to the numpy.genfromtxt method

static read_from_xml(path_to_file, IFO=None, **kwargs)[source]

Read in an xml file and return a numpy array containing the data

Parameters:
  • path_to_file (str) – the path to the file you wish to load

  • IFO (str, optional) – name of the dataset that you wish to load

  • **kwargs (dict) – all kwargs are passed to the gwpy.frequencyseries.FrequencySeries.read method

save_to_file(file_name, comments='#', delimiter='\t')[source]

Save the calibration data to file

Parameters:
  • file_name (str) – name of the file name that you wish to use

  • comments (str, optional) – String that will be prepended to the header and footer strings, to mark them as comments. Default is ‘#’.

  • delimiter (str, optional) – String or character separating columns.

to_pycbc(low_freq_cutoff, f_high=None, length=None, delta_f=None, f_high_override=False)[source]

Convert the PSD object to an interpolated pycbc.types.FrequencySeries

Parameters:
  • length (int, optional) – Length of the frequency series in samples.

  • delta_f (float, optional) – Frequency resolution of the frequency series in Herz.

  • low_freq_cutoff (float, optional) – Frequencies below this value are set to zero.

  • f_high_override (Bool, optional) – Override the final frequency if it is above the maximum stored. Default False

pesummary.gw.file.psd.PSDDict

class pesummary.gw.file.psd.PSDDict(*args)[source]

Class to handle a dictionary of PSDs

Parameters:
  • detectors (list) – list of detectors

  • data (nd list) – list of psd samples for each detector. First column is frequencies, second column is strains

detectors

list of detectors stored in the dictionary

Type:

list

plot:

Generate a plot based on the psd samples stored

to_pycbc:

Convert dictionary of PSD objects to a dictionary of pycbc.frequencyseries objects objects

Examples

>>> from pesummary.gw.file.psd import PSDDict
>>> detectors = ["H1", "V1"]
>>> psd_data = [
...     [[0.00000e+00, 2.50000e-01],
...      [1.25000e-01, 2.50000e-01],
...      [2.50000e-01, 2.50000e-01]],
...     [[0.00000e+00, 2.50000e-01],
...      [1.25000e-01, 2.50000e-01],
...      [2.50000e-01, 2.50000e-01]]
... ]
>>> psd_dict = PSDDict(detectors, psd_data)
>>> psd_data = {
...     "H1": [[0.00000e+00, 2.50000e-01],
...            [1.25000e-01, 2.50000e-01],
...            [2.50000e-01, 2.50000e-01]],
...     "V1": [[0.00000e+00, 2.50000e-01],
...            [1.25000e-01, 2.50000e-01],
...            [2.50000e-01, 2.50000e-01]]
... }
>>> psd_dict = PSDDict(psd_data)
interpolate(low_freq_cutoff, delta_f)[source]

Interpolate a dictionary of PSDs to a new delta_f

Parameters:
  • low_freq_cutoff (float) – Frequencies below this value are set to zero.

  • delta_f (float, optional) – Frequency resolution of the frequency series in Hertz.

plot(**kwargs)[source]

Generate a plot to display the PSD data stored in PSDDict

Parameters:

**kwargs (dict) – all additional kwargs are passed to pesummary.gw.plots.plot._psd_plot

classmethod read(files=None, detectors=None, common_string=None)[source]

Initiate PSDDict with a set of PSD files

Parameters:
  • files (list/dict, optional) – Either a list of files or a dictionary of files to read. If a list of files are provided, a list of corresponding detectors must also be provided

  • common_string (str, optional) – Common string for PSD files. The string must be formattable and take one argument which is the detector. For example common_string=’./{}_psd.dat’. Used if files is not provided

  • detectors (list, optional) – List of detectors to use when loading files. Used if files if not provided or if files is a list or if common_string is provided

to_pycbc(*args, **kwargs)[source]

Transform dictionary to pycbc.frequencyseries objects

Parameters:
  • *args (tuple) – all args passed to PSD.to_pycbc()

  • **kwargs (dict, optional) – all kwargs passed to PSD.to_pycbc()