def empirical_interpolation_for_time_series(waveforms): """Calculate empirical nodes and corresponding empirical interpolating functions. Parameters ---------- waveforms : HDF5TimeSeriesSet Returns ------- empirical_node_indices : List of ints The indices of the empirical nodes in the TimeSeries. B_j : List of TimeSeries The empirical interpolating functions that are 1 at the node T_j and 0 at the other nodes T_i (for i!=j). """ Nwave = len(waveforms.get_parameters()) # Convert the list of TimeSeries to a list of numpy arrays #wave_np = [waveforms[i].numpy() for i in range(Nwave)] wave_np = [waveforms.get_waveform_data(i).numpy() for i in range(Nwave)] # Determine the empirical nodes empirical_node_indices = eim.generate_empirical_nodes(wave_np) # Determine the empirical interpolating functions B_j(t) B_j_np = eim.generate_interpolant_list(wave_np, empirical_node_indices) # Convert the arrays to TimeSeries. delta_t = waveforms.get_waveform_data(0).delta_t epoch = waveforms.get_waveform_data(0).start_time B_j = [pycbc.types.TimeSeries(B_j_np[j], delta_t=delta_t, epoch=epoch) for j in range(Nwave)] return empirical_node_indices, B_j
def empirical_interpolation_for_time_domain_waveform(waveforms, datatype): """Calculate empirical nodes and corresponding empirical interpolating functions from a set of reduced basis waveforms. Parameters ---------- waveforms : HDF5TimeDomainWaveformSet datatype : string {'complex', 'amp', 'phase'} Returns ------- empirical_node_indices : List of ints The indices of the empirical nodes in the TimeDomainWaveforms. B_j : List of TimeDomainWaveform The empirical interpolating functions that are 1 at the node T_j and 0 at the other nodes T_i (for i!=j). """ Nwave = waveforms.get_len() # Convert the list of TimeDomainWaveform to a list of complex numpy arrays if datatype == 'complex': wave_np = [waveforms.get_waveform_data(i).get_complex() for i in range(Nwave)] elif datatype == 'amp': wave_np = [waveforms.get_waveform_data(i).amp for i in range(Nwave)] elif datatype == 'phase': wave_np = [waveforms.get_waveform_data(i).phase for i in range(Nwave)] else: raise Exception, "datatype must be one of {'complex', 'amp', 'phase'}." # Determine the empirical nodes empirical_node_indices = eim.generate_empirical_nodes(wave_np) # Determine the empirical interpolating functions B_j(t) B_j_np = eim.generate_interpolant_list(wave_np, empirical_node_indices) # Convert the arrays to TimeDomainWaveforms. time = waveforms.get_waveform_data(0).time B_j = [] for j in range(Nwave): if datatype == 'complex': comp = B_j_np[j] B_j.append(complex_to_time_domain_waveform(time, comp)) elif datatype == 'amp': amp = B_j_np[j] B_j.append(tdwave.TimeDomainWaveform(time, amp, np.zeros(len(time)))) elif datatype == 'phase': phase = B_j_np[j] B_j.append(tdwave.TimeDomainWaveform(time, np.zeros(len(time)), phase)) else: raise Exception, "datatype must be one of {'complex', 'amp', 'phase'}." return empirical_node_indices, B_j
def empirical_interpolation_for_time_domain_waveform(waveforms, datatype): """Calculate empirical nodes and corresponding empirical interpolating functions from a set of reduced basis waveforms. Parameters ---------- waveforms : List like set of Waveform objects Could be HDF5WaveformSet datatype : string {'amp', 'phase'} Returns ------- empirical_node_indices : List of ints The indices of the empirical nodes in the Waveform objects. B_j : List of Waveform objects The empirical interpolating functions that are 1 at the node T_j and 0 at the other nodes T_i (for i!=j). """ nwave = len(waveforms) # Convert the list of Waveform objects to a list of complex numpy arrays if datatype == 'amp': wave_np = [waveforms[i].amp for i in range(nwave)] elif datatype == 'phase': wave_np = [waveforms[i].phase for i in range(nwave)] else: raise Exception, "datatype must be one of {'amp', 'phase'}." # Determine the empirical nodes empirical_node_indices = eim.generate_empirical_nodes(wave_np) # Determine the empirical interpolating functions B_j(t) B_j_np = eim.generate_interpolant_list(wave_np, empirical_node_indices) # Convert the arrays to Waveform objects. xarr = waveforms[0].x B_j = [] for j in range(nwave): if datatype == 'amp': amp = B_j_np[j] B_j.append( wave.Waveform.from_amp_phase(xarr, amp, np.zeros(len(xarr)))) elif datatype == 'phase': phase = B_j_np[j] B_j.append( wave.Waveform.from_amp_phase(xarr, np.zeros(len(xarr)), phase)) else: raise Exception, "datatype must be one of {'amp', 'phase'}." return empirical_node_indices, B_j