def add_waveform(self, waveform, parameters, index, amp=None, phase=None): """Add a waveform to the hdf5 file. Parameters ---------- waveform : TimeSeries parameters : Parameters of the waveform index : int For index i, the waveform will be stored under the group 'wave_i'. amp : TimeSeries The amplitude. phase : TimeSeries The phase. """ groupname = 'wave_'+str(index) wave = self.ts_file.create_group(groupname) wave['param_names'] = self.param_names wave['parameters'] = parameters wave['delta_t'] = waveform.delta_t # Explicitly cast lal.lal.LIGOTimeGPS to float: wave['epoch'] = float(waveform.start_time) wave['timeseries'] = waveform.numpy() # Calculate amplitude and phase if one or both are not provided if not amp or not phase: amp, phase = tsutils.amp_phase_from_complex(waveform) wave['amplitude'] = amp.numpy() wave['phase'] = phase.numpy()
def max_amp_phase_error(htrue, hrom): # Get amplitude and phase of each waveform amp_true, phase_true = tsutils.amp_phase_from_complex(htrue) amp_rom, phase_rom = tsutils.amp_phase_from_complex(hrom) # Find index of max amplitude true_max, true_maxi = htrue.abs_max_loc() rom_max, rom_maxi = hrom.abs_max_loc() # Calculate |relative-amplitude error| and |phase-difference error| # Dropping the points after max amplitude that have zero amplitude amperror = np.abs(amp_rom.numpy()[:true_maxi]/amp_true.numpy()[:true_maxi]-1) phaseerror = np.abs(phase_rom.numpy()[:true_maxi] - phase_true.numpy()[:true_maxi]) iamperrmax = np.abs(amperror).argmax() tamperrmax = htrue.sample_times[iamperrmax] amperrmax = amperror[iamperrmax] iphaseerrmax = np.abs(phaseerror).argmax() tphaseerrmax = htrue.sample_times[iphaseerrmax] phaseerrmax = phaseerror[iphaseerrmax] return iamperrmax, tamperrmax, amperrmax, iphaseerrmax, tphaseerrmax, phaseerrmax