Skip to content

Commit

Permalink
Use new dot syntax for vector functions
Browse files Browse the repository at this point in the history
Drop support for Julia 0.4.
  • Loading branch information
giordano committed Dec 14, 2016
1 parent 2908781 commit 90472bb
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 38 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -4,7 +4,6 @@ os:
- linux
- osx
julia:
- 0.4
- 0.5
- nightly
notifications:
Expand Down
11 changes: 5 additions & 6 deletions README.md
Expand Up @@ -2,9 +2,8 @@

| **Documentation** | [**Package Evaluator**][pkgeval-link] | **Build Status** | **Code Coverage** |
|:---------------------------------------:|:-------------------------------------:|:-----------------------------------------:|:-------------------------------:|
| [![][docs-stable-img]][docs-stable-url] | [![][pkg-0.4-img]][pkg-0.4-url] | [![Build Status][travis-img]][travis-url] | [![][coveral-img]][coveral-url] |
| [![][docs-latest-img]][docs-latest-url] | [![][pkg-0.5-img]][pkg-0.5-url] | [![Build Status][appvey-img]][appvey-url] | [![][codecov-img]][codecov-url] |
| | [![][pkg-0.6-img]][pkg-0.6-url] | | |
| [![][docs-stable-img]][docs-stable-url] | [![][pkg-0.5-img]][pkg-0.5-url] | [![Build Status][travis-img]][travis-url] | [![][coveral-img]][coveral-url] |
| [![][docs-latest-img]][docs-latest-url] | [![][pkg-0.6-img]][pkg-0.6-url] | [![Build Status][appvey-img]][appvey-url] | [![][codecov-img]][codecov-url] |

Introduction
------------
Expand Down Expand Up @@ -64,7 +63,7 @@ https://media.readthedocs.org/pdf/lombscarglejl/latest/lombscarglejl.pdf.
Installation
------------

