예제 #1
0
def test_jump_by_cluster(setup_NGC6440E):
    """
    Compare selection by MJD with selection by cluster (which by default selects TOAs by 2h gaps)
    """
    m_copy = copy.deepcopy(setup_NGC6440E.m)

    setup_NGC6440E.m.add_component(PhaseJump(), validate=False)
    cp = setup_NGC6440E.m.components["PhaseJump"]
    par = p.maskParameter(name="JUMP",
                          key="mjd",
                          value=0.2,
                          key_value=[54099, 54100],
                          units=u.s)
    # this should be the last group of any TOAs
    cp.add_param(par, setup=True)

    # add clusters to the TOAs
    clusters = setup_NGC6440E.t.get_clusters(2 * u.hr, add_column=False)
    for i, v in zip(np.arange(len(setup_NGC6440E.t)), clusters):
        setup_NGC6440E.t.table[i]["flags"]["toacluster"] = str(v)

    m_copy.add_component(PhaseJump(), validate=False)
    cp_copy = m_copy.components["PhaseJump"]
    par_copy = p.maskParameter(name="JUMP",
                               key="-toacluster",
                               value=0.2,
                               key_value=41,
                               units=u.s)
    # this should be identical to the cluster above
    cp_copy.add_param(par_copy, setup=True)
    assert set(cp.JUMP1.select_toa_mask(setup_NGC6440E.t)) == set(
        cp_copy.JUMP1.select_toa_mask(setup_NGC6440E.t))
예제 #2
0
파일: test_jump.py 프로젝트: devbhakt/PINT
def test_remove_jump_and_flags(setup_NGC6440E):
    setup_NGC6440E.m.add_component(PhaseJump(), validate=False)
    cp = setup_NGC6440E.m.components["PhaseJump"]
    selected_toa_ind = [1, 2, 3]
    selected_toa_ind2 = [10, 11, 12]
    cp.add_jump_and_flags(setup_NGC6440E.t.table["flags"][selected_toa_ind])
    cp.add_jump_and_flags(setup_NGC6440E.t.table["flags"][selected_toa_ind2])
    # test delete_jump_and_flags
    setup_NGC6440E.m.delete_jump_and_flags(setup_NGC6440E.t.table["flags"], 1)
    for dict in setup_NGC6440E.t.table["flags"][selected_toa_ind]:
        assert "jump" not in dict
        assert "gui_jump" not in dict
    # check that other flags at higher indeces adjust
    for dict in setup_NGC6440E.t.table["flags"][selected_toa_ind2]:
        assert dict["jump"] == ["1"]
        assert dict["gui_jump"] == "1"
    assert len(cp.jumps) == 1
    assert "JUMP1" in cp.jumps

    # delete last jump
    setup_NGC6440E.m.delete_jump_and_flags(setup_NGC6440E.t.table["flags"], 1)
    for dict in setup_NGC6440E.t.table["flags"][selected_toa_ind2]:
        assert "jump" not in dict
        assert "gui_jump" not in dict
    assert "PhaseJump" not in setup_NGC6440E.m.components
예제 #3
0
def test_remove_jump_and_flags(setup_NGC6440E):
    setup_NGC6440E.m.add_component(PhaseJump(), validate=False)
    cp = setup_NGC6440E.m.components["PhaseJump"]
    selected_toa_ind = [1, 2, 3]
    selected_toa_ind2 = [10, 11, 12]
    cp.add_jump_and_flags(setup_NGC6440E.t.table["flags"][selected_toa_ind])
    cp.add_jump_and_flags(setup_NGC6440E.t.table["flags"][selected_toa_ind2])
    # test delete_jump_and_flags
    setup_NGC6440E.m.delete_jump_and_flags(setup_NGC6440E.t.table["flags"], 1)
    assert len(cp.jumps) == 1

    # delete last jump
    setup_NGC6440E.m.delete_jump_and_flags(setup_NGC6440E.t.table["flags"], 2)
    for d in setup_NGC6440E.t.table["flags"][selected_toa_ind2]:
        assert "jump" not in d
    assert "PhaseJump" not in setup_NGC6440E.m.components
