Skip to content

Commit 4dc98bb

Browse files
authored
Merge pull request #43 from JuliaAstro/parametric-methods
Use everywhere the new "where" syntax for parametric methods
2 parents 2164d54 + b3057fa commit 4dc98bb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+175
-209
lines changed

src/adstring.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ julia> adstring.([30.4, -15.63], [-1.23, 48.41], precision=1)
7777
" 22 57 28.80 +48 24 36.0"
7878
```
7979
"""
80-
function adstring{T<:AbstractFloat}(ra::T, dec::T;
81-
precision::Int=0, truncate::Bool=false)
80+
function adstring(ra::T, dec::T; precision::Int=0,
81+
truncate::Bool=false) where {T<:AbstractFloat}
8282
# XXX: IDL implementation takes also real values for "precision" and
8383
# truncates it. I think it's better to enforce an integer type and cure
8484
# only negative values.

src/airtovac.jl

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

4-
function _airtovac{T<:AbstractFloat}(wave_air::T)
4+
function airtovac(wave_air::AbstractFloat)
55
if wave_air >= 2000
66
wave_vac = wave_air
77
for iter= 1:2
@@ -60,4 +60,4 @@ julia> airtovac(6056.125)
6060
6161
Code of this function is based on IDL Astronomy User's Library.
6262
"""
63-
airtovac(wave_air::Real) = _airtovac(float(wave_air))
63+
airtovac(wave_air::Real) = airtovac(float(wave_air))

src/altaz2hadec.jl

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

4-
function _altaz2hadec{T<:AbstractFloat}(alt::T, az::T, lat::T)
4+
function altaz2hadec(alt::T, az::T, lat::T) where {T<:AbstractFloat}
55
# Convert to radians.
66
alt_r = deg2rad(alt)
77
az_r = deg2rad(az)
@@ -79,15 +79,14 @@ coordinates.
7979
Code of this function is based on IDL Astronomy User's Library.
8080
"""
8181
altaz2hadec(alt::Real, az::Real, lat::Real) =
82-
_altaz2hadec(promote(float(alt), float(az), float(lat))...)
82+
altaz2hadec(promote(float(alt), float(az), float(lat))...)
8383

8484
altaz2hadec(altaz::Tuple{Real, Real}, lat::Real) = altaz2hadec(altaz..., lat)
8585

86-
function altaz2hadec{R1<:Real, R2<:Real, R3<:Real}(alt::AbstractArray{R1},
87-
az::AbstractArray{R2},
88-
lat::AbstractArray{R3})
86+
function altaz2hadec(alt::AbstractArray{R}, az::AbstractArray{<:Real},
87+
lat::AbstractArray{<:Real}) where {R<:Real}
8988
@assert length(alt) == length(az) == length(lat)
90-
typealt = float(R1)
89+
typealt = float(R)
9190
ha = similar(alt, typealt)
9291
dec = similar(alt, typealt)
9392
for i in eachindex(alt)

src/bprecess.jl

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ const Mbprec =
1818
# Note: IDL version of `bprecess' changes in-place "muradec", "parallax" and
1919
# "radvel". We don't do anything like this, but calculations are below,
2020
# commented, in case someone is interested.
21-
function _bprecess{T<:AbstractFloat}(ra::T, dec::T, parallax::T,
22-
radvel::T, epoch::T, muradec::Vector{T})
21+
function _bprecess(ra::T, dec::T, parallax::T, radvel::T,
22+
epoch::T, muradec::Vector{T}) where {T<:AbstractFloat}
2323
@assert length(muradec) == 2
2424
cosra = cosd(ra)
2525
sinra = sind(ra)
@@ -72,32 +72,27 @@ function _bprecess{T<:AbstractFloat}(ra::T, dec::T, parallax::T,
7272
end
7373

7474
# Main interface.
75-
bprecess{R<:Real}(ra::Real, dec::Real, muradec::Vector{R};
76-
parallax::Real=0.0, radvel::Real=0.0) =
77-
_bprecess(promote(float(ra), float(dec), float(parallax),
78-
float(radvel), NaN)...,
79-
float(muradec))
75+
bprecess(ra::Real, dec::Real, muradec::Vector{<:Real}; parallax::Real=0.0, radvel::Real=0.0) =
76+
_bprecess(promote(float(ra), float(dec), float(parallax), float(radvel), NaN)...,
77+
float(muradec))
8078

8179
bprecess(ra::Real, dec::Real, epoch::Real=2000.0) =
8280
_bprecess(promote(float(ra), float(dec), 0.0, 0.0, float(epoch))...,
8381
zeros(typeof(float(ra)), 2))
8482

8583
# Tuple arguments.
86-
bprecess{R1<:Real,R2<:Real,R3<:Real}(radec::Tuple{R1,R2}, muradec::Vector{R3};
87-
parallax::Real=0.0, radvel::Real=0.0) =
88-
bprecess(radec..., muradec,
89-
parallax=parallax,
90-
radvel=radvel)
84+
bprecess(radec::Tuple{Real,Real}, muradec::Vector{<:Real};
85+
parallax::Real=0.0, radvel::Real=0.0) =
86+
bprecess(radec..., muradec, parallax=parallax, radvel=radvel)
9187

92-
bprecess{R1<:Real,R2<:Real}(radec::Tuple{R1,R2}, epoch::Real=2000.0) =
88+
bprecess(radec::Tuple{Real,Real}, epoch::Real=2000.0) =
9389
bprecess(radec..., epoch)
9490

9591
# Vectorial arguments.
96-
function bprecess{R<:Real,D<:Real,M<:Real,P<:Real,V<:Real}(ra::AbstractArray{R},
97-
dec::AbstractArray{D},
98-
muradec::AbstractArray{M};
99-
parallax::AbstractArray{P}=zeros(R, length(ra)),
100-
radvel::AbstractArray{V}=zeros(R, length(ra)))
92+
function bprecess(ra::AbstractArray{R}, dec::AbstractArray{<:Real},
93+
muradec::AbstractArray{<:Real};
94+
parallax::AbstractArray{<:Real}=zeros(R, length(ra)),
95+
radvel::AbstractArray{<:Real}=zeros(R, length(ra))) where {R<:Real}
10196
@assert length(ra) == length(dec) == size(muradec)[2] == length(parallax) == length(radvel)
10297
typer = float(R)
10398
ra1950 = similar(ra, typer)
@@ -109,9 +104,8 @@ function bprecess{R<:Real,D<:Real,M<:Real,P<:Real,V<:Real}(ra::AbstractArray{R},
109104
return ra1950, dec1950
110105
end
111106

112-
function bprecess{R<:Real,D<:Real}(ra::AbstractArray{R},
113-
dec::AbstractArray{D},
114-
epoch::Real=2000.0)
107+
function bprecess(ra::AbstractArray{R}, dec::AbstractArray{D},
108+
epoch::Real=2000.0) where {R<:Real,D<:Real}
115109
@assert length(ra) == length(dec)
116110
typer = float(R)
117111
ra1950 = similar(ra, typer)

src/co_aberration.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is a part of AstroLib.jl. License is MIT "Expat".
22

3-
function _co_aberration{T<:AbstractFloat}(jd::T, ra::T, dec::T, eps::T)
3+
function _co_aberration(jd::T, ra::T, dec::T, eps::T) where {T<:AbstractFloat}
44
t = (jd - J2000) / JULIANCENTURY
55
if isnan(eps)
66
eps = true_obliquity(jd)
@@ -86,8 +86,8 @@ This function calls [`true_obliquity`](@ref) and [`sunpos`](@ref).
8686
co_aberration(jd::Real, ra::Real, dec::Real, eps::Real=NaN) =
8787
_co_aberration(promote(float(jd), float(ra), float(dec), float(eps))...)
8888

89-
function co_aberration{R<:Real}(jd::AbstractVector{R}, ra::AbstractVector{R},
90-
dec::AbstractVector{R}, eps::Real=NaN)
89+
function co_aberration(jd::AbstractVector{R}, ra::AbstractVector{R},
90+
dec::AbstractVector{R}, eps::Real=NaN) where {R<:Real}
9191
@assert length(jd) == length(ra) == length(dec) "jd, ra and dec vectors should be of the same length"
9292
typejd = float(R)
9393
ra_out = similar(ra, typejd)

src/co_nutate.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ This function calls [`mean_obliquity`](@ref) and [`nutate`](@ref).
8484
co_nutate(jd::Real, ra::Real, dec::Real) =
8585
_co_nutate(promote(float(jd), float(ra), float(dec))...)
8686

87-
function co_nutate(jd::AbstractVector{P}, ra::AbstractVector{Q},
88-
dec::AbstractVector{R}) where {P<:Real, Q<:Real, R<:Real}
87+
function co_nutate(jd::AbstractVector{P}, ra::AbstractVector{<:Real},
88+
dec::AbstractVector{<:Real}) where {P<:Real}
8989
@assert length(jd) == length(ra) == length(dec) "jd, ra and dec vectors
9090
should be of the same length"
9191
typejd = float(P)

src/ct2lst.jl

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

4-
function ct2lst{T<:AbstractFloat}(long::T, jd::T)
4+
function ct2lst(long::T, jd::T) where {T<:AbstractFloat}
55
t0 = jd - J2000
66
t = t0 / JULIANCENTURY
77
# Compute GST in seconds.
@@ -98,13 +98,12 @@ Code of this function is based on IDL Astronomy User's Library.
9898
"""
9999
ct2lst(long::Real, jd::Real) = ct2lst(promote(float(long), float(jd))...)
100100

101-
function ct2lst{T<:AbstractFloat}(long::T, tz::T,
102-
date::DateTime)
101+
function ct2lst(long::T, tz::T, date::DateTime) where {T<:AbstractFloat}
103102
# In order to handle time zones, package "TimeZones.jl" is much better, but
104103
# here we need only to add the time zone to UTC time. All time zones I know
105104
# are either integer, or ±30 or ±45 minutes, so it should be safe enough to
106105
# convert hours to minutes and subtract minutes from "time".
107-
date = date - Dates.Minute(round(Int64, tz*60))
106+
date = date - Dates.Minute(round(Int, tz*60))
108107
return ct2lst(long, jdcnv(date))
109108
end
110109

src/deredd.jl

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

4-
function _deredd{T<:AbstractFloat}(Eby::T, by::T, m1::T, c1::T, ub::T)
4+
function deredd(Eby::T, by::T, m1::T, c1::T, ub::T) where {T<:AbstractFloat}
55
Rm1 = -0.33
66
Rc1 = 0.19
77
Rub = 1.53
@@ -51,13 +51,11 @@ julia> deredd(0.5, 0.2, 1.0, 1.0, 0.1)
5151
Code of this function is based on IDL Astronomy User's Library.
5252
"""
5353
deredd(Eby::Real, by::Real, m1::Real, c1::Real, ub::Real) =
54-
_deredd(promote(float(Eby), float(by), float(m1), float(c1), float(ub))...)
54+
deredd(promote(float(Eby), float(by), float(m1), float(c1), float(ub))...)
5555

56-
function deredd{E<:Real, B<:Real, M<:Real, C<:Real, U<:Real}(Eby::AbstractArray{E},
57-
by::AbstractArray{B},
58-
m1::AbstractArray{M},
59-
c1::AbstractArray{C},
60-
ub::AbstractArray{U})
56+
function deredd(Eby::AbstractArray{E}, by::AbstractArray{<:Real},
57+
m1::AbstractArray{<:Real}, c1::AbstractArray{<:Real},
58+
ub::AbstractArray{<:Real}) where {E<:Real}
6159
@assert length(Eby) == length(by) == length(m1) == length(c1) == length(ub)
6260
typeeby = float(E)
6361
by0 = similar(Eby, typeeby)

src/eci2geo.jl

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

4-
function _eci2geo{T<:AbstractFloat}(x::T, y::T, z::T, jd::T)
4+
function eci2geo(x::T, y::T, z::T, jd::T) where {T<:AbstractFloat}
55
Re = planets["earth"].eqradius*1e-3
66
theta = atan2(y, x) # Azimuth.
77
gst = ct2lst(zero(T), jd)
@@ -78,15 +78,13 @@ coordinates.
7878
Code of this function is based on IDL Astronomy User's Library.
7979
"""
8080
eci2geo(x::Real, y::Real, z::Real, jd::Real) =
81-
_eci2geo(promote(float(x), float(y), float(z), float(jd))...)
81+
eci2geo(promote(float(x), float(y), float(z), float(jd))...)
8282

8383
eci2geo(xyz::Tuple{Real, Real, Real}, jd::Real) =
8484
eci2geo(xyz..., jd)
8585

86-
function eci2geo{X<:Real, Y<:Real, Z<:Real, JD<:Real}(x::AbstractArray{X},
87-
y::AbstractArray{Y},
88-
z::AbstractArray{Z},
89-
jd::AbstractArray{JD})
86+
function eci2geo(x::AbstractArray{X}, y::AbstractArray{<:Real}, z::AbstractArray{<:Real},
87+
jd::AbstractArray{<:Real}) where {X<:Real}
9088
@assert length(x) == length(y) == length(z) == length(jd)
9189
typex = float(X)
9290
lat = similar(x, typex)

src/eqpole.jl

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

4-
function _eqpole{T<:AbstractFloat}(l::T, b::T, southpole::Bool)
4+
function _eqpole(l::T, b::T, southpole::Bool) where {T<:AbstractFloat}
55
sgn = southpole ? -1 : 1
66
l = deg2rad(sgn*l)
77
b = deg2rad(sgn*b)
8-
r = 18 * 3.53553391 * sqrt(2 * (1 - sin(b)))
8+
r = 18 * sqrt(2 * (1 - sin(b))) * 3.53553391
99
return r*sin(l), r*cos(l)
1010
end
1111

@@ -59,9 +59,8 @@ Code of this function is based on IDL Astronomy User's Library.
5959
eqpole(l::Real, b::Real; southpole::Bool=false) =
6060
_eqpole(promote(float(l), float(b))..., southpole)
6161

62-
function eqpole{L<:Real, B<:Real}(l::AbstractArray{L},
63-
b::AbstractArray{B};
64-
southpole::Bool=false)
62+
function eqpole(l::AbstractArray{L}, b::AbstractArray{<:Real};
63+
southpole::Bool=false) where {L<:Real}
6564
@assert length(l) == length(b)
6665
typel = float(L)
6766
x = similar(l, typel)

src/euler.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is a part of AstroLib.jl. License is MIT "Expat".
22

3-
function _euler{T<:AbstractFloat}(ai::T, bi::T, select::Integer, FK4::Bool, radians::Bool)
3+
function _euler(ai::T, bi::T, select::Integer, FK4::Bool, radians::Bool) where {T<:AbstractFloat}
44

55
if select>6 || select<1
66
error("Input for coordinate transformation should be an integer in the range 1:6")

src/flux2mag.jl

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

4-
function _flux2mag{T<:AbstractFloat}(flux::T, zero_point::T, ABwave::T)
4+
function _flux2mag(flux::T, zero_point::T, ABwave::T) where {T<:AbstractFloat}
55
if isnan(ABwave)
66
return -2.5*log10(flux) - zero_point
77
else

src/gal_uvw.jl

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

4-
function _gal_uvw{T<:AbstractFloat}(ra::T, dec::T, pmra::T, pmdec::T,
5-
vrad::T, plx::T, lsr::Bool)
4+
function _gal_uvw(ra::T, dec::T, pmra::T, pmdec::T, vrad::T,
5+
plx::T, lsr::Bool) where {T<:AbstractFloat}
66
cosdec = cosd(dec)
77
sindec = sind(dec)
88
cosra = cosd(ra)
@@ -127,15 +127,10 @@ gal_uvw(ra::Real, dec::Real, pmra::Real, pmdec::Real,
127127
_gal_uvw(promote(float(ra), float(dec), float(pmra), float(pmdec),
128128
float(vrad), float(plx))..., lsr)
129129

130-
function gal_uvw{R<:Real,
131-
D<:Real,
132-
PR<:Real,
133-
PD<:Real,
134-
VR<:Real,
135-
PL<:Real}(ra::AbstractArray{R}, dec::AbstractArray{D},
136-
pmra::AbstractArray{PR}, pmdec::AbstractArray{PD},
137-
vrad::AbstractArray{VR}, plx::AbstractArray{PL};
138-
lsr::Bool=false)
130+
function gal_uvw(ra::AbstractArray{R}, dec::AbstractArray{<:Real},
131+
pmra::AbstractArray{<:Real}, pmdec::AbstractArray{<:Real},
132+
vrad::AbstractArray{<:Real}, plx::AbstractArray{<:Real};
133+
lsr::Bool=false) where {R<:Real}
139134
@assert length(ra) == length(dec) == length(pmra) ==
140135
length(pmdec) == length(vrad) == length(plx)
141136
typer = float(R)

src/gcirc.jl

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

4-
function _gcirc{T<:AbstractFloat}(units::Integer, ra1::T, dec1::T, ra2::T, dec2::T)
4+
function gcirc(units::Integer, ra1::T, dec1::T, ra2::T, dec2::T) where {T<:AbstractFloat}
55
# Convert all quantities to radians.
66
if units == 0
77
# All radians
@@ -92,7 +92,7 @@ julia> gcirc(0, 120, -43, 175, +22)
9292
Code of this function is based on IDL Astronomy User's Library.
9393
"""
9494
gcirc(units::Integer, ra1::Real, dec1::Real, ra2::Real, dec2::Real) =
95-
_gcirc(units, promote(float(ra1), float(dec1), float(ra2), float(dec2))...)
95+
gcirc(units, promote(float(ra1), float(dec1), float(ra2), float(dec2))...)
9696

9797
### Tuples input
9898
gcirc(units::Integer, radec1::Tuple{Real, Real}, ra2::Real, dec2::Real) =

src/geo2eci.jl

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

4-
function geo2eci{T<:AbstractFloat}(lat::T, long::T, alt::T, jd::T)
5-
Re = planets["earth"].eqradius*1e-3
4+
function geo2eci(lat::T, long::T, alt::T, jd::T) where {T<:AbstractFloat}
5+
Re = planets["earth"].eqradius / 1000
66
lat = deg2rad(lat)
77
long = deg2rad(long)
88
gst = ct2lst(zero(T), jd)
@@ -74,10 +74,9 @@ geo2eci(lat::Real, long::Real, alt::Real, jd::Real) =
7474
geo2eci(lla::Tuple{Real, Real, Real}, jd::Real) =
7575
geo2eci(lla..., jd)
7676

77-
function geo2eci{LA<:Real, LO<:Real, AL<:Real, JD<:Real}(lat::AbstractArray{LA},
78-
long::AbstractArray{LO},
79-
alt::AbstractArray{AL},
80-
jd::AbstractArray{JD})
77+
function geo2eci(lat::AbstractArray{LA}, long::AbstractArray{<:Real},
78+
alt::AbstractArray{<:Real},
79+
jd::AbstractArray{<:Real}) where {LA<:Real}
8180
@assert length(lat) == length(long) == length(alt) == length(jd)
8281
typela = float(LA)
8382
x = similar(lat, typela)

src/geo2geodetic.jl

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

4-
function geo2geodetic{T<:AbstractFloat}(lat::T, long::T, alt::T, eqrad::T, polrad::T)
4+
function geo2geodetic(lat::T, long::T, alt::T, eqrad::T, polrad::T) where {T<:AbstractFloat}
55
e = sqrt(eqrad^2 - polrad^2)/eqrad
66
lat = deg2rad(lat)
77
long_rad = deg2rad(long)
@@ -156,10 +156,9 @@ geo2geodetic(lat::Real, long::Real, alt::Real, eq::Real, pol::Real) =
156156
geo2geodetic(lla::Tuple{Real, Real, Real}, eq::Real, pol::Real) =
157157
geo2geodetic(lla..., eq, pol)
158158

159-
function geo2geodetic{LA<:Real, LO<:Real, AL<:Real}(lat::AbstractArray{LA},
160-
long::AbstractArray{LO},
161-
alt::AbstractArray{AL},
162-
eq::Real, pol::Real)
159+
function geo2geodetic(lat::AbstractArray{LA}, long::AbstractArray{<:Real},
160+
alt::AbstractArray{<:Real},
161+
eq::Real, pol::Real) where {LA<:Real}
163162
@assert length(lat) == length(long) == length(alt)
164163
typela = float(LA)
165164
outlat = similar(lat, typela)
@@ -181,10 +180,9 @@ geo2geodetic(lat::Real, long::Real, alt::Real, planet::AbstractString="earth") =
181180
geo2geodetic(lla::Tuple{Real, Real, Real}, planet::AbstractString="earth") =
182181
geo2geodetic(lla..., planet)
183182

184-
function geo2geodetic{LA<:Real, LO<:Real, AL<:Real}(lat::AbstractArray{LA},
185-
long::AbstractArray{LO},
186-
alt::AbstractArray{AL},
187-
planet::AbstractString="earth")
183+
function geo2geodetic(lat::AbstractArray{LA}, long::AbstractArray{<:Real},
184+
alt::AbstractArray{<:Real},
185+
planet::AbstractString="earth") where {LA<:Real}
188186
@assert length(lat) == length(long) == length(alt)
189187
typela = float(LA)
190188
outlat = similar(lat, typela)

0 commit comments

Comments
 (0)