Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use everywhere the new "where" syntax for parametric methods #43

Merged
merged 1 commit into from
Sep 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/adstring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ julia> adstring.([30.4, -15.63], [-1.23, 48.41], precision=1)
" 22 57 28.80 +48 24 36.0"
```
"""
function adstring{T<:AbstractFloat}(ra::T, dec::T;
precision::Int=0, truncate::Bool=false)
function adstring(ra::T, dec::T; precision::Int=0,
truncate::Bool=false) where {T<:AbstractFloat}
# XXX: IDL implementation takes also real values for "precision" and
# truncates it. I think it's better to enforce an integer type and cure
# only negative values.
Expand Down
4 changes: 2 additions & 2 deletions src/airtovac.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file is a part of AstroLib.jl. License is MIT "Expat".
# Copyright (C) 2016 Mosè Giordano.

function _airtovac{T<:AbstractFloat}(wave_air::T)
function airtovac(wave_air::AbstractFloat)
if wave_air >= 2000
wave_vac = wave_air
for iter= 1:2
Expand Down Expand Up @@ -60,4 +60,4 @@ julia> airtovac(6056.125)

Code of this function is based on IDL Astronomy User's Library.
"""
airtovac(wave_air::Real) = _airtovac(float(wave_air))
airtovac(wave_air::Real) = airtovac(float(wave_air))
11 changes: 5 additions & 6 deletions src/altaz2hadec.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file is a part of AstroLib.jl. License is MIT "Expat".
# Copyright (C) 2016 Mosè Giordano.

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

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

function altaz2hadec{R1<:Real, R2<:Real, R3<:Real}(alt::AbstractArray{R1},
az::AbstractArray{R2},
lat::AbstractArray{R3})
function altaz2hadec(alt::AbstractArray{R}, az::AbstractArray{<:Real},
lat::AbstractArray{<:Real}) where {R<:Real}
@assert length(alt) == length(az) == length(lat)
typealt = float(R1)
typealt = float(R)
ha = similar(alt, typealt)
dec = similar(alt, typealt)
for i in eachindex(alt)
Expand Down
36 changes: 15 additions & 21 deletions src/bprecess.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const Mbprec =
# Note: IDL version of `bprecess' changes in-place "muradec", "parallax" and
# "radvel". We don't do anything like this, but calculations are below,
# commented, in case someone is interested.
function _bprecess{T<:AbstractFloat}(ra::T, dec::T, parallax::T,
radvel::T, epoch::T, muradec::Vector{T})
function _bprecess(ra::T, dec::T, parallax::T, radvel::T,
epoch::T, muradec::Vector{T}) where {T<:AbstractFloat}
@assert length(muradec) == 2
cosra = cosd(ra)
sinra = sind(ra)
Expand Down Expand Up @@ -72,32 +72,27 @@ function _bprecess{T<:AbstractFloat}(ra::T, dec::T, parallax::T,
end

# Main interface.
bprecess{R<:Real}(ra::Real, dec::Real, muradec::Vector{R};
parallax::Real=0.0, radvel::Real=0.0) =
_bprecess(promote(float(ra), float(dec), float(parallax),
float(radvel), NaN)...,
float(muradec))
bprecess(ra::Real, dec::Real, muradec::Vector{<:Real}; parallax::Real=0.0, radvel::Real=0.0) =
_bprecess(promote(float(ra), float(dec), float(parallax), float(radvel), NaN)...,
float(muradec))

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

# Tuple arguments.
bprecess{R1<:Real,R2<:Real,R3<:Real}(radec::Tuple{R1,R2}, muradec::Vector{R3};
parallax::Real=0.0, radvel::Real=0.0) =
bprecess(radec..., muradec,
parallax=parallax,
radvel=radvel)
bprecess(radec::Tuple{Real,Real}, muradec::Vector{<:Real};
parallax::Real=0.0, radvel::Real=0.0) =
bprecess(radec..., muradec, parallax=parallax, radvel=radvel)

bprecess{R1<:Real,R2<:Real}(radec::Tuple{R1,R2}, epoch::Real=2000.0) =
bprecess(radec::Tuple{Real,Real}, epoch::Real=2000.0) =
bprecess(radec..., epoch)

# Vectorial arguments.
function bprecess{R<:Real,D<:Real,M<:Real,P<:Real,V<:Real}(ra::AbstractArray{R},
dec::AbstractArray{D},
muradec::AbstractArray{M};
parallax::AbstractArray{P}=zeros(R, length(ra)),
radvel::AbstractArray{V}=zeros(R, length(ra)))
function bprecess(ra::AbstractArray{R}, dec::AbstractArray{<:Real},
muradec::AbstractArray{<:Real};
parallax::AbstractArray{<:Real}=zeros(R, length(ra)),
radvel::AbstractArray{<:Real}=zeros(R, length(ra))) where {R<:Real}
@assert length(ra) == length(dec) == size(muradec)[2] == length(parallax) == length(radvel)
typer = float(R)
ra1950 = similar(ra, typer)
Expand All @@ -109,9 +104,8 @@ function bprecess{R<:Real,D<:Real,M<:Real,P<:Real,V<:Real}(ra::AbstractArray{R},
return ra1950, dec1950
end

function bprecess{R<:Real,D<:Real}(ra::AbstractArray{R},
dec::AbstractArray{D},
epoch::Real=2000.0)
function bprecess(ra::AbstractArray{R}, dec::AbstractArray{D},
epoch::Real=2000.0) where {R<:Real,D<:Real}
@assert length(ra) == length(dec)
typer = float(R)
ra1950 = similar(ra, typer)
Expand Down
6 changes: 3 additions & 3 deletions src/co_aberration.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is a part of AstroLib.jl. License is MIT "Expat".

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

function co_aberration{R<:Real}(jd::AbstractVector{R}, ra::AbstractVector{R},
dec::AbstractVector{R}, eps::Real=NaN)
function co_aberration(jd::AbstractVector{R}, ra::AbstractVector{R},
dec::AbstractVector{R}, eps::Real=NaN) where {R<:Real}
@assert length(jd) == length(ra) == length(dec) "jd, ra and dec vectors should be of the same length"
typejd = float(R)
ra_out = similar(ra, typejd)
Expand Down
4 changes: 2 additions & 2 deletions src/co_nutate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ This function calls [`mean_obliquity`](@ref) and [`nutate`](@ref).
co_nutate(jd::Real, ra::Real, dec::Real) =
_co_nutate(promote(float(jd), float(ra), float(dec))...)

function co_nutate(jd::AbstractVector{P}, ra::AbstractVector{Q},
dec::AbstractVector{R}) where {P<:Real, Q<:Real, R<:Real}
function co_nutate(jd::AbstractVector{P}, ra::AbstractVector{<:Real},
dec::AbstractVector{<:Real}) where {P<:Real}
@assert length(jd) == length(ra) == length(dec) "jd, ra and dec vectors
should be of the same length"
typejd = float(P)
Expand Down
7 changes: 3 additions & 4 deletions src/ct2lst.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file is a part of AstroLib.jl. License is MIT "Expat".
# Copyright (C) 2016 Mosè Giordano.

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

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

Expand Down
12 changes: 5 additions & 7 deletions src/deredd.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file is a part of AstroLib.jl. License is MIT "Expat".
# Copyright (C) 2016 Mosè Giordano.

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

function deredd{E<:Real, B<:Real, M<:Real, C<:Real, U<:Real}(Eby::AbstractArray{E},
by::AbstractArray{B},
m1::AbstractArray{M},
c1::AbstractArray{C},
ub::AbstractArray{U})
function deredd(Eby::AbstractArray{E}, by::AbstractArray{<:Real},
m1::AbstractArray{<:Real}, c1::AbstractArray{<:Real},
ub::AbstractArray{<:Real}) where {E<:Real}
@assert length(Eby) == length(by) == length(m1) == length(c1) == length(ub)
typeeby = float(E)
by0 = similar(Eby, typeeby)
Expand Down
10 changes: 4 additions & 6 deletions src/eci2geo.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file is a part of AstroLib.jl. License is MIT "Expat".
# Copyright (C) 2016 Mosè Giordano.

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

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

function eci2geo{X<:Real, Y<:Real, Z<:Real, JD<:Real}(x::AbstractArray{X},
y::AbstractArray{Y},
z::AbstractArray{Z},
jd::AbstractArray{JD})
function eci2geo(x::AbstractArray{X}, y::AbstractArray{<:Real}, z::AbstractArray{<:Real},
jd::AbstractArray{<:Real}) where {X<:Real}
@assert length(x) == length(y) == length(z) == length(jd)
typex = float(X)
lat = similar(x, typex)
Expand Down
9 changes: 4 additions & 5 deletions src/eqpole.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# This file is a part of AstroLib.jl. License is MIT "Expat".
# Copyright (C) 2016 Mosè Giordano.

function _eqpole{T<:AbstractFloat}(l::T, b::T, southpole::Bool)
function _eqpole(l::T, b::T, southpole::Bool) where {T<:AbstractFloat}
sgn = southpole ? -1 : 1
l = deg2rad(sgn*l)
b = deg2rad(sgn*b)
r = 18 * 3.53553391 * sqrt(2 * (1 - sin(b)))
r = 18 * sqrt(2 * (1 - sin(b))) * 3.53553391
return r*sin(l), r*cos(l)
end

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

function eqpole{L<:Real, B<:Real}(l::AbstractArray{L},
b::AbstractArray{B};
southpole::Bool=false)
function eqpole(l::AbstractArray{L}, b::AbstractArray{<:Real};
southpole::Bool=false) where {L<:Real}
@assert length(l) == length(b)
typel = float(L)
x = similar(l, typel)
Expand Down
2 changes: 1 addition & 1 deletion src/euler.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is a part of AstroLib.jl. License is MIT "Expat".

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

if select>6 || select<1
error("Input for coordinate transformation should be an integer in the range 1:6")
Expand Down
2 changes: 1 addition & 1 deletion src/flux2mag.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file is a part of AstroLib.jl. License is MIT "Expat".
# Copyright (C) 2016 Mosè Giordano.

function _flux2mag{T<:AbstractFloat}(flux::T, zero_point::T, ABwave::T)
function _flux2mag(flux::T, zero_point::T, ABwave::T) where {T<:AbstractFloat}
if isnan(ABwave)
return -2.5*log10(flux) - zero_point
else
Expand Down
17 changes: 6 additions & 11 deletions src/gal_uvw.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# This file is a part of AstroLib.jl. License is MIT "Expat".
# Copyright (C) 2016 Mosè Giordano.

function _gal_uvw{T<:AbstractFloat}(ra::T, dec::T, pmra::T, pmdec::T,
vrad::T, plx::T, lsr::Bool)
function _gal_uvw(ra::T, dec::T, pmra::T, pmdec::T, vrad::T,
plx::T, lsr::Bool) where {T<:AbstractFloat}
cosdec = cosd(dec)
sindec = sind(dec)
cosra = cosd(ra)
Expand Down Expand Up @@ -127,15 +127,10 @@ gal_uvw(ra::Real, dec::Real, pmra::Real, pmdec::Real,
_gal_uvw(promote(float(ra), float(dec), float(pmra), float(pmdec),
float(vrad), float(plx))..., lsr)

function gal_uvw{R<:Real,
D<:Real,
PR<:Real,
PD<:Real,
VR<:Real,
PL<:Real}(ra::AbstractArray{R}, dec::AbstractArray{D},
pmra::AbstractArray{PR}, pmdec::AbstractArray{PD},
vrad::AbstractArray{VR}, plx::AbstractArray{PL};
lsr::Bool=false)
function gal_uvw(ra::AbstractArray{R}, dec::AbstractArray{<:Real},
pmra::AbstractArray{<:Real}, pmdec::AbstractArray{<:Real},
vrad::AbstractArray{<:Real}, plx::AbstractArray{<:Real};
lsr::Bool=false) where {R<:Real}
@assert length(ra) == length(dec) == length(pmra) ==
length(pmdec) == length(vrad) == length(plx)
typer = float(R)
Expand Down
4 changes: 2 additions & 2 deletions src/gcirc.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file is a part of AstroLib.jl. License is MIT "Expat".
# Copyright (C) 2016 Mosè Giordano.

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

### Tuples input
gcirc(units::Integer, radec1::Tuple{Real, Real}, ra2::Real, dec2::Real) =
Expand Down
11 changes: 5 additions & 6 deletions src/geo2eci.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# This file is a part of AstroLib.jl. License is MIT "Expat".
# Copyright (C) 2016 Mosè Giordano.

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

function geo2eci{LA<:Real, LO<:Real, AL<:Real, JD<:Real}(lat::AbstractArray{LA},
long::AbstractArray{LO},
alt::AbstractArray{AL},
jd::AbstractArray{JD})
function geo2eci(lat::AbstractArray{LA}, long::AbstractArray{<:Real},
alt::AbstractArray{<:Real},
jd::AbstractArray{<:Real}) where {LA<:Real}
@assert length(lat) == length(long) == length(alt) == length(jd)
typela = float(LA)
x = similar(lat, typela)
Expand Down
16 changes: 7 additions & 9 deletions src/geo2geodetic.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file is a part of AstroLib.jl. License is MIT "Expat".
# Copyright (C) 2016 Mosè Giordano.

function geo2geodetic{T<:AbstractFloat}(lat::T, long::T, alt::T, eqrad::T, polrad::T)
function geo2geodetic(lat::T, long::T, alt::T, eqrad::T, polrad::T) where {T<:AbstractFloat}
e = sqrt(eqrad^2 - polrad^2)/eqrad
lat = deg2rad(lat)
long_rad = deg2rad(long)
Expand Down Expand Up @@ -156,10 +156,9 @@ geo2geodetic(lat::Real, long::Real, alt::Real, eq::Real, pol::Real) =
geo2geodetic(lla::Tuple{Real, Real, Real}, eq::Real, pol::Real) =
geo2geodetic(lla..., eq, pol)

function geo2geodetic{LA<:Real, LO<:Real, AL<:Real}(lat::AbstractArray{LA},
long::AbstractArray{LO},
alt::AbstractArray{AL},
eq::Real, pol::Real)
function geo2geodetic(lat::AbstractArray{LA}, long::AbstractArray{<:Real},
alt::AbstractArray{<:Real},
eq::Real, pol::Real) where {LA<:Real}
@assert length(lat) == length(long) == length(alt)
typela = float(LA)
outlat = similar(lat, typela)
Expand All @@ -181,10 +180,9 @@ geo2geodetic(lat::Real, long::Real, alt::Real, planet::AbstractString="earth") =
geo2geodetic(lla::Tuple{Real, Real, Real}, planet::AbstractString="earth") =
geo2geodetic(lla..., planet)

function geo2geodetic{LA<:Real, LO<:Real, AL<:Real}(lat::AbstractArray{LA},
long::AbstractArray{LO},
alt::AbstractArray{AL},
planet::AbstractString="earth")
function geo2geodetic(lat::AbstractArray{LA}, long::AbstractArray{<:Real},
alt::AbstractArray{<:Real},
planet::AbstractString="earth") where {LA<:Real}
@assert length(lat) == length(long) == length(alt)
typela = float(LA)
outlat = similar(lat, typela)
Expand Down
Loading