`LombScargle.jl` is available for Julia 0.4 and later versions, and can be
`LombScargle.jl` is available for Julia 0.5 and later versions, and can be
installed with
[Julia built-in package manager](http://docs.julialang.org/en/stable/manual/packages/).
In a Julia session run the commands
Expand All @@ -74,6 +73,8 @@ julia> Pkg.update()
julia> Pkg.add("LombScargle")
```

Older versions are also available for Julia 0.4.

Usage
-----

Expand Down Expand Up @@ -449,8 +450,6 @@ periodogram in Astropy, in particular for the fast method by Press & Rybicki

[pkgeval-link]: http://pkg.julialang.org/?pkg=LombScargle

[pkg-0.4-img]: http://pkg.julialang.org/badges/LombScargle_0.4.svg
[pkg-0.4-url]: http://pkg.julialang.org/detail/LombScargle.html
[pkg-0.5-img]: http://pkg.julialang.org/badges/LombScargle_0.5.svg
[pkg-0.5-url]: http://pkg.julialang.org/detail/LombScargle.html
[pkg-0.6-img]: http://pkg.julialang.org/badges/LombScargle_0.6.svg
Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
@@ -1,2 +1,2 @@
julia 0.4
julia 0.5
Measurements 0.2.0
2 changes: 0 additions & 2 deletions appveyor.yml
@@ -1,7 +1,5 @@
environment:
matrix:
- JULIAVERSION: "julialang/bin/winnt/x86/0.4/julia-0.4-latest-win32.exe"
- JULIAVERSION: "julialang/bin/winnt/x64/0.4/julia-0.4-latest-win64.exe"
- JULIAVERSION: "julialang/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe"
- JULIAVERSION: "julialang/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe"
- JULIAVERSION: "julianightlies/bin/winnt/x86/julia-latest-win32.exe"
Expand Down
4 changes: 3 additions & 1 deletion docs/index.rst
Expand Up @@ -72,7 +72,7 @@ The package provides facilities to:
Installation
------------

``LombScargle.jl`` is available for Julia 0.4 and later versions, and can be
``LombScargle.jl`` is available for Julia 0.5 and later versions, and can be
installed with `Julia built-in package manager
<http://docs.julialang.org/en/stable/manual/packages/>`__. In a Julia session
run the commands
Expand All @@ -82,6 +82,8 @@ run the commands
julia> Pkg.update()
julia> Pkg.add("LombScargle")
Older versions are also available for Julia 0.4.

Usage
-----

Expand Down
8 changes: 4 additions & 4 deletions src/LombScargle.jl
Expand Up @@ -217,10 +217,10 @@ function _press_rybicki{R1<:Real,R2<:Real,R3<:Real,R4<:Real}(times::AbstractVect
# ωτ = 0.5 * atan(tan_2ωτ)
# S2w, C2w = sin(2 * ωτ), cos(2 * ωτ)
# Sw, Cw = sin(ωτ), cos(ωτ)
C2w = 1./(sqrt(1.0 + tan_2ωτ .* tan_2ωτ))
C2w = 1./(sqrt.(1.0 + tan_2ωτ .* tan_2ωτ))
S2w = tan_2ωτ .* C2w
Cw = sqrt(0.5 * (1.0 + C2w))
Sw = sqrt(0.5) .* sign(S2w) .* sqrt(1.0 - C2w)
Cw = sqrt.(0.5 * (1.0 + C2w))
Sw = sqrt(0.5) .* sign(S2w) .* sqrt.(1.0 - C2w)
#---------------------------------------------------------------------------
# 2. Compute the periodogram, following Zechmeister & Kurster
# and using tricks from Press & Rybicki.
Expand Down Expand Up @@ -318,7 +318,7 @@ function _lombscargle{R1<:Real,R2<:Real,R3<:Real,R4<:Real}(times::AbstractVector
elseif normalization == "model"
P = P./(1.0 - P)
elseif normalization == "log"
P = -log(1.0 - P)
P = -log.(1.0 - P)
elseif normalization == "psd"
P *= 0.5*N*(wsignal.^2)
elseif normalization == "Scargle"
Expand Down
4 changes: 2 additions & 2 deletions src/extirpolation.jl
Expand Up @@ -75,14 +75,14 @@ function trig_sum{R1<:Real,R2<:Real}(t::AbstractVector{R1},
Nfft = nextpow2(N * oversampling)
t0 = minimum(t)
if f0 > 0
h = h .* exp(2im * pi * f0 * (t - t0))
h = h .* exp.(2im * pi * f0 * (t - t0))
end
tnorm = mod(((t - t0) * Nfft * df), Nfft)
grid = extirpolate(tnorm, h, Nfft, Mfft)
fftgrid = Nfft * ifft(grid)[1:N]
if t0 != 0
f = f0 + df * (0:N - 1)
fftgrid .*= exp(2im * pi * t0 * f)
fftgrid .*= exp.(2im * pi * t0 * f)
end
C = real(fftgrid)
S = imag(fftgrid)
Expand Down
10 changes: 5 additions & 5 deletions src/utils.jl
Expand Up @@ -278,16 +278,16 @@ function model{R1<:Real,R2<:Real,R3<:Real,R4<:Real}(t::AbstractVector{R1},
# a·cos(ωt) + b·sin(ωt) + c
# In order to find the coefficients a, b, c for the given frequency we can
# solve the linear system A·x = y, where A is the matrix with rows:
# [cos(ωt), sin(ωt), 1]; x is the column vector [a, b, c], and y is the
# [cos(ωt) sin(ωt) 1]; x is the column vector [a, b, c], and y is the
# column vector of the signal
ω = 2pi*f
if fit_mean
a, b, c = hcat(cos*t), sin*t), ones(t))./errors \ y
return a*cos*t_fit) + b*sin*t_fit) + (c + m)
a, b, c = [cos.*t) sin.*t) ones(t)]./errors \ y
return a*cos.*t_fit) + b*sin.*t_fit) + (c + m)
else
# If fit_mean==false, the model to be fitted is a·cos(ωt) + b·sin(ωt)
a, b = hcat(cos*t), sin*t))./errors \ y
return a*cos*t_fit) + b*sin*t_fit) + m
a, b = [cos.*t) sin.*t)] ./ errors \ y
return a*cos.*t_fit) + b*sin.*t_fit) + m
end
end

