Пример #1
0
def test_angle_to_positive():
    """Tests the to_positive() method"""
    a = Angle(-87.32)
    b = Angle(87.32)

    assert abs(a.to_positive()() - 272.68) < TOL, \
        "ERROR: In 1st to_positive() test, value doesn't match"

    assert abs(b.to_positive()() - 87.32) < TOL, \
        "ERROR: In 2nd to_positive() test, value doesn't match"
Пример #2
0
    def true_longitude_coarse(epoch):
        """This method provides the Sun's true longitude with a relatively low
        accuracy of about 0.01 degree.

        :param epoch: Epoch to compute the position of the Sun
        :type epoch: :py:class:`Epoch`

        :returns: A tuple containing the true (ecliptical) longitude (as an
            Angle object) and the radius vector in astronomical units.
        :rtype: tuple
        :raises: TypeError if input value is of wrong type.

        >>> epoch = Epoch(1992, 10, 13)
        >>> true_lon, r = Sun.true_longitude_coarse(epoch)
        >>> print(true_lon.dms_str(n_dec=0))
        199d 54' 36.0''
        >>> print(round(r, 5))
        0.99766
        """

        # First check that input values are of correct types
        if not (isinstance(epoch, Epoch)):
            raise TypeError("Invalid input type")
        # Compute the time in Julian centuries
        t = (epoch - JDE2000) / 36525.0
        # Compute the geometric mean longitude of the Sun
        l0 = 280.46646 + t * (36000.76983 + t * 0.0003032)
        l0 = Angle(l0)
        l0.to_positive()
        # Now, compute the mean anomaly of the Sun
        m = 357.52911 + t * (35999.05029 - t * 0.0001537)
        m = Angle(m)
        mrad = m.rad()
        # The eccentricity of the Earth's orbit
        e = 0.016708634 - t * (0.000042037 + t * 0.0000001267)
        # Equation of the center
        c = ((1.914602 - t * (0.004817 + t * 0.000014)) * sin(mrad) +
             (0.019993 - t * 0.000101) * sin(2.0 * mrad) +
             0.000289 * sin(3.0 * mrad))
        c = Angle(c)
        true_lon = l0 + c
        true_anom = m + c
        # Sun's radius vector
        r = (1.000001018 * (1.0 - e * e)) / (1.0 + e * cos(true_anom.rad()))
        return (true_lon, r)
Пример #3
0
    def apparent_rightascension_declination_coarse(epoch):
        """This method provides the Sun's apparent right ascension and
        declination with a relatively low accuracy of about 0.01 degree.

        :param epoch: Epoch to compute the position of the Sun
        :type epoch: :py:class:`Epoch`

        :returns: A tuple containing the right ascension and the declination
            (as Angle objects) and the radius vector in astronomical units.
        :rtype: tuple
        :raises: TypeError if input value is of wrong type.

        >>> epo = Epoch(1992, 10, 13)
        >>> ra, delta, r = Sun.apparent_rightascension_declination_coarse(epo)
        >>> print(ra.ra_str(n_dec=1))
        13h 13' 31.4''
        >>> print(delta.dms_str(n_dec=0))
        -7d 47' 6.0''
        >>> print(round(r, 5))
        0.99766
        """

        # First check that input values are of correct types
        if not isinstance(epoch, Epoch):
            raise TypeError("Invalid input type")
        # Second, find the apparent longitude
        sun = Sun()
        app_lon, r = sun.apparent_longitude_coarse(epoch)
        # Compute the obliquity of the ecliptic
        e0 = mean_obliquity(epoch)
        # Compute the time in Julian centuries
        t = (epoch - JDE2000) / 36525.0
        # Then correct for nutation and aberration
        omega = 125.04 - 1934.136 * t
        omega = Angle(omega)
        # Correct the obliquity
        e = e0 + 0.00256 * cos(omega.rad())
        alpha = atan2(cos(e.rad()) * sin(app_lon.rad()), cos(app_lon.rad()))
        alpha = Angle(alpha, radians=True)
        alpha.to_positive()
        delta = asin(sin(e.rad()) * sin(app_lon.rad()))
        delta = Angle(delta, radians=True)
        return (alpha, delta, r)
