Esempio n. 1
0
    def test_F0(self):
        """Check whether the value and units of F0 parameter are ok"""
        units = u.Hz
        value = str2longdouble('186.49408156698235146')

        self.assertEqual(self.m.F0.units, units)
        self.assertTrue(numpy.isclose(self.m.F0.value, value, atol=1e-19))
        self.assertEqual(self.m.F0.value, value)
Esempio n. 2
0
    def test_F0(self):
        """Check whether the value and units of F0 parameter are ok"""
        units = u.Hz
        value = str2longdouble('186.49408156698235146')

        self.assertEqual(self.m.F0.units, units)
        self.assertTrue(
                numpy.isclose(self.m.F0.value, value, atol=1e-19))
        self.assertEqual(self.m.F0.value, value)
Esempio n. 3
0
def test_str2longdouble_rejects_bytes(s):
    with pytest.raises(TypeError):
        str2longdouble(s)
Esempio n. 4
0
def test_str2longdouble_handles_unusual_input(s, v):
    if np.isnan(v):
        assert np.isnan(str2longdouble(s))
    else:
        assert str2longdouble(s) == v
Esempio n. 5
0
def test_str2longdouble_raises_valueerror(s):
    with pytest.raises(ValueError):
        str2longdouble(s)
Esempio n. 6
0
def test_longdouble_str_roundtrip_is_exact(i, f):
    ld = np.longdouble(i) + np.longdouble(f)
    assert ld == str2longdouble(longdouble2str(ld))
Esempio n. 7
0
def tempo_polyco_table_reader(filename):
    """Read tempo style polyco file to an astropy table.

    Tempo style: The polynomial ephemerides are written to file 'polyco.dat'.  Entries
    are listed sequentially within the file.  The file format is::

        ====  =======   ============================================
        Line  Columns     Item
        ====  =======   ============================================
         1       1-10   Pulsar Name
                11-19   Date (dd-mmm-yy)
                20-31   UTC (hhmmss.ss)
                32-51   TMID (MJD)
                52-72   DM
                74-79   Doppler shift due to earth motion (10^-4)
                80-86   Log_10 of fit rms residual in periods
         2       1-20   Reference Phase (RPHASE)
                21-38   Reference rotation frequency (F0)
                39-43   Observatory number
                44-49   Data span (minutes)
                50-54   Number of coefficients
                55-75   Observing frequency (MHz)
                76-80   Binary phase
         3*      1-25   Coefficient 1 (COEFF(1))
                26-50   Coefficient 2 (COEFF(2))
                51-75   Coefficient 3 (COEFF(3))
        ====  =======   ============================================
        * Subsequent lines have three coefficients each, up to NCOEFF

    One polyco file could include more then one entrie

    The pulse phase and frequency at time T are then calculated as::

        DT = (T-TMID)*1440
        PHASE = RPHASE + DT*60*F0 + COEFF(1) + DT*COEFF(2) + DT^2*COEFF(3) + ....
        FREQ(Hz) = F0 + (1/60)*(COEFF(2) + 2*DT*COEFF(3) + 3*DT^2*COEFF(4) + ....)

    Parameters
    ----------
    filename : str
        Name of the input poloco file.

    References
    ----------
    http://tempo.sourceforge.net/ref_man_sections/tz-polyco.txt
    """
    f = open(filename, "r")
    # Read entries to the end of file
    entries = []
    while True:
        # Read first line
        line1 = f.readline()
        if len(line1) == 0:
            break

        fields = line1.split()
        psrname = fields[0].strip()
        date = fields[1].strip()
        utc = fields[2]
        tmid = utils.str2longdouble(fields[3])
        dm = float(fields[4])
        doppler = float(fields[5])
        logrms = float(fields[6])
        # Read second line
        line2 = f.readline()
        fields = line2.split()
        refPhaseInt, refPhaseFrac = fields[0].split('.')
        refPhaseInt = data2longdouble(refPhaseInt)
        refPhaseFrac = data2longdouble('.' + refPhaseFrac)
        if refPhaseInt < 0:
            refPhaseFrac = -refPhaseFrac

        refF0 = data2longdouble(fields[1])
        obs = fields[2]
        mjdSpan = data2longdouble(
            fields[3]) / MIN_PER_DAY  # Here change to constant
        nCoeff = int(fields[4])
        obsfreq = float(fields[5].strip())

        try:
            binaryPhase = data2longdouble(fields[6])
        except ValueError:
            binaryPhase = data2longdouble(0.0)

        # Read coefficients
        nCoeffLines = int(np.ceil(nCoeff / 3))

        #if nCoeff%3>0:
        #    nCoeffLines += 1
        coeffs = []

        for i in range(nCoeffLines):
            line = f.readline()
            for c in line.split():
                coeffs.append(data2longdouble(c))
        coeffs = np.array(coeffs)

        tmid = tmid * u.day
        mjdspan = mjdSpan * u.day
        tstart = data2longdouble(tmid) - data2longdouble(mjdspan) / 2.0
        tstop = data2longdouble(tmid) + data2longdouble(mjdspan) / 2.0
        rphase = Phase(refPhaseInt, refPhaseFrac)
        refF0 = data2longdouble(refF0)
        coeffs = data2longdouble(coeffs)
        entry = polycoEntry(tmid, mjdspan, refPhaseInt, refPhaseFrac, refF0,
                            nCoeff, coeffs, obs)

        entries.append(
            (psrname, date, utc, tmid.value, dm, doppler, logrms, binaryPhase,
             mjdspan, tstart, tstop, obs, obsfreq, entry))
    entry_list = []
    for ii in range(len(entries[0])):
        entry_list.append([t[ii] for t in entries])

    #Construct the polyco data table
    pTable = table.Table(entry_list,
                         names=('psr', 'date', 'utc', 'tmid', 'dm', 'doppler',
                                'logrms', 'binary_phase', 'mjd_span',
                                't_start', 't_stop', 'obs', 'obsfreq',
                                'entry'),
                         meta={'name': 'Polyco Data Table'})

    pTable['index'] = np.arange(len(entries))
    return pTable