diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 1cc7db9e..897f7e81 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -31,6 +31,9 @@ jobs: with: languages: ${{ matrix.language }} queries: +security-and-quality + paths-ignore: 'generate/template/astronomy.*' + paths-ignore: 'generate/eclipse/*.html' + paths-ignore: '**/astronomy.browser.js' - name: Autobuild uses: github/codeql-action/autobuild@v2 diff --git a/demo/python/astro_demo_common.py b/demo/python/astro_demo_common.py index b9722701..5893eedd 100644 --- a/demo/python/astro_demo_common.py +++ b/demo/python/astro_demo_common.py @@ -5,7 +5,6 @@ # Utility functions shared by Python demo programs. # import sys -import re import astronomy def ParseArgs(args): diff --git a/demo/python/astronomy.py b/demo/python/astronomy.py index f3778846..111cb5c7 100644 --- a/demo/python/astronomy.py +++ b/demo/python/astronomy.py @@ -60,8 +60,6 @@ EUROPA_RADIUS_KM = 1560.8 # The mean radius of Jupiter's moon Europ GANYMEDE_RADIUS_KM = 2631.2 # The mean radius of Jupiter's moon Ganymede, expressed in kilometers. CALLISTO_RADIUS_KM = 2410.3 # The mean radius of Jupiter's moon Callisto, expressed in kilometers. -_CalcMoonCount = 0 - _RAD2HOUR = 3.819718634205488 # 12/pi = factor to convert radians to sidereal hours _HOUR2RAD = 0.2617993877991494365 # pi/12 = factor to convert sidereal hours to radians _DAYS_PER_TROPICAL_YEAR = 365.24217 @@ -1872,9 +1870,6 @@ class _moonpos: self.distance_au = dist def _CalcMoon(time): - global _CalcMoonCount - _CalcMoonCount += 1 - T = time.tt / 36525 ex = _Array2(-6, 6, 1, 4) @@ -3489,10 +3484,6 @@ def _VsopDeriv(formula, t): return deriv _DAYS_PER_MILLENNIUM = 365250.0 -_LON_INDEX = 0 -_LAT_INDEX = 1 -_RAD_INDEX = 2 - def _VsopRotate(eclip): # Convert ecliptic cartesian coordinates to equatorial cartesian coordinates. @@ -5860,6 +5851,8 @@ def SearchMaxElongation(body, startTime): startTime = t2.AddDays(1.0) iter_count += 1 + raise InternalError() # should never take more than 2 iterations + def _sun_offset(targetLon, time): ecl = SunPosition(time) diff --git a/demo/python/constellation.py b/demo/python/constellation.py index 43914c71..6a680227 100755 --- a/demo/python/constellation.py +++ b/demo/python/constellation.py @@ -57,6 +57,7 @@ def FindConstellationChanges(body, startTime, stopTime, dayIncrement): # No constellation change in this time step. Try again on the next time step. c1 = c2 t1 = t2 + return 0 #------------------------------------------------------------------------------ diff --git a/demo/python/galactic.py b/demo/python/galactic.py index 3b84b451..8c329ff7 100755 --- a/demo/python/galactic.py +++ b/demo/python/galactic.py @@ -9,7 +9,6 @@ # import sys -import math from astronomy import * UsageText = r''' diff --git a/demo/python/positions.py b/demo/python/positions.py index e5204dcc..1a03a6ff 100755 --- a/demo/python/positions.py +++ b/demo/python/positions.py @@ -12,7 +12,7 @@ # program uses the computer's current date and time. # import sys -from astronomy import Body, Time, Refraction, Equator, Horizon +from astronomy import Body, Refraction, Equator, Horizon from astro_demo_common import ParseArgs if __name__ == '__main__': diff --git a/demo/python/stars_near_moon.py b/demo/python/stars_near_moon.py index 42cae43a..3d0a760b 100755 --- a/demo/python/stars_near_moon.py +++ b/demo/python/stars_near_moon.py @@ -11,7 +11,7 @@ # import sys import csv -from astronomy import Body, GeoMoon, ObserverVector, Spherical, VectorFromSphere, AngleBetween +from astronomy import GeoMoon, ObserverVector, Spherical, VectorFromSphere, AngleBetween from astro_demo_common import ParseArgs if __name__ == '__main__': diff --git a/generate/magnitude/findmax.py b/generate/magnitude/findmax.py index 51f23964..efb0e080 100755 --- a/generate/magnitude/findmax.py +++ b/generate/magnitude/findmax.py @@ -61,5 +61,7 @@ def FindMaxMagEvents(filename): prev_item = None first_brightest_item = None #print('min_rlon={:0.2f}, max_rlon={:0.2f}'.format(min_rlon, max_rlon)) - -FindMaxMagEvents('Venus2.txt') + +if __name__ == '__main__': + FindMaxMagEvents('Venus2.txt') + sys.exit(0) diff --git a/generate/make_constellation_data.py b/generate/make_constellation_data.py index 8d6aaf5a..1d65ba72 100755 --- a/generate/make_constellation_data.py +++ b/generate/make_constellation_data.py @@ -10,17 +10,14 @@ import re def Translate(inFileName, outFileName): - if False: - ignore = set() - else: - # Ignore disagreements with hygdata_v3. - # See: https://github.com/astronexus/HYG-Database/issues/21 - ignore = set([ - 3865, 7751, 10342, 19173, 22400, 27992, 29366, - 30112, 52886, 58221, 59234, 67599, 72017, 74021, 78313, - 84413, 85957, 87694, 89105, 91382, 92907, 93308, - 95468, 100777, 101541, 105623 - ]) + # Ignore disagreements with hygdata_v3. + # See: https://github.com/astronexus/HYG-Database/issues/21 + ignore = set([ + 3865, 7751, 10342, 19173, 22400, 27992, 29366, + 30112, 52886, 58221, 59234, 67599, 72017, 74021, 78313, + 84413, 85957, 87694, 89105, 91382, 92907, 93308, + 95468, 100777, 101541, 105623 + ]) count = 0 with open(inFileName, 'rt') as infile: diff --git a/generate/plotdist.py b/generate/plotdist.py index ae4491bc..4e80746b 100755 --- a/generate/plotdist.py +++ b/generate/plotdist.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 import sys -import re import matplotlib.pyplot as plt diff --git a/generate/template/astronomy.py b/generate/template/astronomy.py index 2239f8fb..d26ed537 100644 --- a/generate/template/astronomy.py +++ b/generate/template/astronomy.py @@ -60,8 +60,6 @@ EUROPA_RADIUS_KM = 1560.8 # The mean radius of Jupiter's moon Europ GANYMEDE_RADIUS_KM = 2631.2 # The mean radius of Jupiter's moon Ganymede, expressed in kilometers. CALLISTO_RADIUS_KM = 2410.3 # The mean radius of Jupiter's moon Callisto, expressed in kilometers. -_CalcMoonCount = 0 - _RAD2HOUR = 3.819718634205488 # 12/pi = factor to convert radians to sidereal hours _HOUR2RAD = 0.2617993877991494365 # pi/12 = factor to convert sidereal hours to radians _DAYS_PER_TROPICAL_YEAR = 365.24217 @@ -1336,9 +1334,6 @@ class _moonpos: self.distance_au = dist def _CalcMoon(time): - global _CalcMoonCount - _CalcMoonCount += 1 - T = time.tt / 36525 ex = _Array2(-6, 6, 1, 4) @@ -1638,10 +1633,6 @@ def _VsopDeriv(formula, t): return deriv _DAYS_PER_MILLENNIUM = 365250.0 -_LON_INDEX = 0 -_LAT_INDEX = 1 -_RAD_INDEX = 2 - def _VsopRotate(eclip): # Convert ecliptic cartesian coordinates to equatorial cartesian coordinates. @@ -3818,6 +3809,8 @@ def SearchMaxElongation(body, startTime): startTime = t2.AddDays(1.0) iter_count += 1 + raise InternalError() # should never take more than 2 iterations + def _sun_offset(targetLon, time): ecl = SunPosition(time) diff --git a/generate/test.html b/generate/test.html deleted file mode 100644 index adc54f78..00000000 --- a/generate/test.html +++ /dev/null @@ -1,252 +0,0 @@ - - - - Astronomy unit test - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bodycoordsRADECazimuthaltitudeculmphasedistmag
Sun
Moon
Mercury
Venus
Earth
Mars
Jupiter
Saturn
Uranus
Neptune
Pluto
- -
-
-
Sun Ecliptic Coordinates
- - - - - - - - - - - - - - - - - - - - - -
x
y
z
lat
lon
- - diff --git a/generate/test.js b/generate/test.js index d345a14b..14185df2 100644 --- a/generate/test.js +++ b/generate/test.js @@ -317,7 +317,7 @@ function MoonReversePhase(longitude) { const ut1 = utList[k]; const ut2 = utList[k+1]; for (i = 1; i < nslots; ++i) { - const ut = ut1 + (i/nslots)*(ut2 - ut1) + const ut = ut1 + (i/nslots)*(ut2 - ut1); time = Astronomy.MakeTime(ut); const before = Astronomy.SearchMoonPhase(longitude, time, -40); diff --git a/generate/test.py b/generate/test.py index 75b8f4fc..404f9da9 100755 --- a/generate/test.py +++ b/generate/test.py @@ -189,7 +189,7 @@ def Seasons(filename = 'seasons/seasons.txt'): minute = int(m.group(5)) name = m.group(6) if year != current_year: - current_year = current_year + current_year = year seasons = astronomy.Seasons(year) correct_time = astronomy.Time.Make(year, month, day, hour, minute, 0) if name == 'Equinox': @@ -1007,7 +1007,7 @@ def Test_GAL_EQJ_NOVAS(filename): gal_sphere = astronomy.SphereFromVector(gal_vec) dlat = gal_sphere.lat - glat dlon = math.cos(math.radians(glat)) * (gal_sphere.lon - glon) - diff = 3600.0 * math.sqrt(dlon*dlon + dlat*dlat) + diff = 3600.0 * math.hypot(dlon, dlat) if diff > THRESHOLD_SECONDS: print('PY Test_GAL_EQJ_NOVAS({} line {}): EXCESSIVE ERROR = {:0.3f}'.format(filename, lnum, diff)) sys.exit(1) @@ -2165,7 +2165,6 @@ class JplStateRecord: def JplHorizonsStateVectors(filename): - stateList = [] with open(filename, 'rt') as infile: lnum = 0 part = 0 @@ -2199,6 +2198,7 @@ def JplHorizonsStateVectors(filename): vx, vy, vz = float(match.group(1)), float(match.group(2)), float(match.group(3)) yield JplStateRecord(lnum, astronomy.StateVector(rx, ry, rz, vx, vy, vz, time)) part = (part + 1) % 3 + return 0 def VerifyStateBody(func, filename, r_thresh, v_thresh): @@ -2899,7 +2899,7 @@ def GravSimFile(filename, originBody, nsteps, rthresh, vthresh): max_rdiff = 0.0 max_vdiff = 0.0 for rec in JplHorizonsStateVectors(filename): - if sim == None: + if sim is None: sim = astronomy.GravitySimulator(originBody, rec.state.t, [rec.state]) time = rec.state.t smallBodyArray = sim.Update(time) diff --git a/source/python/astronomy/astronomy.py b/source/python/astronomy/astronomy.py index f3778846..111cb5c7 100644 --- a/source/python/astronomy/astronomy.py +++ b/source/python/astronomy/astronomy.py @@ -60,8 +60,6 @@ EUROPA_RADIUS_KM = 1560.8 # The mean radius of Jupiter's moon Europ GANYMEDE_RADIUS_KM = 2631.2 # The mean radius of Jupiter's moon Ganymede, expressed in kilometers. CALLISTO_RADIUS_KM = 2410.3 # The mean radius of Jupiter's moon Callisto, expressed in kilometers. -_CalcMoonCount = 0 - _RAD2HOUR = 3.819718634205488 # 12/pi = factor to convert radians to sidereal hours _HOUR2RAD = 0.2617993877991494365 # pi/12 = factor to convert sidereal hours to radians _DAYS_PER_TROPICAL_YEAR = 365.24217 @@ -1872,9 +1870,6 @@ class _moonpos: self.distance_au = dist def _CalcMoon(time): - global _CalcMoonCount - _CalcMoonCount += 1 - T = time.tt / 36525 ex = _Array2(-6, 6, 1, 4) @@ -3489,10 +3484,6 @@ def _VsopDeriv(formula, t): return deriv _DAYS_PER_MILLENNIUM = 365250.0 -_LON_INDEX = 0 -_LAT_INDEX = 1 -_RAD_INDEX = 2 - def _VsopRotate(eclip): # Convert ecliptic cartesian coordinates to equatorial cartesian coordinates. @@ -5860,6 +5851,8 @@ def SearchMaxElongation(body, startTime): startTime = t2.AddDays(1.0) iter_count += 1 + raise InternalError() # should never take more than 2 iterations + def _sun_offset(targetLon, time): ecl = SunPosition(time) diff --git a/source/python/setup.py b/source/python/setup.py index 3347e660..b8ed9fa8 100644 --- a/source/python/setup.py +++ b/source/python/setup.py @@ -1,15 +1,19 @@ from setuptools import setup +def _LoadFile(filename): + with open(filename) as infile: + return infile.read() + setup( name='astronomy-engine', version='2.1.8', description='Astronomy calculation for Sun, Moon, and planets.', - long_description=open('README.md').read(), + long_description=_LoadFile('README.md'), long_description_content_type='text/markdown', author='Donald Cross', author_email='cosinekitty@gmail.com', url='https://github.com/cosinekitty/astronomy', - license=open('LICENSE').read(), + license=_LoadFile('LICENSE'), classifiers=[ "Intended Audience :: Science/Research", "License :: OSI Approved :: MIT License",