Expand Down
8 changes: 4 additions & 4 deletions test/astropy.jl
Expand Up @@ -9,7 +9,7 @@ ntimes = 401
# Un-evenly spaced data.
t = linspace(0.01, 10pi, ntimes)
t += step(t)*rand(ntimes)
for f in (x -> sinpi(x), x -> sin(x) + 1.5*cospi(4*x) + 3)
for f in (x -> sinpi.(x), x -> sin.(x) + 1.5*cospi.(4*x) + 3)
s = f(t)
# "psd" normalization in LombScargle slightly differ from that of
# Astropy and the test would fail if we includ it.
Expand All @@ -33,7 +33,7 @@ end
# Evenly spaced data. Use both heteroskedastic and homoskedastic uncertainties.
t = linspace(0.01, 10pi, ntimes)
errors = rand(0.1:1e-3:4.0, ntimes)
for f in (x -> sinpi(x), x -> sin(x) + 1.5*cospi(4*x) + 3), err in (ones(ntimes), errors)
for f in (x -> sinpi.(x), x -> sin.(x) + 1.5*cospi.(4*x) + 3), err in (ones(ntimes), errors)
s = f(t)
# "psd" normalization in LombScargle slightly differ from that of
# Astropy and the test would fail if we includ it.
Expand Down Expand Up @@ -61,7 +61,7 @@ end
# Test heteroskedastic uncertainties with non-fast method. Test only standard
# normalization, the only one for which LombScargle and Astropy give similar
# results.
for f in (x -> sinpi(x), x -> sin(x) + 1.5*cospi(4*x) + 3)
for f in (x -> sinpi.(x), x -> sin.(x) + 1.5*cospi.(4*x) + 3)
s = f(t)
for fitmean in (true, false), nrm in ("standard", "model"),
fast in ((true, "fast"), (false, "cython")), center in (true, false)
Expand All @@ -83,7 +83,7 @@ for f in (x -> sinpi(x), x -> sin(x) + 1.5*cospi(4*x) + 3)
end

# Test the model functions
for f in (x -> sinpi(x), x -> sin(x) + 1.5*cospi(4*x) + 3)
for f in (x -> sinpi.(x), x -> sin.(x) + 1.5*cospi.(4*x) + 3)
s = f(t)
for fm in (true, false), cd in (true, false)
m_jl = LombScargle.model(t, s, 1/2pi, fit_mean=fm, center_data=cd)
Expand Down
24 changes: 12 additions & 12 deletions test/runtests.jl
Expand Up @@ -11,7 +11,7 @@ t = linspace(0.01, 10pi, ntimes)
# Randomize times
t += step(t)*rand(ntimes)
# The signal
s = sinpi(t) + cospi(2t) + rand(ntimes)
s = sinpi.(t) + cospi.(2t) + rand(ntimes)
# Frequency grid
nfreqs = 10000
freqs = linspace(0.01, 3, nfreqs)
Expand All @@ -28,7 +28,7 @@ Sys.WORD_SIZE == 64 && @test(!(Inf in power(pgram1)) && !(Inf in power(pgram2)))

# Simple signal, without any randomness
t = collect(linspace(0.01, 10pi, ntimes))
s = sin(t)
s = sin.(t)
pgram1 = lombscargle(t, s, fast = false, fit_mean=false)
pgram2 = lombscargle(t, s, fast = false, fit_mean=true)
@test_approx_eq_eps power(pgram1) power(pgram2) 2e-7
Expand All @@ -55,11 +55,11 @@ err = collect(linspace(0.5, 1.5, ntimes))
@test_approx_eq power(lombscargle(t, s, err, frequencies=0.1:0.1:1, fit_mean=false)) [0.0664002483305464,0.09219168665786254,0.006625915010614472,0.0015663421089042564,0.0005085109569237008,0.00019703233981948823,9.6577091433651e-5,6.33101344670203e-5,4.9033581990442793e-5,3.7944076990210425e-5]
@test_approx_eq power(lombscargle(t, s, err, frequencies=0.1:0.1:1, fit_mean=false, center_data=false)) [0.06920814049261209,0.09360344864985352,0.006634919960009565,0.0015362072871144769,0.0004858250831632676,0.00018179850370583626,8.543727416919218e-5,5.379994730581837e-5,4.0107232867763e-5,2.9784059487535237e-5]
@test power(lombscargle(t, s, err)) ==
power(lombscargle(t, measurement(s, err)))
power(lombscargle(t, measurement.(s, err)))

