Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make whitened residuals available #1671

Merged
merged 7 commits into from
Nov 14, 2023
Merged

Conversation

abhisrkckl
Copy link
Contributor

@abhisrkckl abhisrkckl commented Nov 3, 2023

This partially overlaps with the stale PR #1000.

whitened_resids = (resids - noise_resids) / scaled_toa_error

If the fitting has been done properly, the whitened residuals should be normally distributed with unit variance.

@abhisrkckl abhisrkckl linked an issue Nov 3, 2023 that may be closed by this pull request
@abhisrkckl abhisrkckl changed the title Make whitened residuals available WIP: Make whitened residuals available Nov 3, 2023
Copy link

codecov bot commented Nov 3, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (f2da697) 68.47% compared to head (cbb1924) 68.47%.

❗ Current head cbb1924 differs from pull request most recent head 7c869fb. Consider uploading reports for the commit 7c869fb to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1671   +/-   ##
=======================================
  Coverage   68.47%   68.47%           
=======================================
  Files         104      104           
  Lines       24289    24294    +5     
  Branches     4336     4336           
=======================================
+ Hits        16631    16636    +5     
  Misses       6572     6572           
  Partials     1086     1086           
Files Coverage Δ
src/pint/residuals.py 76.48% <100.00%> (+0.28%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@abhisrkckl
Copy link
Contributor Author

image

Code:

from pint.models import get_model
from pint.simulation import make_fake_toas_uniform
from pint.fitter import Fitter
from pint.logging import setup as setup_log

from matplotlib import pyplot as plt
from astropy import units as u
import numpy as np

setup_log(level="WARNING")

m = get_model(
   StringIO(
        """
        RAJ    		05:00:00
        DECJ   		20:00:00
        F0     		100     1 
        F1     		-1e-14  1
        PEPOCH 		58000
        DM     		15
        EFAC tel gbt 	1.3
        TNRedAmp 	-14
        TNRedGam 	4.5
        TNRedC 		30
        """	
    )
)
t = make_fake_toas_uniform(
    57000, 
    60000, 
    1000, 
    model=m, 
    error=1 * u.us, 
    freq=u.Quantity([1400*u.MHz, 2500*u.MHz]), 
    add_noise=True, 
    add_correlated_noise=m.has_correlated_errors
)


ftr = Fitter.auto(t, m)
ftr.fit_toas()

# ===========

plt.subplot(211)
plt.errorbar(t.get_mjds(), ftr.resids.time_resids, ftr.resids.get_data_error(), ls="", marker="+")
plt.ylabel("resids (s)")
plt.xlabel("mjd")

plt.subplot(223)
plt.scatter(t.get_mjds(), ftr.resids.calc_whitened_resids(), marker="+")
plt.ylabel("wh. resids (s)")
plt.xlabel("mjd")

plt.subplot(224)
plt.hist(ftr.resids.calc_whitened_resids(), density=True, orientation="horizontal")

plt.show()

@abhisrkckl abhisrkckl changed the title WIP: Make whitened residuals available Make whitened residuals available Nov 8, 2023
@abhisrkckl abhisrkckl added the awaiting review This PR needs someone to review it so it can be merged label Nov 8, 2023
@dlakaplan
Copy link
Contributor

Does this work for WB data?

@@ -500,6 +500,12 @@ def calc_time_resids(
)
return (phase_resids / self.get_PSR_freq(calctype=calctype)).to(u.s)

def calc_whitened_resids(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it better to have a separate method, or calc_time_resids() with a flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be a separate method since whitened residuals are dimensionless, whereas time resids have the dimentions of time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then probably add a "See Also" to the other residual methods

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated documentation.

@abhisrkckl
Copy link
Contributor Author

Does this work for WB data?

It should. But I haven't tried it yet.

@dlakaplan
Copy link
Contributor

Looks good to me. ready to go?

@abhisrkckl
Copy link
Contributor Author

Looks good to me. ready to go?

Yes.

@dlakaplan dlakaplan merged commit 88683ba into nanograv:master Nov 14, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review This PR needs someone to review it so it can be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PINT does not easily provide whitened residuals
2 participants