Skip to content

Commit 0e9502d

Browse files
authored
Merge pull request #1 from HolyLab/cjg/updates
Cjg/updates
2 parents 88be845 + 3eaf287 commit 0e9502d

11 files changed

+135
-149
lines changed

.travis.yml

+17-13
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ os:
44
- linux
55
- osx
66
julia:
7-
- 0.6
8-
- nightly
7+
- 1.0
8+
- 1.1
99
notifications:
1010
email: false
1111
git:
@@ -18,18 +18,22 @@ git:
1818
# - julia: nightly
1919

2020
## uncomment and modify the following lines to manually install system packages
21-
#addons:
22-
# apt: # apt-get for linux
23-
# packages:
24-
# - gfortran
25-
#before_script: # homebrew for mac
26-
# - if [ $TRAVIS_OS_NAME = osx ]; then brew install gcc; fi
21+
addons:
22+
apt:
23+
packages:
24+
- build-essential
25+
- gfortran
26+
- pkg-config
27+
- hdf5-tools
2728

2829
## uncomment the following lines to override the default test script
29-
#script:
30-
# - julia -e 'Pkg.clone(pwd()); Pkg.build("ImageInterpLast"); Pkg.test("ImageInterpLast"; coverage=true)'
30+
script:
31+
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
32+
- julia ci_prep.jl
33+
- julia -e 'using Pkg; Pkg.build(); Pkg.test("ImageInterpLast"; coverage=true)'
3134
after_success:
32-
# push coverage results to Coveralls
33-
- julia -e 'cd(Pkg.dir("ImageInterpLast")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
3435
# push coverage results to Codecov
35-
- julia -e 'cd(Pkg.dir("ImageInterpLast")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
36+
- julia -e 'import Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
37+
# update the documentation
38+
# - julia -e 'using Pkg; Pkg.add("Documenter")'
39+
# - julia -e 'using CachedCalls; cd(dirname(dirname(pathof(CachedCalls)))); ENV["DOCUMENTER_DEBUG"] = "true"; include(joinpath("docs", "make.jl"))'

Project.toml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name = "ImageInterpLast"
2+
uuid = "2857f282-5c94-11e9-0b5d-cb5f26255b42"
3+
version = "0.1.0"
4+
5+
[deps]
6+
AxisArrays = "39de3d68-74b9-583c-8d2d-e117c070f3a9"
7+
CachedArrays = "d8fd01e4-1764-11e9-0a01-8f76bebf08d8"
8+
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
9+
10+
[extras]
11+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
12+
13+
[targets]
14+
test = ["Test"]

REQUIRE

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
julia 0.6
2-
CachedSeries
1+
julia 1.0
2+
CachedArrays
33
Images
44
AxisArrays

appveyor.yml

+18-28
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
environment:
22
matrix:
3-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
4-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
5-
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
6-
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
3+
- julia_version: 1
4+
- julia_version: 1.1
5+
#- julia_version: nightly
76

8-
## uncomment the following lines to allow failures on nightly julia
9-
## (tests will run but not make your overall status red)
10-
#matrix:
11-
# allow_failures:
12-
# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
13-
# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
7+
platform:
8+
- x86 # 32-bit
9+
- x64 # 64-bit
10+
11+
# # Uncomment the following lines to allow failures on nightly julia
12+
# # (tests will run but not make your overall status red)
13+
# matrix:
14+
# allow_failures:
15+
# - julia_version: nightly
1416

1517
branches:
1618
only:
@@ -24,24 +26,12 @@ notifications:
2426
on_build_status_changed: false
2527

2628
install:
27-
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
28-
# If there's a newer build queued for the same PR, cancel this one
29-
- ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
30-
https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
31-
Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
32-
throw "There are newer queued builds for this pull request, failing early." }
33-
# Download most recent Julia Windows binary
34-
- ps: (new-object net.webclient).DownloadFile(
35-
$env:JULIA_URL,
36-
"C:\projects\julia-binary.exe")
37-
# Run installer silently, output to C:\projects\julia
38-
- C:\projects\julia-binary.exe /S /D=C:\projects\julia
29+
- ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1"))
3930

