Skip to content

Commit

Permalink
Merge cd81e49 into 42755dd
Browse files Browse the repository at this point in the history
  • Loading branch information
notZaki committed Aug 23, 2020
2 parents 42755dd + cd81e49 commit b4655d3
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 43 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
@@ -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
@@ -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
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
@@ -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
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
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
@@ -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
@@ -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

0 comments on commit b4655d3

Please sign in to comment.