|
| 1 | +import bilby |
| 2 | +import matplotlib.pyplot as plt |
| 3 | +import numpy as np |
| 4 | + |
| 5 | +duration = 8.0 |
| 6 | +sampling_frequency = 2048.0 |
| 7 | +glitch_snr = 12 |
| 8 | +injection_parameters = dict( |
| 9 | + mass_1=36.0, |
| 10 | + mass_2=29.0, |
| 11 | + a_1=0.4, |
| 12 | + a_2=0.3, |
| 13 | + tilt_1=0.5, |
| 14 | + tilt_2=1.0, |
| 15 | + phi_12=1.7, |
| 16 | + phi_jl=0.3, |
| 17 | + luminosity_distance=2100.0, |
| 18 | + theta_jn=0.4, |
| 19 | + psi=2.659, |
| 20 | + phase=1.3, |
| 21 | + geocent_time=205.0, |
| 22 | + ra=1.375, |
| 23 | + dec=-1.2108, |
| 24 | +) |
| 25 | + |
| 26 | +bilby.core.utils.random.seed(23) |
| 27 | + |
| 28 | + |
| 29 | +def sine_gaussian_glitch( |
| 30 | + time_array, amplitude=1e-22, f0=100.0, tau=0.1, t0=0.0, phase=0.0 |
| 31 | +): |
| 32 | + """Generate a sine-Gaussian waveform. |
| 33 | +
|
| 34 | + Parameters |
| 35 | + ---------- |
| 36 | + time_array : array_like |
| 37 | + Time samples. |
| 38 | + amplitude : float |
| 39 | + Peak amplitude. |
| 40 | + f0 : float |
| 41 | + Central frequency in Hz. |
| 42 | + tau : float |
| 43 | + Decay time (Gaussian width) in seconds. |
| 44 | + t0 : float |
| 45 | + Central time of the burst in seconds. |
| 46 | + phase : float |
| 47 | + Phase offset in radians. |
| 48 | + """ |
| 49 | + envelope = np.exp(-((time_array - t0) ** 2) / (2 * tau**2)) |
| 50 | + return amplitude * envelope * np.sin(2 * np.pi * f0 * (time_array - t0) + phase) |
| 51 | + |
| 52 | + |
| 53 | +# Fixed arguments passed into the source model |
| 54 | +waveform_arguments = dict( |
| 55 | + waveform_approximant="IMRPhenomXPHM", |
| 56 | + reference_frequency=50.0, |
| 57 | + minimum_frequency=20.0, |
| 58 | +) |
| 59 | + |
| 60 | +# Create the waveform_generator using a LAL BinaryBlackHole source function |
| 61 | +# the generator will convert all the parameters |
| 62 | +waveform_generator = bilby.gw.WaveformGenerator( |
| 63 | + duration=duration, |
| 64 | + sampling_frequency=sampling_frequency, |
| 65 | + frequency_domain_source_model=bilby.gw.source.lal_binary_black_hole, |
| 66 | + parameter_conversion=bilby.gw.conversion.convert_to_lal_binary_black_hole_parameters, |
| 67 | + waveform_arguments=waveform_arguments, |
| 68 | +) |
| 69 | + |
| 70 | +# Set up interferometers. In this case we'll use two interferometers |
| 71 | +# (LIGO-Hanford (H1), LIGO-Livingston (L1). These default to their design |
| 72 | +# sensitivity |
| 73 | +ifos = bilby.gw.detector.InterferometerList(["H1", "L1"]) |
| 74 | +ifos.set_strain_data_from_zero_noise( |
| 75 | + sampling_frequency=sampling_frequency, |
| 76 | + duration=duration, |
| 77 | + start_time=injection_parameters["geocent_time"] - 4, |
| 78 | +) |
| 79 | + |
| 80 | +ifos.inject_signal( |
| 81 | + waveform_generator=waveform_generator, parameters=injection_parameters |
| 82 | +) |
| 83 | + |
| 84 | +inject_glitch_from_time_domain_strain = True |
| 85 | + |
| 86 | +if inject_glitch_from_time_domain_strain: |
| 87 | + glitch_sample_times = np.arange(0, 2, 1 / 256) |
| 88 | + from scipy.signal.windows import tukey |
| 89 | + |
| 90 | + glitch = sine_gaussian_glitch(glitch_sample_times, tau=0.1, t0=0.5) * tukey( |
| 91 | + len(glitch_sample_times), alpha=0.2 |
| 92 | + ) |
| 93 | + |
| 94 | + # Inject glitch |
| 95 | + glitch_parameters = { |
| 96 | + "onset_time": injection_parameters["geocent_time"] + 1, |
| 97 | + "snr": glitch_snr, |
| 98 | + } |
| 99 | + ifos[0].inject_glitch( |
| 100 | + glitch_snr, |
| 101 | + glitch_parameters=glitch_parameters, |
| 102 | + glitch_time_domain_strain=glitch, |
| 103 | + glitch_sample_times=glitch_sample_times, |
| 104 | + ) |
| 105 | + |
| 106 | + |
| 107 | +inject_glitch_from_a_glitch_waveform_generator = False |
| 108 | +if inject_glitch_from_a_glitch_waveform_generator: |
| 109 | + |
| 110 | + glitch_waveform_generator = bilby.gw.WaveformGenerator( |
| 111 | + duration=duration, |
| 112 | + sampling_frequency=sampling_frequency, |
| 113 | + time_domain_source_model=sine_gaussian_glitch, |
| 114 | + ) |
| 115 | + glitch_parameters = { |
| 116 | + "onset_time": injection_parameters["geocent_time"] + 1, |
| 117 | + "amplitude": 1e-22, |
| 118 | + "f0": 100.0, |
| 119 | + "tau": 0.1, |
| 120 | + "t0": 1.3, |
| 121 | + "phase": 0.0, |
| 122 | + "snr": glitch_snr, |
| 123 | + } |
| 124 | + |
| 125 | + ifos[0].inject_glitch( |
| 126 | + glitch_parameters=glitch_parameters, |
| 127 | + glitch_waveform_generator=glitch_waveform_generator, |
| 128 | + ) |
| 129 | + |
| 130 | + |
| 131 | +fig, axes = plt.subplots(2, 1) |
| 132 | +ax = axes[0] |
| 133 | + |
| 134 | +ax.axvline(x=injection_parameters["geocent_time"], color="black", label="Merger time") |
| 135 | +ax.axvline(x=glitch_parameters["onset_time"], color="blue", label="glitch onset time") |
| 136 | +ax.legend() |
| 137 | + |
| 138 | +ax.plot(ifos[0].time_array, ifos[0].time_domain_strain) |
| 139 | +fig.savefig("./time_domain_strain.pdf") |
0 commit comments