CodeQL tweaks and fixes.

Updated CodeQL config to ignore source templates,
because they are not syntactically valid source code.
Ignore other stuff that is irrelevant to published
code quality.

Made various fixes based on helpful CodeQL analysis.
This commit is contained in:
Don Cross
2022-11-07 15:31:05 -05:00
parent b05df95974
commit 5eca7d7760
16 changed files with 35 additions and 304 deletions

View File

@@ -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

View File

@@ -5,7 +5,6 @@
# Utility functions shared by Python demo programs.
#
import sys
import re
import astronomy
def ParseArgs(args):

View File

@@ -60,8 +60,6 @@ EUROPA_RADIUS_KM = 1560.8 #<const> The mean radius of Jupiter's moon Europ
GANYMEDE_RADIUS_KM = 2631.2 #<const> The mean radius of Jupiter's moon Ganymede, expressed in kilometers.
CALLISTO_RADIUS_KM = 2410.3 #<const> 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)

View File

@@ -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
#------------------------------------------------------------------------------

View File

@@ -9,7 +9,6 @@
#
import sys
import math
from astronomy import *
UsageText = r'''

View File

@@ -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__':

View File

@@ -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__':

View File

@@ -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)

View File

@@ -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:

View File

@@ -1,7 +1,6 @@
#!/usr/bin/env python3
import sys
import re
import matplotlib.pyplot as plt

View File

@@ -60,8 +60,6 @@ EUROPA_RADIUS_KM = 1560.8 #<const> The mean radius of Jupiter's moon Europ
GANYMEDE_RADIUS_KM = 2631.2 #<const> The mean radius of Jupiter's moon Ganymede, expressed in kilometers.
CALLISTO_RADIUS_KM = 2410.3 #<const> 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)

View File

@@ -1,252 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Astronomy unit test</title>
<script src="../source/js/astronomy.browser.js"></script>
<script>
window.onload = function() {
function FormatDec(x) {
var neg = (x < 0);
x = Math.abs(x);
var deg = Math.floor(x);
var dz = '';
if (deg < 10) dz += '0';
var min = 60 * (x % 1);
var mz = '';
if (min < 10) mz += '0';
var prefix = neg ? '-' : '+';
return `${prefix}${dz}${deg.toFixed(0)}:${mz}${min.toFixed(2)}`;
}
function FormatRa(x) {
var neg = (x < 0);
x = Math.abs(x);
var deg = Math.floor(x);
var dz = '';
if (deg < 10) dz += '0';
var min = 60 * (x % 1);
var mz = '';
if (min < 10) mz += '0';
return `${dz}${deg.toFixed(0)}:${mz}${min.toFixed(2)}`;
}
var now = new Date();
const observer = new Astronomy.Observer(29, -81, 10);
var body, pos;
document.getElementById('CurrentDateTime').innerText = now.toLocaleString();
for (body of ['Sun', 'Moon', 'Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune', 'Pluto']) {
if (body === 'Moon')
pos = Astronomy.GeoVector(body, now, false);
else
pos = Astronomy.HelioVector(body, now);
var cell = document.getElementById('pos_' + body);
cell.innerText = `(${pos.x.toFixed(6)}, ${pos.y.toFixed(6)}, ${pos.z.toFixed(6)})`;
if (body !== 'Earth') {
if (body !== 'Moon') // prevent redundant calculation
pos = Astronomy.GeoVector(body, now, false);
var j2000 = Astronomy.Equator(body, now, observer, false, false);
var ofdate = Astronomy.Equator(body, now, observer, true, true);
var hor = Astronomy.Horizon(now, observer, ofdate.ra, ofdate.dec);
var raCell = document.getElementById('ra_' + body);
raCell.innerText = FormatRa(j2000.ra);
var decCell = document.getElementById('dec_' + body);
decCell.innerText = FormatDec(j2000.dec);
var azCell = document.getElementById('az_' + body);
azCell.innerText = hor.azimuth.toFixed(3);
var altCell = document.getElementById('alt_' + body);
altCell.innerText = hor.altitude.toFixed(3);
var culm = Astronomy.SearchHourAngle(body, observer, 0, now);
cell = document.getElementById('culm_' + body);
cell.innerText = culm.time.date.toLocaleTimeString();
const illum = Astronomy.Illumination(body, now);
cell = document.getElementById('phase_' + body);
cell.innerText = illum.phase_angle.toFixed(3);
cell = document.getElementById('dist_' + body);
cell.innerText = illum.geo_dist.toFixed(6);
cell = document.getElementById('mag_' + body);
cell.innerText = (illum.mag > 0 ? '+' : '') + illum.mag.toFixed(2);
}
}
const sun = Astronomy.SunPosition(now);
document.getElementById('SunEcliptic_x').innerText = sun.ex.toFixed(6);
document.getElementById('SunEcliptic_y').innerText = sun.ey.toFixed(6);
document.getElementById('SunEcliptic_z').innerText = sun.ez.toFixed(6);
document.getElementById('SunEcliptic_lat').innerText = sun.elat.toFixed(6);
document.getElementById('SunEcliptic_lon').innerText = sun.elon.toFixed(6);
}
</script>
</head>
<body style="font-family: 'Courier New', Courier, monospace;">
<div id='CurrentDateTime'></div>
<table border="1" cellspacing="0" cellpadding="8">
<tr>
<td>body</td>
<td>coords</td>
<td>RA</td>
<td>DEC</td>
<td>azimuth</td>
<td>altitude</td>
<td>culm</td>
<td>phase</td>
<td>dist</td>
<td>mag</td>
</tr>
<tr>
<td>Sun</td>
<td id='pos_Sun'></td>
<td id='ra_Sun'></td>
<td id='dec_Sun'></td>
<td id='az_Sun'></td>
<td id='alt_Sun'></td>
<td id='culm_Sun'></td>
<td id='phase_Sun'></td>
<td id='dist_Sun'></td>
<td id='mag_Sun'></td>
</tr>
<tr>
<td>Moon</td>
<td id='pos_Moon'></td>
<td id='ra_Moon'></td>
<td id='dec_Moon'></td>
<td id='az_Moon'></td>
<td id='alt_Moon'></td>
<td id='culm_Moon'></td>
<td id='phase_Moon'></td>
<td id='dist_Moon'></td>
<td id='mag_Moon'></td>
</tr>
<tr>
<td>Mercury</td>
<td id='pos_Mercury'></td>
<td id='ra_Mercury'></td>
<td id='dec_Mercury'></td>
<td id='az_Mercury'></td>
<td id='alt_Mercury'></td>
<td id='culm_Mercury'></td>
<td id='phase_Mercury'></td>
<td id='dist_Mercury'></td>
<td id='mag_Mercury'></td>
</tr>
<tr>
<td>Venus</td>
<td id='pos_Venus'></td>
<td id='ra_Venus'></td>
<td id='dec_Venus'></td>
<td id='az_Venus'></td>
<td id='alt_Venus'></td>
<td id='culm_Venus'></td>
<td id='phase_Venus'></td>
<td id='dist_Venus'></td>
<td id='mag_Venus'></td>
</tr>
<tr>
<td>Earth</td>
<td id='pos_Earth'></td>
</tr>
<tr>
<td>Mars</td>
<td id='pos_Mars'></td>
<td id='ra_Mars'></td>
<td id='dec_Mars'></td>
<td id='az_Mars'></td>
<td id='alt_Mars'></td>
<td id='culm_Mars'></td>
<td id='phase_Mars'></td>
<td id='dist_Mars'></td>
<td id='mag_Mars'></td>
</tr>
<tr>
<td>Jupiter</td>
<td id='pos_Jupiter'></td>
<td id='ra_Jupiter'></td>
<td id='dec_Jupiter'></td>
<td id='az_Jupiter'></td>
<td id='alt_Jupiter'></td>
<td id='culm_Jupiter'></td>
<td id='phase_Jupiter'></td>
<td id='dist_Jupiter'></td>
<td id='mag_Jupiter'></td>
</tr>
<tr>
<td>Saturn</td>
<td id='pos_Saturn'></td>
<td id='ra_Saturn'></td>
<td id='dec_Saturn'></td>
<td id='az_Saturn'></td>
<td id='alt_Saturn'></td>
<td id='culm_Saturn'></td>
<td id='phase_Saturn'></td>
<td id='dist_Saturn'></td>
<td id='mag_Saturn'></td>
</tr>
<tr>
<td>Uranus</td>
<td id='pos_Uranus'></td>
<td id='ra_Uranus'></td>
<td id='dec_Uranus'></td>
<td id='az_Uranus'></td>
<td id='alt_Uranus'></td>
<td id='culm_Uranus'></td>
<td id='phase_Uranus'></td>
<td id='dist_Uranus'></td>
<td id='mag_Uranus'></td>
</tr>
<tr>
<td>Neptune</td>
<td id='pos_Neptune'></td>
<td id='ra_Neptune'></td>
<td id='dec_Neptune'></td>
<td id='az_Neptune'></td>
<td id='alt_Neptune'></td>
<td id='culm_Neptune'></td>
<td id='phase_Neptune'></td>
<td id='dist_Neptune'></td>
<td id='mag_Neptune'></td>
</tr>
<tr>
<td>Pluto</td>
<td id='pos_Pluto'></td>
<td id='ra_Pluto'></td>
<td id='dec_Pluto'></td>
<td id='az_Pluto'></td>
<td id='alt_Pluto'></td>
<td id='culm_Pluto'></td>
<td id='phase_Pluto'></td>
<td id='dist_Pluto'></td>
<td id='mag_Pluto'></td>
</tr>
</table>
<br>
<br>
<div>Sun Ecliptic Coordinates</div>
<table border="1" cellspacing="0" cellpadding="8">
<tr>
<td>x</td>
<td id="SunEcliptic_x"></td>
</tr>
<tr>
<td>y</td>
<td id="SunEcliptic_y"></td>
</tr>
<tr>
<td>z</td>
<td id="SunEcliptic_z"></td>
</tr>
<tr>
<td>lat</td>
<td id="SunEcliptic_lat"></td>
</tr>
<tr>
<td>lon</td>
<td id="SunEcliptic_lon"></td>
</tr>
</table>
</body>
</html>

View File

@@ -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);

View File

@@ -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)

View File

@@ -60,8 +60,6 @@ EUROPA_RADIUS_KM = 1560.8 #<const> The mean radius of Jupiter's moon Europ
GANYMEDE_RADIUS_KM = 2631.2 #<const> The mean radius of Jupiter's moon Ganymede, expressed in kilometers.
CALLISTO_RADIUS_KM = 2410.3 #<const> 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)

View File

@@ -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",