From 99862c47be69741ff9308fcaca5830cbce11907d Mon Sep 17 00:00:00 2001 From: Abhimanyu Susobhanan Date: Thu, 5 Dec 2024 10:03:35 +0100 Subject: [PATCH 1/6] introduces_dm_errors --- CHANGELOG-unreleased.md | 1 + src/pint/models/noise_model.py | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/CHANGELOG-unreleased.md b/CHANGELOG-unreleased.md index cd766f352..6f36aec17 100644 --- a/CHANGELOG-unreleased.md +++ b/CHANGELOG-unreleased.md @@ -20,6 +20,7 @@ the released changes. - When TCB->TDB conversion info is missing, will print parameter name - Piecewise-constant model for chromatic variations (CMX) - `add_param` returns the name of the parameter (useful for numbered parameters) +- `introduces_dm_errors` class attribute in `NoiseComponent`s to distinguish DM noise ### Fixed - Changed WAVE_OM units from 1/d to rad/d. - When EQUAD is created from TNEQ, has proper TCB->TDB conversion info diff --git a/src/pint/models/noise_model.py b/src/pint/models/noise_model.py index 299787fe5..00d68c816 100644 --- a/src/pint/models/noise_model.py +++ b/src/pint/models/noise_model.py @@ -13,6 +13,9 @@ class NoiseComponent(Component): + + introduces_dm_errors = False + def __init__( self, ): @@ -232,6 +235,7 @@ class ScaleDmError(NoiseComponent): category = "scale_dm_error" introduces_correlated_errors = False + introduces_dm_errors = True def __init__( self, @@ -469,6 +473,7 @@ class PLDMNoise(NoiseComponent): category = "pl_DM_noise" introduces_correlated_errors = True + introduces_dm_errors = True is_time_correlated = True def __init__( From 90d6539d5053392bbf4c05e2722205d688644775 Mon Sep 17 00:00:00 2001 From: Abhimanyu Susobhanan Date: Thu, 5 Dec 2024 10:05:54 +0100 Subject: [PATCH 2/6] Simulate correlated DM noise for wideband TOAss --- CHANGELOG-unreleased.md | 1 + src/pint/simulation.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/CHANGELOG-unreleased.md b/CHANGELOG-unreleased.md index 6f36aec17..f4e20a224 100644 --- a/CHANGELOG-unreleased.md +++ b/CHANGELOG-unreleased.md @@ -21,6 +21,7 @@ the released changes. - Piecewise-constant model for chromatic variations (CMX) - `add_param` returns the name of the parameter (useful for numbered parameters) - `introduces_dm_errors` class attribute in `NoiseComponent`s to distinguish DM noise +- Simulate correlated DM noise for wideband TOAs ### Fixed - Changed WAVE_OM units from 1/d to rad/d. - When EQUAD is created from TNEQ, has proper TCB->TDB conversion info diff --git a/src/pint/simulation.py b/src/pint/simulation.py index 51ccde641..451693d8d 100644 --- a/src/pint/simulation.py +++ b/src/pint/simulation.py @@ -10,6 +10,7 @@ from loguru import logger as log from astropy import time +from pint.models.noise_model import NoiseComponent from pint.types import time_like, file_like import pint.residuals import pint.toa @@ -185,6 +186,7 @@ def update_fake_dms( ts: pint.toa.TOAs, dm_error: u.Quantity, add_noise: bool, + add_correlated_noise: bool, ) -> pint.toa.TOAs: """Update simulated wideband DM information in TOAs. @@ -209,6 +211,21 @@ def update_fake_dms( if add_noise: dms += scaled_dm_errors.to(pint.dmu) * np.random.randn(len(scaled_dm_errors)) + if add_correlated_noise: + dm_noise = np.zeros(len(toas)) * pint.dmu + for ncomp in model.NoiseComponent_list: + noise_comp = model.components[ncomp] + if ( + noise_comp.introduces_correlated_errors + and noise_comp.introduces_dm_errors + ): + U = noise_comp.get_noise_basis(toas) + b = noise_comp.get_noise_weights(toas) + delay = (U @ (b**0.5 * np.random.normal(size=len(b)))) << u.s + freqs = model.barycentric_radio_freq(toas) + dm_noise += (delay / pint.DMconst * freqs**2).to(pint.dmu) + dms += dm_noise + for f, dm in zip(toas.table["flags"], dms): f["pp_dm"] = str(dm.to_value(pint.dmu)) From 45ff99f299d1db5cd23bfebebf083ec413b5e37a Mon Sep 17 00:00:00 2001 From: Abhimanyu Susobhanan Date: Thu, 5 Dec 2024 10:43:43 +0100 Subject: [PATCH 3/6] fix for --- src/pint/simulation.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pint/simulation.py b/src/pint/simulation.py index 451693d8d..e90fa58bf 100644 --- a/src/pint/simulation.py +++ b/src/pint/simulation.py @@ -213,8 +213,7 @@ def update_fake_dms( if add_correlated_noise: dm_noise = np.zeros(len(toas)) * pint.dmu - for ncomp in model.NoiseComponent_list: - noise_comp = model.components[ncomp] + for noise_comp in model.NoiseComponent_list: if ( noise_comp.introduces_correlated_errors and noise_comp.introduces_dm_errors @@ -355,7 +354,9 @@ def make_fake_toas_uniform( ) if wideband: - ts = update_fake_dms(model, ts, wideband_dm_error, add_noise) + ts = update_fake_dms( + model, ts, wideband_dm_error, add_noise, add_correlated_noise + ) return make_fake_toas( ts, From fdf0ba9475cd3fe163e552450d894be944c74aa0 Mon Sep 17 00:00:00 2001 From: Abhimanyu Susobhanan Date: Thu, 5 Dec 2024 10:54:56 +0100 Subject: [PATCH 4/6] test_fake_toas --- tests/test_fake_toas.py | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tests/test_fake_toas.py b/tests/test_fake_toas.py index 199389d2e..ba97efb99 100644 --- a/tests/test_fake_toas.py +++ b/tests/test_fake_toas.py @@ -511,3 +511,57 @@ def test_simulate_uniform_multifreq(multifreq): multi_freqs_in_epoch=multifreq, ) assert len(t) == ntoas + + +def test_simulate_wideband_dmgp(): + par = """ + PSRJ J0023+0923 + RAJ 00:23:16.8790858 1 0.00002408141295805134 + DECJ +09:23:23.86936 1 0.00082010713730773120 + F0 327.84702062954047136 1 0.00000000000295205483 + F1 -1.2278326306812866375e-15 1 3.8219244605614075223e-19 + PEPOCH 56199.999797564144902 + POSEPOCH 56199.999797564144902 + DMEPOCH 56200 + DM 14.327978186774068347 1 0.00006751663559857748 + BINARY ELL1 + PB 0.13879914244858396754 1 0.00000000003514075083 + A1 0.034841158415224894973 1 0.00000012173038389247 + TASC 56178.804891768506529 1 0.00000007765191894742 + EPS1 1.6508830631753595232e-05 1 0.00000477568412215803 + EPS2 3.9656838708709247373e-06 1 0.00000458951091435993 + CLK TT(BIPM2015) + MODE 1 + UNITS TDB + TIMEEPH FB90 + DILATEFREQ N + PLANET_SHAPIRO N + CORRECT_TROPOSPHERE N + EPHEM DE436 + TNRedAmp -13.3087 + TNRedGam 1.5 + TNRedC 14 + TNDMAMP -12.2 + TNDMGAM 3.5 + TNDMC 15 + """ + + m = get_model(io.StringIO(par)) + t = pint.simulation.make_fake_toas_uniform( + startMJD=54000, + endMJD=56000, + ntoas=200, + model=m, + add_noise=True, + wideband=True, + add_correlated_noise=True, + ) + + assert t.is_wideband() + + # There is correlated noise in DMs + assert ( + sum(((t.get_dms() - m.total_dm(t)) / m.scaled_dm_uncertainty(t)) ** 2).si.value + / len(t) + > 10 + ) From fb94676c8adbe9b57263bbfdada190fca48f5eed Mon Sep 17 00:00:00 2001 From: Abhimanyu Susobhanan Date: Thu, 5 Dec 2024 11:27:53 +0100 Subject: [PATCH 5/6] fix function call --- src/pint/simulation.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pint/simulation.py b/src/pint/simulation.py index e90fa58bf..ac977cf60 100644 --- a/src/pint/simulation.py +++ b/src/pint/simulation.py @@ -484,7 +484,9 @@ def make_fake_toas_fromMJDs( ) if wideband: - ts = update_fake_dms(model, ts, wideband_dm_error, add_noise) + ts = update_fake_dms( + model, ts, wideband_dm_error, add_noise, add_correlated_noise + ) return make_fake_toas( ts, @@ -535,7 +537,7 @@ def make_fake_toas_fromtim( if ts.is_wideband(): dm_errors = ts.get_dm_errors() - ts = update_fake_dms(model, ts, dm_errors, add_noise) + ts = update_fake_dms(model, ts, dm_errors, add_noise, add_correlated_noise) return make_fake_toas( ts, From 0f37e159f492472f384370c2491c92658b94196d Mon Sep 17 00:00:00 2001 From: Abhimanyu Susobhanan Date: Fri, 6 Dec 2024 21:27:21 +0100 Subject: [PATCH 6/6] cleanup --- CHANGELOG-unreleased.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGELOG-unreleased.md b/CHANGELOG-unreleased.md index bab143435..e553210c5 100644 --- a/CHANGELOG-unreleased.md +++ b/CHANGELOG-unreleased.md @@ -20,10 +20,8 @@ the released changes. - When TCB->TDB conversion info is missing, will print parameter name - Piecewise-constant model for chromatic variations (CMX) - `add_param` returns the name of the parameter (useful for numbered parameters) - - `introduces_dm_errors` class attribute in `NoiseComponent`s to distinguish DM noise - Simulate correlated DM noise for wideband TOAs - - micromamba CI environment for testing macOS-latest, without tox ### Fixed