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

WIP: Noise updates #77

Open
wants to merge 25 commits into
base: NG20
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b34a24c
Update lite_utils.py
JamisonTalley Jun 29, 2024
b4b1181
Update lite_utils.py
JamisonTalley Jul 3, 2024
6314ac8
Update lite_utils.py
JamisonTalley Jul 3, 2024
01a1854
Update lite_utils.py
JamisonTalley Jul 3, 2024
e8ef1da
Update lite_utils.py
JamisonTalley Jul 19, 2024
fdeb76a
Update lite_utils.py
JamisonTalley Jul 23, 2024
88b90da
Merge pull request #1 from JamisonTalley/jump_flags_v1.2
JamisonTalley Jul 23, 2024
c02eb90
Update lite_utils.py
JamisonTalley Jul 23, 2024
b6a56f5
Merge pull request #2 from nanograv/tcb2tdb_hotfix
JamisonTalley Jul 26, 2024
87c201f
Merge pull request #66 from JamisonTalley/main
rossjjennings Aug 2, 2024
b86c019
Merge remote-tracking branch 'nanograv/NG20' into NG20
Aug 25, 2024
816599a
adding a gibbs sampler for noise analyses
Aug 25, 2024
d609d11
i initially added the wrong version of the gibbs sampler -- lol
Aug 25, 2024
3e4629e
adding gibbs to noise_utils
jeremy-baier Aug 25, 2024
14f848b
un-hard-coding model inclusion
jeremy-baier Aug 25, 2024
2be8f09
fix sampler import bug
jeremy-baier Aug 28, 2024
f30616e
moving gibbs sampler to enterprise extensions; adding some initial di…
jeremy-baier Sep 11, 2024
8c6a839
getting back onnnit
jeremy-baier Oct 18, 2024
86c8c74
adding discovery to noise utils
jeremy-baier Oct 18, 2024
8fd746b
commiting what i have rn
jeremy-baier Oct 19, 2024
f0aa78d
adding solar wind stuff
jeremy-baier Oct 20, 2024
7920c13
bug fixes
Oct 21, 2024
7a0b140
more bug fix
Oct 21, 2024
59c890d
swapping some kwargs & adding some logs
Oct 22, 2024
16bfa71
random fixes
Oct 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 69 additions & 9 deletions src/pint_pal/lite_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ def add_flag_jumps(mo,flag,flaglist,base=False):
JUMPn = maskParameter('JUMP',key=flagval,key_value=[j],value=0.0,units=u.second,convert_tcb2tdb=False)
phasejump.add_param(JUMPn,setup=True)

def large_residuals(fo,threshold_us,threshold_dm=None,*,n_sigma=None,max_sigma=None,prefit=False,ignore_ASP_dms=True,print_bad=True):
def large_residuals(fo,threshold_us,threshold_dm=None,*,n_sigma=None,max_sigma=None,prefit=False,ignore_ASP_dms=True,print_bad=True, check_jumps=False):
"""Quick and dirty routine to find outlier residuals based on some threshold.
Automatically deals with Wideband vs. Narrowband fitters.

Expand All @@ -553,6 +553,8 @@ def large_residuals(fo,threshold_us,threshold_dm=None,*,n_sigma=None,max_sigma=N
If True, it will not flag/excise any TOAs from ASP or GASP data based on DM criteria
print_bad: bool
If True, prints bad-toa lines that can be copied directly into a yaml file
check_jumps: bool
If True, prints a list of likely and potential Jump flags that appear in the toas with large residuals, alongside the percent of such toas from each PTA that share that flag.

Returns
=======
Expand Down Expand Up @@ -607,14 +609,72 @@ def large_residuals(fo,threshold_us,threshold_dm=None,*,n_sigma=None,max_sigma=N
c = c_toa

badlist = np.where(c)
names = fo.toas.get_flag_value('name')[0]
chans = fo.toas.get_flag_value('chan')[0]
subints = fo.toas.get_flag_value('subint')[0]
for ibad in badlist[0]:
name = names[ibad]
chan = chans[ibad]
subint = subints[ibad]
if print_bad: print(f" - [{name}, {chan}, {subint}]")
good_list = np.where(~c)

if check_jumps:
bad_length = sum(c)
jump_flag_names = ['pta', 'sys', 'fe', 'h', 'g', 'j', 'f', 'group',
'medusa_59200_jump', 'medusa_58925_jump']
pta_flags = [['sys'],['sys'],['pta'],['fe'],
['h', 'g', 'j', 'f', 'group','medusa_59200_jump', 'medusa_58925_jump']]
pta_nums = {'EPTA':0, 'InPTA':1, 'MPTA':2, 'NANOGrav':3, 'PPTA':4}
pta_names = ['EPTA', 'InPTA', 'MPTA', 'NANOGrav', 'PPTA']
pta_toas = [0,0,0,0,0]
bad_jump_flags = {}
dubious_jump_flags = {}

flag_values = []
for i1 in range(len(jump_flag_names)):
flag_values.append(fo.toas.get_flag_value(jump_flag_names[i1])[0])

for ibad in badlist[0]:
pta = flag_values[0][ibad]
pta_num = pta_nums[pta]
for i1 in range(len(jump_flag_names)):
flag = jump_flag_names[i1]
if (flag in pta_flags[pta_num]) and (flag_values[i1][ibad] != None):
key = '({}) -'.format(pta) + flag + ' ' + flag_values[i1][ibad]
if key not in bad_jump_flags.keys():
bad_jump_flags[key] = 0
bad_jump_flags[key] += 1
pta_toas[pta_num] += 1

for i1 in range(len(jump_flag_names)):
flag = jump_flag_names[i1]
for igood in good_list[0]:
pta = flag_values[0][igood]
if flag_values[i1][igood] != None:
key = '({}) -'.format(pta) + flag + ' ' + flag_values[i1][igood]
if key in bad_jump_flags.keys():
dubious_jump_flags[key] = bad_jump_flags[key]
bad_jump_flags.pop(key)

likely_flags = sorted(bad_jump_flags.items(), reverse=True, key=lambda item: item[1])
possible_flags = sorted(dubious_jump_flags.items(), reverse=True, key=lambda item: item[1])
print("Jumps that are likely improperly fit: ")
for likely_flag in likely_flags:
if (likely_flag[1] > 0) and (likely_flag[1] <= bad_length):
pta_num = pta_nums[likely_flag[0].split(')')[0][1:]]
print(likely_flag[0] + ': {:.2f}'.format(100 * (likely_flag[1] / pta_toas[pta_num])) + "%")

if len(possible_flags) != 0:
print("\nJumps that are possibly improperly fit: ")
for possible_flag in possible_flags:
pta_num = pta_nums[possible_flag[0].split(')')[0][1:]]
print(possible_flag[0] + ': {:.2f}'.format(100 * (possible_flag[1] / pta_toas[pta_num])) + "%")
print("\n Large Residual TOAs:")

if print_bad:
names = fo.toas.get_flag_value('name')[0]
chans = fo.toas.get_flag_value('chan')[0]
subints = fo.toas.get_flag_value('subint')[0]
for ibad in badlist[0]:
name = names[ibad]
chan = chans[ibad]
subint = subints[ibad]
print(f" - [{name}, {chan}, {subint}]")


mask = ~c
log.info(f'Selecting {sum(mask)} TOAs of {fo.toas.ntoas} ({sum(c)} removed) based on large_residual() criteria.')
return fo.toas[mask]
Expand Down
Loading
Loading