예제 #4
0
def test_jump_params_to_flags(setup_NGC6440E):
    """ Check jump_params_to_flags function. """
    setup_NGC6440E.m.add_component(PhaseJump(), validate=False)
    cp = setup_NGC6440E.m.components["PhaseJump"]

    par = p.maskParameter(
        name="JUMP", key="freq", value=0.2, key_value=[1440, 1700], units=u.s
    )  # TOAs indexed 48, 49, 54 in NGC6440E are within this frequency range
    cp.add_param(par, setup=True)

    # sanity check - ensure no jump flags from initialization
    for i in range(setup_NGC6440E.t.ntoas):
        assert "jump" not in setup_NGC6440E.t.table["flags"][i]

    # add flags based off jumps added to model
    setup_NGC6440E.m.jump_params_to_flags(setup_NGC6440E.t)

    # index to affected TOAs and ensure appropriate flags set
    toa_indeces = [48, 49, 54]
    for i in toa_indeces:
        assert "jump" in setup_NGC6440E.t.table["flags"][i]
        assert setup_NGC6440E.t.table["flags"][i]["jump"][0] == "1"
    # ensure no extraneous flags added to unaffected TOAs
    for i in range(setup_NGC6440E.t.ntoas):
        if i not in toa_indeces:
            assert "jump" not in setup_NGC6440E.t.table["flags"][i]

    # check case where multiple calls are performed (no-ops)
    old_table = setup_NGC6440E.t.table
    setup_NGC6440E.m.jump_params_to_flags(setup_NGC6440E.t)
    assert all(old_table) == all(setup_NGC6440E.t.table)

    # check that adding overlapping jump works
    par2 = p.maskParameter(
        name="JUMP", key="freq", value=0.2, key_value=[1600, 1900], units=u.s
    )  # frequency range overlaps with par, 2nd jump will have common TOAs w/ 1st
    cp.add_param(par2, setup=True)
    # add flags based off jumps added to model
    setup_NGC6440E.m.jump_params_to_flags(setup_NGC6440E.t)
    mask2 = par2.select_toa_mask(setup_NGC6440E.t)
    intersect = np.intersect1d(toa_indeces, mask2)
    assert intersect is not []
    for i in mask2:
        assert "2" in setup_NGC6440E.t.table["flags"][i]["jump"]
    for i in toa_indeces:
        assert "1" in setup_NGC6440E.t.table["flags"][i]["jump"]
예제 #5
0
def test_add_overlapping_jump(setup_NGC6440E):
    setup_NGC6440E.m.add_component(PhaseJump(), validate=False)
    cp = setup_NGC6440E.m.components["PhaseJump"]
    selected_toa_ind = [1, 2, 3]
    selected_toa_ind2 = [10, 11, 12]
    cp.add_jump_and_flags(setup_NGC6440E.t.table["flags"][selected_toa_ind])
    cp.add_jump_and_flags(setup_NGC6440E.t.table["flags"][selected_toa_ind2])
    # attempt to add overlapping jump - should not add jump
    selected_toa_ind3 = [9, 10, 11]
    cp.add_jump_and_flags(setup_NGC6440E.t.table["flags"][selected_toa_ind3])
    # check previous jump flags unaltered
    for d in setup_NGC6440E.t.table["flags"][selected_toa_ind]:
        assert d["gui_jump"] == "1"
    for d in setup_NGC6440E.t.table["flags"][selected_toa_ind2]:
        assert d["gui_jump"] == "2"
    # check that no flag added to index 9
    assert "jump" not in setup_NGC6440E.t.table[9].colnames
    assert "gui_jump" not in setup_NGC6440E.t.table[9].colnames
예제 #6
0
def test_add_jumps_and_flags(setup_NGC6440E):
    setup_NGC6440E.m.add_component(PhaseJump(), validate=False)
    cp = setup_NGC6440E.m.components["PhaseJump"]

    # simulate selecting TOAs in pintk and jumping them
    selected_toa_ind = [1, 2, 3]  # arbitrary set of TOAs
    cp.add_jump_and_flags(setup_NGC6440E.t.table["flags"][selected_toa_ind])
    for d in setup_NGC6440E.t.table["flags"][selected_toa_ind]:
        assert d["gui_jump"] == "1"

    # add second jump to different set of TOAs
    selected_toa_ind2 = [10, 11, 12]
    cp.add_jump_and_flags(setup_NGC6440E.t.table["flags"][selected_toa_ind2])
    # check previous jump flags unaltered
    for d in setup_NGC6440E.t.table["flags"][selected_toa_ind]:
        assert d["gui_jump"] == "1"
    # check appropriate flags added
    for d in setup_NGC6440E.t.table["flags"][selected_toa_ind2]:
        assert d["gui_jump"] == "2"
예제 #7
0
def test_multijump_toa(setup_NGC6440E):
    setup_NGC6440E.m.add_component(PhaseJump(), validate=False)
    cp = setup_NGC6440E.m.components["PhaseJump"]
    par = p.maskParameter(
        name="JUMP", key="freq", value=0.2, key_value=[1440, 1700], units=u.s
    )  # TOAs indexed 48, 49, 54 in NGC6440E are within this frequency range
    selected_toa_ind = [48, 49, 54]
    cp.add_param(par, setup=True)

    # check that one can still add "gui jumps" to model-jumped TOAs
    cp.add_jump_and_flags(setup_NGC6440E.t.table["flags"][selected_toa_ind])
    # add flags based off jumps added to model
    setup_NGC6440E.m.jump_params_to_flags(setup_NGC6440E.t)
    for dict in setup_NGC6440E.t.table["flags"][selected_toa_ind]:
        assert dict["jump"] in ["1,2", "2,1"]
        assert dict["gui_jump"] == "2"
    assert len(cp.jumps) == 2

    setup_NGC6440E.m.delete_jump_and_flags(setup_NGC6440E.t.table["flags"], 2)
    for dict in setup_NGC6440E.t.table["flags"][selected_toa_ind]:
        assert "jump" in dict
    assert len(cp.jumps) == 1
    assert "JUMP1" in cp.jumps