From 3816e841d22c6e0f1c228f740480db6881953856 Mon Sep 17 00:00:00 2001 From: Mark Wieczorek Date: Fri, 4 Oct 2024 09:16:17 +0200 Subject: [PATCH 1/6] Add __str__ to classes --- boule/_ellipsoid.py | 14 ++++++++++++++ boule/_realizations.py | 6 +++--- boule/_sphere.py | 13 +++++++++++++ boule/_triaxialellipsoid.py | 15 +++++++++++++++ 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/boule/_ellipsoid.py b/boule/_ellipsoid.py index 6568d029..cd09085f 100644 --- a/boule/_ellipsoid.py +++ b/boule/_ellipsoid.py @@ -7,6 +7,7 @@ """ Module for defining and setting the reference ellipsoid. """ +import textwrap from warnings import warn import attr @@ -394,6 +395,19 @@ def gravity_pole(self): ) return result + def __str__(self): + str = self.name + " - " + self.long_name + "\n" + str += "Oblate ellipsoid:\n" + str += f" Semimajor axis: {self.semimajor_axis} m\n" + str += f" Flattening: {self.flattening}\n" + str += f" GM: {self.geocentric_grav_const} m³/s²\n" + str += f" Angular velocity: {self.angular_velocity} rad/s\n" + str += "Source:\n" + str += textwrap.fill( + self.reference, width=72, initial_indent=" ", subsequent_indent=" " + ) + return str + def geocentric_radius(self, latitude, geodetic=True): r""" Radial distance from the center of the ellipsoid to its surface. diff --git a/boule/_realizations.py b/boule/_realizations.py index 6989d0c9..61062b97 100644 --- a/boule/_realizations.py +++ b/boule/_realizations.py @@ -65,7 +65,7 @@ angular_velocity=7292115e-11, reference=( "Hofmann-Wellenhof, B., & Moritz, H. (2006). Physical Geodesy " - "(2nd, corr. ed. 2006 edition ed.). Wien ; New York: Springer." + "(2nd, corr. ed. 2006 edition ed.). Wien; New York: Springer." ), ) @@ -79,7 +79,7 @@ angular_velocity=7292115e-11, reference=( "Hofmann-Wellenhof, B., & Moritz, H. (2006). Physical Geodesy " - "(2nd, corr. ed. 2006 edition ed.). Wien ; New York: Springer." + "(2nd, corr. ed. 2006 edition ed.). Wien; New York: Springer." ), ) @@ -120,7 +120,7 @@ reference=( "Ardalan, A. A., Karimi, R., & Grafarend, E. W. (2009). A New Reference " "Equipotential Surface, and Reference Ellipsoid for the Planet Mars. " - "Earth, Moon, and Planets, 106(1), 1. " + "Earth, Moon, and Planets, 106, 1-13. " "doi:10.1007/s11038-009-9342-7" ), ) diff --git a/boule/_sphere.py b/boule/_sphere.py index 84f08bd8..0ae9a085 100644 --- a/boule/_sphere.py +++ b/boule/_sphere.py @@ -7,6 +7,7 @@ """ Define the reference sphere (ellipsoid with 0 flattening). """ +import textwrap from warnings import warn import attr @@ -280,6 +281,18 @@ def reference_normal_gravitational_potential(self): """ return self.geocentric_grav_const / self.radius + def __str__(self): + str = self.name + " - " + self.long_name + "\n" + str += "Spheroid:\n" + str += f" Radius: {self.radius} m\n" + str += f" GM: {self.geocentric_grav_const} m³/s²\n" + str += f" Angular velocity: {self.angular_velocity} rad/s\n" + str += "Source:\n" + str += textwrap.fill( + self.reference, width=72, initial_indent=" ", subsequent_indent=" " + ) + return str + def normal_gravity(self, latitude, height, si_units=False): r""" Normal gravity of the sphere at the given latitude and height. diff --git a/boule/_triaxialellipsoid.py b/boule/_triaxialellipsoid.py index c1ab8a4e..82c01a20 100644 --- a/boule/_triaxialellipsoid.py +++ b/boule/_triaxialellipsoid.py @@ -7,6 +7,7 @@ """ Define a reference triaxial ellipsoid. """ +import textwrap from warnings import warn import attr @@ -325,6 +326,20 @@ def meridional_flattening(self): """ return (self.semimajor_axis - self.semiminor_axis) / self.semimajor_axis + def __str__(self): + str = self.name + " - " + self.long_name + "\n" + str += "Triaxial ellipsoid:\n" + str += f" Semimajor axis: {self.semimajor_axis} m\n" + str += f" Semimedium axis: {self.semimedium_axis} m\n" + str += f" Semiminor axis: {self.semiminor_axis} m\n" + str += f" GM: {self.geocentric_grav_const} m³/s²\n" + str += f" Angular velocity: {self.angular_velocity} rad/s\n" + str += "Source:\n" + str += textwrap.fill( + self.reference, width=72, initial_indent=" ", subsequent_indent=" " + ) + return str + def geocentric_radius(self, longitude, latitude): r""" Radial distance from the center of the ellipsoid to its surface. From 5317d936b482845d8dcf474d887a81ce9676b7cc Mon Sep 17 00:00:00 2001 From: Mark Wieczorek Date: Fri, 4 Oct 2024 14:04:59 +0200 Subject: [PATCH 2/6] Improve __str__ handling of optional parameters --- boule/_ellipsoid.py | 39 +++++++++++------ boule/_sphere.py | 33 ++++++++++----- boule/_triaxialellipsoid.py | 84 +++++++++++++++++++++++-------------- 3 files changed, 102 insertions(+), 54 deletions(-) diff --git a/boule/_ellipsoid.py b/boule/_ellipsoid.py index cd09085f..b9746cc6 100644 --- a/boule/_ellipsoid.py +++ b/boule/_ellipsoid.py @@ -89,7 +89,16 @@ class Ellipsoid: ... ), ... ) >>> print(ellipsoid) # doctest: +ELLIPSIS - Ellipsoid(name='WGS84', ...) + WGS84 - World Geodetic System 1984 + Oblate ellipsoid: + Semimajor axis: 6378137 m + Flattening: 0.0033528106647474805 + GM: 398600441800000.0 m³/s² + Angular velocity: 7.292115e-05 rad/s + Source: + Hofmann-Wellenhof, B., & Moritz, H. (2006). Physical Geodesy (2nd, + corr. ed. 2006 edition ed.). Wien ; New York: Springer. + >>> print(ellipsoid.long_name) World Geodetic System 1984 @@ -396,17 +405,23 @@ def gravity_pole(self): return result def __str__(self): - str = self.name + " - " + self.long_name + "\n" - str += "Oblate ellipsoid:\n" - str += f" Semimajor axis: {self.semimajor_axis} m\n" - str += f" Flattening: {self.flattening}\n" - str += f" GM: {self.geocentric_grav_const} m³/s²\n" - str += f" Angular velocity: {self.angular_velocity} rad/s\n" - str += "Source:\n" - str += textwrap.fill( - self.reference, width=72, initial_indent=" ", subsequent_indent=" " - ) - return str + s = self.name + " - " + self.long_name + "\n" + s += "Oblate ellipsoid:\n" + s += f" Semimajor axis: {self.semimajor_axis} m\n" + s += f" Flattening: {self.flattening}\n" + s += f" GM: {self.geocentric_grav_const} m³/s²\n" + s += f" Angular velocity: {self.angular_velocity} rad/s" + if self.reference is not None: + s += "\nSource:\n" + s += textwrap.fill( + self.reference, width=72, initial_indent=" ", subsequent_indent=" " + ) + if self.comments is not None: + s += "\nComments:\n" + s += textwrap.fill( + self.comments, width=72, initial_indent=" ", subsequent_indent=" " + ) + return s def geocentric_radius(self, latitude, geodetic=True): r""" diff --git a/boule/_sphere.py b/boule/_sphere.py index 0ae9a085..37162af4 100644 --- a/boule/_sphere.py +++ b/boule/_sphere.py @@ -82,7 +82,12 @@ class Sphere: ... angular_velocity=0.5, ... ) >>> print(sphere) # doctest: +ELLIPSIS - Sphere(name='Moon', ...) + Moon - That's no moon + Spheroid: + Radius: 1 m + GM: 2 m³/s² + Angular velocity: 0.5 rad/s + >>> print(sphere.long_name) That's no moon @@ -282,16 +287,22 @@ def reference_normal_gravitational_potential(self): return self.geocentric_grav_const / self.radius def __str__(self): - str = self.name + " - " + self.long_name + "\n" - str += "Spheroid:\n" - str += f" Radius: {self.radius} m\n" - str += f" GM: {self.geocentric_grav_const} m³/s²\n" - str += f" Angular velocity: {self.angular_velocity} rad/s\n" - str += "Source:\n" - str += textwrap.fill( - self.reference, width=72, initial_indent=" ", subsequent_indent=" " - ) - return str + s = self.name + " - " + self.long_name + "\n" + s += "Spheroid:\n" + s += f" Radius: {self.radius} m\n" + s += f" GM: {self.geocentric_grav_const} m³/s²\n" + s += f" Angular velocity: {self.angular_velocity} rad/s" + if self.reference is not None: + s += "\nSource:\n" + s += textwrap.fill( + self.reference, width=72, initial_indent=" ", subsequent_indent=" " + ) + if self.comments is not None: + s += "\nComments:\n" + s += textwrap.fill( + self.comments, width=72, initial_indent=" ", subsequent_indent=" " + ) + return s def normal_gravity(self, latitude, height, si_units=False): r""" diff --git a/boule/_triaxialellipsoid.py b/boule/_triaxialellipsoid.py index 82c01a20..49721164 100644 --- a/boule/_triaxialellipsoid.py +++ b/boule/_triaxialellipsoid.py @@ -85,22 +85,37 @@ class TriaxialEllipsoid: We can define an ellipsoid by setting the 5 key numerical parameters: >>> ellipsoid = TriaxialEllipsoid( - ... name="VESTA", + ... name="Vesta", ... long_name="Vesta Triaxial Ellipsoid", - ... semimajor_axis=286_300, - ... semimedium_axis=278_600, - ... semiminor_axis=223_200, - ... geocentric_grav_const=1.729094e10, - ... angular_velocity=326.71050958367e-6, + ... semimajor_axis=280_413, + ... semimedium_axis=274_572, + ... semiminor_axis=231_253, + ... geocentric_grav_const=17.288e9, + ... angular_velocity=3.267e-4, + ... semimajor_axis_longitude=8.29, ... reference=( - ... "Russell, C. T., Raymond, C. A., Coradini, A., McSween, " - ... "H. Y., Zuber, M. T., Nathues, A., et al. (2012). Dawn at " - ... "Vesta: Testing the Protoplanetary Paradigm. Science. " - ... "doi:10.1126/science.1219381" + ... "Karimi, R., Azmoudeh Ardalan, A., & Vasheghani Farahani, S. " + ... "(2017). The size, shape and orientation of the asteroid " + ... "Vesta based on data from the Dawn mission. Earth and " + ... "Planetary Science Letters, 475, 71–82. " + ... "https://doi.org/10.1016/j.epsl.2017.07.033" ... ), ... ) >>> print(ellipsoid) # doctest: +ELLIPSIS - TriaxialEllipsoid(name='VESTA', ...) + Vesta - Vesta Triaxial Ellipsoid + Triaxial ellipsoid: + Semimajor axis: 280413 m + Semimedium axis: 274572 m + Semiminor axis: 231253 m + Semiminor axis longitude: 8.29 + GM: 17288000000.0 m³/s² + Angular velocity: 0.0003267 rad/s + Source: + Karimi, R., Azmoudeh Ardalan, A., & Vasheghani Farahani, S. (2017). + The size, shape and orientation of the asteroid Vesta based on data + from the Dawn mission. Earth and Planetary Science Letters, 475, + 71–82. https://doi.org/10.1016/j.epsl.2017.07.033 + >>> print(ellipsoid.long_name) Vesta Triaxial Ellipsoid @@ -108,21 +123,21 @@ class TriaxialEllipsoid: parameters: >>> print(f"{ellipsoid.mean_radius:.0f} m") - 259813 m + 260344 m >>> print(f"{ellipsoid.semiaxes_mean_radius:.0f} m") - 262700 m + 262079 m >>> print(f"{ellipsoid.area:.10e} m²") - 8.6562393883e+11 m² + 8.6210266337e+11 m² >>> print(f"{ellipsoid.area_equivalent_radius:0.0f} m") - 262458 m + 261924 m >>> print(f"{ellipsoid.volume_equivalent_radius:.0f} m") - 261115 m + 261124 m >>> print(f"{ellipsoid.mass:.10e} kg") - 2.5906746775e+20 kg + 2.5902341819e+20 kg >>> print(f"{ellipsoid.mean_density:.0f} kg/m³") - 3474 kg/m³ + 3473 kg/m³ >>> print(f"{ellipsoid.volume * 1e-9:.0f} km³") - 74573626 km³ + 74581373 km³ """ @@ -327,18 +342,25 @@ def meridional_flattening(self): return (self.semimajor_axis - self.semiminor_axis) / self.semimajor_axis def __str__(self): - str = self.name + " - " + self.long_name + "\n" - str += "Triaxial ellipsoid:\n" - str += f" Semimajor axis: {self.semimajor_axis} m\n" - str += f" Semimedium axis: {self.semimedium_axis} m\n" - str += f" Semiminor axis: {self.semiminor_axis} m\n" - str += f" GM: {self.geocentric_grav_const} m³/s²\n" - str += f" Angular velocity: {self.angular_velocity} rad/s\n" - str += "Source:\n" - str += textwrap.fill( - self.reference, width=72, initial_indent=" ", subsequent_indent=" " - ) - return str + s = self.name + " - " + self.long_name + "\n" + s += "Triaxial ellipsoid:\n" + s += f" Semimajor axis: {self.semimajor_axis} m\n" + s += f" Semimedium axis: {self.semimedium_axis} m\n" + s += f" Semiminor axis: {self.semiminor_axis} m\n" + s += f" Semiminor axis longitude: {self.semimajor_axis_longitude}\n" + s += f" GM: {self.geocentric_grav_const} m³/s²\n" + s += f" Angular velocity: {self.angular_velocity} rad/s" + if self.reference is not None: + s += "\nSource:\n" + s += textwrap.fill( + self.reference, width=72, initial_indent=" ", subsequent_indent=" " + ) + if self.comments is not None: + s += "\nComments:\n" + s += textwrap.fill( + self.comments, width=72, initial_indent=" ", subsequent_indent=" " + ) + return s def geocentric_radius(self, longitude, latitude): r""" From 850a8ac48aa999ca47e3570535ed721a0e9574fa Mon Sep 17 00:00:00 2001 From: markwieczorek Date: Sat, 5 Oct 2024 22:47:11 +0200 Subject: [PATCH 3/6] Update boule/_triaxialellipsoid.py fix typo and add degree symbol Co-authored-by: Santiago Soler --- boule/_triaxialellipsoid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boule/_triaxialellipsoid.py b/boule/_triaxialellipsoid.py index 49721164..ebd5b237 100644 --- a/boule/_triaxialellipsoid.py +++ b/boule/_triaxialellipsoid.py @@ -347,7 +347,7 @@ def __str__(self): s += f" Semimajor axis: {self.semimajor_axis} m\n" s += f" Semimedium axis: {self.semimedium_axis} m\n" s += f" Semiminor axis: {self.semiminor_axis} m\n" - s += f" Semiminor axis longitude: {self.semimajor_axis_longitude}\n" + s += f" Semimajor axis longitude: {self.semimajor_axis_longitude}°\n" s += f" GM: {self.geocentric_grav_const} m³/s²\n" s += f" Angular velocity: {self.angular_velocity} rad/s" if self.reference is not None: From 2983012d5ab80ea00531e14a323a6f7417c83302 Mon Sep 17 00:00:00 2001 From: Mark Wieczorek Date: Sat, 5 Oct 2024 23:15:38 +0200 Subject: [PATCH 4/6] Reformat __str__ for multiple references --- boule/_ellipsoid.py | 11 +++++----- boule/_realizations.py | 41 ++++++++++++++++++------------------- boule/_sphere.py | 9 ++++---- boule/_triaxialellipsoid.py | 17 +++++++-------- 4 files changed, 40 insertions(+), 38 deletions(-) diff --git a/boule/_ellipsoid.py b/boule/_ellipsoid.py index b9746cc6..621a8c81 100644 --- a/boule/_ellipsoid.py +++ b/boule/_ellipsoid.py @@ -97,7 +97,7 @@ class Ellipsoid: Angular velocity: 7.292115e-05 rad/s Source: Hofmann-Wellenhof, B., & Moritz, H. (2006). Physical Geodesy (2nd, - corr. ed. 2006 edition ed.). Wien ; New York: Springer. + corr. ed. 2006 edition ed.). Wien ; New York: Springer. >>> print(ellipsoid.long_name) World Geodetic System 1984 @@ -412,10 +412,11 @@ def __str__(self): s += f" GM: {self.geocentric_grav_const} m³/s²\n" s += f" Angular velocity: {self.angular_velocity} rad/s" if self.reference is not None: - s += "\nSource:\n" - s += textwrap.fill( - self.reference, width=72, initial_indent=" ", subsequent_indent=" " - ) + s += "\nSource:" + for ref in self.reference.splitlines(): + s += "\n" + textwrap.fill( + ref, width=72, initial_indent=" ", subsequent_indent=" " + ) if self.comments is not None: s += "\nComments:\n" s += textwrap.fill( diff --git a/boule/_realizations.py b/boule/_realizations.py index 61062b97..ef3d947f 100644 --- a/boule/_realizations.py +++ b/boule/_realizations.py @@ -23,7 +23,7 @@ reference=( "Wieczorek, MA (2015). 10.05 - Gravity and Topography of the Terrestrial " "Planets, Treatise of Geophysics (Second Edition); Elsevier. " - "doi:10.1016/B978-0-444-53802-4.00169-X" + "https://doi.org/10.1016/B978-0-444-53802-4.00169-X" ), ) @@ -35,11 +35,11 @@ angular_velocity=1.2400141739494342e-06, reference=( "Radius: Maia, J. (2024). Spherical harmonic models of the shape of " - "Mercury [Data set]. Zenodo. https://doi.org/10.5281/zenodo.10809345; " + "Mercury [Data set]. Zenodo. https://doi.org/10.5281/zenodo.10809345\n" "GM, angular velocity: Mazarico, E., et al. (2014), The gravity field, " "orientation, and ephemeris of Mercury from MESSENGER observations " "after three years in orbit, J. Geophys. Res. Planets, 119, " - "2417-2436, doi:10.1002/2014JE004675." + "2417-2436. https://doi.org/10.1002/2014JE004675" ), ) @@ -52,7 +52,7 @@ reference=( "Wieczorek, MA (2015). 10.05 - Gravity and Topography of the Terrestrial " "Planets, Treatise of Geophysics (Second Edition); Elsevier. " - "doi:10.1016/B978-0-444-53802-4.00169-X" + "https://doi.org/10.1016/B978-0-444-53802-4.00169-X" ), ) @@ -106,7 +106,7 @@ reference=( "Wieczorek, MA (2015). 10.05 - Gravity and Topography of the Terrestrial " "Planets, Treatise of Geophysics (Second Edition); Elsevier. " - "doi:10.1016/B978-0-444-53802-4.00169-X" + "https://doi.org/10.1016/B978-0-444-53802-4.00169-X" ), ) @@ -121,7 +121,7 @@ "Ardalan, A. A., Karimi, R., & Grafarend, E. W. (2009). A New Reference " "Equipotential Surface, and Reference Ellipsoid for the Planet Mars. " "Earth, Moon, and Planets, 106, 1-13. " - "doi:10.1007/s11038-009-9342-7" + "https://doi.org/10.1007/s11038-009-9342-7" ), ) @@ -135,7 +135,7 @@ reference=( "Semimajor axis, flattening: Park, R. S., et al. (2019). High-resolution " "shape model of Ceres from stereophotoclinometry using Dawn Imaging Data. " - "Icarus, 319, 812–827. https://doi.org/10.1016/j.icarus.2018.10.024; " + "Icarus, 319, 812–827. https://doi.org/10.1016/j.icarus.2018.10.024\n" "GM, angular velocity: Konopliv, A. S., et al. (2018). The Ceres gravity " "field, spin pole, rotation period and orbit from the Dawn radiometric " "tracking and optical data. Icarus, 299, 411–429. " @@ -189,10 +189,10 @@ reference=( "Semi-axis: Thomas, P. C., et al. (1998). The Shape of Io from Galileo " "Limb Measurements. Icarus, 135(1), 175–180. " - "https://doi.org/10.1006/icar.1998.5987; " + "https://doi.org/10.1006/icar.1998.5987\n" "GM: Anderson, J. D., et al. (2001). Io's gravity field and interior " "structure. J. Geophys. Res., 106, 32963–32969. " - "https://doi.org/10.1029/2000JE001367; " + "https://doi.org/10.1029/2000JE001367\n" "Angular velocity: R. A. Jacobson (2021), The Orbits of the Regular " "Jovian Satellites and the Orientation of the Pole of Jupiter, personal " "communication to Horizons/NAIF. Accessed via JPL Solar System " @@ -212,11 +212,10 @@ reference=( "Semi-axis: Nimmo, F., et al. (2007). The global shape of Europa: " "Constraints on lateral shell thickness variations. Icarus, 191(1), " - "183–192. https://doi.org/10.1016/j.icarus.2007.04.021" - "https://doi.org/10.1006/icar.1998.5987; " + "183–192. https://doi.org/10.1016/j.icarus.2007.04.021\n" "GM: Anderson, J. D., et al. (1998). Europa's differentiated internal " "structure: Inferences from four Galileo encounters. Science, 281, " - "2019–2022. https://doi.org/10.1126/science.281.5385.2019; " + "2019–2022. https://doi.org/10.1126/science.281.5385.2019\n" "Angular velocity: R. A. Jacobson (2021), The Orbits of the Regular " "Jovian Satellites and the Orientation of the Pole of Jupiter, personal " "communication to Horizons/NAIF. Accessed via JPL Solar System " @@ -236,10 +235,10 @@ reference=( "Semi-axis: Zubarev, A., et al. (2015). New Ganymede control point " "network and global shape model. Planetary and Space Science, 117, " - "246–249. https://doi.org/10.1016/j.pss.2015.06.022; " + "246–249. https://doi.org/10.1016/j.pss.2015.06.022\n" "GM: Gomez Casajus, L., et al. (2022). Gravity Field of Ganymede After " "the Juno Extended Mission. Geophysical Research Letters, 49(24), " - "e2022GL099475, doi:10.1029/2022GL099475.; " + "e2022GL099475. https://doi.org/doi:10.1029/2022GL099475\n" "Angular velocity: R. A. Jacobson (2021), The Orbits of the Regular " "Jovian Satellites and the Orientation of the Pole of Jupiter, personal " "communication to Horizons/NAIF. Accessed via JPL Solar System " @@ -257,7 +256,7 @@ reference=( "Radius, GM: Anderson, J. D., et al. (2001). Shape, mean radius, gravity " "field, and interior structure of Callisto. Icarus, 153(1), 157–161. " - "https://doi.org/10.1006/icar.2001.6664; " + "https://doi.org/10.1006/icar.2001.6664\n" "Angular velocity: Satellites and the Orientation of the Pole of Jupiter, " "personal communication to Horizons/NAIF. Accessed via JPL Solar " "System Dynamics, https://ssd.jpl.nasa.gov, JUP365." @@ -290,10 +289,10 @@ reference=( "Semi-axis: Corlies, P., et al. (2017). Titan’s Topography and Shape at " "the End of the Cassini Mission. Geophysical Research Letters, 44(23), " - "11,754-11,761. https://doi.org/10.1002/2017GL075518; " + "11,754-11,761. https://doi.org/10.1002/2017GL075518\n" "GM: Durante, D., et al. (2019). Titan’s gravity field and interior " "structure after Cassini. Icarus, 326, 123–132. " - "https://doi.org/10.1016/j.icarus.2019.03.003; " + "https://doi.org/10.1016/j.icarus.2019.03.003\n" "Angular velocity: Jacobson, R. (2022). The Orbits of the Main Saturnian " "Satellites, the Saturnian System Gravity Field, and the Orientation " "of Saturn's Pole. The Astronomical Journal, 164, 199. " @@ -313,10 +312,10 @@ reference=( "Radius: Nimmo, et al. (2017). Mean radius and shape of Pluto and Charon " "from New Horizons images. Icarus, 287, 12–29. " - "https://doi.org/10.1016/j.icarus.2016.06.027; " + "https://doi.org/10.1016/j.icarus.2016.06.027\n" "GM, angular velocity: Brozović, M., et al. (2015). The orbits and masses of " "satellites of Pluto. Icarus, 246, 317–329. " - "https://doi.org/10.1016/j.icarus.2014.03.015; " + "https://doi.org/10.1016/j.icarus.2014.03.015" ), ) @@ -329,9 +328,9 @@ reference=( "Radius: Nimmo, et al. (2017). Mean radius and shape of Pluto and Charon " "from New Horizons images. Icarus, 287, 12–29. " - "https://doi.org/10.1016/j.icarus.2016.06.027; " + "https://doi.org/10.1016/j.icarus.2016.06.027\n" "GM, angular velocity: Brozović, M., et al. (2015). The orbits and masses of " "satellites of Pluto. Icarus, 246, 317–329. " - "https://doi.org/10.1016/j.icarus.2014.03.015; " + "https://doi.org/10.1016/j.icarus.2014.03.015" ), ) diff --git a/boule/_sphere.py b/boule/_sphere.py index 37162af4..9540c089 100644 --- a/boule/_sphere.py +++ b/boule/_sphere.py @@ -293,10 +293,11 @@ def __str__(self): s += f" GM: {self.geocentric_grav_const} m³/s²\n" s += f" Angular velocity: {self.angular_velocity} rad/s" if self.reference is not None: - s += "\nSource:\n" - s += textwrap.fill( - self.reference, width=72, initial_indent=" ", subsequent_indent=" " - ) + s += "\nSource:" + for ref in self.reference.splitlines(): + s += "\n" + textwrap.fill( + ref, width=72, initial_indent=" ", subsequent_indent=" " + ) if self.comments is not None: s += "\nComments:\n" s += textwrap.fill( diff --git a/boule/_triaxialellipsoid.py b/boule/_triaxialellipsoid.py index ebd5b237..e32afb0f 100644 --- a/boule/_triaxialellipsoid.py +++ b/boule/_triaxialellipsoid.py @@ -107,14 +107,14 @@ class TriaxialEllipsoid: Semimajor axis: 280413 m Semimedium axis: 274572 m Semiminor axis: 231253 m - Semiminor axis longitude: 8.29 + Semimajor axis longitude: 8.29° GM: 17288000000.0 m³/s² Angular velocity: 0.0003267 rad/s Source: Karimi, R., Azmoudeh Ardalan, A., & Vasheghani Farahani, S. (2017). - The size, shape and orientation of the asteroid Vesta based on data - from the Dawn mission. Earth and Planetary Science Letters, 475, - 71–82. https://doi.org/10.1016/j.epsl.2017.07.033 + The size, shape and orientation of the asteroid Vesta based on data + from the Dawn mission. Earth and Planetary Science Letters, 475, + 71–82. https://doi.org/10.1016/j.epsl.2017.07.033 >>> print(ellipsoid.long_name) Vesta Triaxial Ellipsoid @@ -351,10 +351,11 @@ def __str__(self): s += f" GM: {self.geocentric_grav_const} m³/s²\n" s += f" Angular velocity: {self.angular_velocity} rad/s" if self.reference is not None: - s += "\nSource:\n" - s += textwrap.fill( - self.reference, width=72, initial_indent=" ", subsequent_indent=" " - ) + s += "\nSource:" + for ref in self.reference.splitlines(): + s += "\n" + textwrap.fill( + ref, width=72, initial_indent=" ", subsequent_indent=" " + ) if self.comments is not None: s += "\nComments:\n" s += textwrap.fill( From 67d46ce2ae55f9ff827f3850524f676167546711 Mon Sep 17 00:00:00 2001 From: Mark Wieczorek Date: Mon, 7 Oct 2024 12:58:02 +0200 Subject: [PATCH 5/6] Fix docstring tests for comments and reference --- boule/_ellipsoid.py | 11 ++++---- boule/_sphere.py | 55 ++++++++++++++++++++----------------- boule/_triaxialellipsoid.py | 16 ++++------- 3 files changed, 40 insertions(+), 42 deletions(-) diff --git a/boule/_ellipsoid.py b/boule/_ellipsoid.py index 621a8c81..2186f540 100644 --- a/boule/_ellipsoid.py +++ b/boule/_ellipsoid.py @@ -83,10 +83,8 @@ class Ellipsoid: ... flattening=1 / 298.257223563, ... geocentric_grav_const=3986004.418e8, ... angular_velocity=7292115e-11, - ... reference=( - ... "Hofmann-Wellenhof, B., & Moritz, H. (2006). Physical Geodesy " - ... "(2nd, corr. ed. 2006 edition ed.). Wien ; New York: Springer." - ... ), + ... reference="Hofmann-Wellenhof & Moritz (2006)", + ... comments="This is the same as the boule WGS84 ellipsoid.", ... ) >>> print(ellipsoid) # doctest: +ELLIPSIS WGS84 - World Geodetic System 1984 @@ -96,8 +94,9 @@ class Ellipsoid: GM: 398600441800000.0 m³/s² Angular velocity: 7.292115e-05 rad/s Source: - Hofmann-Wellenhof, B., & Moritz, H. (2006). Physical Geodesy (2nd, - corr. ed. 2006 edition ed.). Wien ; New York: Springer. + Hofmann-Wellenhof & Moritz (2006) + Comments: + This is the same as the boule WGS84 ellipsoid. >>> print(ellipsoid.long_name) World Geodetic System 1984 diff --git a/boule/_sphere.py b/boule/_sphere.py index 9540c089..ba9774ad 100644 --- a/boule/_sphere.py +++ b/boule/_sphere.py @@ -76,29 +76,34 @@ class Sphere: >>> sphere = Sphere( ... name="Moon", - ... long_name="That's no moon", - ... radius=1, - ... geocentric_grav_const=2, - ... angular_velocity=0.5, + ... long_name="Moon Spheroid", + ... radius=1737151, + ... geocentric_grav_const=4902800070000.0, + ... angular_velocity=2.6617073e-06, + ... reference="Wieczorek (2015)", + ... comments="This is the same as the boule Moon2015 spheroid." ... ) >>> print(sphere) # doctest: +ELLIPSIS - Moon - That's no moon + Moon - Moon Spheroid Spheroid: - Radius: 1 m - GM: 2 m³/s² - Angular velocity: 0.5 rad/s + Radius: 1737151 m + GM: 4902800070000.0 m³/s² + Angular velocity: 2.6617073e-06 rad/s + Source: + Wieczorek (2015) + Comments: + This is the same as the boule Moon2015 spheroid. >>> print(sphere.long_name) - That's no moon + Moon Spheroid - The sphere defines semi-axis, flattening, and some eccentricities similar - to :class:`~bould.Ellipsoid` for compatibility with the coordinate - conversion functions of pymap3d: + The sphere defines semi-axess, flattening, and some eccentricities similar + to :class:`~bould.Ellipsoid` for compatibility: >>> print(sphere.semiminor_axis) - 1 + 1737151 >>> print(sphere.semimajor_axis) - 1 + 1737151 >>> print(sphere.first_eccentricity) 0 >>> print(sphere.eccentricity) @@ -108,23 +113,23 @@ class Sphere: >>> print(sphere.thirdflattening) 0 >>> print(sphere.mean_radius) - 1 + 1737151 >>> print(sphere.semiaxes_mean_radius) - 1 + 1737151 >>> print(f"{sphere.volume_equivalent_radius:.1f} m") - 1.0 m - >>> print(f"{sphere.volume:.10f} m³") - 4.1887902048 m³ - >>> print(f"{sphere.area:.10f} m²") - 12.5663706144 m² + 1737151.0 m + >>> print(f"{sphere.volume:.12e} m³") + 2.195843181718e+19 m³ + >>> print(f"{sphere.area:.12e} m²") + 3.792145613798e+13 m² >>> print(sphere.area_equivalent_radius) - 1 + 1737151 >>> print(f"{sphere.mass:.12e} kg") - 2.996568928577e+10 kg + 7.345789176393e+22 kg >>> print(f"{sphere.mean_density:.0f} kg/m³") - 7153781359 kg/m³ + 3345 kg/m³ >>> print(f"{sphere.reference_normal_gravitational_potential:.3f} m²/s²") - 2.000 m²/s² + 2822322.337 m²/s² """ diff --git a/boule/_triaxialellipsoid.py b/boule/_triaxialellipsoid.py index e32afb0f..928d5381 100644 --- a/boule/_triaxialellipsoid.py +++ b/boule/_triaxialellipsoid.py @@ -93,13 +93,8 @@ class TriaxialEllipsoid: ... geocentric_grav_const=17.288e9, ... angular_velocity=3.267e-4, ... semimajor_axis_longitude=8.29, - ... reference=( - ... "Karimi, R., Azmoudeh Ardalan, A., & Vasheghani Farahani, S. " - ... "(2017). The size, shape and orientation of the asteroid " - ... "Vesta based on data from the Dawn mission. Earth and " - ... "Planetary Science Letters, 475, 71–82. " - ... "https://doi.org/10.1016/j.epsl.2017.07.033" - ... ), + ... reference="Karimi et al. (2017)", + ... comments="This is the same as the VestaTriaxial2017 ellipsoid." ... ) >>> print(ellipsoid) # doctest: +ELLIPSIS Vesta - Vesta Triaxial Ellipsoid @@ -111,10 +106,9 @@ class TriaxialEllipsoid: GM: 17288000000.0 m³/s² Angular velocity: 0.0003267 rad/s Source: - Karimi, R., Azmoudeh Ardalan, A., & Vasheghani Farahani, S. (2017). - The size, shape and orientation of the asteroid Vesta based on data - from the Dawn mission. Earth and Planetary Science Letters, 475, - 71–82. https://doi.org/10.1016/j.epsl.2017.07.033 + Karimi et al. (2017) + Comments: + This is the same as the VestaTriaxial2017 ellipsoid. >>> print(ellipsoid.long_name) Vesta Triaxial Ellipsoid From 1a474af74f7373fd0340d5bc6af714b739453978 Mon Sep 17 00:00:00 2001 From: Mark Wieczorek Date: Wed, 9 Oct 2024 11:55:55 +0200 Subject: [PATCH 6/6] Add bullets to parameters defined in __str__ --- boule/_ellipsoid.py | 23 ++++++++++++---------- boule/_realizations.py | 39 ++++++++++++++++++++++++------------- boule/_sphere.py | 19 ++++++++++-------- boule/_triaxialellipsoid.py | 31 ++++++++++++++++------------- 4 files changed, 67 insertions(+), 45 deletions(-) diff --git a/boule/_ellipsoid.py b/boule/_ellipsoid.py index 2186f540..7d38721b 100644 --- a/boule/_ellipsoid.py +++ b/boule/_ellipsoid.py @@ -89,10 +89,10 @@ class Ellipsoid: >>> print(ellipsoid) # doctest: +ELLIPSIS WGS84 - World Geodetic System 1984 Oblate ellipsoid: - Semimajor axis: 6378137 m - Flattening: 0.0033528106647474805 - GM: 398600441800000.0 m³/s² - Angular velocity: 7.292115e-05 rad/s + • Semimajor axis: 6378137 m + • Flattening: 0.0033528106647474805 + • GM: 398600441800000.0 m³/s² + • Angular velocity: 7.292115e-05 rad/s Source: Hofmann-Wellenhof & Moritz (2006) Comments: @@ -406,20 +406,23 @@ def gravity_pole(self): def __str__(self): s = self.name + " - " + self.long_name + "\n" s += "Oblate ellipsoid:\n" - s += f" Semimajor axis: {self.semimajor_axis} m\n" - s += f" Flattening: {self.flattening}\n" - s += f" GM: {self.geocentric_grav_const} m³/s²\n" - s += f" Angular velocity: {self.angular_velocity} rad/s" + s += f" • Semimajor axis: {self.semimajor_axis} m\n" + s += f" • Flattening: {self.flattening}\n" + s += f" • GM: {self.geocentric_grav_const} m³/s²\n" + s += f" • Angular velocity: {self.angular_velocity} rad/s" if self.reference is not None: s += "\nSource:" for ref in self.reference.splitlines(): s += "\n" + textwrap.fill( - ref, width=72, initial_indent=" ", subsequent_indent=" " + ref, width=72, initial_indent=2 * " ", subsequent_indent=4 * " " ) if self.comments is not None: s += "\nComments:\n" s += textwrap.fill( - self.comments, width=72, initial_indent=" ", subsequent_indent=" " + self.comments, + width=72, + initial_indent=2 * " ", + subsequent_indent=2 * " ", ) return s diff --git a/boule/_realizations.py b/boule/_realizations.py index ef3d947f..614b4281 100644 --- a/boule/_realizations.py +++ b/boule/_realizations.py @@ -35,7 +35,8 @@ angular_velocity=1.2400141739494342e-06, reference=( "Radius: Maia, J. (2024). Spherical harmonic models of the shape of " - "Mercury [Data set]. Zenodo. https://doi.org/10.5281/zenodo.10809345\n" + "Mercury [Data set]. Zenodo. https://doi.org/10.5281/zenodo.10809345" + "\n" "GM, angular velocity: Mazarico, E., et al. (2014), The gravity field, " "orientation, and ephemeris of Mercury from MESSENGER observations " "after three years in orbit, J. Geophys. Res. Planets, 119, " @@ -135,7 +136,8 @@ reference=( "Semimajor axis, flattening: Park, R. S., et al. (2019). High-resolution " "shape model of Ceres from stereophotoclinometry using Dawn Imaging Data. " - "Icarus, 319, 812–827. https://doi.org/10.1016/j.icarus.2018.10.024\n" + "Icarus, 319, 812–827. https://doi.org/10.1016/j.icarus.2018.10.024" + "\n" "GM, angular velocity: Konopliv, A. S., et al. (2018). The Ceres gravity " "field, spin pole, rotation period and orbit from the Dawn radiometric " "tracking and optical data. Icarus, 299, 411–429. " @@ -189,10 +191,12 @@ reference=( "Semi-axis: Thomas, P. C., et al. (1998). The Shape of Io from Galileo " "Limb Measurements. Icarus, 135(1), 175–180. " - "https://doi.org/10.1006/icar.1998.5987\n" + "https://doi.org/10.1006/icar.1998.5987" + "\n" "GM: Anderson, J. D., et al. (2001). Io's gravity field and interior " "structure. J. Geophys. Res., 106, 32963–32969. " - "https://doi.org/10.1029/2000JE001367\n" + "https://doi.org/10.1029/2000JE001367" + "\n" "Angular velocity: R. A. Jacobson (2021), The Orbits of the Regular " "Jovian Satellites and the Orientation of the Pole of Jupiter, personal " "communication to Horizons/NAIF. Accessed via JPL Solar System " @@ -212,10 +216,12 @@ reference=( "Semi-axis: Nimmo, F., et al. (2007). The global shape of Europa: " "Constraints on lateral shell thickness variations. Icarus, 191(1), " - "183–192. https://doi.org/10.1016/j.icarus.2007.04.021\n" + "183–192. https://doi.org/10.1016/j.icarus.2007.04.021" + "\n" "GM: Anderson, J. D., et al. (1998). Europa's differentiated internal " "structure: Inferences from four Galileo encounters. Science, 281, " - "2019–2022. https://doi.org/10.1126/science.281.5385.2019\n" + "2019–2022. https://doi.org/10.1126/science.281.5385.2019" + "\n" "Angular velocity: R. A. Jacobson (2021), The Orbits of the Regular " "Jovian Satellites and the Orientation of the Pole of Jupiter, personal " "communication to Horizons/NAIF. Accessed via JPL Solar System " @@ -235,10 +241,12 @@ reference=( "Semi-axis: Zubarev, A., et al. (2015). New Ganymede control point " "network and global shape model. Planetary and Space Science, 117, " - "246–249. https://doi.org/10.1016/j.pss.2015.06.022\n" + "246–249. https://doi.org/10.1016/j.pss.2015.06.022" + "\n" "GM: Gomez Casajus, L., et al. (2022). Gravity Field of Ganymede After " "the Juno Extended Mission. Geophysical Research Letters, 49(24), " - "e2022GL099475. https://doi.org/doi:10.1029/2022GL099475\n" + "e2022GL099475. https://doi.org/doi:10.1029/2022GL099475" + "\n" "Angular velocity: R. A. Jacobson (2021), The Orbits of the Regular " "Jovian Satellites and the Orientation of the Pole of Jupiter, personal " "communication to Horizons/NAIF. Accessed via JPL Solar System " @@ -256,7 +264,8 @@ reference=( "Radius, GM: Anderson, J. D., et al. (2001). Shape, mean radius, gravity " "field, and interior structure of Callisto. Icarus, 153(1), 157–161. " - "https://doi.org/10.1006/icar.2001.6664\n" + "https://doi.org/10.1006/icar.2001.6664" + "\n" "Angular velocity: Satellites and the Orientation of the Pole of Jupiter, " "personal communication to Horizons/NAIF. Accessed via JPL Solar " "System Dynamics, https://ssd.jpl.nasa.gov, JUP365." @@ -289,10 +298,12 @@ reference=( "Semi-axis: Corlies, P., et al. (2017). Titan’s Topography and Shape at " "the End of the Cassini Mission. Geophysical Research Letters, 44(23), " - "11,754-11,761. https://doi.org/10.1002/2017GL075518\n" + "11,754-11,761. https://doi.org/10.1002/2017GL075518" + "\n" "GM: Durante, D., et al. (2019). Titan’s gravity field and interior " "structure after Cassini. Icarus, 326, 123–132. " - "https://doi.org/10.1016/j.icarus.2019.03.003\n" + "https://doi.org/10.1016/j.icarus.2019.03.003" + "\n" "Angular velocity: Jacobson, R. (2022). The Orbits of the Main Saturnian " "Satellites, the Saturnian System Gravity Field, and the Orientation " "of Saturn's Pole. The Astronomical Journal, 164, 199. " @@ -312,7 +323,8 @@ reference=( "Radius: Nimmo, et al. (2017). Mean radius and shape of Pluto and Charon " "from New Horizons images. Icarus, 287, 12–29. " - "https://doi.org/10.1016/j.icarus.2016.06.027\n" + "https://doi.org/10.1016/j.icarus.2016.06.027" + "\n" "GM, angular velocity: Brozović, M., et al. (2015). The orbits and masses of " "satellites of Pluto. Icarus, 246, 317–329. " "https://doi.org/10.1016/j.icarus.2014.03.015" @@ -328,7 +340,8 @@ reference=( "Radius: Nimmo, et al. (2017). Mean radius and shape of Pluto and Charon " "from New Horizons images. Icarus, 287, 12–29. " - "https://doi.org/10.1016/j.icarus.2016.06.027\n" + "https://doi.org/10.1016/j.icarus.2016.06.027" + "\n" "GM, angular velocity: Brozović, M., et al. (2015). The orbits and masses of " "satellites of Pluto. Icarus, 246, 317–329. " "https://doi.org/10.1016/j.icarus.2014.03.015" diff --git a/boule/_sphere.py b/boule/_sphere.py index ba9774ad..eaf1a979 100644 --- a/boule/_sphere.py +++ b/boule/_sphere.py @@ -86,9 +86,9 @@ class Sphere: >>> print(sphere) # doctest: +ELLIPSIS Moon - Moon Spheroid Spheroid: - Radius: 1737151 m - GM: 4902800070000.0 m³/s² - Angular velocity: 2.6617073e-06 rad/s + • Radius: 1737151 m + • GM: 4902800070000.0 m³/s² + • Angular velocity: 2.6617073e-06 rad/s Source: Wieczorek (2015) Comments: @@ -294,19 +294,22 @@ def reference_normal_gravitational_potential(self): def __str__(self): s = self.name + " - " + self.long_name + "\n" s += "Spheroid:\n" - s += f" Radius: {self.radius} m\n" - s += f" GM: {self.geocentric_grav_const} m³/s²\n" - s += f" Angular velocity: {self.angular_velocity} rad/s" + s += f" • Radius: {self.radius} m\n" + s += f" • GM: {self.geocentric_grav_const} m³/s²\n" + s += f" • Angular velocity: {self.angular_velocity} rad/s" if self.reference is not None: s += "\nSource:" for ref in self.reference.splitlines(): s += "\n" + textwrap.fill( - ref, width=72, initial_indent=" ", subsequent_indent=" " + ref, width=72, initial_indent=2 * " ", subsequent_indent=4 * " " ) if self.comments is not None: s += "\nComments:\n" s += textwrap.fill( - self.comments, width=72, initial_indent=" ", subsequent_indent=" " + self.comments, + width=72, + initial_indent=2 * " ", + subsequent_indent=2 * " ", ) return s diff --git a/boule/_triaxialellipsoid.py b/boule/_triaxialellipsoid.py index 928d5381..35c1a377 100644 --- a/boule/_triaxialellipsoid.py +++ b/boule/_triaxialellipsoid.py @@ -99,12 +99,12 @@ class TriaxialEllipsoid: >>> print(ellipsoid) # doctest: +ELLIPSIS Vesta - Vesta Triaxial Ellipsoid Triaxial ellipsoid: - Semimajor axis: 280413 m - Semimedium axis: 274572 m - Semiminor axis: 231253 m - Semimajor axis longitude: 8.29° - GM: 17288000000.0 m³/s² - Angular velocity: 0.0003267 rad/s + • Semimajor axis: 280413 m + • Semimedium axis: 274572 m + • Semiminor axis: 231253 m + • Semimajor axis longitude: 8.29° + • GM: 17288000000.0 m³/s² + • Angular velocity: 0.0003267 rad/s Source: Karimi et al. (2017) Comments: @@ -338,22 +338,25 @@ def meridional_flattening(self): def __str__(self): s = self.name + " - " + self.long_name + "\n" s += "Triaxial ellipsoid:\n" - s += f" Semimajor axis: {self.semimajor_axis} m\n" - s += f" Semimedium axis: {self.semimedium_axis} m\n" - s += f" Semiminor axis: {self.semiminor_axis} m\n" - s += f" Semimajor axis longitude: {self.semimajor_axis_longitude}°\n" - s += f" GM: {self.geocentric_grav_const} m³/s²\n" - s += f" Angular velocity: {self.angular_velocity} rad/s" + s += f" • Semimajor axis: {self.semimajor_axis} m\n" + s += f" • Semimedium axis: {self.semimedium_axis} m\n" + s += f" • Semiminor axis: {self.semiminor_axis} m\n" + s += f" • Semimajor axis longitude: {self.semimajor_axis_longitude}°\n" + s += f" • GM: {self.geocentric_grav_const} m³/s²\n" + s += f" • Angular velocity: {self.angular_velocity} rad/s" if self.reference is not None: s += "\nSource:" for ref in self.reference.splitlines(): s += "\n" + textwrap.fill( - ref, width=72, initial_indent=" ", subsequent_indent=" " + ref, width=72, initial_indent=2 * " ", subsequent_indent=4 * " " ) if self.comments is not None: s += "\nComments:\n" s += textwrap.fill( - self.comments, width=72, initial_indent=" ", subsequent_indent=" " + self.comments, + width=72, + initial_indent=2 * " ", + subsequent_indent=2 * " ", ) return s