Esempio n. 1
0
    def get_magnitude(self, t_struct):
        """
        Calculates the planet's magnitude for the given date.
        """
        if self.id == planet_enum.SUN:
            return -27.0
        if self.id == planet_enum.MOON:
            return -10.0

        # First, determine position in the solar system.
        planet_coords = hc_get_instance(planet=self, t_struct=t_struct)

        # Second, determine position relative to Earth
        earth_coords = hc_get_instance(
            t_struct=t_struct,
            planet=Planet(planet_enum.SUN, res[planet_enum.SUN][0], res[planet_enum.SUN][1], res[planet_enum.SUN][2]),
        )
        earth_distance = planet_coords.distance_from(earth_coords)

        # Third, calculate the phase of the body.
        phase = Geometry.radians_to_degrees(
            math.acos(
                (
                    earth_distance * earth_distance
                    + planet_coords.radius * planet_coords.radius
                    - earth_coords.radius * earth_coords.radius
                )
                / (2.0 * earth_distance * planet_coords.radius)
            )
        )
        p = phase / 100.0  # Normalized phase angle

        # Finally, calculate the magnitude of the body.
        mag = -100.0  # Apparent visual magnitude

        if self.id == planet_enum.MERCURY:
            mag = -0.42 + (3.80 - (2.73 - 2.00 * p) * p) * p
        elif self.id == planet_enum.VENUS:
            mag = -4.40 + (0.09 + (2.39 - 0.65 * p) * p) * p
        elif self.id == planet_enum.MARS:
            mag = -1.52 + 1.6 * p
        elif self.id == planet_enum.JUPITER:
            mag = -9.40 + 0.5 * p
        elif self.id == planet_enum.SATURN:
            mag = -8.75
        elif self.id == planet_enum.URANUS:
            mag = -7.19
        elif self.id == planet_enum.NEPTUNE:
            mag = -6.87
        elif self.id == planet_enum.PLUTO:
            mag = -1.0
        else:
            mag = 100
        return mag + 5.0 * math.log10(planet_coords.radius * earth_distance)
Esempio n. 2
0
 def get_magnitude(self, t_struct):
     '''
     Calculates the planet's magnitude for the given date.
     '''
     if self.id == planet_enum.SUN:
         return -27.0
     if self.id == planet_enum.MOON:
         return -10.0
     
     # First, determine position in the solar system.
     planet_coords = hc_get_instance(planet=self, t_struct=t_struct)
     
     # Second, determine position relative to Earth
     earth_coords = hc_get_instance(t_struct=t_struct,
                                    planet=Planet(planet_enum.SUN, 
                                                  res[planet_enum.SUN][0], 
                                                  res[planet_enum.SUN][1], 
                                                  res[planet_enum.SUN][2]))
     earth_distance = planet_coords.distance_from(earth_coords)
     
     # Third, calculate the phase of the body.
     phase = Geometry.radians_to_degrees(\
                 math.acos((earth_distance * earth_distance + \
                 planet_coords.radius * planet_coords.radius - \
                 earth_coords.radius * earth_coords.radius) / \
                 (2.0 * earth_distance * planet_coords.radius)))
     p = phase/100.0     # Normalized phase angle
     
     # Finally, calculate the magnitude of the body.
     mag = -100.0      # Apparent visual magnitude
     
     if self.id == planet_enum.MERCURY:
         mag = -0.42 + (3.80 - (2.73 - 2.00 * p) * p) * p
     elif self.id == planet_enum.VENUS:
         mag = -4.40 + (0.09 + (2.39 - 0.65 * p) * p) * p
     elif self.id == planet_enum.MARS:
         mag = -1.52 + 1.6 * p
     elif self.id == planet_enum.JUPITER:
         mag = -9.40 + 0.5 * p
     elif self.id == planet_enum.SATURN:
         mag = -8.75
     elif self.id == planet_enum.URANUS:
         mag = -7.19
     elif self.id == planet_enum.NEPTUNE:
         mag = -6.87
     elif self.id == planet_enum.PLUTO:
         mag = -1.0
     else:
         mag = 100
     return (mag + 5.0 * math.log10(planet_coords.radius * earth_distance))
Esempio n. 3
0
def get_instance(geo_coord=None, earth_coord=None, planet=None, time=None):
    '''
    Returns a RaDec instance given either geocentric coordinates
    or heliocentric coordinates with a planet and the time.
    '''

    if geo_coord == None and earth_coord == None:
        raise Exception("must provide geo_coords or helio_coords")
    if geo_coord != None:
        raRad = math.atan2(geo_coord.y, geo_coord.x)
        if (raRad < 0): raRad += math.pi * 2.0
        decRad = math.atan2(geo_coord.z,
                            math.sqrt(geo_coord.x * geo_coord.x + \
                                      geo_coord.y * geo_coord.y))

        return RaDec(radians_to_degrees(raRad), radians_to_degrees(decRad))
    else:
        if planet.id == planet_enum.MOON:
            return planet.calculate_lunar_geocentric_location(time)

        coords = None
        if planet.id == planet_enum.SUN:
            # Invert the view, since we want the Sun in earth coordinates, not the Earth in sun
            # coordinates.
            coords = HeliocentricCoordinates(earth_coord.radius,
                                             earth_coord.x * -1.0,
                                             earth_coord.y * -1.0,
                                             earth_coord.z * -1.0)
        else:
            coords = hc_get_instance(None, planet, time)
            coords.subtract(earth_coord)

        equ = coords.calculate_equitorial_coords()
        return calculate_ra_dec_dist(equ)
