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

Resolve errors in validation/tests #52

Merged
merged 8 commits into from
Aug 23, 2020
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 .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
language: julia
julia:
- 1.0
- 1
- nightly
before_install:
- sudo apt-get install python3-matplotlib
after_success:
- julia -e 'cd(Pkg.dir("DCEMRI")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
- julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Coveralls.submit(process_folder())'
## uncomment the following lines to override the default test script
#script:
# - julia --color=yes -e 'using Pkg; Pkg.activate(); Pkg.instantiate(); Pkg.test()'
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
environment:
matrix:
- julia_version: 1.3
- julia_version: 1.5
- julia_version: nightly

platform:
Expand Down
8 changes: 1 addition & 7 deletions src/DCEMRI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module DCEMRI

using ArgParse
using Calculus #.jacobian
using MAT
using MAT, PyPlot
using Pkg, LinearAlgebra, Random, Statistics, Distributed, Printf, LsqFit

export ser, r1eff, tissueconc, fitr1, fitdce, fitdata,
Expand All @@ -11,12 +11,6 @@ export ser, r1eff, tissueconc, fitr1, fitdce, fitdata,
const verbose = true
const version = v"0.2.2"

if haskey(Pkg.installed(),"PyPlot")
using PyPlot
else
# println("Optional package (PyPlot) not installed.")
end

include("util.jl")
include("fitting.jl")
include("models.jl")
Expand Down
26 changes: 10 additions & 16 deletions src/demo.jl
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
function demo(outdir::AbstractString="results")
cd(joinpath(dirname(pathof(DCEMRI)), "..", "demo"))
if outdir == "results"
outdir = joinpath(dirname(pathof(DCEMRI)), "..", "demo", "results")
end
outdir = abspath(outdir)
isdir(outdir) || mkdir(outdir)
println("Processing in vivo data ...")

datafile = joinpath(dirname(pathof(DCEMRI)), "..", "demo", "invivo.mat")
# run the model
results = fitdata(datafile="invivo.mat", outfile="$outdir/results.mat", models=[2])

if !haskey(Pkg.installed(), "PyPlot")
# Do no make plots if PyPlot not installed
println("PyPlot not installed. Plots will not be produced.")
else
# plot the results
println("Plotting results ...")
makeplots(results; outdir=outdir)
if outdir == "results"
println("Results can be found in ", Pkg.dir("DCEMRI/demo/$outdir"))
else
println("Results can be found in $outdir")
end
end
results = fitdata(datafile=datafile, outfile="$outdir/results.mat", models=[2])

# plot the results
println("Plotting results ...")
makeplots(results; outdir=outdir)
println("Results can be found in $outdir")
println("Demo run complete.")
end
18 changes: 10 additions & 8 deletions src/plotting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function oplot2(front::Array{Float64,2}, back::Array{Float64,2}, mask::Array{Boo
if r == 0.0
back[:] = 0.0
else
back = (back - minimum(back)) / r
@. back = (back - minimum(back)) / r
end
n,m = size(front)
img = zeros(n,m,3)
Expand All @@ -64,10 +64,12 @@ function oplot2(front::Array{Float64,2}, back::Array{Float64,2}, mask::Array{Boo
img[j,k,:] = jetrgb(s)
else
s = back[j,k]
cmidx = 100 - round(Int,99.0*s)
img[j,k,1] = s
img[j,k,2] = s
img[j,k,3] = s
if !isnan(s)
cmidx = 100 - round(Int,99.0*s)
img[j,k,1] = s
img[j,k,2] = s
img[j,k,3] = s
end
end
end
img
Expand All @@ -84,8 +86,8 @@ function makeplots(mat::Dict; outdir::AbstractString="results")
vp = mat["vp"]
resid = mat["resid"]
q = quantile(S0map[:], 0.99)
S0map[S0map .> q] = q
back = (S0map - minimum(S0map)) / (maximum(S0map) - minimum(S0map))
S0map[S0map .> q] .= q
back = @. (S0map - minimum(S0map)) / (maximum(S0map) - minimum(S0map))
mask = convert(Array{Bool,2}, mat["mask"])

figure(figsize=(4.5,4.5))
Expand Down Expand Up @@ -126,7 +128,7 @@ function makeplots(mat::Dict; outdir::AbstractString="results")

figure()
clf()
Ct = squeeze(maximum(Ct,1),1)
Ct = dropdims(maximum(Ct; dims=1); dims=1)
x = oplot2(clamp.(Ct, 0.0, 5.0), back, mask)
imshow(x, interpolation="nearest", cmap="jet", vmin=0, vmax=5)
title("max tissue conc., \$C_t\$ (mmol)")
Expand Down
1 change: 1 addition & 0 deletions src/science.jl
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ function fitdata(opts::Dict)
end
R1 = r1eff(dcedata, R10, TR, dceflip)
Ct = tissueconc(R1, R10, relaxivity)
@. Ct[!isfinite(Ct)] = 0
params, resid, modelmap = fitdce(Ct, mask, t, Cp, models=models)

results = Dict()
Expand Down
8 changes: 1 addition & 7 deletions src/validate.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
function analyzer(mat::Dict, outdir::AbstractString; dx=1, makeplots=true, isExt=false)

if (makeplots==true) && !haskey(Pkg.installed(),"PyPlot")
# Do no make plots if PyPlot not installed
println("PyPlot not installed. Plots will not be produced.")
makeplots=false
end

R1map = mat["R10"]
S0map = mat["S0"]
modelmap = mat["modelmap"]
Expand Down Expand Up @@ -272,7 +266,7 @@ function makeQibaNoisy(n; nRep=10, doOverwrite=true, noiseSigma=-1.0)
noiseSigma = 0.2 * dceDat[1,1,1] / sqrt(2)
end
# Add complex noise
Random.seed!(9876543210) # Fixed arbitrary seed for reproducible noise
Random.seed!(8702572558940514935) # Fixed arbitrary seed for reproducible noise
dceDat = dceDat + noiseSigma * ( randn(size(dceDat)) + im*randn(size(dceDat)) )
# Take the magntude of the complex signal
dceDat = abs.(dceDat)
Expand Down
8 changes: 6 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using DCEMRI
using Test

ccc4, cccnoisy4 = validate(4, makeplots=false)
ccc4, cccnoisy4 = validate(4)
@testset "QIBA v4 Extended Tofts Phantom" begin
@test ccc4[1] >= 0.9998
@test ccc4[2] >= 0.8904
Expand All @@ -11,10 +11,14 @@ ccc4, cccnoisy4 = validate(4, makeplots=false)
@test round(cccnoisy4[3], sigdigits=2) >= 0.97
end

ccc6, cccnoisy6 = validate(6, makeplots=false)
ccc6, cccnoisy6 = validate(6)
@testset "QIBA v6 Standard Tofts Phantom" begin
@test ccc6[1] >= 0.9999
@test ccc6[2] >= 0.9999
@test round(cccnoisy6[1], sigdigits=2) >= 0.84
@test round(cccnoisy6[2], sigdigits=2) >= 0.86
end

@testset "In-vivo demo" begin
demo() # Just test if the function runs
end