Skip to content

Commit ff0dd07

Browse files
STY: rewrite literals $\geq$ 1e6 in scientific notation
Following pylint's bad-number-notation (C0329) check with the same $\geq$ 1e6 threshold as Python's 'g' format specifier, normalize literals such as 2456293.25 to 2.45629325e6 and 299792458.0 to 2.99792458e8. Mantissas are kept at the shortest length that round-trips to the same float64 value, so no numerical drift.
1 parent 89e54d2 commit ff0dd07

38 files changed

Lines changed: 197 additions & 190 deletions

‎astropy/constants/codata2010.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class EMCODATA2010(CODATA2010, EMConstant):
9393
R = CODATA2010("R", "Gas constant", 8.3144621, "J / (K mol)", 0.0000075, system="si")
9494

9595
Ryd = CODATA2010(
96-
"Ryd", "Rydberg constant", 10973731.568539, "1 / (m)", 0.000055, system="si"
96+
"Ryd", "Rydberg constant", 1.0973731568539e7, "1 / (m)", 0.000055, system="si"
9797
)
9898

9999
a0 = CODATA2010("a0", "Bohr radius", 5.2917721092e-11, "m", 1.7e-20, system="si")

‎astropy/constants/codata2014.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class EMCODATA2014(CODATA2014, EMConstant):
3737
)
3838

3939
c = CODATA2014(
40-
"c", "Speed of light in vacuum", 299792458.0, "m / (s)", 0.0, system="si"
40+
"c", "Speed of light in vacuum", 2.99792458e8, "m / (s)", 0.0, system="si"
4141
)
4242

4343

@@ -79,7 +79,7 @@ class EMCODATA2014(CODATA2014, EMConstant):
7979
R = CODATA2014("R", "Gas constant", 8.3144598, "J / (K mol)", 0.0000048, system="si")
8080

8181
Ryd = CODATA2014(
82-
"Ryd", "Rydberg constant", 10973731.568508, "1 / (m)", 0.000065, system="si"
82+
"Ryd", "Rydberg constant", 1.0973731568508e7, "1 / (m)", 0.000065, system="si"
8383
)
8484

8585
a0 = CODATA2014("a0", "Bohr radius", 5.2917721067e-11, "m", 1.2e-20, system="si")

‎astropy/constants/codata2018.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class EMCODATA2018(CODATA2018, EMConstant):
3131
k_B = CODATA2018("k_B", "Boltzmann constant", 1.380649e-23, "J / (K)", 0.0, system="si")
3232

3333
c = CODATA2018(
34-
"c", "Speed of light in vacuum", 299792458.0, "m / (s)", 0.0, system="si"
34+
"c", "Speed of light in vacuum", 2.99792458e8, "m / (s)", 0.0, system="si"
3535
)
3636

3737

@@ -80,7 +80,7 @@ class EMCODATA2018(CODATA2018, EMConstant):
8080
)
8181

8282
Ryd = CODATA2018(
83-
"Ryd", "Rydberg constant", 10973731.568160, "1 / (m)", 0.000021, system="si"
83+
"Ryd", "Rydberg constant", 1.097373156816e7, "1 / (m)", 0.000021, system="si"
8484
)
8585

8686
a0 = CODATA2018("a0", "Bohr radius", 5.29177210903e-11, "m", 8.0e-21, system="si")

‎astropy/constants/codata2022.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class EMCODATA2022(CODATA2022, EMConstant):
3131
k_B = CODATA2022("k_B", "Boltzmann constant", 1.380649e-23, "J / (K)", 0.0, system="si")
3232

3333
c = CODATA2022(
34-
"c", "Speed of light in vacuum", 299792458.0, "m / (s)", 0.0, system="si"
34+
"c", "Speed of light in vacuum", 2.99792458e8, "m / (s)", 0.0, system="si"
3535
)
3636

3737
G = CODATA2022(
@@ -79,7 +79,7 @@ class EMCODATA2022(CODATA2022, EMConstant):
7979
)
8080

8181
Ryd = CODATA2022(
82-
"Ryd", "Rydberg constant", 10973731.568157, "1 / (m)", 0.000012, system="si"
82+
"Ryd", "Rydberg constant", 1.0973731568157e7, "1 / (m)", 0.000012, system="si"
8383
)
8484

8585
a0 = CODATA2022("a0", "Bohr radius", 5.29177210544e-11, "m", 8.2e-21, system="si")

‎astropy/constants/iau2012.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class IAU2012(Constant):
9595
"Solar radius",
9696
6.95508e8,
9797
"m",
98-
0.00026e8,
98+
26000.0,
9999
"Allen's Astrophysical Quantities 4th Ed.",
100100
system="si",
101101
)

‎astropy/coordinates/builtin_frames/fk4.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def fk4_e_terms(equinox):
158158
# Eccentricity of the Earth's orbit
159159
ek = math.radians(k) * ((-1.26e-7 * T - 0.00004193) * T + 0.01673011)
160160
# Mean longitude of perigee of the solar orbit
161-
g = np.radians((((0.012 * T + 1.65) * T + 6190.67) * T + 1015489.951) / 3600.0)
161+
g = np.radians((((0.012 * T + 1.65) * T + 6190.67) * T + 1.015489951e6) / 3600.0)
162162
minus_ek_cos_g = -ek * np.cos(g)
163163
# Obliquity of the ecliptic
164164
o = erfa.obl80(equinox.jd, 0)