Пример #4
0
    def equation_of_time(epoch):
        """This method computes the equation of time for a given epoch,
        understood as the difference between apparent and mean time, or the
        difference between the hour angle of the true Sun and the mean Sun.

        :param epoch: Epoch to compute the equation of time, as an Epoch object
        :type epoch: :py:class:`Epoch`

        :returns: Difference between apparent and mean time, as a tuple, in
            minutes (int) and seconds (float) of time
        :rtype: tuple
        :raises: TypeError if input values are of wrong type.

        >>> epoch = Epoch(1992, 10, 13.0)
        >>> m, s = Sun.equation_of_time(epoch)
        >>> print(m)
        13
        >>> print(round(s, 1))
        42.6
        """

        # First check that input values are of correct types
        if not isinstance(epoch, Epoch):
            raise TypeError("Invalid input type")
        # Compute time in Julian millenia from J2000.0
        t = (epoch - JDE2000) / 365250
        l0 = (280.4664567 + t * (360007.6982779 + t *
                                 (0.03032028 + t *
                                  (1.0 / 49931.0 + t *
                                   (-1.0 / 15300.0 - t * 1.0 / 2000000.0)))))
        l0 = Angle(l0)
        l0 = l0.to_positive()
        # Compute the apparent position of the Sun
        lon, lat, r = Sun.apparent_geocentric_position(epoch)
        # Now, get the true obliquity
        epsilon = true_obliquity(epoch)
        # Transform from eclliptical to equatorial coordinates
        alpha, dec = ecliptical2equatorial(lon, lat, epsilon)
        alpha = alpha.to_positive()
        # Now we need the nutation in longitude
        deltapsi = nutation_longitude(epoch)
        e = l0() - 0.0057183 - alpha + deltapsi * cos(epsilon.rad())
        e *= 4.0
        # Extract seconds
        s = (abs(e()) % 1) * 60.0
        m = int(e())
        return m, s
Пример #5
0
    def geocentric_position(epoch):
        """This method computes the geocentric position of Pluto (right
        ascension and declination) for the given epoch, for the standard
        equinox J2000.0.

        :param epoch: Epoch to compute geocentric position, as an Epoch object
        :type epoch: :py:class:`Epoch`

        :returns: A tuple containing the right ascension and the declination as
            Angle objects
        :rtype: tuple
        :raises: TypeError if input value is of wrong type.
        :raises: ValueError if input epoch outside the 1885-2099 range.

        >>> epoch = Epoch(1992, 10, 13.0)
        >>> ra, dec = Pluto.geocentric_position(epoch)
        >>> print(ra.ra_str(n_dec=1))
        15h 31' 43.7''
        >>> print(dec.dms_str(n_dec=0))
        -4d 27' 29.0''
        """

        # First check that input value is of correct types
        if not isinstance(epoch, Epoch):
            raise TypeError("Invalid input type")
        # Check that the input epoch is within valid range
        y = epoch.year()
        if y < 1885.0 or y > 2099.0:
            raise ValueError("Epoch outside the 1885-2099 range")
        # Compute the heliocentric position of Pluto
        ll, b, r = Pluto.geometric_heliocentric_position(epoch)
        # Change angles to radians
        ll = ll.rad()
        b = b.rad()
        # Values corresponding to obliquity of ecliptic (epsilon) for J2000.0
        sine = 0.397777156
        cose = 0.917482062
        x = r * cos(ll) * cos(b)
        y = r * (sin(ll) * cos(b) * cose - sin(b) * sine)
        z = r * (sin(ll) * cos(b) * sine + sin(b) * cose)
        # Compute Sun's J2000.0 rectacngular coordinates
        xs, ys, zs = Sun.rectangular_coordinates_j2000(epoch)
        # Compute auxiliary quantities
        xi = x + xs
        eta = y + ys
        zeta = z + zs
        # Compute Pluto's distance to Earth
        delta = sqrt(xi * xi + eta * eta + zeta * zeta)
        # Get the light-time difference
        tau = 0.0057755183 * delta
        # Repeat the computations using the light-time correction
        ll, b, r = Pluto.geometric_heliocentric_position(epoch - tau)
        # Change angles to radians
        ll = ll.rad()
        b = b.rad()
        x = r * cos(ll) * cos(b)
        y = r * (sin(ll) * cos(b) * cose - sin(b) * sine)
        z = r * (sin(ll) * cos(b) * sine + sin(b) * cose)
        # Compute auxiliary quantities
        xi = x + xs
        eta = y + ys
        zeta = z + zs
        # Compute Pluto's distance to Earth
        delta = sqrt(xi * xi + eta * eta + zeta * zeta)
        # Compute right ascension and declination
        alpha = Angle(atan2(eta, xi), radians=True)
        dec = Angle(asin(zeta / delta), radians=True)
        return alpha.to_positive(), dec