# Test fast method
t = linspace(0.01, 10pi, ntimes)
s = sin(t)
s = sin.(t)
pgram5 = lombscargle(t, s, maximum_frequency=30, fast=true)
pgram6 = lombscargle(t, s, maximum_frequency=30, fast=false)
@test_approx_eq_eps power(pgram5) power(pgram6) 2e-6
Expand All @@ -70,7 +70,7 @@ pgram6 = lombscargle(t, s, maximum_frequency=30, fast=false)
@test_approx_eq power(lombscargle(t, s, err, frequencies=0.2:0.2:1, fast=true, fit_mean=false)) [0.09219168665786258,0.0015654342453078724,0.00019403694017215876,6.088944186950046e-5,6.05771360378885e-5]
@test_approx_eq power(lombscargle(t, s, err, frequencies=0.2:0.2:1, fast=true, center_data=false, fit_mean=false)) [0.09360344864985332,0.0015354489715019735,0.0001784388515190763,4.744247354697125e-5,3.240223498703448e-5]
@test power(lombscargle(t, s, err)) ==
power(lombscargle(t, measurement(s, err)))
power(lombscargle(t, measurement.(s, err)))

# Compare result of uncertainties with both methods (fast and non-fast).
errors = rand(0.1:1e-3:4.0, ntimes)
Expand All @@ -86,7 +86,7 @@ errors = rand(0.1:1e-3:4.0, ntimes)
@test_approx_eq findmaxperiod(pgram1) 1./findmaxfreq(pgram1)
@test_approx_eq findmaxperiod(pgram1, 0.965) 1./findmaxfreq(pgram1, 0.965)
t = linspace(0.01, 10pi, 1001)
s = sinpi(2t) + cospi(4t)
s = sinpi.(2t) + cospi.(4t)
p = lombscargle(t, s, maximum_frequency=4)
@test_approx_eq findmaxfreq(p, [0.9, 1.1]) 1.0029954048320957
@test_approx_eq findmaxfreq(p, [1.9, 2.1]) 2.002806697267899
Expand All @@ -100,11 +100,11 @@ p = lombscargle(t, s, maximum_frequency=4)
@test_approx_eq LombScargle.autofrequency(t, maximum_frequency=10) 0.003184112396292367:0.006368224792584734:9.99492881196174
# This last test also makes sure that `freq` and `power` fields of a Periodogram
# object can have different type.
@test_approx_eq freq(lombscargle(1:11, big(sin(1:11)))) 0.01:0.02:2.75
@test_approx_eq freq(lombscargle(1:11, big(sin.(1:11)))) 0.01:0.02:2.75

# Test probabilities and FAP
t = collect(linspace(0.01, 10pi, 101))
s = sin(t)
s = sin.(t)
for norm in ("standard", "Scargle", "HorneBaliunas", "Cumming")
P = lombscargle(t, s, normalization = norm)
for z_0 in (0.1, 0.5, 0.9)
Expand All @@ -118,8 +118,8 @@ P = lombscargle(t, s, normalization = "log")

# Test model function
@test_approx_eq s LombScargle.model(t, s, 1/2pi, center_data=false, fit_mean=false)
s = sinpi(t) + pi*cospi(t) + e
@test_approx_eq s LombScargle.model(t, measurement(s, ones(s)), 0.5)
s = sinpi.(t) + pi*cospi.(t) + e
@test_approx_eq s LombScargle.model(t, measurement.(s, ones(s)), 0.5)

# Test add_at!
a = ones(Int, 3)
Expand All @@ -128,7 +128,7 @@ LombScargle.add_at!(a, [3, 1, 3, 1, 2], 1:5)

# Test extirpolation function
x = linspace(0, 10)
y = sin(x)
y = sin.(x)
@test_approx_eq LombScargle.extirpolate(x, y) [0.39537718210649553,3.979484140636793,4.833090108345013,0.506805556164743,-3.828112427525919,-4.748341359084166,-1.3022050566901917,3.3367666084342256,5.070478111668922,1.291245296032218,-0.8264466821981216,0.0,0.0]
@test_approx_eq LombScargle.extirpolate(x, y, 11) LombScargle.extirpolate(x, y)[1:11]

Expand All @@ -142,5 +142,5 @@ srand(1)
b = LombScargle.bootstrap(50, x, y)
@test_approx_eq fap(b, fapinv(b, 0.02)) 0.02
err = collect(linspace(0.5, 1.5))
b = LombScargle.bootstrap(50, x, measurement(y, err))
b = LombScargle.bootstrap(50, x, measurement.(y, err))
@test_approx_eq fap(b, fapinv(b, 0.02)) 0.02

0 comments on commit 90472bb

Please sign in to comment.