r8inv = lal.CreateREAL8Vector(len(r8in)) r8inv.data = r8in c16outv = lal.CreateCOMPLEX16Vector(len(r8in) // 2 + 1) plan = lal.CreateForwardREAL8FFTPlan(len(r8in), 0) lal.REAL8ForwardFFT(c16outv, r8inv, plan) c16out = numpy.zeros(numpy.shape(c16outv.data), dtype=c16outv.data.dtype) lal.REAL8ForwardFFT(c16out, r8in, plan) assert ((c16out == c16outv.data).all()) del r8inv del c16outv del plan lal.CheckMemoryLeaks() c16inv = lal.CreateCOMPLEX16Vector(len(c16in)) c16inv.data = c16in r8outv = lal.CreateREAL8Vector((len(c16in) - 1) * 2) plan = lal.CreateReverseREAL8FFTPlan((len(c16in) - 1) * 2, 0) lal.REAL8ReverseFFT(r8outv, c16inv, plan) r8out = numpy.zeros(numpy.shape(r8outv.data), dtype=r8outv.data.dtype) lal.REAL8ReverseFFT(r8out, c16in, plan) assert ((r8out == r8outv.data).all()) del c16inv del r8outv del plan lal.CheckMemoryLeaks() r4inv = lal.CreateREAL4Vector(len(r4in)) r4inv.data = r4in r4outv = lal.CreateREAL4Vector(len(r4in)) plan = lal.CreateForwardREAL4FFTPlan(len(r4in), 0) lal.REAL4VectorFFT(r4outv, r4inv, plan) r4out = numpy.zeros(numpy.shape(r4outv.data), dtype=r4outv.data.dtype) lal.REAL4VectorFFT(r4out, r4in, plan)
def analyze_event(P_list, indx_event, data_dict, psd_dict, fmax, opts, inv_spec_trunc_Q=inv_spec_trunc_Q, T_spec=T_spec): nEvals = 0 P = P_list[indx_event] # Precompute t_window = 0.15 rholms_intp, cross_terms, cross_terms_V, rholms, rest = factored_likelihood.PrecomputeLikelihoodTerms( fiducial_epoch, t_window, P, data_dict, psd_dict, opts.l_max, fmax, False, inv_spec_trunc_Q, T_spec, NR_group=NR_template_group, NR_param=NR_template_param, use_external_EOB=opts.use_external_EOB, nr_lookup=opts.nr_lookup, nr_lookup_valid_groups=opts.nr_lookup_group, perturbative_extraction=opts.nr_perturbative_extraction, use_provided_strain=opts.nr_use_provided_strain, hybrid_use=opts.nr_hybrid_use, hybrid_method=opts.nr_hybrid_method, ROM_group=opts.rom_group, ROM_param=opts.rom_param, ROM_use_basis=opts.rom_use_basis, verbose=opts.verbose, quiet=not opts.verbose, ROM_limit_basis_size=opts.rom_limit_basis_size_to, no_memory=opts.no_memory, skip_interpolation=opts.vectorized) # Only allocate the FFT plans ONCE ifo0 = psd_dict.keys()[0] npts = data_dict[ifo0].data.length print(" Allocating FFT forward, reverse plans ", npts) fwdplan = lal.CreateForwardREAL8FFTPlan(npts, 0) revplan = lal.CreateReverseREAL8FFTPlan(npts, 0) for ifo in psd_dict: # Plot PSDs plt.figure(99) # PSD figure) fvals = psd_dict[ifo].f0 + np.arange( psd_dict[ifo].data.length) * psd_dict[ifo].deltaF plt.plot(fvals, np.log10(np.sqrt(psd_dict[ifo].data.data)), label=ifo) plt.figure(88) plt.plot(fvals, fvals**(-14. / 6.) / psd_dict[ifo].data.data) plt.figure(1) # Plot inverse spectrum filters # - see lalsimutils code for inv_spec_trunc_Q , copied verbatim plt.figure(98) IP_here = lalsimutils.ComplexOverlap(P.fmin, fmax, 1. / 2 / P.deltaT, P.deltaF, psd_dict[ifo], False, inv_spec_trunc_Q, T_spec) WFD = lal.CreateCOMPLEX16FrequencySeries('FD root inv. spec.', lal.LIGOTimeGPS(0.), 0., IP_here.deltaF, lal.DimensionlessUnit, IP_here.len1side) WTD = lal.CreateREAL8TimeSeries('TD root inv. spec.', lal.LIGOTimeGPS(0.), 0., IP_here.deltaT, lal.DimensionlessUnit, IP_here.len2side) print(ifo, IP_here.len2side) # if not(fwdplan is None): WFD.data.data[:] = np.sqrt(IP_here.weights) # W_FD is 1/sqrt(S_n(f)) WFD.data.data[0] = WFD.data.data[-1] = 0. # zero 0, f_Nyq bins lal.REAL8FreqTimeFFT(WTD, WFD, revplan) # IFFT to TD tvals = IP_here.deltaT * np.arange(IP_here.len2side) plt.plot(tvals, np.log10(np.abs(WTD.data.data)), label=ifo) # Plot Q's plt.figure(1) plt.clf() for mode in rholms[ifo]: Q_here = rholms[ifo][mode] tvals = lalsimutils.evaluate_tvals(Q_here) - P.tref plt.plot(tvals, np.abs(Q_here.data.data), label=ifo + str(mode[0]) + "," + str(mode[1])) plt.legend() plt.xlabel("t (s)") plt.xlim(-0.1, 0.1) plt.xlabel("$Q_{lm}$") plt.title(ifo) plt.savefig(ifo + "_Q.png") plt.figure(99) plt.legend() plt.xlabel("f(Hz)") plt.ylabel(r'$\sqrt{S_h}$') plt.ylim(-24, -21) plt.savefig("PSD_plots.png") plt.xlim(5, 800) plt.savefig("PSD_plots_detail.png") plt.xlim(10, 400) plt.ylim(-23.5, -22) plt.savefig("PSD_plots_detail_fine.png") plt.figure(98) plt.legend() plt.xlabel("t (s)") plt.savefig("PSD_inv_plots.png") plt.figure(88) plt.legend() plt.xlabel("f (Hz)") plt.ylabel(r'$(S_h f^{15/6})^{-1}$') plt.savefig("PSD_weight_f.png")