Esempio n. 4
0
def get_instance(geo_coord=None, earth_coord=None,
                 planet=None, time=None):
    '''
    Returns a RaDec instance given either geocentric coordinates
    or heliocentric coordinates with a planet and the time.
    '''
    
    if geo_coord == None and earth_coord == None: 
        raise Exception("must provide geo_coords or helio_coords")
    if geo_coord != None:
        raRad = math.atan2(geo_coord.y, geo_coord.x)
        if (raRad < 0): raRad += math.pi * 2.0
        decRad = math.atan2(geo_coord.z,
                            math.sqrt(geo_coord.x * geo_coord.x + \
                                      geo_coord.y * geo_coord.y));
                                          
        return RaDec(radians_to_degrees(raRad), radians_to_degrees(decRad))
    else:
        if planet.id == planet_enum.MOON:
            return planet.calculate_lunar_geocentric_location(time)
            
        coords = None
        if planet.id == planet_enum.SUN:
            # Invert the view, since we want the Sun in earth coordinates, not the Earth in sun
            # coordinates.
            coords = HeliocentricCoordinates(earth_coord.radius, earth_coord.x * -1.0, 
                                             earth_coord.y * -1.0, earth_coord.z * -1.0)
        else:
            coords = hc_get_instance(None, planet, time)
            coords.subtract(earth_coord)
            
        equ = coords.calculate_equitorial_coords()
        return calculate_ra_dec_dist(equ)
Esempio n. 5
0
    def calculate_phase_angle(self, t_struct):
        """
        Calculates the phase angle of the planet, in degrees.
        """
        # For the moon, we will approximate phase angle by calculating the
        # elongation of the moon relative to the sun. This is accurate to within
        # about 1%.
        if self.id == planet_enum.MOON:
            moon_ra_dec = self.calculate_lunar_geocentric_location(t_struct)
            moon = gc_get_instance(moon_ra_dec.ra, moon_ra_dec.dec)

            sun_coords = hc_get_instance(
                t_struct=t_struct,
                planet=Planet(
                    planet_enum.SUN, res[planet_enum.SUN][0], res[planet_enum.SUN][1], res[planet_enum.SUN][2]
                ),
            )
            sun_ra_dec = calculate_ra_dec_dist(sun_coords)
            sun = gc_get_instance(sun_ra_dec.ra, sun_ra_dec.dec)

            return 180.0 - Geometry.radians_to_degrees(math.acos(sun.x * moon.x + sun.y * moon.y + sun.z * moon.z))

        # First, determine position in the solar system.
        planet_coords = hc_get_instance(planet=self, t_struct=t_struct)

        # Second, determine position relative to Earth
        earth_coords = hc_get_instance(
            t_struct=t_struct,
            planet=Planet(planet_enum.SUN, res[planet_enum.SUN][0], res[planet_enum.SUN][1], res[planet_enum.SUN][2]),
        )
        earth_distance = planet_coords.distance_from(earth_coords)

        # Finally, calculate the phase of the body.
        phase = Geometry.radians_to_degrees(
            math.acos(
                (
                    earth_distance * earth_distance
                    + planet_coords.radius * planet_coords.radius
                    - earth_coords.radius * earth_coords.radius
                )
                / (2.0 * earth_distance * planet_coords.radius)
            )
        )

        return phase
Esempio n. 6
0
def get_solar_position(time):
    '''
    # Calculates the position of the Sun in Ra and Dec
    '''
    sun = Planet(planet_enum.SUN, res[planet_enum.SUN][0], 
                 res[planet_enum.SUN][1], res[planet_enum.SUN][2])
    sun_coords = hc_get_instance(None, sun, time)
    
    ra_dec = radec_get_instance(None, sun_coords, sun, time)
    return ra_dec
Esempio n. 7
0
 def calculate_phase_angle(self, t_struct):
     '''
     Calculates the phase angle of the planet, in degrees.
     '''
     # For the moon, we will approximate phase angle by calculating the
     # elongation of the moon relative to the sun. This is accurate to within
     # about 1%.
     if self.id == planet_enum.MOON:
         moon_ra_dec = self.calculate_lunar_geocentric_location(t_struct)
         moon = gc_get_instance(moon_ra_dec.ra, moon_ra_dec.dec)
         
         sun_coords = hc_get_instance(t_struct=t_struct,
                                      planet=Planet(planet_enum.SUN, 
                                                    res[planet_enum.SUN][0], 
                                                    res[planet_enum.SUN][1], 
                                                    res[planet_enum.SUN][2]))
         sun_ra_dec = calculate_ra_dec_dist(sun_coords)
         sun = gc_get_instance(sun_ra_dec.ra, sun_ra_dec.dec)
         
         return 180.0 - \
             Geometry.radians_to_degrees(math.acos(sun.x * moon.x + sun.y * moon.y + sun.z * moon.z))
             
     # First, determine position in the solar system.
     planet_coords = hc_get_instance(planet=self, t_struct=t_struct)
     
     # Second, determine position relative to Earth
     earth_coords = hc_get_instance(t_struct=t_struct, 
                                    planet=Planet(planet_enum.SUN, 
                                                  res[planet_enum.SUN][0], 
                                                  res[planet_enum.SUN][1], 
                                                  res[planet_enum.SUN][2]))
     earth_distance = planet_coords.distance_from(earth_coords)
     
     # Finally, calculate the phase of the body.
     phase = Geometry.radians_to_degrees(\
             math.acos((earth_distance * earth_distance + \
                        planet_coords.radius * planet_coords.radius - \
                        earth_coords.radius * earth_coords.radius) / \
                        (2.0 * earth_distance * planet_coords.radius)))
                       
     return phase