-
Notifications
You must be signed in to change notification settings - Fork 67
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
Merge EPTA version part 2 #374
Changes from 4 commits
b0d492d
34737cf
6b6912d
9b69705
1b897e3
7905de2
bfe4b44
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,9 +13,12 @@ | |
__all__ = [ | ||
"createfourierdesignmatrix_red", | ||
"createfourierdesignmatrix_dm", | ||
"createfourierdesignmatrix_dm_tn", | ||
"createfourierdesignmatrix_env", | ||
"createfourierdesignmatrix_ephem", | ||
"createfourierdesignmatrix_eph", | ||
"createfourierdesignmatrix_chromatic", | ||
"createfourierdesignmatrix_general", | ||
] | ||
|
||
|
||
|
@@ -124,6 +127,42 @@ def createfourierdesignmatrix_dm( | |
return F * Dm[:, None], Ffreqs | ||
|
||
|
||
@function | ||
def createfourierdesignmatrix_dm_tn( | ||
toas, freqs, nmodes=30, Tspan=None, pshift=False, fref=1400, logf=False, fmin=None, fmax=None, idx=2, modes=None | ||
): | ||
""" | ||
Construct DM-variation fourier design matrix. Current | ||
normalization expresses DM signal as a deviation [seconds] | ||
at fref [MHz] | ||
|
||
:param toas: vector of time series in seconds | ||
:param freqs: radio frequencies of observations [MHz] | ||
:param nmodes: number of fourier coefficients to use | ||
:param Tspan: option to some other Tspan | ||
:param pshift: option to add random phase shift | ||
:param fref: reference frequency [MHz] | ||
:param logf: use log frequency spacing | ||
:param fmin: lower sampling frequency | ||
:param fmax: upper sampling frequency | ||
:param modes: option to provide explicit list or array of | ||
sampling frequencies | ||
|
||
:return: F: DM-variation fourier design matrix | ||
:return: f: Sampling frequencies | ||
""" | ||
|
||
# get base fourier design matrix and frequencies | ||
F, Ffreqs = createfourierdesignmatrix_red( | ||
toas, nmodes=nmodes, Tspan=Tspan, logf=logf, fmin=fmin, fmax=fmax, pshift=pshift, modes=modes | ||
) | ||
|
||
# compute the DM-variation vectors | ||
Dm = (fref / freqs) ** idx * np.sqrt(12) * np.pi / 1400 / 1400 / 2.41e-4 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The matrix Please make this consistent. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is the normalization difference between the enterprise and temponest default amplitude normalization for DM power law. There is the 12pi^2 from the definition of A, the scaling to 1MHz vs 1400 MHz and the DM constant. I added a bit of comments to this in the code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Understood, if it's a definition matter we should leave it. Looking up the origin, this is a really pointless normalization though. This 12pi^2 comes from the definition of the characteristic strain h_c in the red noise spectral density. It has absolutely nothing to do with DM, and it was introduced by mindlessly copying code from the definition of red noise to DM. It makes me cringe. (Not a critique of this PR) |
||
return F * Dm[:, None], Ffreqs | ||
|
||
|
||
@function | ||
def createfourierdesignmatrix_env( | ||
toas, | ||
|
@@ -218,7 +257,9 @@ def createfourierdesignmatrix_eph( | |
|
||
|
||
@function | ||
def createfourierdesignmatrix_chromatic(toas, freqs, nmodes=30, Tspan=None, logf=False, fmin=None, fmax=None, idx=4): | ||
def createfourierdesignmatrix_chromatic( | ||
toas, freqs, nmodes=30, Tspan=None, logf=False, fmin=None, fmax=None, idx=4, modes=None | ||
): | ||
|
||
""" | ||
Construct Scattering-variation fourier design matrix. | ||
|
@@ -232,15 +273,82 @@ def createfourierdesignmatrix_chromatic(toas, freqs, nmodes=30, Tspan=None, logf | |
:param fmin: lower sampling frequency | ||
:param fmax: upper sampling frequency | ||
:param idx: Index of chromatic effects | ||
:param modes: option to provide explicit list or array of | ||
sampling frequencies | ||
|
||
:return: F: Chromatic-variation fourier design matrix | ||
:return: f: Sampling frequencies | ||
""" | ||
|
||
# get base fourier design matrix and frequencies | ||
F, Ffreqs = createfourierdesignmatrix_red(toas, nmodes=nmodes, Tspan=Tspan, logf=logf, fmin=fmin, fmax=fmax) | ||
F, Ffreqs = createfourierdesignmatrix_red( | ||
toas, nmodes=nmodes, Tspan=Tspan, logf=logf, fmin=fmin, fmax=fmax, modes=modes | ||
) | ||
|
||
# compute the DM-variation vectors | ||
Dm = (1400 / freqs) ** idx | ||
|
||
return F * Dm[:, None], Ffreqs | ||
|
||
|
||
@function | ||
def createfourierdesignmatrix_general( | ||
toas, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: is this not just a superset of the regular There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it is a superset of "createfourierdesignmatrix_red", "..._dm", "..._dm_tn" and "..._chromatic". Where the "chromatic" is a superset of "dm" by the way. The "general" also allows to mask toas from chosen flags. It is pretty convenient as it is the only current way to make a selection on spatially correlated common signals (as far as I know). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, selecting on common signals is in another PR as well. Have a look: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missed that, very nice ! It still need to be merged if I've understood well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. I wanted to review it the other day, but I wasn't sure whether it was relevant since it had been 2 years. I should ping @vallis again regarding it. |
||
freqs, | ||
flags, | ||
flagname="group", | ||
flagval=None, | ||
idx=None, | ||
tndm=False, | ||
nmodes=30, | ||
Tspan=None, | ||
psrTspan=True, | ||
logf=False, | ||
fmin=None, | ||
fmax=None, | ||
modes=None, | ||
pshift=None, | ||
pseed=None | ||
): | ||
""" | ||
Construct fourier design matrix with possibility of adding selection and/or chromatic index envelope. | ||
|
||
:param toas: vector of time series in seconds | ||
:param freqs: radio frequencies of observations [MHz] | ||
:param flags: Flags from timfiles | ||
:param nmodes: number of fourier coefficients to use | ||
:param Tspan: option to some other Tspan | ||
:param psrTspan: option to use pulsar time span. Used only if sub-group of ToAs is chosen | ||
:param logf: use log frequency spacing | ||
:param fmin: lower sampling frequency | ||
:param fmax: upper sampling frequency | ||
:param log10_Amp: log10 of the Amplitude [s] | ||
:param idx: Index of chromatic effects | ||
:param modes: option to provide explicit list or array of | ||
sampling frequencies | ||
|
||
:return: F: fourier design matrix | ||
:return: f: Sampling frequencies | ||
""" | ||
if flagval and not psrTspan: | ||
sel_toas = toas[np.where(flags[flagname]==flagval)] | ||
Tspan = sel_toas.max() - sel_toas.min() | ||
|
||
# get base fourier design matrix and frequencies | ||
F, Ffreqs = createfourierdesignmatrix_red( | ||
toas, nmodes=nmodes, Tspan=Tspan, logf=logf, fmin=fmin, fmax=fmax, modes=modes, pshift=pshift, pseed=pseed | ||
) | ||
|
||
# compute the chromatic-variation vectors | ||
if idx: | ||
if tndm: | ||
chrom_fac = (1400 / freqs) ** idx * np.sqrt(12) * np.pi / 1400 / 1400 / 2.41e-4 | ||
else: | ||
chrom_fac = (1400 / freqs) ** idx | ||
F *= chrom_fac[:, None] | ||
|
||
# compute the mask for the selection | ||
if flagval: | ||
F *= np.array([flags[flagname]==flagval]*F.shape[1]).T | ||
|
||
return F, Ffreqs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter
idx
needs a docstringThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added docstring for the parameter
idx