def calculate_percent_illuminated(self, t_struct): """ Calculate the percent of the body that is illuminated. The value returned is a fraction in the range from 0.0 to 100.0. """ phase_angle = self.calculate_phase_angle(t_struct) return 50.0 * (1.0 + math.cos(Geometry.degrees_to_radians(phase_angle)))
def calculate_percent_illuminated(self, t_struct): ''' Calculate the percent of the body that is illuminated. The value returned is a fraction in the range from 0.0 to 100.0. ''' phase_angle = self.calculate_phase_angle(t_struct) return 50.0 * (1.0 + math.cos(Geometry.degrees_to_radians(phase_angle)))
def calculate_hour_angle(self, altitude, latitude, declination): ''' Calculates the hour angle of a given declination for the given location. This is a helper application for the rise and set calculations. Its probably not worth using as a general purpose method. All values are in degrees. This method calculates the hour angle from the meridian using the following equation from the Astronomical Almanac (p487): cos ha = (sin alt - sin lat * sin dec) / (cos lat * cos dec) ''' alt_rads = Geometry.degrees_to_radians(altitude) lat_rads = Geometry.degrees_to_radians(latitude) dec_rads = Geometry.degrees_to_radians(declination) cos_ha = (math.sin(alt_rads) - math.sin(lat_rads) * math.sin(dec_rads)) / \ (math.cos(lat_rads) * math.cos(dec_rads)) return Geometry.radians_to_degrees(math.acos(cos_ha))
def calculate_hour_angle(self, altitude, latitude, declination): """ Calculates the hour angle of a given declination for the given location. This is a helper application for the rise and set calculations. Its probably not worth using as a general purpose method. All values are in degrees. This method calculates the hour angle from the meridian using the following equation from the Astronomical Almanac (p487): cos ha = (sin alt - sin lat * sin dec) / (cos lat * cos dec) """ alt_rads = Geometry.degrees_to_radians(altitude) lat_rads = Geometry.degrees_to_radians(latitude) dec_rads = Geometry.degrees_to_radians(declination) cos_ha = (math.sin(alt_rads) - math.sin(lat_rads) * math.sin(dec_rads)) / ( math.cos(lat_rads) * math.cos(dec_rads) ) return Geometry.radians_to_degrees(math.acos(cos_ha))
def calculate_lunar_geocentric_location(self, t_struct): ''' Calculate the geocentric right ascension and declination of the moon using an approximation as described on page D22 of the 2008 Astronomical Almanac All of the variables in this method use the same names as those described in the text: lambda = Ecliptic longitude (degrees) beta = Ecliptic latitude (degrees) pi = horizontal parallax (degrees) r = distance (Earth radii) NOTE: The text does not give a specific time period where the approximation is valid, but it should be valid through at least 2009. ''' # First, calculate the number of Julian centuries from J2000.0. t = ((calculate_julian_day(t_struct) - 2451545.0) / 36525.0) # Second, calculate the approximate geocentric orbital elements. lambda_val = 218.32 + 481267.881 * t + 6.29 \ * math.sin(Geometry.degrees_to_radians(135.0 + 477198.87 * t)) - 1.27 \ * math.sin(Geometry.degrees_to_radians(259.3 - 413335.36 * t)) + 0.66 \ * math.sin(Geometry.degrees_to_radians(235.7 + 890534.22 * t)) + 0.21 \ * math.sin(Geometry.degrees_to_radians(269.9 + 954397.74 * t)) - 0.19 \ * math.sin(Geometry.degrees_to_radians(357.5 + 35999.05 * t)) - 0.11 \ * math.sin(Geometry.degrees_to_radians(186.5 + 966404.03 * t)) beta = 5.13 \ * math.sin(Geometry.degrees_to_radians(93.3 + 483202.02 * t)) + 0.28 \ * math.sin(Geometry.degrees_to_radians(228.2 + 960400.89 * t)) - 0.28 \ * math.sin(Geometry.degrees_to_radians(318.3 + 6003.15 * t)) - 0.17 \ * math.sin(Geometry.degrees_to_radians(217.6 - 407332.21 * t)) # Third, convert to RA and Dec. l = math.cos(Geometry.degrees_to_radians(beta)) \ * math.cos(Geometry.degrees_to_radians(lambda_val)) m = 0.9175 * math.cos(Geometry.degrees_to_radians(beta)) \ * math.sin(Geometry.degrees_to_radians(lambda_val)) - 0.3978 \ * math.sin(Geometry.degrees_to_radians(beta)) n = 0.3978 * math.cos(Geometry.degrees_to_radians(beta)) \ * math.sin(Geometry.degrees_to_radians(lambda_val)) + 0.9175 \ * math.sin(Geometry.degrees_to_radians(beta)) ra = Geometry.radians_to_degrees(Geometry.mod_2_pi(math.atan2(m, l))) dec = Geometry.radians_to_degrees(math.asin(n)) return RaDec(ra, dec)
def get_orbital_elements(self, t_struct): # Centuries since J2000 jc = julian_centuries(t_struct) if self.id == planet_enum.MERCURY: a = 0.38709927 + 0.00000037 * jc e = 0.20563593 + 0.00001906 * jc i = Geometry.degrees_to_radians(7.00497902 - 0.00594749 * jc) l = Geometry.mod_2_pi(Geometry.degrees_to_radians(252.25032350 + 149472.67411175 * jc)) w = Geometry.degrees_to_radians(77.45779628 + 0.16047689 * jc) o = Geometry.degrees_to_radians(48.33076593 - 0.12534081 * jc) return OrbitalElements(a, e, i, o, w, l) elif self.id == planet_enum.VENUS: a = 0.72333566 + 0.00000390 * jc e = 0.00677672 - 0.00004107 * jc i = Geometry.degrees_to_radians(3.39467605 - 0.00078890 * jc) l = Geometry.mod_2_pi(Geometry.degrees_to_radians(181.97909950 + 58517.81538729 * jc)) w = Geometry.degrees_to_radians(131.60246718 + 0.00268329 * jc) o = Geometry.degrees_to_radians(76.67984255 - 0.27769418 * jc) return OrbitalElements(a, e, i, o, w, l) elif self.id == planet_enum.SUN: # Note that this is the orbital data for Earth. a = 1.00000261 + 0.00000562 * jc e = 0.01671123 - 0.00004392 * jc i = Geometry.degrees_to_radians(-0.00001531 - 0.01294668 * jc) l = Geometry.mod_2_pi(Geometry.degrees_to_radians(100.46457166 + 35999.37244981 * jc)) w = Geometry.degrees_to_radians(102.93768193 + 0.32327364 * jc) o = 0.0 return OrbitalElements(a, e, i, o, w, l) elif self.id == planet_enum.MARS: a = 1.52371034 + 0.00001847 * jc e = 0.09339410 + 0.00007882 * jc i = Geometry.degrees_to_radians(1.84969142 - 0.00813131 * jc) l = Geometry.mod_2_pi(Geometry.degrees_to_radians(-4.55343205 + 19140.30268499 * jc)) w = Geometry.degrees_to_radians(-23.94362959 + 0.44441088 * jc) o = Geometry.degrees_to_radians(49.55953891 - 0.29257343 * jc) return OrbitalElements(a, e, i, o, w, l) elif self.id == planet_enum.JUPITER: a = 5.20288700 - 0.00011607 * jc e = 0.04838624 - 0.00013253 * jc i = Geometry.degrees_to_radians(1.30439695 - 0.00183714 * jc) l = Geometry.mod_2_pi(Geometry.degrees_to_radians(34.39644051 + 3034.74612775 * jc)) w = Geometry.degrees_to_radians(14.72847983 + 0.21252668 * jc) o = Geometry.degrees_to_radians(100.47390909 + 0.20469106 * jc) return OrbitalElements(a, e, i, o, w, l) elif self.id == planet_enum.SATURN: a = 9.53667594 - 0.00125060 * jc e = 0.05386179 - 0.00050991 * jc i = Geometry.degrees_to_radians(2.48599187 + 0.00193609 * jc) l = Geometry.mod_2_pi(Geometry.degrees_to_radians(49.95424423 + 1222.49362201 * jc)) w = Geometry.degrees_to_radians(92.59887831 - 0.41897216 * jc) o = Geometry.degrees_to_radians(113.66242448 - 0.28867794 * jc) return OrbitalElements(a, e, i, o, w, l) elif self.id == planet_enum.URANUS: a = 19.18916464 - 0.00196176 * jc e = 0.04725744 - 0.00004397 * jc i = Geometry.degrees_to_radians(0.77263783 - 0.00242939 * jc) l = Geometry.mod_2_pi(Geometry.degrees_to_radians(313.23810451 + 428.48202785 * jc)) w = Geometry.degrees_to_radians(170.95427630 + 0.40805281 * jc) o = Geometry.degrees_to_radians(74.01692503 + 0.04240589 * jc) return OrbitalElements(a, e, i, o, w, l) elif self.id == planet_enum.NEPTUNE: a = 30.06992276 + 0.00026291 * jc e = 0.00859048 + 0.00005105 * jc i = Geometry.degrees_to_radians(1.77004347 + 0.00035372 * jc) l = Geometry.mod_2_pi(Geometry.degrees_to_radians(-55.12002969 + 218.45945325 * jc)) w = Geometry.degrees_to_radians(44.96476227 - 0.32241464 * jc) o = Geometry.degrees_to_radians(131.78422574 - 0.00508664 * jc) return OrbitalElements(a, e, i, o, w, l) elif self.id == planet_enum.PLUTO: a = 39.48211675 - 0.00031596 * jc e = 0.24882730 + 0.00005170 * jc i = Geometry.degrees_to_radians(17.14001206 + 0.00004818 * jc) l = Geometry.mod_2_pi(Geometry.degrees_to_radians(238.92903833 + 145.20780515 * jc)) w = Geometry.degrees_to_radians(224.06891629 - 0.04062942 * jc) o = Geometry.degrees_to_radians(110.30393684 - 0.01183482 * jc) return OrbitalElements(a, e, i, o, w, l) else: raise RuntimeError("Unknown Planet:" + str(self.id))
def calculate_lunar_geocentric_location(self, t_struct): """ Calculate the geocentric right ascension and declination of the moon using an approximation as described on page D22 of the 2008 Astronomical Almanac All of the variables in this method use the same names as those described in the text: lambda = Ecliptic longitude (degrees) beta = Ecliptic latitude (degrees) pi = horizontal parallax (degrees) r = distance (Earth radii) NOTE: The text does not give a specific time period where the approximation is valid, but it should be valid through at least 2009. """ # First, calculate the number of Julian centuries from J2000.0. t = (calculate_julian_day(t_struct) - 2451545.0) / 36525.0 # Second, calculate the approximate geocentric orbital elements. lambda_val = ( 218.32 + 481267.881 * t + 6.29 * math.sin(Geometry.degrees_to_radians(135.0 + 477198.87 * t)) - 1.27 * math.sin(Geometry.degrees_to_radians(259.3 - 413335.36 * t)) + 0.66 * math.sin(Geometry.degrees_to_radians(235.7 + 890534.22 * t)) + 0.21 * math.sin(Geometry.degrees_to_radians(269.9 + 954397.74 * t)) - 0.19 * math.sin(Geometry.degrees_to_radians(357.5 + 35999.05 * t)) - 0.11 * math.sin(Geometry.degrees_to_radians(186.5 + 966404.03 * t)) ) beta = ( 5.13 * math.sin(Geometry.degrees_to_radians(93.3 + 483202.02 * t)) + 0.28 * math.sin(Geometry.degrees_to_radians(228.2 + 960400.89 * t)) - 0.28 * math.sin(Geometry.degrees_to_radians(318.3 + 6003.15 * t)) - 0.17 * math.sin(Geometry.degrees_to_radians(217.6 - 407332.21 * t)) ) # Third, convert to RA and Dec. l = math.cos(Geometry.degrees_to_radians(beta)) * math.cos(Geometry.degrees_to_radians(lambda_val)) m = 0.9175 * math.cos(Geometry.degrees_to_radians(beta)) * math.sin( Geometry.degrees_to_radians(lambda_val) ) - 0.3978 * math.sin(Geometry.degrees_to_radians(beta)) n = 0.3978 * math.cos(Geometry.degrees_to_radians(beta)) * math.sin( Geometry.degrees_to_radians(lambda_val) ) + 0.9175 * math.sin(Geometry.degrees_to_radians(beta)) ra = Geometry.radians_to_degrees(Geometry.mod_2_pi(math.atan2(m, l))) dec = Geometry.radians_to_degrees(math.asin(n)) return RaDec(ra, dec)