‎astropy/coordinates/earth.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class GeodeticLocation(NamedTuple):
4646
"""The height above the reference ellipsoid."""
4747

4848

49-
OMEGA_EARTH = (1.002_737_811_911_354_48 * u.cycle / u.day).to(
49+
OMEGA_EARTH = (1.0027378119113546 * u.cycle / u.day).to(
5050
1 / u.s, u.dimensionless_angles()
5151
)
5252
"""

‎astropy/coordinates/tests/accuracy/test_altaz_icrs.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def test_against_hor2eq():
5656
lon=Angle("-111d36.0m"), lat=Angle("31d57.8m"), height=2120.0 * u.m
5757
)
5858

59-
obstime = Time(2451545.0, format="jd", scale="ut1")
59+
obstime = Time(2.451545e6, format="jd", scale="ut1")
6060

6161
altaz_frame = AltAz(
6262
obstime=obstime,
@@ -102,7 +102,7 @@ def run_pyephem():
102102
observer.lon = -1 * np.radians(109 + 24 / 60.0 + 53.1 / 60**2)
103103
observer.lat = np.radians(33 + 41 / 60.0 + 46.0 / 60.0**2)
104104
observer.elevation = 300
105-
observer.date = 2455822.868055556 - ephem.julian_date(0)
105+
observer.date = 2.455822868055556e6 - ephem.julian_date(0)
106106

107107
ra, dec = observer.radec_of(np.radians(6.8927), np.radians(60.7665))
108108
print(f"EPHEM: {observer.date}: {np.degrees(ra)}, {np.degrees(dec)}")

‎astropy/coordinates/tests/test_distance.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_distances():
4343

4444
# standard units are pre-defined
4545
npt.assert_allclose(distance.lyr, 39.138765325702551)
46-
npt.assert_allclose(distance.km, 370281309776063.0)
46+
npt.assert_allclose(distance.km, 3.70281309776063e14)
4747

4848
# Coordinate objects can be assigned a distance object, giving them a full
4949
# 3D position
@@ -197,7 +197,7 @@ def test_distmod():
197197
assert d.kpc == 100
198198

199199
d = Distance(distmod=-1.0, unit=u.au)
200-
npt.assert_allclose(d.value, 1301442.9440836983)
200+
npt.assert_allclose(d.value, 1.3014429440836983e6)
201201

202202
with pytest.raises(ValueError, match=MULTIPLE_INPUTS_ERROR_MSG):
203203
d = Distance(value=d, distmod=20)

‎astropy/coordinates/tests/test_earth.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,21 @@ def test_gd2gc():
7474

7575
location = EarthLocation.from_geodetic(e, p, h, ellipsoid="WGS84")
7676
xyz = tuple(v.to(u.m) for v in location.to_geocentric())
77-
vvd(xyz[0], -5599000.5577049947, 1e-7, "eraGd2gc", "0/1", status)
77+
vvd(xyz[0], -5.599000557704994e6, 1e-7, "eraGd2gc", "0/1", status)
7878
vvd(xyz[1], 233011.67223479203, 1e-7, "eraGd2gc", "1/1", status)
79-
vvd(xyz[2], -3040909.4706983363, 1e-7, "eraGd2gc", "2/1", status)
79+
vvd(xyz[2], -3.040909470698336e6, 1e-7, "eraGd2gc", "2/1", status)
8080

8181
location = EarthLocation.from_geodetic(e, p, h, ellipsoid="GRS80")
8282
xyz = tuple(v.to(u.m) for v in location.to_geocentric())
83-
vvd(xyz[0], -5599000.5577260984, 1e-7, "eraGd2gc", "0/2", status)
83+
vvd(xyz[0], -5.599000557726098e6, 1e-7, "eraGd2gc", "0/2", status)
8484
vvd(xyz[1], 233011.6722356703, 1e-7, "eraGd2gc", "1/2", status)
85-
vvd(xyz[2], -3040909.4706095476, 1e-7, "eraGd2gc", "2/2", status)
85+
vvd(xyz[2], -3.0409094706095476e6, 1e-7, "eraGd2gc", "2/2", status)
8686

8787
location = EarthLocation.from_geodetic(e, p, h, ellipsoid="WGS72")
8888
xyz = tuple(v.to(u.m) for v in location.to_geocentric())
89-
vvd(xyz[0], -5598998.7626301490, 1e-7, "eraGd2gc", "0/3", status)
89+
vvd(xyz[0], -5.598998762630149e6, 1e-7, "eraGd2gc", "0/3", status)
9090
vvd(xyz[1], 233011.5975297822, 1e-7, "eraGd2gc", "1/3", status)
91-
vvd(xyz[2], -3040908.6861467111, 1e-7, "eraGd2gc", "2/3", status)
91+
vvd(xyz[2], -3.040908686146711e6, 1e-7, "eraGd2gc", "2/3", status)
9292

9393

9494
class TestInput:

0 commit comments

Comments
 (0)