|
| 1 | +""" |
| 2 | +Test the Matcher class with a NR waveform |
| 3 | +""" |
| 4 | + |
| 5 | +import numpy as np |
| 6 | +import matplotlib.pyplot as plt |
| 7 | +from PyART.catalogs import sxs |
| 8 | +from PyART.analysis.match import Matcher |
| 9 | + |
| 10 | +sxs_id = '0180' |
| 11 | +nr = sxs.Waveform_SXS(ID=sxs_id, download=True, ignore_deprecation=True) |
| 12 | +nr_2 = sxs.Waveform_SXS(ID=sxs_id, download=False, ignore_deprecation=True) |
| 13 | +nr.cut(300) |
| 14 | +nr_2.cut(300) |
| 15 | +M = 100 |
| 16 | +fmin = 5 |
| 17 | +fmax = 2048 |
| 18 | +srate = 8192 |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | +def test_self_match_ell_emms(): |
| 23 | + """ |
| 24 | + Test that the self-match of the single modes |
| 25 | + is 1.0 within numerical accuracy. |
| 26 | + """ |
| 27 | + |
| 28 | + settings={ |
| 29 | + 'kind':'single-mode', |
| 30 | + 'initial_frequency_mm':fmin, |
| 31 | + 'final_frequency_mm':fmax, |
| 32 | + 'tlen':len(nr.u), |
| 33 | + 'dt':1/srate, |
| 34 | + 'M':M, |
| 35 | + 'resize_factor':4, |
| 36 | + 'modes-or-pol':'modes', |
| 37 | + 'pad_end_frac':0.5, |
| 38 | + 'taper_alpha':0.2, |
| 39 | + 'taper_start':0.05, |
| 40 | + 'taper':'sigmoid', |
| 41 | + 'debug':False |
| 42 | + } |
| 43 | + |
| 44 | + for mode in nr.hlm.keys(): |
| 45 | + these_settings = settings.copy() |
| 46 | + these_settings['modes'] = [mode] |
| 47 | + m = Matcher(nr, nr_2, settings=settings) |
| 48 | + match = 1 - m.mismatch |
| 49 | + assert np.isclose(match, 1.0, atol=1e-7) |
| 50 | + |
| 51 | +def test_self_match_pol(): |
| 52 | + """ |
| 53 | + Test that the self-match of the two polarizations |
| 54 | + is 1.0 within numerical accuracy. |
| 55 | + """ |
| 56 | + |
| 57 | + settings={ |
| 58 | + 'kind':'hm', |
| 59 | + 'initial_frequency_mm':fmin, |
| 60 | + 'final_frequency_mm':fmax, |
| 61 | + 'tlen':len(nr.u), |
| 62 | + 'dt':1/srate, |
| 63 | + 'M':M, |
| 64 | + 'resize_factor':4, |
| 65 | + 'pad_end_frac':0.5, |
| 66 | + 'taper_alpha':0.2, |
| 67 | + 'taper_start':0.05, |
| 68 | + 'taper':'sigmoid', |
| 69 | + 'debug':True, |
| 70 | + } |
| 71 | + |
| 72 | + def test_self_match_pol_helper(cp, ep): |
| 73 | + """ |
| 74 | + Helper function to test self-match for given |
| 75 | + coalescence phase and effective polarization. |
| 76 | + """ |
| 77 | + |
| 78 | + settings_cp = settings.copy() |
| 79 | + settings_cp['coa_phase'] = [cp] |
| 80 | + settings_cp['eff_pols'] = [ep] |
| 81 | + |
| 82 | + m = Matcher(nr, nr_2, settings=settings_cp) |
| 83 | + match = 1 - m.mismatch |
| 84 | + assert np.isclose(match, 1.0, atol=1e-7) |
| 85 | + print(f'cp: {cp:.2f}, ep: {ep:.2f}, match: {match}') |
| 86 | + |
| 87 | + for cp in [0, np.pi/4, np.pi/2]: |
| 88 | + for ep in [0, np.pi/4, np.pi/2]: |
| 89 | + test_self_match_pol_helper(cp, ep) |
| 90 | + |
| 91 | + pass |
| 92 | + |
0 commit comments