예제 #1
0
 def _from_string_time (cls, s, ** kw) :
     future = kw.get ("future")
     date   = kw.get ("date")   or CAL.Date ()
     now    = kw.get ("time")   or CAL.Time ()
     time   = CAL.Time.from_string (s)
     if future and time < now :
         date += 1
     return cls.combine (date, time)
예제 #2
0
 def _to_local_time(self, hours_ut):
     dt = CAL.Date_Time.combine(self.day, self.time_ut)
     delta = self.loc.tz.utcoffset(dt._body)
     return CAL.Time(time=(dt + delta)._body.time())
예제 #3
0
파일: Earth.py 프로젝트: xiaochang91/tapyr
class Time (TFL.Meta.Object) :
    """Model astronomical time for a single Date.

    ### Example 12.a of J. Meeus, p. 88
    >>> date = CAL.Date (1987, 4, 10)
    >>> xa   = Time (date)
    >>> print (portable_repr (xa.t))
    -0.127296372348

    >>> print (xa.mean_sidereal_time)
    13:10:46.366826
    >>> print (xa.sidereal_time)
    13:10:46.357311

    ### Example 12.b of J. Meeus, p. 89
    >>> dt  = CAL.Date_Time (1987, 4, 10, 19, 21, 0)
    >>> xb  = Time (dt)
    >>> print (portable_repr (xb.t))
    -0.127274298426

    >>> print (xb.mean_sidereal_time)
    08:34:57.089579

    """

    time = CAL.Time (0)

    def __init__ (self, date) :
        """`date` must be in UT."""
        if isinstance (date, CAL.Date_Time) :
            self.time      = date.as_time ()
        self.date          = date
        self.JC_2k         = self.t  = t  = date.JC_J2000
        self.JC_2k_squared = self.t2 = t2 = t * t
        self.JC_2k_cubed   = self.t3      = t * t2
    # end def __init__

    @Once_Property
    def eccentriticy_earth_orbit (self) :
        """Eccentricity of earth's orbit (unitless)."""
        ### Eq. (25.4)
        return 0.016708634 - self.t * 0.000042037 - self.t2 * 0.0000001267
    # end def eccentriticy_earth_orbit

    @Once_Property
    def geometric_mean_anomaly_sun (self) :
        """Geometric mean anomaly of the sun (in degrees)."""
        ### Eq. (25.3)
        return Angle_D.normalized \
            (357.52911 + self.t * 35999.05029 - self.t2 * 0.0001537)
    # end def geometric_mean_anomaly_sun

    @Once_Property
    def geometric_mean_longitude_moon (self) :
        """Geometric mean longitude of the moon (in degrees)."""
        ### see J. Meeus, p. 144;
        return Angle_D.normalized \
            (218.3165 + self.t * 481267.8813)
    # end def geometric_mean_longitude_moon

    @Once_Property
    def geometric_mean_longitude_sun (self) :
        """Geometric mean longitude of the sun (in degrees)."""
        ### see J. Meeus, p. 144; Eq. (25.2)
        return Angle_D.normalized \
            ( 280.46646
            + self.t * 36000.76983
            + self.t2 * 0.0003032
            )
    # end def geometric_mean_longitude_sun

    @Once_Property
    def longitude_ascending_node_moon (self) :
        """Longitude of the (mean) ascending node of the moon's orbit on the
           ecliptic.
        """
        ### see J. Meeus, p. 144; p.343, Eq. (47.7)
        return Angle_D \
            ( 125.04452
            - self.t  * 1934.136261
            + self.t2 * 0.0020708
            + self.t3 / 450000.0
            )
    # end def longitude_ascending_node_moon

    @Once_Property
    def mean_obliquity_ecliptic (self) :
        """Mean obliquity of the ecliptic (in degrees)."""
        ### see J. Meeus, p. 147, Eq. (22.2)
        return \
            ( Angle_D (23, 26, 21.448)
            - Angle_D (seconds = 46.815000) * self.t
            - Angle_D (seconds =  0.000590) * self.t2
            + Angle_D (seconds =  0.001813) * self.t3
            )
    # end def mean_obliquity_ecliptic

    @Once_Property
    def mean_sidereal_deg (self) :
        """Mean sidereal time at `self.date` and `self.time` in degrees."""
        seconds = self.time.seconds
        if seconds == 0 :
            ### J. Meeus, eq. (12.3), p. 87
            result = 100.46061837 + 36000.770053608 * self.t
        else :
            ### J. Meeus, eq. (12.4), p. 88
            result = \
                ( 280.46061837
                + 360.98564736629 * (self.date.JD - 2451545.0)
                )
        ### J. Meeus, eq. (12.3 + 12.4), p. 87
        result += 0.000387933 * self.t2 - self.t3 / 38710000.0
        return result % 360.0
    # end def mean_sidereal_deg

    @Once_Property
    def mean_sidereal_time (self) :
        """Mean sidereal time at `self.date` and `self.time`."""
        return CAL.Time.from_degrees (self.mean_sidereal_deg)
    # end def mean_sidereal_time

    @Once_Property
    def nutation_longitude (self) :
        """Nutation in longitude (delta-phi)."""
        ### see J. Meeus, pp. 143–4
        omega  = self.longitude_ascending_node_moon
        om_2   = omega * 2
        ls_2   = self.geometric_mean_longitude_sun  * 2
        lm_2   = self.geometric_mean_longitude_moon * 2
        result = \
            ( Angle_D (seconds = -17.20) * omega.sin
            - Angle_D (seconds = - 1.32) * ls_2.sin
            - Angle_D (seconds =   0.23) * lm_2.sin
            + Angle_D (seconds =   0.21) * om_2.sin
            )
        return result
    # end def nutation_longitude

    @Once_Property
    def nutation_obliquity (self) :
        """Nutation in obliquity (delta-epsilon)."""
        ### see J. Meeus, pp. 143–4
        omega  = self.longitude_ascending_node_moon
        om_2   = omega * 2
        ls_2   = self.geometric_mean_longitude_sun  * 2
        lm_2   = self.geometric_mean_longitude_moon * 2
        result = \
            ( Angle_D (seconds =   9.20) * omega.cos
            + Angle_D (seconds =   0.57) * ls_2.cos
            + Angle_D (seconds =   0.10) * lm_2.cos
            - Angle_D (seconds =   0.09) * om_2.cos
            )
        return result
    # end def nutation_obliquity

    @Once_Property
    def obliquity_corrected (self) :
        """Corrected obliquity of the ecliptic (in degrees)."""
        ### Eq. (25.8)
        return \
            ( self.mean_obliquity_ecliptic
            + 0.00256 * self.longitude_ascending_node_moon.cos
            )
    # end def obliquity_corrected

    @Once_Property
    def sidereal_deg (self) :
        """Apparent sidereal time at `self.date` and `self.time` in degrees."""
        ### see J. Meeus, p. 95
        result = \
            ( Angle_D.normalized (self.mean_sidereal_deg)
            + (self.nutation_longitude / 15) * self.obliquity_corrected.cos
            )
        return result
    # end def sidereal_deg

    @Once_Property
    def sidereal_time (self) :
        """Apparent sidereal time at `self.date` and `self.time`."""
        return CAL.Time.from_degrees (self.sidereal_deg)
예제 #4
0
 def as_time (self) :
     """Return `self` converted to pure `Time`."""
     return CAL.Time (time = self._body.time ())