From bbd16d299a5e4981e584d8e2ae7a0cd535090644 Mon Sep 17 00:00:00 2001 From: Don Cross Date: Thu, 1 Apr 2021 10:43:37 -0400 Subject: [PATCH] Minor cleanup in Python documentation. --- demo/python/astronomy.py | 12 ++++++------ generate/template/astronomy.py | 12 ++++++------ pydown/pydown.py | 10 ++++++++-- source/python/README.md | 19 ++++++++++++++++--- source/python/astronomy.py | 12 ++++++------ 5 files changed, 42 insertions(+), 23 deletions(-) diff --git a/demo/python/astronomy.py b/demo/python/astronomy.py index f7a93f47..72e99227 100644 --- a/demo/python/astronomy.py +++ b/demo/python/astronomy.py @@ -37,6 +37,7 @@ import enum import re KM_PER_AU = 1.4959787069098932e+8 # The number of kilometers per astronomical unit. +C_AUDAY = 173.1446326846693 # The speed of light expressed in astronomical units per day. _CalcMoonCount = 0 @@ -46,7 +47,6 @@ _EPOCH = datetime.datetime(2000, 1, 1, 12) _ASEC360 = 1296000.0 _ASEC2RAD = 4.848136811095359935899141e-6 _ARC = 3600.0 * 180.0 / math.pi # arcseconds per radian -_C_AUDAY = 173.1446326846693 # speed of light in AU/day _METERS_PER_AU = KM_PER_AU * 1000.0 _ANGVEL = 7.2921150e-5 _SECONDS_PER_DAY = 24.0 * 3600.0 @@ -3724,7 +3724,7 @@ def GeoVector(body, time, aberration): earth = _CalcEarth(ltime) geo = Vector(h.x-earth.x, h.y-earth.y, h.z-earth.z, time) - ltime2 = time.AddDays(-geo.Length() / _C_AUDAY) + ltime2 = time.AddDays(-geo.Length() / C_AUDAY) dt = abs(ltime2.tt - ltime.tt) if dt < 1.0e-9: return geo @@ -4196,7 +4196,7 @@ def SunPosition(time): """ # Correct for light travel time from the Sun. # Otherwise season calculations (equinox, solstice) will all be early by about 8 minutes! - adjusted_time = time.AddDays(-1.0 / _C_AUDAY) + adjusted_time = time.AddDays(-1.0 / C_AUDAY) earth2000 = _CalcEarth(adjusted_time) sun2000 = [-earth2000.x, -earth2000.y, -earth2000.z] @@ -6387,11 +6387,11 @@ def Rotation_HOR_ECL(time, observer): class ConstellationInfo: """Reports the constellation that a given celestial point lies within. - The #Constellation function returns this struct + The #Constellation function returns a `ConstellationInfo` object to report which constellation corresponds with a given point in the sky. Constellations are defined with respect to the B1875 equatorial system - per IAU standard. Although `Constellation` requires J2000 equatorial - coordinates, the struct contains converted B1875 coordinates for reference. + per IAU standard. Although the `Constellation` function requires J2000 equatorial + coordinates as input, the returned object contains converted B1875 coordinates for reference. Attributes ---------- diff --git a/generate/template/astronomy.py b/generate/template/astronomy.py index f7a983f8..8d23959a 100644 --- a/generate/template/astronomy.py +++ b/generate/template/astronomy.py @@ -37,6 +37,7 @@ import enum import re KM_PER_AU = 1.4959787069098932e+8 # The number of kilometers per astronomical unit. +C_AUDAY = 173.1446326846693 # The speed of light expressed in astronomical units per day. _CalcMoonCount = 0 @@ -46,7 +47,6 @@ _EPOCH = datetime.datetime(2000, 1, 1, 12) _ASEC360 = 1296000.0 _ASEC2RAD = 4.848136811095359935899141e-6 _ARC = 3600.0 * 180.0 / math.pi # arcseconds per radian -_C_AUDAY = 173.1446326846693 # speed of light in AU/day _METERS_PER_AU = KM_PER_AU * 1000.0 _ANGVEL = 7.2921150e-5 _SECONDS_PER_DAY = 24.0 * 3600.0 @@ -1827,7 +1827,7 @@ def GeoVector(body, time, aberration): earth = _CalcEarth(ltime) geo = Vector(h.x-earth.x, h.y-earth.y, h.z-earth.z, time) - ltime2 = time.AddDays(-geo.Length() / _C_AUDAY) + ltime2 = time.AddDays(-geo.Length() / C_AUDAY) dt = abs(ltime2.tt - ltime.tt) if dt < 1.0e-9: return geo @@ -2299,7 +2299,7 @@ def SunPosition(time): """ # Correct for light travel time from the Sun. # Otherwise season calculations (equinox, solstice) will all be early by about 8 minutes! - adjusted_time = time.AddDays(-1.0 / _C_AUDAY) + adjusted_time = time.AddDays(-1.0 / C_AUDAY) earth2000 = _CalcEarth(adjusted_time) sun2000 = [-earth2000.x, -earth2000.y, -earth2000.z] @@ -4490,11 +4490,11 @@ def Rotation_HOR_ECL(time, observer): class ConstellationInfo: """Reports the constellation that a given celestial point lies within. - The #Constellation function returns this struct + The #Constellation function returns a `ConstellationInfo` object to report which constellation corresponds with a given point in the sky. Constellations are defined with respect to the B1875 equatorial system - per IAU standard. Although `Constellation` requires J2000 equatorial - coordinates, the struct contains converted B1875 coordinates for reference. + per IAU standard. Although the `Constellation` function requires J2000 equatorial + coordinates as input, the returned object contains converted B1875 coordinates for reference. Attributes ---------- diff --git a/pydown/pydown.py b/pydown/pydown.py index 2de9a3df..9463d5d2 100755 --- a/pydown/pydown.py +++ b/pydown/pydown.py @@ -290,6 +290,12 @@ def Markdown(module, const_md): md += '\n' md += '\n' md += '## Constants\n' + md += 'The following numeric constants are exported by the `astronomy` module.\n' + md += 'They may be of use for unit conversion.\n' + md += 'Note: For the other supported programming languages, Astronomy Engine defines\n' + md += 'helper constants `DEG2RAD` and `RAD2DEG` to convert between angular degrees and radians.\n' + md += 'However, because Python defines the [angular conversion functions](https://docs.python.org/3/library/math.html#angular-conversion)\n' + md += '`math.degrees()` and `math.radians()`, they are not needed in the Python version.\n' md += '\n' md += const_md @@ -332,7 +338,7 @@ def Markdown(module, const_md): return md -def ParseConstants(inPythonFileName): +def ConstantsMd(inPythonFileName): md = '' with open(inPythonFileName) as infile: for line in infile: @@ -367,7 +373,7 @@ def main(): prefix = infile.read() module = LoadModule(inPythonFileName) - const_md = ParseConstants(inPythonFileName) + const_md = ConstantsMd(inPythonFileName) md = Markdown(module, const_md) with open(outMarkdownFileName, 'wt') as outfile: diff --git a/source/python/README.md b/source/python/README.md index 48bf1c70..a55607ea 100644 --- a/source/python/README.md +++ b/source/python/README.md @@ -149,6 +149,12 @@ these are used in function and type names. ## Constants +The following numeric constants are exported by the `astronomy` module. +They may be of use for unit conversion. +Note: For the other supported programming languages, Astronomy Engine defines +helper constants `DEG2RAD` and `RAD2DEG` to convert between angular degrees and radians. +However, because Python defines the [angular conversion functions](https://docs.python.org/3/library/math.html#angular-conversion) +`math.degrees()` and `math.radians()`, they are not needed in the Python version. --- @@ -159,6 +165,13 @@ these are used in function and type names. --- + +### `C_AUDAY = 173.1446326846693` + +**The speed of light expressed in astronomical units per day.** + +--- + ## Classes @@ -193,11 +206,11 @@ to iterate through consecutive alternating perigees and apogees. **Reports the constellation that a given celestial point lies within.** -The [`Constellation`](#Constellation) function returns this struct +The [`Constellation`](#Constellation) function returns a `ConstellationInfo` object to report which constellation corresponds with a given point in the sky. Constellations are defined with respect to the B1875 equatorial system -per IAU standard. Although `Constellation` requires J2000 equatorial -coordinates, the struct contains converted B1875 coordinates for reference. +per IAU standard. Although the `Constellation` function requires J2000 equatorial +coordinates as input, the returned object contains converted B1875 coordinates for reference. | Type | Attribute | Description | | --- | --- | --- | diff --git a/source/python/astronomy.py b/source/python/astronomy.py index f7a93f47..72e99227 100644 --- a/source/python/astronomy.py +++ b/source/python/astronomy.py @@ -37,6 +37,7 @@ import enum import re KM_PER_AU = 1.4959787069098932e+8 # The number of kilometers per astronomical unit. +C_AUDAY = 173.1446326846693 # The speed of light expressed in astronomical units per day. _CalcMoonCount = 0 @@ -46,7 +47,6 @@ _EPOCH = datetime.datetime(2000, 1, 1, 12) _ASEC360 = 1296000.0 _ASEC2RAD = 4.848136811095359935899141e-6 _ARC = 3600.0 * 180.0 / math.pi # arcseconds per radian -_C_AUDAY = 173.1446326846693 # speed of light in AU/day _METERS_PER_AU = KM_PER_AU * 1000.0 _ANGVEL = 7.2921150e-5 _SECONDS_PER_DAY = 24.0 * 3600.0 @@ -3724,7 +3724,7 @@ def GeoVector(body, time, aberration): earth = _CalcEarth(ltime) geo = Vector(h.x-earth.x, h.y-earth.y, h.z-earth.z, time) - ltime2 = time.AddDays(-geo.Length() / _C_AUDAY) + ltime2 = time.AddDays(-geo.Length() / C_AUDAY) dt = abs(ltime2.tt - ltime.tt) if dt < 1.0e-9: return geo @@ -4196,7 +4196,7 @@ def SunPosition(time): """ # Correct for light travel time from the Sun. # Otherwise season calculations (equinox, solstice) will all be early by about 8 minutes! - adjusted_time = time.AddDays(-1.0 / _C_AUDAY) + adjusted_time = time.AddDays(-1.0 / C_AUDAY) earth2000 = _CalcEarth(adjusted_time) sun2000 = [-earth2000.x, -earth2000.y, -earth2000.z] @@ -6387,11 +6387,11 @@ def Rotation_HOR_ECL(time, observer): class ConstellationInfo: """Reports the constellation that a given celestial point lies within. - The #Constellation function returns this struct + The #Constellation function returns a `ConstellationInfo` object to report which constellation corresponds with a given point in the sky. Constellations are defined with respect to the B1875 equatorial system - per IAU standard. Although `Constellation` requires J2000 equatorial - coordinates, the struct contains converted B1875 coordinates for reference. + per IAU standard. Although the `Constellation` function requires J2000 equatorial + coordinates as input, the returned object contains converted B1875 coordinates for reference. Attributes ----------