Skip to content

Commit ed717ac

Browse files
authored
Merge pull request #35 from JuliaAstro/remove-cirrange
Get rid of cirrange
2 parents 71a69a6 + 10cfa18 commit ed717ac

19 files changed

+40
-44
lines changed

TODO.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Already Present in Julia
2424
------------------------
2525

2626
* `asinh`
27+
* `cirrange`. It is equivalent to `mod(x, 360)`, or to `mod2pi(x)` for the `[0,
28+
2pi)` range.
2729
* `minmax`. It is called `extrema` in Julia.
2830
* `permute`. It is called `randperm` in Julia.
2931
* `to_hex`. It is called `hex` in Julia.

docs/src/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ This is not the only effort to bundle astronomical functions written in Julia la
7373
Because of this, some of IDL AstroLib’s utilities are not provided in `AstroLib.jl` as they are already present in other Julia packages. Here is a list of such utilities:
7474

7575
- `aper`, see [AperturePhotometry.jl](https://github.com/kbarbary/AperturePhotometry.jl) package
76+
- `asinh`, already present in Julia with the same name
77+
- `cirrange`, it is equivalent to `mod(x, 360)`. To restrict a number to the
78+
range `[0, 2pi)` use `mod2pi(x)`
7679
- `cosmo_param`, see [Cosmology.jl](https://github.com/JuliaAstro/Cosmology.jl) package
7780
- `galage`, see [Cosmology.jl](https://github.com/JuliaAstro/Cosmology.jl) package
7881
- `glactc_pm`, see [SkyCoords.jl](https://github.com/kbarbary/SkyCoords.jl) package

docs/src/ref.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ julia> AstroLib.planets["saturn"].mass
147147

148148
[`airtovac()`](@ref),
149149
[`calz_unred()`](@ref),
150-
[`cirrange()`](@ref),
151150
[`deredd()`](@ref),
152151
[`flux2mag()`](@ref),
153152
[`gal_uvw()`](@ref),

src/bprecess.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function _bprecess{T<:AbstractFloat}(ra::T, dec::T, parallax::T,
6464
# parallax = parallax / rmag
6565
# end
6666
if ra1950 < 0
67-
ra1950 += 2pi
67+
ra1950 += 2 * T(pi)
6868
end
6969
ra1950 = rad2deg(ra1950)
7070
dec1950 = rad2deg(dec1950)

src/ct2lst.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function ct2lst{T<:AbstractFloat}(long::T, jd::T)
66
t = t0 / JULIANCENTURY
77
# Compute GST in seconds.
88
θ = ct2lst_c[1] + (ct2lst_c[2]*t0) + t*t*(ct2lst_c[3] - t / ct2lst_c[4])
9-
return cirrange((θ + long)/15, 24)
9+
return mod((θ + long)/15, 24)
1010
end
1111

1212
"""

src/eci2geo.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function _eci2geo{T<:AbstractFloat}(x::T, y::T, z::T, jd::T)
66
theta = atan2(y, x) # Azimuth.
77
gst = ct2lst(zero(T), jd)
88
sid_angle = gst*pi/12 # Sidereal angle.
9-
long = cirrange(rad2deg(theta - sid_angle)) # Longitude.
9+
long = mod(rad2deg(theta - sid_angle), 360) # Longitude.
1010
r = hypot(x, y)
1111
lat = atan2(z, r) # Latitude.
1212
alt = r/cos(lat) - Re # Altitude.

src/hadec2altaz.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ function _hadec2altaz{T<:AbstractFloat}(ha::T, dec::T, lat::T, ws::Bool)
1515
r = hypot(x, y)
1616

1717
# Now get altitude, azimuth
18-
az = cirrange(rad2deg(atan2(y, x)))
18+
az = mod(rad2deg(atan2(y, x)), 360)
1919
alt = rad2deg(atan2(z, r))
2020
# Convert azimuth to West from South, if desired
2121
if ws
22-
az = cirrange(az + 180.0)
22+
az = mod(az + 180, 360)
2323
end
2424
return alt, az
2525
end

src/helio.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function _helio(jd::T, num::Integer, radians::Bool) where {T<:AbstractFloat}
3333
m = mlong - plong
3434
nu = trueanom(kepler_solver(m, eccen), eccen)
3535
hrad = a * (1 - eccen * cos(e))
36-
hlong = cirrange(nu + plong, 2 * pi)
36+
hlong = mod2pi(nu + plong)
3737
hlat = asin(sin(hlong - along) * sin(inc))
3838
if !radians
3939
return hrad, rad2deg(hlong), rad2deg(hlat)

src/jprecess.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function _jprecess{T<:AbstractFloat}(ra::T, dec::T, parallax::T,
6565
# parallax = parallax / rmag
6666
# end
6767
if ra2000 < 0
68-
ra2000 += 2pi
68+
ra2000 += 2 * T(pi)
6969
end
7070
ra2000 = rad2deg(ra2000)
7171
dec2000 = rad2deg(dec2000)

src/kepler_solver.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ julia> E = kepler_solver(8pi/3, ecc)
9898
9999
(2) Plot the eccentric anomaly as a function of mean anomaly for eccentricity
100100
\$e = 0\$, \$0.5\$, \$0.9\$. Recall that `kepler_solver` gives \$E \\in [-\\pi,
101-
\\pi]\$, use `cirrange` to have it in \$[0, 2\\pi]\$. Use
101+
\\pi]\$, use `mod2pi` to have it in \$[0, 2\\pi]\$. Use
102102
[PyPlot.jl](https://github.com/JuliaPlots/Plots.jl/) for plotting.
103103
104104
```julia
105-
using PyPlot
105+
using AstroLib, PyPlot
106106
M = linspace(0, 2pi, 1001)[1:end-1];
107-
for ecc in (0, 0.5, 0.9); plot(M, cirrange.(kepler_solver.(M, ecc), 2pi)); end
107+
for ecc in (0, 0.5, 0.9); plot(M, mod2pi.(kepler_solver.(M, ecc))); end
108108
```
109109
110110
### Notes ###

src/misc.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# This file is a part of AstroLib.jl. License is MIT "Expat".
22
# Copyright (C) 2016 Mosè Giordano.
33

4-
include("cirrange.jl")
5-
export cirrange
6-
74
include("ordinal.jl")
85
export ordinal
96

src/moonpos.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,22 @@ function _moonpos{T<:AbstractFloat}(jd::T, radians::Bool)
5959
# Number of Julian centuries since 2000-01-01T12:00:00
6060
t = (jd - J2000) / JULIANCENTURY
6161
# Mean longitude of the moon referred to mean equinox of the date
62-
Lprimed = cirrange(@evalpoly(t, 218.3164477, 481267.88123421,
63-
-0.0015786, inv(538841), -inv(6.5194e7)))
62+
Lprimed = mod(@evalpoly(t, 218.3164477, 481267.88123421,
63+
-0.0015786, inv(538841), -inv(6.5194e7)), 360)
6464
Lprime = deg2rad(Lprimed)
6565
# Mean elongation of the Moon
66-
d = deg2rad(cirrange(@evalpoly(t, 297.8501921, 445267.1114034, -0.0018819,
67-
inv(545868), -inv(1.13065e8))))
66+
d = deg2rad(mod(@evalpoly(t, 297.8501921, 445267.1114034, -0.0018819,
67+
inv(545868), -inv(1.13065e8)), 360))
6868
# Sun's mean anomaly
69-
M = deg2rad(cirrange(@evalpoly(t, 357.5291092, 35999.0502909, -0.0001536,
70-
inv(2.449e7))))
69+
M = deg2rad(mod(@evalpoly(t, 357.5291092, 35999.0502909, -0.0001536,
70+
inv(2.449e7)), 360))
7171
# Moon's mean anomaly
72-
Mprime = deg2rad(cirrange(@evalpoly(t, 134.9633964, 477198.8675055,
73-
0.0087414, inv(6.9699e4),
74-
-inv(1.4712e7))))
72+
Mprime = deg2rad(mod(@evalpoly(t, 134.9633964, 477198.8675055,
73+
0.0087414, inv(6.9699e4),
74+
-inv(1.4712e7)), 360))
7575
# Moon's argument of latitude
76-
F = deg2rad(cirrange(@evalpoly(t, 93.2720950, 483202.0175233, -0.0036539,
77-
-inv(3.526e7), inv(8.6331e8))))
76+
F = deg2rad(mod(@evalpoly(t, 93.2720950, 483202.0175233, -0.0036539,
77+
-inv(3.526e7), inv(8.6331e8)), 360))
7878
# Eccentricity of Earth's orbit around the Sun
7979
E = @evalpoly t 1 -0.002516 -7.4e-6
8080
E2 = E*E
@@ -110,14 +110,14 @@ function _moonpos{T<:AbstractFloat}(jd::T, radians::Bool)
110110
arg = moon_d_lat*d + moon_M_lat*M + moon_Mprime_lat*Mprime + moon_F_lat*F
111111
geolat = (sum(sinlat.*sin.(arg)) + sumb_add)/1000000
112112
nlong, elong = nutate(jd)
113-
geolong = cirrange(geolong + nlong/3600)
113+
geolong = mod(geolong + nlong/3600, 360)
114114
λ = deg2rad(geolong)
115115
β = deg2rad(geolat)
116116
# Find mean obliquity and convert λ, β to right ascension and declination.
117117
ɛ = ten(23, 26) + @evalpoly(t/100, 21.448, -4680.93, -1.55, 1999.25, -51.38,
118118
-249.67, -39.05, 7.12, 27.87, 5.79, 2.45)/3600
119119
ɛ = deg2rad+ elong/3600)
120-
ra = cirrange(atan2(sin(λ)*cos(ɛ) - tan(β)*sin(ɛ), cos(λ)), 2.*pi)
120+
ra = mod2pi(atan2(sin(λ)*cos(ɛ) - tan(β)*sin(ɛ), cos(λ)))
121121
dec = asin(sin(β)*cos(ɛ) + cos(β)*sin(ɛ)*sin(λ))
122122
if radians
123123
return ra, dec, dis, λ, β

src/nutate.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ function nutate(jd::AbstractFloat)
4343
# Number of Julian centuries since 2000-01-01T12:00:00
4444
t = (jd - J2000) / JULIANCENTURY
4545
# Mean elongation of the Moon
46-
d = deg2rad(cirrange(@evalpoly(t, 297.85036, 445267.111480, -0.0019142, inv(189474))))
46+
d = deg2rad(mod(@evalpoly(t, 297.85036, 445267.111480, -0.0019142, inv(189474)), 360))
4747
# Sun's mean anomaly
48-
M = deg2rad(cirrange(@evalpoly(t, 357.52772, 35999.050340, -0.0001603, -inv(3e5))))
48+
M = deg2rad(mod(@evalpoly(t, 357.52772, 35999.050340, -0.0001603, -inv(3e5)), 360))
4949
# Moon's mean anomaly
50-
Mprime = deg2rad(cirrange(@evalpoly(t, 134.96298, 477198.867398, 0.0086972, inv(5.625e4))))
50+
Mprime = deg2rad(mod(@evalpoly(t, 134.96298, 477198.867398, 0.0086972, inv(5.625e4)), 360))
5151
# Moon's argument of latitude
52-
F = deg2rad(cirrange(@evalpoly(t, 93.27191, 483202.017538, -0.0036825, -inv(3.27270e5))))
52+
F = deg2rad(mod(@evalpoly(t, 93.27191, 483202.017538, -0.0036825, -inv(3.27270e5)), 360))
5353
# Longitude of the ascending node of the Moon's mean orbit on the ecliptic,
5454
# measured from the mean equinox of the date
55-
ω = deg2rad(cirrange(@evalpoly(t, 125.04452, -1934.136261, 0.0020708, inv(4.5e5))))
55+
ω = deg2rad(mod(@evalpoly(t, 125.04452, -1934.136261, 0.0020708, inv(4.5e5)), 360))
5656
arg = d_lng .* d .+ M_lng .* M .+ Mprime_lng .* Mprime .+ F_lng .* F .+ ω_lng .* ω
5757
long = sum((sdelt .* t .+ sin_lng) .* sin.(arg)) / 10000
5858
obliq = sum((cdelt .* t .+ cos_lng) .* cos.(arg)) / 10000

src/precess.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ function _precess{T<:AbstractFloat}(ra::T, dec::T, equinox1::T, equinox2::T,
1818
ra_rad = atan2(x2[2], x2[1])
1919
dec_rad = asin(x2[3])
2020
if radians
21-
return cirrange(ra_rad, 2 * T(pi)), dec_rad
21+
return mod2pi(ra_rad), dec_rad
2222
else
23-
return cirrange(rad2deg(ra_rad)), rad2deg(dec_rad)
23+
return mod(rad2deg(ra_rad), 360), rad2deg(dec_rad)
2424
end
2525
end
2626

src/radec.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
function _radec{T<:AbstractFloat}(ra::T, dec::T, hours::Bool)
55
# Compute right ascension.
66
if hours
7-
ra_hr, ra_min, ra_sec = sixty(cirrange(ra, 24))
7+
ra_hr, ra_min, ra_sec = sixty(mod(ra, 24))
88
else
9-
ra_hr, ra_min, ra_sec = sixty(cirrange(ra) / 15)
9+
ra_hr, ra_min, ra_sec = sixty(mod(ra, 360) / 15)
1010
end
1111
# Compute declination.
1212
dec_deg, dec_min, dec_sec = sixty(dec)

src/rhotheta.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function _rhotheta{T<:AbstractFloat}(period::T, periastron::T, eccentricity::T,
1818
theta = omega + atan2(sin(nu + omega2)*cos(inclination), cos(nu + omega2))
1919
rho = r*cos(nu + omega2)/cos(theta - omega)
2020
# Convert theta to degrees and for it to be in [0, 360) range.
21-
theta = cirrange(rad2deg(theta))
21+
theta = mod(rad2deg(theta), 360)
2222
return rho, theta
2323
end
2424

src/sunpos.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function _sunpos{T<:AbstractFloat}(jd::T, radians::Bool)
5050
oblt = 23.452294 - 0.0130125 * t + 9.2 * cosd(omega) / 3600
5151
# Right Ascension and Declination
5252
l /= 3600
53-
ra = cirrange(atan2(sind(l)*cosd(oblt), cosd(l)), 2pi)
53+
ra = mod2pi(atan2(sind(l)*cosd(oblt), cosd(l)))
5454
dec = asin(sind(l)*sind(oblt))
5555
oblt = deg2rad(oblt)
5656
if radians

src/trueanom.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ plotting.
4848
using PyPlot
4949
M = linspace(0, 2pi, 1001)[1:end-1];
5050
for ecc in (0, 0.5, 0.9)
51-
plot(M, cirrange.(trueanom.(kepler_solver.(M, ecc), ecc), 2pi))
51+
plot(M, mod2pi.(trueanom.(kepler_solver.(M, ecc), ecc)))
5252
end
5353
```
5454

test/misc-tests.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
# This file is a part of AstroLib.jl. License is MIT "Expat".
22
# Copyright (C) 2016 Mosè Giordano.
33

4-
# Test cirrange
5-
@test cirrange(12345) 105.0
6-
@test cirrange.([3*e, 10, -86.95, 6*pi], 2*pi)
7-
[1.8716601781975495, 3.7168146928204138, 1.0145943005142044, 0.0]
8-
94
@testset "ordinal" begin
105
@test ordinal.([3, 32, 391, 2412, 1000000]) ==
116
["3rd", "32nd", "391st", "2412th", "1000000th"]

0 commit comments

Comments
 (0)