Keep parameters as float128 values in tm_delay #228
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In the
tm_delay
function, the parameters to be varied are set asnp.double
precision values. The original values in thet2pulsar
object (in particular the frequency parameters) are stored asnp.float128
, so the recasting asdouble
's loses some precision. This isn't generally problematic, but it can be problematic if you are doing simulations with very low noise and truncation of, e.g., the frequency, caused by converting todouble
's throws off other parameters.I will show a concrete example. I generate some fake TOAs for J2145-0750 using the Tempo2
fake
plugin, with the very low noise of 0.1ns:where the
.par
file contained:Now, if I assume that
F2
is actually unknown and I want to estimate its value from the TOAs, I could set up a.par
, called, say,J2145-0750_no_f2.par
file containing:and run (the below assumes #226 has been applied to allow it to run with
white_vary=False
):it gives:
where the
F2
value is completely wrong (note that a fit with Tempo2 itself gets the correct value).From digging into why this is happening, I find that when the
F0
value gets converted fromfloat128
todouble
in timing.py, it gets truncated from:to
With the very low noise, this difference in frequency is enough to throw off the estimation of
F2
. If I apply the patch in this PR and run the above code again, I get:which has the correct
F2
value.