4031
build_script:
41-
# Need to convert from shallow to complete for Pkg.clone to work
42-
- IF EXIST .git\shallow (git fetch --unshallow)
43-
- C:\projects\julia\bin\julia -e "versioninfo();
44-
Pkg.clone(pwd(), \"ImageInterpLast\"); Pkg.build(\"ImageInterpLast\")"
45-
32+
- C:\julia\bin\julia ci_prep.jl
33+
- echo "%JL_BUILD_SCRIPT%"
34+
- C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%"
4635
test_script:
47-
- C:\projects\julia\bin\julia -e "Pkg.test(\"ImageInterpLast\")"
36+
- echo "%JL_TEST_SCRIPT%
37+
- C:\julia\bin\julia -e "%JL_TEST_SCRIPT%"

ci_prep.jl

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Pkg, LibGit2;
2+
user_regs = joinpath(DEPOT_PATH[1],"registries");
3+
mkpath(user_regs);
4+
all_registries = Dict("General" => "https://github.com/JuliaRegistries/General.git",
5+
"HolyLabRegistry" => "https://github.com/HolyLab/HolyLabRegistry.git");
6+
Base.shred!(LibGit2.CachedCredentials()) do creds
7+
for (reg, url) in all_registries
8+
path = joinpath(user_regs, reg);
9+
LibGit2.with(Pkg.GitTools.clone(url, path; header = "registry $reg from $(repr(url))", credentials = creds)) do repo end
10+
end
11+
end

src/ImageInterpLast.jl

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
__precompile__()
2-
31
module ImageInterpLast
42

5-
using CachedSeries, Images, AxisArrays
3+
using CachedArrays, Images, AxisArrays
4+
const axes = Base.axes
65

7-
import CachedSeries: update_cache!, cache, cache_idxs
6+
import CachedArrays: update_cache!, cache, AbstractCachedArray
87
import Base: size, getindex, show
98

10-
export interplast, ImageInterpLast2, ImageInterpLast3
9+
export interp_last, ImgItpLast
1110

1211
include("util.jl")
13-
include("interp_last2.jl")
14-
include("interp_last3.jl")
1512
include("interp_last.jl")
1613

1714
end

src/interp_last.jl

+55-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,65 @@
1-
#user interface
1+
mutable struct ImgItpLast{TO,N,TI,NC,A<:AbstractArray{TI,N}} <: AbstractCachedArray{TO,N,TI,NC,A}
2+
parent::A
3+
coefs::Vector{Float64}
4+
cached::Array{TO,NC}
5+
current_I::Tuple
6+
end
7+
8+
function ImgItpLast(img::Array34{T}, coefs, nd_cache=ndims(img)-1, out_type=Float64) where {T}
9+
nd = ndims(img)
10+
map(check01, coefs)
11+
if size(img,3) !== length(coefs)
12+
error("Input image size in the Z-slice dimension (3) should equal the number of interpolation coefficients provided")
13+
end
14+
if nd_cache > nd
15+
error("nd_cache must be less than or equal to ndims(img)")
16+
end
17+
ncache_rngs = axes(img)[nd_cache+1:nd]
18+
ci = map(first, ncache_rngs)
19+
za = ImgItpLast{out_type,nd,T,nd_cache,typeof(img)}(img, coefs, zeros(out_type, size(img)[1:nd_cache]...), ci)
20+
update_cache!(za, ci)
21+
return za
22+
end
223

3-
interplast(A::AbstractArray, coef::Float64; kwargs...) = interplast(A, fill(coef, size(A,3)); kwargs...)
24+
ImgItpLast(img::Array34{T}, coef::Float64, nd_cache=ndims(img)-1, out_type=Float64) where {T} =
25+
ImgItpLast(img, fill(coef, size(img, 3)), nd_cache, out_type)
26+
27+
function update_cache!(A::ImgItpLast{TO,N,TI,2}, inds::NTuple{NQ, Int}) where {TO,N,TI,NQ}
28+
#sometimes indexing works better than views with memory-mapped arrays
29+
pslice = A.parent[:, :, inds...]
30+
pslice_next = A.parent[:, :, Base.front(inds)...,last(inds)+1]
31+
coef = A.coefs[first(inds)] #get coef for this slice
32+
interp!(A.cached, pslice, pslice_next, coef)
33+
A.current_I = inds
34+
end
35+
36+
function update_cache!(A::ImgItpLast{TO,N,TI,3}, inds::NTuple{NQ,Int}) where {TO,N,TI,NQ}
37+
#sometimes indexing works better than views with memory-mapped arrays
38+
pslice = A.parent[:, :, :, inds...]
39+
pslice_next = A.parent[:, :, :, Base.front(inds)...,last(inds)+1]
40+
interp!(A.cached, pslice, pslice_next, A.coefs)
41+
A.current_I = inds
42+
end
43+
44+
size(A::ImgItpLast) = (Base.front(size(A.parent))...,last(size(A.parent))-1,)
45+
Base.axes(A::ImgItpLast) = (Base.front(axes(parent(A)))..., first(last(axes(parent(A)))):(last(last(axes(parent(A))))-1),)
46+
show(io::IO, A::ImgItpLast{TO}) where {TO} = print(io, "ImgItpLast of size $(size(A)) mapped to element type $TO\n")
47+
show(io::IO, ::MIME"text/plain", A::ImgItpLast{TO}) where {TO} = show(io, A)
48+
49+
ImgItpLast(img::ImageMeta, coefs, out_type=Float64; kwargs...) = ImageMeta(ImgItpLast(data(img), coefs, out_type; kwargs...), properties(img))
50+
ImgItpLast(img::AxisArray, coefs, out_type=Float64; kwargs...) = match_axisspacing(ImgItpLast(data(img),coefs,out_type; kwargs...), img)
51+
52+
53+
#user interface
54+
interp_last(A::AbstractArray, coef::Float64; kwargs...) = interp_last(A, fill(coef, size(A,3)); kwargs...)
455

5-
function interplast(A::AbstractArray{T,N}, coefs::Vector{Float64}; cache3d=false, out_type=Float64) where {T,N}
56+
function interp_last(A::AbstractArray{T,N}, coefs::Vector{Float64}; cache3d=false, out_type=Float64) where {T,N}
657
if !in(N, (3,4))
758
warn("$N-dimensional input was provided. Only 3D and 4D inputs are tested; this will probably fail")
859
end
960
if N ==3 && cache3d
1061
cache3d = false
1162
warn("The cache3d kwarg was set for a 3D input matrix. This is only useful for 4D timeseries; ignoring kwarg")
1263
end
13-
return cache3d ? ImageInterpLast3(A, coefs, out_type) : ImageInterpLast2(A, coefs, out_type)
64+
return cache3d ? ImgItpLast(A, coefs, 3, out_type) : ImgItpLast(A, coefs, 2, out_type)
1465
end

src/interp_last2.jl

-39
This file was deleted.

src/interp_last3.jl

-44
This file was deleted.

src/util.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
const Array34{T} = Union{AbstractArray{T,3}, AbstractArray{T,4}}
22

3-
function interp!(ca::AbstractArray{T,3}, img1::AbstractArray{T,3}, img2::AbstractArray{T,3}, coefs::Vector{Float64}) where {T}
3+
function interp!(ca::AbstractArray{TO,3}, img1::AbstractArray{T,3}, img2::AbstractArray{T,3}, coefs::Vector) where {TO,T}
44
for i = 1:size(ca,3)
55
interp!(view(ca,:,:,i), view(img1,:,:,i), view(img2,:,:,i), coefs[i])
66
end
77
return ca
88
end
99

10-
function interp!(ca::AbstractArray{T,2}, img1::AbstractArray{T,2}, img2::AbstractArray{T,2}, coef::Float64) where {T}
10+
function interp!(ca::AbstractArray{TO,2}, img1::AbstractArray{T,2}, img2::AbstractArray{T,2}, coef) where {TO,T}
1111
for i in eachindex(ca)
1212
ca[i] = img1[i]*coef + img2[i]*(1.0-coef)
1313
end

test/runtests.jl

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
using ImageInterpLast
22

3-
using Base.Test
3+
using Test
44

55
a = zeros(10,10,10,10)
66
for t = 1:10
7-
a[:,:,:,t] = t
7+
a[:,:,:,t] .= t
88
end
99

10-
img2 = ImageInterpLast2(a, 0.5, Float64)
11-
img3 = ImageInterpLast3(a, 0.5, Float64)
10+
img0 = interp_last(a, 0.5; cache3d=false, out_type=Float64)
11+
img1 = interp_last(a, 0.5; cache3d=false, out_type=Float32)
12+
img2 = ImgItpLast(a, 0.5, 2, Float64)
13+
img3 = ImgItpLast(a, 0.5, 3, Float64)
1214

13-
for img in (img2,img3)
15+
for img in (img0,img1,img2,img3)
1416
@test all(img[:,:,:,1].==1.5)
1517
@test all(img[1:2,:,:,1].==1.5)
1618
@test all(img[1:2,:,2,1].==1.5)
@@ -20,10 +22,10 @@ for img in (img2,img3)
2022
end
2123

2224
coefs = fill(0.25, 10)
23-
coefs[6:10] = 1.0
25+
coefs[6:10] .= 1.0
2426

25-
img2 = ImageInterpLast2(a, coefs, Float64)
26-
img3 = ImageInterpLast3(a, coefs, Float64)
27+
img2 = ImgItpLast(a, coefs, 2, Float64)
28+
img3 = ImgItpLast(a, coefs, 3, Float64)
2729

2830
for img in (img2,img3)
2931
@test all(img[:,:,1:5,1].==1.75)
@@ -43,8 +45,8 @@ for img in (img2,img3)
4345
@test all(img[1:2,:,7,2].==2.0)
4446
end
4547

46-
img4 = interplast(a, coefs; cache3d=false, out_type=Float64)
47-
img5 = interplast(a, coefs; cache3d=true, out_type=Float64)
48+
img4 = interp_last(a, coefs; cache3d=false, out_type=Float64)
49+
img5 = interp_last(a, coefs; cache3d=true, out_type=Float64)
4850

4951
@test all(img4[:,:,:,:].==img2[:,:,:,:])
5052
@test all(img5[:,:,:,:].==img3[:,:,:,:])

0 commit comments

Comments
 (0)