Exemple #1
0
def test_nicer_result_bary_polyco(capsys):
    "Check that barycentered NICER data is processed correctly with --polyco."
    outfile = "polycos-photonphase-test.evt"
    cmd = "--polycos --outfile {0} {1} {2}".format(
        outfile, eventfile_nicer, parfile_nicer
    )
    photonphase.main(cmd.split())
    out, err = capsys.readouterr()
    v = 0.0
    for l in out.split("\n"):
        if l.startswith("Htest"):
            v = float(l.split()[2])
    # Check that H-test is 216.67
    assert abs(v - 216.67) < 1

    # Check that the phases are the same with and without polycos
    assert os.path.exists(outfile)
    hdul = fits.open(outfile)
    cols = hdul[1].columns.names
    assert "PULSE_PHASE" in cols
    data = hdul[1].data
    phases = data["PULSE_PHASE"]

    outfile2 = "photonphase-test.evt"
    cmd2 = "--outfile {0} {1} {2}".format(outfile2, eventfile_nicer, parfile_nicer)
    photonphase.main(cmd2.split())
    assert os.path.exists(outfile2)
    hdul2 = fits.open(outfile2)
    cols2 = hdul2[1].columns.names
    assert "PULSE_PHASE" in cols2
    data2 = hdul2[1].data
    phases2 = data2["PULSE_PHASE"]

    assert (phases - phases2).std() < 0.00001
Exemple #2
0
def test_nicer_result_bary(capsys):
    "Check that barycentered NICER data is processed correctly."
    cmd = "{0} {1}".format(eventfile_nicer, parfile_nicer)
    photonphase.main(cmd.split())
    out, err = capsys.readouterr()
    v = 0.0
    for l in out.split("\n"):
        if l.startswith("Htest"):
            v = float(l.split()[2])
    # Check that H-test is 216.67
    assert abs(v - 216.67) < 1
Exemple #3
0
def test_nicer_result_topo(capsys):
    "Check that topocentric NICER data and orbit files are processed correctly."
    cmd = "--minMJD 59132.780 --maxMJD 59132.782 --orbfile {0} {1} {2}".format(
        orbfile_nicer_topo, eventfile_nicer_topo, parfile_nicer_topo)
    photonphase.main(cmd.split())
    out, err = capsys.readouterr()
    v = 0.0
    for l in out.split("\n"):
        if l.startswith("Htest"):
            v = float(l.split()[2])
    # H should be 183.21
    assert abs(v - 183.21) < 1
Exemple #4
0
def test_rxte_result(capsys):
    "Test that processing RXTE data with orbit file gives correct result"
    cmd = "--minMJD 55576.640 --maxMJD 55576.645 --plot --plotfile photontest.png --outfile photontest.fits {0} {1} --orbfile={2} ".format(
        eventfile, parfile, orbfile)
    photonphase.main(cmd.split())
    out, err = capsys.readouterr()
    v = 0.0
    for l in out.split("\n"):
        if l.startswith("Htest"):
            v = float(l.split()[2])
    # H-test should be 87.5
    assert abs(v - 87.5) < 1
Exemple #5
0
def test_result(capsys):
    "Test that processing RXTE data with orbit file gives correct result"
    cmd = "--plot --plotfile photontest.png --outfile photontest.fits {0} {1} --orbfile={2} ".format(
        eventfile, parfile, orbfile
    )
    photonphase.main(cmd.split())
    out, err = capsys.readouterr()
    v = 0.0
    for l in out.split("\n"):
        if l.startswith("Htest"):
            v = float(l.split()[2])
    # Check that H-test is greater than 725
    assert v > 725
Exemple #6
0
 def test_result(self):
     #pass
     saved_stdout, photonphase.sys.stdout = photonphase.sys.stdout, StringIO('_')
     cmd = '--plot --plotfile photontest.png --outfile photontest.fits {0} {1} --orbfile={2} '.format(eventfile,parfile,orbfile)
     photonphase.main(cmd.split())
     lines = photonphase.sys.stdout.getvalue()
     v = 999.0
     for l in lines.split('\n'):
         if l.startswith('Htest'):
             v = float(l.split()[2])
     # Check that H-test is greater than 725
     log.warning('V:\t%f' % v)
     self.assertTrue(v>725)
     photonphase.sys.stdout = saved_stdout
Exemple #7
0
 def test_result(self):
     #pass
     saved_stdout, photonphase.sys.stdout = photonphase.sys.stdout, StringIO('_')
     cmd = '--plot --plotfile photontest.png --outfile photontest.fits {0} {1} --orbfile={2} '.format(eventfile,parfile,orbfile)
     photonphase.main(cmd.split())
     lines = photonphase.sys.stdout.getvalue()
     v = 999.0
     for l in lines.split('\n'):
         if l.startswith('Htest'):
             v = float(l.split()[2])
     # Check that H-test is greater than 725
     log.warning('V:\t%f' % v)
     self.assertTrue(v>725)
     photonphase.sys.stdout = saved_stdout
Exemple #8
0
def test_OrbPhase_column():
    "Verify that the ORBIT_PHASE column is calculated and added correctly"

    outfile = "photonphase-test.evt"
    cmd = "--addorbphase --outfile {0} {1} {2}".format(outfile,
                                                       eventfile_nicer_binary,
                                                       parfile_nicer_binary)
    photonphase.main(cmd.split())

    # Check that output file got made
    assert os.path.exists(outfile)
    # Check that column got added
    hdul = fits.open(outfile)
    cols = hdul[1].columns.names
    assert "ORBIT_PHASE" in cols
    # Check that first and last entry have expected values and values are monotonic
    data = hdul[1].data
    orbphases = data["ORBIT_PHASE"]
    assert abs(orbphases[0] - 0.1763) < 0.0001
    assert abs(orbphases[-1] - 0.3140) < 0.0001
    assert np.all(np.diff(orbphases) > 0)

    hdul.close()
    os.remove(outfile)
Exemple #9
0
def test_OrbPhase_exception():
    "Verify that trying to add ORBIT_PHASE column with no BINARY parameter in the par file raises exception"
    with pytest.raises(ValueError):
        cmd = "--addorbphase {0} {1}".format(eventfile_nicer, parfile_nicer)
        photonphase.main(cmd.split())
Exemple #10
0
def test_AbsPhase_exception():
    "Verify that passing par file with no TZR* parameters raises exception"
    with pytest.raises(ValueError):
        cmd = "{0} {1}".format(eventfile_nicer, parfile_nicerbad)
        photonphase.main(cmd.split())