Package documentation

Generator class

class Generator.Generator

Bases: object

Transient noise artifacts generator from ‘“Generating transient noise artefacts in gravitational-wave detector data with generative adversarial networks by Powell et. al. ” <https://arxiv.org/abs/2207.00207>’

clear_queue()

Clears the current queue of artifacts.

generate(glitch, n_images_to_generate=10, SNR=10.0, clean=True)

Generates images for the given glitch in the form of numpy arrays, and adds it to the ‘queue’.

Parameters:
  • glitch (str) – Name of the glitch to be generated

  • n_images_to_generate (int, optional) – Number of images to be generated, defaults to 10

  • SNR (Any, optional) –

    The signal to noise ratio for the glitches, defaults to 10.

    Input can be:

    float - a constant SNR for all glitches generated.
    array - an array of SNR for each individual glitch. The order of the SNRs given matches up to the order the glitches are generated. One may use np.random.normal(mean, std, n_images_to_generate) in order to generate a normal distribution or np.random.uniform(low, high, n_images_to_generate) in order to generate a uniform distribution.
    str - “realistic”, which assigns a differing SNR to each glitch based on their distribution seen in LIGOs observing runs.

  • clean (bool, optional) – Whether or not to remove the background noise from the generated glitches, defaults to True

Returns:

A (n_images_to_generate x 140 x 170) numpy array of the images generated and a (n_images_to_generate) list of corresponding glitch labels

Return type:

tuple

generate_all(n_images_to_generate=1, SNR=10.0, clean=True)

Generates images for all the glitches, in the form of numpy arrays. The generated array can be accessed through ‘generator.curr_array’ and the glitch labels through ‘generator.curr_glitch’.

Parameters:
  • n_images_to_generate (int, optional) – Number of each image to be generated, defaults to 1

  • SNR (Any, optional) –

    The signal to noise ratio for the glitches, defaults to 10.

    Input can be:

    float - a constant SNR for all glitches generated.
    array - an array of SNR for each individual glitch. The order of the SNRs given matches up to the order the glitches are generated. One may use np.random.normal(mean, std, n_images_to_generate) in order to generate a normal distribution or np.random.uniform(low, high, n_images_to_generate) in order to generate a uniform distribution.
    str - “realistic”, which assigns a differing SNR to each glitch based on their distribution seen in LIGOs observing runs.

  • clean (bool, optional) – Whether or not to remove the background noise from the generated glitches, defaults to True

Returns:

a ((n_images_to_generate * num_of_glitches) x 140 x 170) numpy array of the images generated and a (n_images_to_generate * num_of_glitches) list of corresponding glitch labels.

Return type:

tuple

save_as_array(path, name='glitch_file', clear_queue=False)

Saves the queue of artifacts, which are in the form of a spectrogram - in their basic array form. The 2d arrays, which are 170x140, are saved into a hdf5 file. Each glitch type has its own dataset - within each of these datasets there is a Nx170x140 array, for a N of a specific glitch.

Parameters:
  • path (str) – Folder where the timeseries file will be created

  • name (str, optional) – name of the file, defaults to “glitch_file”

  • clear_queue (bool, optional) – Value for if the queue will be cleared after the images are saved, defaults to False

save_as_png(path=None, clear_queue=False)

Saves the queue of artifacts, which are in the form of a spectrogram, as seperate png files.

Parameters:
  • path (str) – Folder where the images will be saved

  • clear_queue (bool, optional) – Value for if the queue will be cleared after the images are saved, defaults to False

save_as_timeseries(path=None, name='timeseries', noise=True, length='Default', position=None, format='gwf', t0=1238166018.0, clear_queue=False)

Saves the queue of artifacts in a file. The snippets are 1/3 * num of glitches seconds long, unless specified otherwise. Sample rate and the position of the glitches are saved into the file. The channel name of the timeseries is the same as the name of the file.

Parameters:
  • path (str) – Folder where the timeseries file will be created

  • name (str, optional) – name of the file and the channel in the file, defaults to “timeseries”

  • noise (bool, optional) – Whether or not gaussian noise should be added to the timeseries (Note - for best results, set clean=True in the generation of the glitches if noise=True is wanted), defaults to True

  • length (float, optional) – The length (in seconds) of the snippet. Default is 1/3 * the number of glitches given, defaults to “Default”

  • position (list, optional) – The positions of the start of glitches and must be a list or numpy array of size len(self.glitches), with the positons give in seconds, defaults to None

  • format (str, optional) – Name of the format that the file will be saved as with pptions “gwf”, “hdf5”, defaults to “gwf”

  • t0 (float, optional) – The time (GPS epoch) inserted into the file as the start gps time of the timeseries, defaults to 1238166018.0 (start of O3 run)

  • clear_queue (bool, optional) – Value for if the queue will be cleared after the images are saved, defaults to False