### Install PyMeeus via pip Source: https://pymeeus.readthedocs.io/en/latest/index.html Standard installation commands for the PyMeeus library. ```bash pip install pymeeus ``` ```bash pip install --user pymeeus ``` ```bash pip3 install --user pymeeus ``` ```bash pip3 install -U pymeeus ``` -------------------------------- ### Angle Class Initialization Source: https://pymeeus.readthedocs.io/en/latest/_modules/pymeeus/Angle.html Example of creating an Angle object using degrees, minutes, and seconds. ```python a = Angle(-23.0, 26.0, 48.999983999) print("a = Angle(-23.0, 26.0, 48.999983999)") ``` -------------------------------- ### Corrected Script Implementation Source: https://pymeeus.readthedocs.io/en/latest/examples/ex-General.html The corrected version of the initial example using the 'from' import statement. ```python from pymeeus.Epoch import Epoch mydate = Epoch(1992, 10, 13.0) ``` -------------------------------- ### Mars Class Usage Examples Source: https://pymeeus.readthedocs.io/en/latest/_modules/pymeeus/Mars.html Comprehensive example showing how to compute heliocentric and geocentric positions for Mars. ```python def main(): # Let's define a small helper function def print_me(msg, val): print("{}: {}".format(msg, val)) # Let's show some uses of Mars class print("\n" + 35 * "*") print("*** Use of Mars class") print(35 * "*" + "\n") # Let's now compute the heliocentric position for a given epoch epoch = Epoch(2018, 10, 27.0) lon, lat, r = Mars.geometric_heliocentric_position(epoch) print_me("Geometric Heliocentric Longitude", lon.to_positive()) print_me("Geometric Heliocentric Latitude", lat) print_me("Radius vector", r) print("") # Compute the geocentric position for 1992/12/20: epoch = Epoch(1992, 12, 20.0) ra, dec, elon = Mars.geocentric_position(epoch) print_me("Right ascension", ra.ra_str(n_dec=1)) print_me("Declination", dec.dms_str(n_dec=1)) print_me("Elongation", elon.dms_str(n_dec=1)) print("") ``` -------------------------------- ### Perform astronomical date calculations Source: https://pymeeus.readthedocs.io/en/latest/_modules/pymeeus/Epoch.html Comprehensive example demonstrating Epoch instantiation, calendar utilities, and leap second lookups. ```python def main(): # Let's define a small helper function def print_me(msg, val): print("{}: {}".format(msg, val)) # Let's do some work with the Epoch class print("\n" + 35 * "*") print("*** Use of Epoch class") print(35 * "*" + "\n") e = Epoch(1987, 6, 19.5) print_me("JDE for 1987/6/19.5", e) # Redefine the Epoch object e.set(333, "Jan", 27, 12) print_me("JDE for 333/1/27.5", e) # We can create an Epoch from a 'date' or 'datetime' object d = datetime.datetime(837, 4, 10, 7, 12, 0, 0) f = Epoch(d) print_me("JDE for 837/4/10.3", f) print("") # Check if a given date belong to the Julian or Gregorian calendar print_me("Is 1590/4/21.4 a Julian date?", Epoch.is_julian(1590, 4, 21.4)) print("") # We can also check if a given year is leap or not print_me("Is -1000 a leap year?", Epoch.is_leap(-1000)) print_me("Is 1800 a leap year?", Epoch.is_leap(1800)) print_me("Is 2012 a leap year?", Epoch.is_leap(2012)) print("") # Get the Day Of Year corresponding to a given date print_me("Day Of Year (DOY) of 1978/11/14", Epoch.get_doy(1978, 11, 14)) print_me("Day Of Year (DOY) of -400/2/29.9", Epoch.get_doy(-400, 2, 29.9)) # As before, but using the contents of the Epoch object e = Epoch(2017, 12, 31.7) print_me("Day Of Year (DOY) of 2017/12/31.7", round(e.doy(), 1)) print("") # Now the opposite: Get a date from a DOY t = Epoch.doy2date(2017, 365.7) s = str(t[0]) + "/" + str(t[1]) + "/" + str(round(t[2], 2)) print_me("Date from DOY 2017:365.7", s) t = Epoch.doy2date(-4, 60) s = str(t[0]) + "/" + str(t[1]) + "/" + str(round(t[2], 2)) print_me("Date from DOY -4:60", s) print("") # There is an internal table which we can use to get the leap seconds print_me("Number of leap seconds applied up to July 1983", Epoch.leap_seconds(1983, 7)) print("") # We can convert the internal JDE value back to a date e = Epoch(2436116.31) y, m, d = e.get_date() s = str(y) + "/" + str(m) + "/" + str(round(d, 2)) print_me("Date from JDE 2436116.31", s) print("") ``` -------------------------------- ### Demonstrate Neptune Class Usage Source: https://pymeeus.readthedocs.io/en/latest/_modules/pymeeus/Neptune.html Example script showing how to compute heliocentric and geocentric positions for Neptune. ```python def main(): # Let's define a small helper function def print_me(msg, val): print("{}: {}".format(msg, val)) # Let's show some uses of Neptune class print("\n" + 35 * "*") print("*** Use of Neptune class") print(35 * "*" + "\n") # Let's now compute the heliocentric position for a given epoch epoch = Epoch(2018, 10, 27.0) lon, lat, r = Neptune.geometric_heliocentric_position(epoch) print_me("Geometric Heliocentric Longitude", lon.to_positive()) print_me("Geometric Heliocentric Latitude", lat) print_me("Radius vector", r) print("") # Compute the geocentric position for 1992/12/20: epoch = Epoch(1992, 12, 20.0) ra, dec, elon = Neptune.geocentric_position(epoch) print_me("Right ascension", ra.ra_str(n_dec=1)) print_me("Declination", dec.dms_str(n_dec=1)) print_me("Elongation", elon.dms_str(n_dec=1)) ``` -------------------------------- ### Interpolation Class Usage Examples Source: https://pymeeus.readthedocs.io/en/latest/_modules/pymeeus/Interpolation.html Demonstrates initializing the Interpolation class, using the copy constructor, performing interpolation, and calculating derivatives and roots. ```python def main(): # Let's define a small helper function def print_me(msg, val): print("{}: {}".format(msg, val)) # Let's now work with the Interpolation class print("\n" + 35 * "*") print("*** Use of Interpolation class") print(35 * "*" + "\n") i = Interpolation([5, 3, 6, 1, 2, 4, 9], [10, 6, 12, 2, 4, 8]) print("i = Interpolation([5, 3, 6, 1, 2, 4, 9], [10, 6, 12, 2, 4, 8])") print(i) print("NOTE:") print(" a. They are ordered in 'x'") print(" b. The extra value in 'x' was dropped") print("") # Use the copy constructor print("We can easily make a copy of an Interpolation object") j = Interpolation(i) print("j = Interpolation(i)") print(j) print("") # Get the number of interpolation points stored print_me("Number or interpolation points in 'j'", len(j)) # 6 print("") j = Interpolation([0.0, 1.0, 3.0], [-1.0, -2.0, 2.0]) print("j = Interpolation([0.0, 1.0, 3.0], [-1.0, -2.0, 2.0])") print(j) print_me("j(2)", j(2)) print_me("j(0.5)", j(0.5)) # Test with a value already in the data table print_me("j(1)", j(1)) print("") # We can interpolate Angles too k = Interpolation( [27.0, 27.5, 28.0, 28.5, 29.0], [ Angle(0, 54, 36.125), Angle(0, 54, 24.606), Angle(0, 54, 15.486), Angle(0, 54, 8.694), Angle(0, 54, 4.133), ], ) print( "k = Interpolation([27.0, 27.5, 28.0, 28.5, 29.0],\n\ [Angle(0, 54, 36.125), Angle(0, 54, 24.606),\n\ Angle(0, 54, 15.486), Angle(0, 54, 8.694),\n\ Angle(0, 54, 4.133)])" ) print_me("k(28.278)", Angle(k(28.278)).dms_str()) print("") m = Interpolation([-1.0, 0.0, 1.0], [-2.0, 3.0, 2.0]) print("m = Interpolation([-1.0, 0.0, 1.0], [-2.0, 3.0, 2.0])") print(m) # Get interpolated values print_me("m(-0.5)", m(-0.5)) print_me("m(0.5)", m(0.5)) # Get derivatives print_me("m'(-1.0)", m.derivative(-1.0)) print_me("m'(-0.5)", m.derivative(-0.5)) print_me("m'(0.0)", m.derivative(0.0)) print_me("m'(0.5)", m.derivative(0.5)) print_me("m'(1.0)", m.derivative(1.0)) # Get the root within the interval print_me("m.root()", m.root()) # Get the extremum within the interval print_me("m.minmax()", m.minmax()) m = Interpolation( [29.43, 30.97, 27.69, 28.11, 31.58, 33.05], [ 0.4913598528, 0.5145891926, 0.4646875083, 0.4711658342, 0.5236885653, 0.5453707057, ], ) print_me("sin(29.5)\t", m(29.5)) print_me("sin(30.0)\t", m(30.0)) print_me("sin(30.5)\t", m(30.5)) # Derivative must be adjusted because degrees were used instead of radians print_me("sin'(29.5)\t", degrees(m.derivative(29.5))) print_me("sin'(30.0)\t", degrees(m.derivative(30.0))) print_me("sqrt(3.0)/2.0\t", sqrt(3.0) / 2.0) print_me("sin'(30.5)\t", degrees(m.derivative(30.5))) if __name__ == "__main__": main() ``` -------------------------------- ### Demonstrate Saturn Class Usage Source: https://pymeeus.readthedocs.io/en/latest/_modules/pymeeus/Saturn.html Example script showing how to compute heliocentric and geocentric positions for specific epochs. ```python def main(): # Let's define a small helper function def print_me(msg, val): print("{}: {}".format(msg, val)) # Let's show some uses of Saturn class print("\n" + 35 * "*") print("*** Use of Saturn class") print(35 * "*" + "\n") # Let's now compute the heliocentric position for a given epoch epoch = Epoch(2018, 10, 27.0) lon, lat, r = Saturn.geometric_heliocentric_position(epoch) print_me("Geometric Heliocentric Longitude", lon.to_positive()) print_me("Geometric Heliocentric Latitude", lat) print_me("Radius vector", r) print("") # Compute the geocentric position for 1992/12/20: epoch = Epoch(1992, 12, 20.0) ra, dec, elon = Saturn.geocentric_position(epoch) print_me("Right ascension", ra.ra_str(n_dec=1)) print_me("Declination", dec.dms_str(n_dec=1)) print_me("Elongation", elon.dms_str(n_dec=1)) print("") ``` -------------------------------- ### Traceback Error Example Source: https://pymeeus.readthedocs.io/en/latest/examples/ex-General.html The error message generated when attempting to access a class directly from the library root. ```text Traceback (most recent call last): File "/home/user/test/test.py", line 3, in epoch = pymeeus.Epoch(1992, 10, 13.0) AttributeError: module 'pymeeus' has no attribute 'Epoch' ``` -------------------------------- ### Calculate planet alignment with stars Source: https://pymeeus.readthedocs.io/en/latest/_modules/pymeeus/Coordinates.html Example usage of planet_stars_in_line to determine alignment of celestial bodies. ```python >>> alpha_1 = Angle( 7, 55, 55.36, ra=True) >>> delta_1 = Angle(21, 41, 3.0) >>> alpha_2 = Angle( 7, 58, 22.55, ra=True) >>> delta_2 = Angle(21, 35, 23.4) >>> alpha_3 = Angle( 8, 0, 48.99, ra=True) >>> delta_3 = Angle(21, 29, 38.2) >>> alpha_4 = Angle( 8, 3, 14.66, ra=True) >>> delta_4 = Angle(21, 23, 47.5) >>> alpha_5 = Angle( 8, 5, 39.54, ra=True) >>> delta_5 = Angle(21, 17, 51.4) >>> alpha_star1 = Angle( 7, 34, 16.40, ra=True) >>> delta_star1 = Angle(31, 53, 51.2) >>> alpha_star2 = Angle( 7, 45, 0.10, ra=True) >>> delta_star2 = Angle(28, 2, 12.5) >>> alpha_list = [alpha_1, alpha_2, alpha_3, alpha_4, alpha_5] >>> delta_list = [delta_1, delta_2, delta_3, delta_4, delta_5] >>> n = planet_stars_in_line(alpha_list, delta_list, alpha_star1, \ delta_star1, alpha_star2, delta_star2) >>> print(round(n, 4)) 0.2233 ``` -------------------------------- ### Find Extremum with Interpolation Source: https://pymeeus.readthedocs.io/en/latest/_modules/pymeeus/Interpolation.html Example usage of the minmax method to find the extremum of an interpolated function. ```python >>> m = Interpolation([-1.0, 0.0, 1.0], [-2.0, 3.0, 2.0]) >>> round(m.minmax(), 8) 0.33333333 ``` -------------------------------- ### Jupiter Class Usage Examples Source: https://pymeeus.readthedocs.io/en/latest/_modules/pymeeus/Jupiter.html A comprehensive script demonstrating various calculations including heliocentric/geocentric positions, orbital elements, and conjunction dates. ```python def main(): # Let's define a small helper function def print_me(msg, val): print("{}: {}".format(msg, val)) # Let's show some uses of Jupiter class print("\n" + 35 * "*") print("*** Use of Jupiter class") print(35 * "*" + "\n") # Let's now compute the heliocentric position for a given epoch epoch = Epoch(2018, 10, 27.0) lon, lat, r = Jupiter.geometric_heliocentric_position(epoch) print_me("Geometric Heliocentric Longitude", lon.to_positive()) print_me("Geometric Heliocentric Latitude", lat) print_me("Radius vector", r) print("") # Compute the geocentric position for 1992/12/20: epoch = Epoch(1992, 12, 20.0) ra, dec, elon = Jupiter.geocentric_position(epoch) print_me("Right ascension", ra.ra_str(n_dec=1)) print_me("Declination", dec.dms_str(n_dec=1)) print_me("Elongation", elon.dms_str(n_dec=1)) print("") # Print mean orbital elements for Jupiter at 2065.6.24 epoch = Epoch(2065, 6, 24.0) l, a, e, i, ome, arg = Jupiter.orbital_elements_mean_equinox(epoch) print_me("Mean longitude of the planet", round(l, 6)) # 222.433723 print_me("Semimajor axis of the orbit (UA)", round(a, 8)) # 5.20260333 print_me("Eccentricity of the orbit", round(e, 7)) # 0.0486046 print_me("Inclination on plane of the ecliptic", round(i, 6)) # 1.29967 print_me("Longitude of the ascending node", round(ome, 5)) # 101.13309 print_me("Argument of the perihelion", round(arg, 6)) # -85.745532 print("") # Compute the time of the conjunction close to 1993/10/1 epoch = Epoch(1993, 10, 1.0) conj = Jupiter.conjunction(epoch) y, m, d = conj.get_date() d = round(d, 4) date = "{}/{}/{}".format(y, m, d) print_me("Conjunction date", date) ``` -------------------------------- ### Module Execution Entry Point Source: https://pymeeus.readthedocs.io/en/latest/_modules/pymeeus/base.html Demonstrates the usage of the module's utility functions and constants. ```python def main(): # Let's define a small helper function def print_me(msg, val): print("{}: {}".format(msg, val)) # Let's print the tolerance print_me("The default value for the tolerance is", TOL) # Find the accuracy of this computer j, d = machine_accuracy() print_me("Number of significant BITS in the mantissa\t", j) print_me("Number of significant DIGITS in a decimal number", d) print("") print_me("The suffix for ordinal 2 is", get_ordinal_suffix(2)) print_me("The suffix for ordinal 11 is", get_ordinal_suffix(11)) print_me("The suffix for ordinal 12 is", get_ordinal_suffix(12)) print_me("The suffix for ordinal 13 is", get_ordinal_suffix(13)) print_me("The suffix for ordinal 14 is", get_ordinal_suffix(14)) print_me("The suffix for ordinal 16 is", get_ordinal_suffix(16)) print_me("The suffix for ordinal 23 is", get_ordinal_suffix(23)) if __name__ == "__main__": main() ``` -------------------------------- ### Angle Initialization and Basic Output Source: https://pymeeus.readthedocs.io/en/latest/_modules/pymeeus/Angle.html Demonstrates creating Angle objects and printing them using different methods. ```python # First we print using the __call__ method (note the extra parentheses) print_me("The angle 'a()' is", a()) # -23.44694444 # Second we print using the __str__ method (no extra parentheses needed) print_me("The angle 'a' is", a) # -23.44694444 print("") # Use the copy constructor b = Angle(a) print_me("Angle 'b', which is a copy of 'a', is", b) ``` -------------------------------- ### Calculate Geometric Heliocentric Position Source: https://pymeeus.readthedocs.io/en/latest/_modules/pymeeus/Uranus.html Example usage of the geometric_heliocentric_position method. ```python >>> epoch = Epoch(2018, 10, 27.0) >>> l, b, r = Uranus.geometric_heliocentric_position(epoch) >>> print(round(l.to_positive(), 4)) 30.5888 >>> print(round(b, 4)) -0.5315 >>> print(round(r, 5)) 19.86964 ``` -------------------------------- ### Sun.beginning_synodic_rotation Source: https://pymeeus.readthedocs.io/en/latest/bodies/Sun.html Calculates the epoch when the Carrington’s synodic rotation starts. ```APIDOC ## Sun.beginning_synodic_rotation(number) ### Description Calculates the epoch when the Carrington’s synodic rotation No. 'number' starts. ### Parameters - **number** (int) - Required - Number of Carrington’s synodic rotation. ### Returns - **Epoch** - Epoch when the provided rotation starts. ``` -------------------------------- ### Generate HTML Documentation Source: https://pymeeus.readthedocs.io/en/latest/index.html Command to build the project documentation locally using Sphinx. ```bash make html ``` -------------------------------- ### Get Object Representation Source: https://pymeeus.readthedocs.io/en/latest/core/CurveFitting.html Provides a string representation that can be used to recreate the object. ```python >>> i = CurveFitting([5, 3, 6, 1, 2, 4, 9], [10, 6, 12, 2, 4, 8]) >>> repr(i) 'CurveFitting([5, 3, 6, 1, 2, 4], [10, 6, 12, 2, 4, 8])' ``` -------------------------------- ### Incorrect Library Import Pattern Source: https://pymeeus.readthedocs.io/en/latest/index.html Example of an incorrect import attempt that results in an AttributeError. ```python import pymeeus mydate = pymeeus.Epoch(1992, 10, 13.0) ``` ```text Traceback (most recent call last): File "/home/user/test/test.py", line 3, in epoch = pymeeus.Epoch(1992, 10, 13.0) AttributeError: module 'pymeeus' has no attribute 'Epoch' ``` -------------------------------- ### Perform Quadratic Curve Fitting Source: https://pymeeus.readthedocs.io/en/latest/_modules/pymeeus/CurveFitting.html Demonstrates how to initialize the CurveFitting class with data points and calculate quadratic coefficients. ```python >>> cf2 = CurveFitting([-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, ... 2.0, 2.5,3.0], ... [-9.372, -3.821, 0.291, 3.730, 5.822, 8.324, ... 9.083, 6.957, 7.006, 0.365, -1.722]) >>> a, b, c = cf2.quadratic_fitting() >>> print("a = {}; b = {}; c = {}".format(round(a, 2), round(b, 2), ... round(c, 2))) a = -2.22; b = 3.76; c = 6.64 ``` -------------------------------- ### Initialize CurveFitting with various input formats Source: https://pymeeus.readthedocs.io/en/latest/_modules/pymeeus/CurveFitting.html Demonstrates initializing the CurveFitting class using different input structures such as lists, sequences, and existing objects. ```python >>> i = CurveFitting([5, 3, 6, 1, 2, 4, 9], [10, 6, 12, 2, 4, 8]) >>> print(i._x) [5, 3, 6, 1, 2, 4] >>> print(i._y) [10, 6, 12, 2, 4, 8] >>> j = CurveFitting([3, -8, 1, 12, 2, 5, 8]) >>> print(j._x) [0, 1, 2, 3, 4, 5, 6] >>> print(j._y) [3, -8, 1, 12, 2, 5, 8] >>> k = CurveFitting(3, -8, 1, 12, 2, 5, 8) >>> print(k._x) [3, 1, 2] >>> print(k._y) [-8, 12, 5] >>> m = CurveFitting(k) >>> print(m._x) [3, 1, 2] >>> print(m._y) [-8, 12, 5] ``` -------------------------------- ### Get Number of Data Pairs Source: https://pymeeus.readthedocs.io/en/latest/core/CurveFitting.html Returns the count of value pairs stored in the object. ```python >>> i = CurveFitting([5, 3, 6, 1, 2, 4, 9], [10, 6, 12, 2, 4, 8]) >>> len(i) 6 ``` -------------------------------- ### Radians and Right Ascension Handling Source: https://pymeeus.readthedocs.io/en/latest/_modules/pymeeus/Angle.html Shows how to initialize angles with radians or Right Ascension and perform conversions. ```python # We can define the angle as in radians. It will be converted to degrees b = Angle(pi, radians=True) print_me("b = Angle(pi, radians=True); print(b)", b) # 180.0 # And we can easily carry out the 'degrees to radians' conversion print_me("print(b.rad())", b.rad()) # 3.14159265359 print("") # We can also specify the angle as a Right Ascension print("Angle can be given as a Right Ascension: Hours, Minutes, Seconds") a.set_ra(9, 14, 55.8) print("a.set_ra(9, 14, 55.8)") print_me(" print(a)", a) b = Angle(9, 14, 55.8, ra=True) print("b = Angle(9, 14, 55.8, ra=True)") print_me(" print(b)", b) print("") # We can print the Angle as Right Ascension, as a float and as string a = Angle(138.75) print("a = Angle(138.75)") print_me(" print(a.get_ra())", a.get_ra()) print_me(" print(a.ra_str())", a.ra_str()) print_me(" print(a.ra_str(False))", a.ra_str(False)) ``` -------------------------------- ### Initialize and Print Angle Objects Source: https://pymeeus.readthedocs.io/en/latest/_modules/pymeeus/Angle.html Demonstrates creating an Angle object from sexagesimal components and copying an existing Angle instance. ```python >>> a = Angle(-13, 30, 0.0) >>> print(a) -13.5 >>> b = Angle(a) >>> print(b) -13.5 ``` -------------------------------- ### Perform Linear and Quadratic Curve Fitting Source: https://pymeeus.readthedocs.io/en/latest/_modules/pymeeus/CurveFitting.html Demonstrates initializing a CurveFitting object, performing linear regression, using the copy constructor, and executing quadratic fitting on a dataset. ```python cf1 = CurveFitting( [ 73.0, 38.0, 35.0, 42.0, 78.0, 68.0, 74.0, 42.0, 52.0, 54.0, 39.0, 61.0, 42.0, 49.0, 50.0, 62.0, 44.0, 39.0, 43.0, 54.0, 44.0, 37.0, ], [ 90.4, 125.3, 161.8, 143.4, 52.5, 50.8, 71.5, 152.8, 131.3, 98.5, 144.8, 78.1, 89.5, 63.9, 112.1, 82.0, 119.8, 161.2, 208.4, 111.6, 167.1, 162.1, ], ) # Let's use 'linear_fitting()' a, b = cf1.linear_fitting() print("Linear fitting for cf1:") print(" a = {}\tb = {}".format(round(a, 2), round(b, 2))) print("") # Use the copy constructor print("Let's make a copy:") cf2 = CurveFitting(cf1) print(" cf2 = CurveFitting(cf1)") a, b = cf2.linear_fitting() print("Linear fitting for cf2:") print(" a = {}\tb = {}".format(round(a, 2), round(b, 2))) print("") # Get the number of value pairs internally stored print_me("Number of value pairs inside 'cf2'", len(cf2)) # 22 print("") # Compute the correlation coefficient r = cf1.correlation_coeff() print("Correlation coefficient:") print_me(" r", round(r, 3)) cf2 = CurveFitting( [-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0], [ -9.372, -3.821, 0.291, 3.730, 5.822, 8.324, 9.083, 6.957, 7.006, 0.365, -1.722, ], ) print("") # Now use 'quadratic_fitting()' a, b, c = cf2.quadratic_fitting() # Original curve: y = -2.0*x*x + 3.5*x + 7.0 + noise print("Quadratic fitting:") print(" a = {}\tb = {}\tc = {}".format(round(a, 2), round(b, 2), round(c, 2))) ``` -------------------------------- ### Get Interpolation Point Count Source: https://pymeeus.readthedocs.io/en/latest/_modules/pymeeus/Interpolation.html Returns the number of interpolation points currently stored in the object. ```python >>> i = Interpolation([5, 3, 6, 1, 2, 4, 9], [10, 6, 12, 2, 4, 8]) >>> len(i) 6 ``` -------------------------------- ### Calculate Topocentric Coordinates Source: https://pymeeus.readthedocs.io/en/latest/_modules/pymeeus/Earth.html Example usage of the parallax_ecliptical method to convert geocentric coordinates to topocentric ones. ```python >>> longitude = Angle(181, 46, 22.5) >>> latitude = Angle(2, 17, 26.2) >>> semidiameter = Angle(0, 16, 15.5) >>> obs_lat = Angle(50, 5, 7.8) >>> obliquity = Angle(23, 28, 0.8) >>> sidereal_time = Angle(209, 46, 7.9) >>> distance = 0.0024650163 >>> topo_lon, topo_lat, topo_diam = \ Earth.parallax_ecliptical(longitude, latitude, semidiameter, \ obs_lat, obliquity, sidereal_time, \ distance) >>> print(topo_lon.dms_str(n_dec=1)) 181d 48' 5.0'' >>> print(topo_lat.dms_str(n_dec=1)) 1d 29' 7.1'' >>> print(topo_diam.dms_str(n_dec=1)) 16' 25.5'' ``` -------------------------------- ### Initialize quadratic fitting object Source: https://pymeeus.readthedocs.io/en/latest/examples/ex-CurveFitting.html Create a CurveFitting object with data for quadratic regression. ```python cf2 = CurveFitting([-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0], [-9.372, -3.821, 0.291, 3.730, 5.822, 8.324, 9.083, 6.957, 7.006, 0.365, -1.722]) ``` -------------------------------- ### Calculate Jupiter's position Source: https://pymeeus.readthedocs.io/en/latest/_modules/pymeeus/JupiterMoons.html Example usage for calculating the distance and position of Jupiter relative to an epoch. ```python >>> utc_1992_12_16_00_00_00 = Epoch(1992, 12, 16, utc=True) >>> delta, tau, l, b, r = JupiterMoons.calculate_delta( \ utc_1992_12_16_00_00_00) >>> print(round(delta, 10)) 5.6611211815 >>> print(round(tau, 10)) 0.032695909 ``` -------------------------------- ### Correct Module Import Patterns Source: https://pymeeus.readthedocs.io/en/latest/index.html Demonstrates the correct way to import specific modules and components from the PyMeeus library. ```python import pymeeus.Angle ``` ```python import pymeeus.Angle i = pymeeus.Angle.Angle(11.94524) ``` ```python from pymeeus.Angle import Angle from pymeeus.Epoch import Epoch, JDE2000 from math import sin, cos, tan, acos, atan2, sqrt, radians, log10 ``` ```python from pymeeus.Epoch import Epoch mydate = Epoch(1992, 10, 13.0) ``` -------------------------------- ### Creating Epoch from datetime Source: https://pymeeus.readthedocs.io/en/latest/examples/ex-Epoch.html Shows how to initialize an Epoch object using a standard Python datetime object. ```python d = datetime.datetime(837, 4, 10, 7, 12, 0, 0) f = Epoch(d) print_me("JDE for 837/4/10.3", f) ``` -------------------------------- ### Compute Jupiter Conjunction Time Source: https://pymeeus.readthedocs.io/en/latest/_modules/pymeeus/Jupiter.html Example usage of the conjunction method to find the time of conjunction for a given epoch. ```python >>> epoch = Epoch(1993, 10, 1.0) >>> conj = Jupiter.conjunction(epoch) >>> y, m, d = conj.get_date() >>> print(y) 1993 >>> print(m) 10 >>> print(round(d, 4)) 18.3341 ``` -------------------------------- ### Retrieving interpolation point count Source: https://pymeeus.readthedocs.io/en/latest/examples/ex-Interpolation.html Uses the len() function to get the number of points stored in the interpolation object. ```python print_me("Number or interpolation points in 'j'", len(j)) # Number or interpolation points in 'j': 3 ``` -------------------------------- ### Working with radians Source: https://pymeeus.readthedocs.io/en/latest/examples/ex-Angle.html Initializing an Angle from radians and converting back to radians. ```python b = Angle(pi, radians=True) print_me("b = Angle(pi, radians=True); print(b)", b) # b = Angle(pi, radians=True); print(b): 180.0 ``` ```python print_me("print(b.rad())", b.rad()) # print(b.rad()): 3.14159265359 ``` -------------------------------- ### Initialize CurveFitting data Source: https://pymeeus.readthedocs.io/en/latest/_modules/pymeeus/CurveFitting.html Demonstrates how to initialize the CurveFitting object using different input formats such as lists, tuples, or individual arguments. ```python >>> i = CurveFitting() >>> i.set([5, 3, 6, 1, 2, 4, 9], [10, 6, 12, 2, 4, 8]) >>> print(i._x) [5, 3, 6, 1, 2, 4] >>> print(i._y) [10, 6, 12, 2, 4, 8] >>> j = CurveFitting() >>> j.set([3, -8, 1, 12, 2, 5, 8]) >>> print(j._x) [0, 1, 2, 3, 4, 5, 6] >>> print(j._y) [3, -8, 1, 12, 2, 5, 8] >>> k = CurveFitting(3, -8, 1, 12, 2, 5, 8) >>> print(k._x) [3, 1, 2] >>> print(k._y) [-8, 12, 5] ``` -------------------------------- ### Get Ordinal Suffix Source: https://pymeeus.readthedocs.io/en/latest/_modules/pymeeus/base.html Returns the English ordinal suffix (st, nd, rd, th) for a given number. ```python def get_ordinal_suffix(ordinal): """Method to get the suffix of a given ordinal number, like 1'st', 2'nd', 15'th', etc. :param ordinal: Ordinal number :type ordinal: int :returns: Suffix corresponding to input ordinal number :rtype: str :raises: TypeError if input type is invalid. >>> get_ordinal_suffix(40) 'th' >>> get_ordinal_suffix(101) 'st' >>> get_ordinal_suffix(2) 'nd' >>> get_ordinal_suffix(19) 'th' >>> get_ordinal_suffix(23) 'rd' """ if not isinstance(ordinal, (int, float)): raise TypeError("Invalid input type") else: ordinal = int(floor(ordinal)) unit = ordinal % 10 if unit == 1 and ordinal != 11: return "st" elif unit == 2 and ordinal != 12: return "nd" elif unit == 3 and ordinal != 13: return "rd" else: return "th" ``` -------------------------------- ### Interpolation object initialization Source: https://pymeeus.readthedocs.io/en/latest/examples/ex-Interpolation.html Demonstrates creating an Interpolation object. Note that input data is automatically ordered by x-values and extra values may be dropped. ```python i = Interpolation([5, 3, 6, 1, 2, 4, 9], [10, 6, 12, 2, 4, 8]) print(i) # X: [1, 2, 3, 4, 5, 6] # Y: [2, 4, 6, 8, 10, 12] ``` -------------------------------- ### Get official string representation Source: https://pymeeus.readthedocs.io/en/latest/_modules/pymeeus/Interpolation.html Demonstrates the official string representation of an Interpolation instance that can be used to recreate the object. ```python >>> i = Interpolation([5, 3, 6, 1, 2, 4, 9], [10, 6, 12, 2, 4, 8]) >>> repr(i) 'Interpolation([1, 2, 3, 4, 5, 6], [2, 4, 6, 8, 10, 12])' ``` -------------------------------- ### Calculate parallax correction for equatorial coordinates Source: https://pymeeus.readthedocs.io/en/latest/_modules/pymeeus/Earth.html Example usage of the parallax_correction method to adjust geocentric coordinates to topocentric coordinates. ```python >>> right_ascension = Angle(22, 38, 7.25, ra=True) >>> declination = Angle(-15, 46, 15.9) >>> latitude = Angle(33, 21, 22) >>> distance = 0.37276 >>> hour_angle = Angle(288.7958) >>> topo_ra, topo_dec = Earth.parallax_correction(right_ascension, declination, latitude, distance, hour_angle) >>> print(topo_ra.ra_str(n_dec=2)) 22h 38' 8.54'' >>> print(topo_dec.dms_str(n_dec=1)) -15d 46' 30.0'' ``` -------------------------------- ### Creating and setting Epoch objects Source: https://pymeeus.readthedocs.io/en/latest/examples/ex-Epoch.html Demonstrates initializing an Epoch object with specific dates and updating it using the set method. ```python e = Epoch(1987, 6, 19.5) print_me("JDE for 1987/6/19.5", e) ``` ```python e.set(333, 'Jan', 27, 12) print_me("JDE for 333/1/27.5", e) ``` -------------------------------- ### Compute Uranus Conjunction Time Source: https://pymeeus.readthedocs.io/en/latest/_modules/pymeeus/Uranus.html Example usage of the conjunction method to find the time of conjunction closest to a given epoch. ```python >>> epoch = Epoch(1993, 10, 1.0) >>> conj = Uranus.conjunction(epoch) >>> y, m, d = conj.get_date() >>> print(y) 1994 >>> print(m) 1 >>> print(round(d, 4)) 12.7365 ``` -------------------------------- ### Comparison and Addition Source: https://pymeeus.readthedocs.io/en/latest/_modules/pymeeus/Angle.html Demonstrates comparison operators and adding angles or numbers. ```python # Comparison operators print_me(" d == e", d == e) # False print_me(" d != e", d != e) # True print_me(" d > e", d > e) # True print_me(" c >= 180.0", c >= 180.0) # False print_me(" c < 180.0", c < 180.0) # True print_me(" c <= 180.0", c <= 180.0) # True print("") # It is very easy to add Angles to obtain a new Angle e = c + d print_me(" c + d", e) # 133.7825 # We can also directly add a decimal angle e = c + 11.5 print_me(" c + 11.5", e) # 150.2325 print("") # Types allowed are int, float and Angle print('e = c + "32.5"') try: e = c + "32.5" except TypeError: print("TypeError!: Valid types are int, float, and Angle, not string!") ``` -------------------------------- ### Calculate Inferior Conjunction Source: https://pymeeus.readthedocs.io/en/latest/_modules/pymeeus/Venus.html Example usage of the inferior_conjunction method to find the time of the inferior conjunction closest to a provided epoch. ```python >>> epoch = Epoch(1882, 12, 1.0) >>> conjunction = Venus.inferior_conjunction(epoch) >>> y, m, d = conjunction.get_date() >>> print(y) 1882 >>> print(m) 12 >>> print(round(d, 1)) 6.7 ``` -------------------------------- ### Initialize CurveFitting object Source: https://pymeeus.readthedocs.io/en/latest/examples/ex-CurveFitting.html Create a CurveFitting instance with provided x and y data points. ```python cf1 = CurveFitting([73.0, 38.0, 35.0, 42.0, 78.0, 68.0, 74.0, 42.0, 52.0, 54.0, 39.0, 61.0, 42.0, 49.0, 50.0, 62.0, 44.0, 39.0, 43.0, 54.0, 44.0, 37.0], [90.4, 125.3, 161.8, 143.4, 52.5, 50.8, 71.5, 152.8, 131.3, 98.5, 144.8, 78.1, 89.5, 63.9, 112.1, 82.0, 119.8, 161.2, 208.4, 111.6, 167.1, 162.1]) ``` -------------------------------- ### Compute Moon Librations Source: https://pymeeus.readthedocs.io/en/latest/_modules/pymeeus/Moon.html Example usage of the moon_librations method to calculate optical, physical, and total librations for a given epoch. ```python >>> epoch = Epoch(1992, 4, 12.0) >>> lopt, bopt, lphys, bphys, ltot, btot = Moon.moon_librations(epoch) >>> print(round(lopt, 3)) -1.206 >>> print(round(bopt, 3)) 4.194 >>> print(round(lphys, 3)) -0.025 >>> print(round(bphys, 3)) 0.006 >>> print(round(ltot, 2)) -1.23 >>> print(round(btot, 3)) 4.2 ``` -------------------------------- ### Calculate Neptune Conjunction Time Source: https://pymeeus.readthedocs.io/en/latest/_modules/pymeeus/Neptune.html Example usage of the conjunction method to find the time of the conjunction closest to a given epoch. ```python >>> epoch = Epoch(1993, 10, 1.0) >>> conj = Neptune.conjunction(epoch) >>> y, m, d = conj.get_date() >>> print(y) 1994 >>> print(m) 1 >>> print(round(d, 4)) 11.3057 ```