Exemple #1
0
def greg_to_mjd(greg):
    """
    Convert gregorian date into MJD.

    Parameters
    ----------
    greg : string
        Gregorian date (format: YYYYMMDD_HHMMSS)

    Returns
    ----------
    mjd : float
        Date in the format MJD.

    Examples
    ----------
    >>> greg = '19881103_000000'
    >>> mjd = greg_to_mjd(greg)
    >>> print('GREG={} ->'.format(greg), 'MJD={}'.format(round(mjd, 2)))
    GREG=19881103_000000 -> MJD=47468.0
    """
    year = int(greg[:4])
    month = int(greg[4:6])
    day = int(greg[6:8])
    hour = int(greg[9:11])
    minute = int(greg[11:13])
    second = int(greg[13:15])

    fracday, status = slalib.sla_dtf2d(hour, minute, second)
    mjd, status = slalib.sla_cldj(year, month, day)
    mjd += fracday

    return mjd
Exemple #2
0
def gregorian_to_ut_mjd(date):
    '''Convert Gregorian calendar date to UTC MJD.'''
    # Do the date part
    caldj_error = {
        0: 'OK',
        1: 'bad year (MJD not computed)',
        2: 'bad month (MJD not computed)',
        3: 'bad day (MJD not computed)',
    }
    caldj_status = 0

    mjd, caldj_status = sla.sla_caldj(date.year, date.month, date.day)

    if caldj_status != 0:
        raise InvalidDateTimeError('Error:' + caldj_error[caldj_status])

    # Do the time part
    dtf2d_error = {
        0: 'OK',
        1: 'IHOUR outside range 0-23',
        2: 'IMIN outside range 0-59',
        3: 'SEC outside range 0-59.999 ',
    }
    dtf2d_status = 0

    days, dtf2d_status = sla.sla_dtf2d(date.hour, date.minute,
                                       date.second + (date.microsecond / 1e6))

    if dtf2d_status != 0:
        raise InvalidDateTimeError('Error:' + dtf2d_error[dtf2d_status])

    mjd += days

    return mjd
Exemple #3
0
def current_MJD():
    """
    current_MJD():
        Return the current MJD accurate to ~1 sec.
    """
    YY, MM, DD, hh, mm, ss, wday, yday, isdst = time.gmtime()
    mjd_f, J = s.sla_dtf2d(hh, mm, ss)
    mjd_i, J = s.sla_cldj(YY, MM, DD)
    return mjd_i + mjd_f
Exemple #4
0
def current_MJD():
    """
    current_MJD():
        Return the current MJD accurate to ~1 sec.
    """
    YY, MM, DD, hh, mm, ss, wday, yday, isdst = time.gmtime()
    mjd_f, J = s.sla_dtf2d(hh, mm, ss)
    mjd_i, J = s.sla_cldj(YY, MM, DD)
    return  mjd_i + mjd_f
def datetime2mjd_utc(d):
    
# Compute MJD for UTC
    (mjd, status) = S.sla_cldj(d.year, d.month, d.day)
    if status != 0:
    	return None
    (fday, status ) = S.sla_dtf2d(d.hour, d.minute, d.second+(d.microsecond/1e6))
    if status != 0:
    	return None
    mjd_utc = mjd + fday

    return mjd_utc
def datetime_to_mjd_utc(d):
    """Function to calculate MJD for a given UTC"""

    (mjd, status) = slalib.sla_cldj(d.year, d.month, d.day)
    if status != 0:
        return None
    (fday, status ) = slalib.sla_dtf2d(d.hour, d.minute, d.second+(d.microsecond/1e6))
    if status != 0:
        return None
    mjd_utc = mjd + fday
    
    return mjd_utc
Exemple #7
0
def datetime2mjd_utc(d):
    """Converts a passed datetime object in UTC to the equivalent Modified Julian
    Date (MJD), which is returned"""
    # Compute MJD for UTC
    (mjd, status) = S.sla_cldj(d.year, d.month, d.day)
    if status != 0:
        return None
    (fday, status) = S.sla_dtf2d(d.hour, d.minute,
                                 d.second + (d.microsecond / 1e6))
    if status != 0:
        return None
    mjd_utc = mjd + fday

    return mjd_utc
Exemple #8
0
def epochToMJD(t=None):
    """
        Return the current MJD accurate to ~1 sec if no argument
        otherwise convert argument from unix epoch to MJD
    """
    from pyslalib import slalib as s
    if t is None:
        YY, MM, DD, hh, mm, ss, wday, yday, isdst = time.gmtime()
    else:
        YY, MM, DD, hh, mm, ss, wday, yday, isdst = time.gmtime(t)
    mjd_f, J = s.sla_dtf2d(hh, mm, ss)
    mjd_i, J = s.sla_cldj(YY, MM, DD)
    return  mjd_i + mjd_f
        
    
Exemple #9
0
    def _convert_coordinates(self, lat, long, ra_ref, dec_ref, date, time):
        """ Accurate conversion from equatorial coordiantes (RA, DEC) to Spherical (TH,PH) coordinates.
        The code uses the pyslalib library for a number of functions from the SLALIB Fortran library converted to Python.
        :param lat: latitude (decimal degrees)
        :param long: longitude (decimal degrees)
        :param ra_ref: RA(J2000) (decimal hours)
        :param dec_ref: Dec(J2000) (decimal degrees)
        :param date: vector date [iyear, imonth, iday]
        :param time: vector time [ihour imin isec]
        :return: [theta, pi]: Theta and Phi angles (degrees)
        """

        const_2pi = 2.0 * math.pi
        d2r = math.pi / 180
        r2d = 180 / math.pi

        # Conversion factor seconds of time to days
        const_st2day = 1.0/(24 * 3600)

        # Specify latitude and longitude (radians)
        lat *= d2r
        long *= d2r

        # Specify catalogued position (J2000 coordinates, radians)
        ra_ref = ra_ref * 15 * d2r
        dec_ref *= d2r

        # Specify current time and date %
        isec   = time[2]
        imin   = time[1]
        ihour  = time[0]
        iday   = date[2]
        imonth = date[1]
        iyear  = date[0]

        # Convert current UTC to Modified Julian date
        djm, j1   = slalib.sla_cldj(iyear, imonth, iday)
        fdutc, j2 = slalib.sla_dtf2d(ihour, imin, isec)
        djutc     = djm + fdutc

        # Calculate Greenwich Mean Sidereal Time from MJD
        gmst1 = slalib.sla_gmst(djutc)

        # Add longitude and Equation of Equinoxes for Local Apparent ST
        djtt = djutc + slalib.sla_dtt(djutc)*const_st2day
        last = gmst1 + long + slalib.sla_eqeqx(djtt)
        if last < 0.0:
            last += const_2pi

        # Convert catalogued position to apparent RA, Dec at current date
        pr = 0.e0
        pd = 0.e0
        px = 0.e0
        rv = 0.e0
        eq = 2000.0e0
        [raobs, decobs] = slalib.sla_map(ra_ref, dec_ref, pr, pd, px, rv, eq, djutc)

        # Get Hour Angle and Declination
        ha = last - raobs
        if ha < -math.pi:
            ha += const_2pi

        if ha > math.pi:
            ha -= const_2pi
        dec = decobs

        # Convert to Azimuth and Elevation
        azim, elev = slalib.sla_de2h(ha, dec, lat)

        theta = (90 - elev * r2d).real
        phi = (azim * r2d).real

        return [theta, phi]