Ejemplo n.º 1
0
def time_to_mjd_string(t, prec=15):
    """Print an MJD time with lots of digits (number is 'prec').

    astropy does not seem to provide this capability (yet?).
    """
    if t.format == 'pulsar_mjd':
        (imjd, fmjd) = day_frac(t.jd1 - DJM0, t.jd2)
        imjd = int(imjd)
        if fmjd<0.0: 
            imjd -= 1
        y, mo, d, hmsf = d2dtf('UTC',9,t.jd1,t.jd2)
        fmjd = (hmsf[...,0]/24.0 + hmsf[...,1]/1440.0 
                + hmsf[...,2]/86400.0 + hmsf[...,3]/86400.0e9)
    else:
        (imjd, fmjd) = day_frac(t.jd1 - DJM0, t.jd2)
        imjd = int(imjd)
        assert np.fabs(fmjd) < 2.0
        if fmjd >= 1.0:
            imjd += 1
            fmjd -= 1.0
        if fmjd < 0.0:
            imjd -= 1
            fmjd += 1.0

    fmt = "%." + "%sf" % prec
    return str(imjd) + (fmt % fmjd)[1:]
Ejemplo n.º 2
0
def time_to_mjd_string(t, prec=15):
    """Print an MJD time with lots of digits (number is 'prec').

    astropy does not seem to provide this capability (yet?).
    """

    if t.format == 'pulsar_mjd':
        (imjd, fmjd) = day_frac(t.jd1 - DJM0, t.jd2)
        imjd = int(imjd)
        if fmjd < 0.0:
            imjd -= 1
        y, mo, d, hmsf = d2dtf('UTC', 9, t.jd1, t.jd2)

        if hmsf[0].size == 1:
            hmsf = np.array([list(hmsf)])
        fmjd = (hmsf[..., 0] / 24.0 + hmsf[..., 1] / 1440.0 +
                hmsf[..., 2] / 86400.0 + hmsf[..., 3] / 86400.0e9)
    else:
        (imjd, fmjd) = day_frac(t.jd1 - DJM0, t.jd2)
        imjd = int(imjd)
        assert np.fabs(fmjd) < 2.0
        while fmjd >= 1.0:
            imjd += 1
            fmjd -= 1.0
        while fmjd < 0.0:
            imjd -= 1
            fmjd += 1.0

    fmt = "%." + "%sf" % prec
    return str(imjd) + (fmt % fmjd)[1:]