gwnrtools / nr-catalog-tools

A unified interface to various catalogs of Numerical Relativity simulations of compact binary mergers.
https://github.com/gwnrtools/nr-catalog-tools
GNU General Public License v3.0
1 stars 5 forks source link

Add functionality to calculate error norm between two waveforms #11

Open adivijaykumar opened 1 year ago

adivijaykumar commented 1 year ago

PR #10 proposes to remove all legacy code, including calculation of the error norms between waveforms. However, it would be nice to have a version of the error norm compatible with this package. Will have to think a bit more about the best way to design this function, so creating this issue to make a note, and also to solicit input. The old code is pasted below:


    def get_L2_norm(self):
        sum_num = 0
        norm = 0
        for mode in self.modes:
            times_maya, hlm_maya = self.get_mode(mode=mode)
            times_sur, hlm_sur = self.get_mode_surrogate(mode=mode)
            phase_maya = np.unwrap(np.angle(hlm_maya))
            phase_maya = phase_maya - phase_maya[0]
            phase_sur = np.unwrap(np.angle(hlm_sur))
            phase_sur = phase_sur - phase_sur[0]
            amp_maya = np.abs(hlm_maya)
            amp_maya_interp = InterpolatedUnivariateSpline(
                times_maya, amp_maya)
            phase_maya_interp = InterpolatedUnivariateSpline(
                times_maya, phase_maya)
            amp_sur = np.abs(hlm_sur)
            aligned_strain_maya = (amp_maya_interp(times_sur) *
                                   np.exp(1j * phase_maya_interp(times_sur)))
            aligned_strain_sur = amp_sur * np.exp(1j * phase_sur)

            diff = np.sum(
                np.abs(aligned_strain_maya - aligned_strain_sur)**2 *
                self.delta_t)
            sum_num += diff
            norm += np.sum(np.abs(aligned_strain_maya)**2 * self.delta_t)
        return 0.5 * (sum_num / norm)