Skip to content

Commit

Permalink
Merge pull request #6 from JakobAsslaender/UpdateCompatNTests
Browse files Browse the repository at this point in the history
update compat + tests
  • Loading branch information
dfsp-spirit authored Nov 13, 2024
2 parents 66ae868 + 2a2d348 commit 1f5a4ab
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 56 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
*.jl.cov
*.jl.mem
/docs/build/
Manifest.toml
test/Manifest.toml
7 changes: 4 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
TranscodingStreams = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"

[compat]
CSV = "0.8"
CSV = "0.8, 0.10"
CodecZlib = "0.6, 0.7"
Colors = "0.12"
Colors = "0.12, 0.13"
DataFrames = "0.22, 1.0"
DelimitedFiles = "1"
Reexport = "1.0"
TranscodingStreams = "0.9.5"
TranscodingStreams = "0.9.5, 0.11"
julia = "1"

[extras]
Expand Down
2 changes: 1 addition & 1 deletion src/fs_label.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function read_label(file::AbstractString)
csv_data_reader = CSV.File(file; header=column_names, delim=" ", ignorerepeated=true, skipto=3, limit=num_vertices, types=column_types, comment="#")

df = DataFrame(csv_data_reader)
return(df)
return df
end

"""
Expand Down
3 changes: 3 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
5 changes: 1 addition & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import Base.length, Base.maximum, Base.minimum, Base.fieldcount
# The easiest way to run these tests with the current version of your code
# seems to be the following one:
# - start a JULIA interpreter with `cd develop/NeuroFormats.jl; julia --project=.`, then:
# - run: `using Pkg; Pkg.test("NeuroFormats");`


include("./utils_for_testing.jl")
# - run: `using Pkg; Pkg.test("NeuroFormats");`

# Common utility tests
include("./test_utils.jl")
Expand Down
4 changes: 2 additions & 2 deletions test/test_dti_tck.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Tests for reading TCK files.

@testset "Read DTI tracks from a MRtrix3 TCK file." begin
TCK_FILE = joinpath(get_testdata_dir(), "DTI/simple_big_endian.tck")

TCK_FILE = joinpath(Base.source_dir(), "data/DTI/simple_big_endian.tck")
tck = read_tck(TCK_FILE)

# test header
Expand Down
4 changes: 2 additions & 2 deletions test/test_dti_trk.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Tests for reading TRK files.

@testset "Read DTI tracks from a DiffusionToolkit TRK file." begin
TRK_FILE = joinpath(get_testdata_dir(), "DTI/complex_big_endian.trk")

TRK_FILE = joinpath(Base.source_dir(), "data/DTI/complex_big_endian.trk")
trk = read_trk(TRK_FILE)

@test trk.header.hdr_size == 1000
Expand Down
4 changes: 2 additions & 2 deletions test/test_fs_annot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

@testset "Read a FreeSurfer annotation and compute properties" begin

ANNOT_FILE = joinpath(get_testdata_dir(), "subjects_dir/subject1/label/lh.aparc.annot")
ANNOT_FILE = joinpath(Base.source_dir(), "data/subjects_dir/subject1/label/lh.aparc.annot")
fs_annot = read_annot(ANNOT_FILE)

@test Base.length(fs_annot.vertex_indices) == 149244
Expand All @@ -29,7 +29,7 @@ end

@testset "Derive per-vertex color information from a FreeSurfer annotation" begin

ANNOT_FILE = joinpath(get_testdata_dir(), "subjects_dir/subject1/label/lh.aparc.annot")
ANNOT_FILE = joinpath(Base.source_dir(), "data/subjects_dir/subject1/label/lh.aparc.annot")
fs_annot = read_annot(ANNOT_FILE)

@test Base.length(vertex_colors(fs_annot)) == 149244
Expand Down
10 changes: 5 additions & 5 deletions test/test_fs_common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


@testset "fs_common.jl: read fs int24" begin
CURV_LH_THICKNESS_FILE = joinpath(get_testdata_dir(), "subjects_dir/subject1/surf/lh.thickness")

CURV_LH_THICKNESS_FILE = joinpath(Base.source_dir(), "data/subjects_dir/subject1/surf/lh.thickness")
file_io = open(CURV_LH_THICKNESS_FILE, "r")
int24 = NeuroFormats.FreeSurfer._read_fs_int24(file_io)
close(file_io)
Expand All @@ -14,11 +14,11 @@ end

@testset "fs_common.jl: interpret fs int24" begin

CURV_LH_THICKNESS_FILE = joinpath(get_testdata_dir(), "subjects_dir/subject1/surf/lh.thickness")
CURV_LH_THICKNESS_FILE = joinpath(Base.source_dir(), "data/subjects_dir/subject1/surf/lh.thickness")
curv = read_curv(CURV_LH_THICKNESS_FILE, with_header = true)

int24 = NeuroFormats.FreeSurfer._interpret_fs_int24(curv.header.curv_magic_b1, curv.header.curv_magic_b2, curv.header.curv_magic_b3)

@test int24 == 16777215
end

Expand Down
10 changes: 5 additions & 5 deletions test/test_fs_curv.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@


@testset "fs_curv.jl: read curv with header" begin
CURV_LH_THICKNESS_FILE = joinpath(get_testdata_dir(), "subjects_dir/subject1/surf/lh.thickness")

CURV_LH_THICKNESS_FILE = joinpath(Base.source_dir(), "data/subjects_dir/subject1/surf/lh.thickness")
curv = read_curv(CURV_LH_THICKNESS_FILE, with_header = true)

# Header
Expand All @@ -22,7 +22,7 @@ end

@testset "fs_curv.jl: read curv without header" begin

CURV_LH_THICKNESS_FILE = joinpath(get_testdata_dir(), "subjects_dir/subject1/surf/lh.thickness")
CURV_LH_THICKNESS_FILE = joinpath(Base.source_dir(), "data/subjects_dir/subject1/surf/lh.thickness")
curv_data = read_curv(CURV_LH_THICKNESS_FILE, with_header = false)

# Content
Expand All @@ -34,13 +34,13 @@ end

@testset "fs_curv.jl: write and re-read curv file" begin

CURV_LH_THICKNESS_FILE = joinpath(get_testdata_dir(), "subjects_dir/subject1/surf/lh.thickness")
CURV_LH_THICKNESS_FILE = joinpath(Base.source_dir(), "data/subjects_dir/subject1/surf/lh.thickness")
curv_data = read_curv(CURV_LH_THICKNESS_FILE, with_header = false)

# Write and re-read
tf = tempname()
write_curv(tf, curv_data)
curv_re = read_curv(tf, with_header = true)
curv_re = read_curv(tf, with_header = true)

# Header
@test curv_re.header.curv_magic_b1 == 0xff
Expand Down
4 changes: 2 additions & 2 deletions test/test_fs_label.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using DataFrames

@testset "A FreeSurfer surface label file can be read" begin

LABEL_FILE = joinpath(get_testdata_dir(), "subjects_dir/subject1/label/lh.entorhinal_exvivo.label")
LABEL_FILE = joinpath(Base.source_dir(), "data/subjects_dir/subject1/label/lh.entorhinal_exvivo.label")
fs_label = read_label(LABEL_FILE)

@test typeof(fs_label) == DataFrames.DataFrame
Expand All @@ -14,7 +14,7 @@ end

@testset "A FreeSurfer surface label file can be read, written and re-read" begin

LABEL_FILE = joinpath(get_testdata_dir(), "subjects_dir/subject1/label/lh.entorhinal_exvivo.label")
LABEL_FILE = joinpath(Base.source_dir(), "data/subjects_dir/subject1/label/lh.entorhinal_exvivo.label")
fs_label = read_label(LABEL_FILE)

@test typeof(fs_label) == DataFrames.DataFrame
Expand Down
16 changes: 8 additions & 8 deletions test/test_fs_mgh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

@testset "Read a 3D/4D FreeSurfer MGH file." begin

MGH_FILE = joinpath(get_testdata_dir(), "subjects_dir/subject1/mri/brain.mgz")
MGH_FILE = joinpath(Base.source_dir(), "data/subjects_dir/subject1/mri/brain.mgz")
mgh = read_mgh(MGH_FILE)

# Test header.
Expand Down Expand Up @@ -31,7 +31,7 @@ end

@testset "Compute vox2ras matrix for MGH file." begin

MGH_FILE = joinpath(get_testdata_dir(), "subjects_dir/subject1/mri/brain.mgz")
MGH_FILE = joinpath(Base.source_dir(), "data/subjects_dir/subject1/mri/brain.mgz")
mgh = read_mgh(MGH_FILE)

# Use FreeSurfer's `mri_info` command line tool on the brain.mgz file to get this info:
Expand All @@ -45,9 +45,9 @@ end

@testset "fs_mgh.jl: write and re-read MGH file uncompressed" begin

MGH_FILE = joinpath(get_testdata_dir(), "subjects_dir/subject1/mri/brain.mgz")
MGH_FILE = joinpath(Base.source_dir(), "data/subjects_dir/subject1/mri/brain.mgz")
mgh = read_mgh(MGH_FILE)

# Write and re-read
tf = tempname()
write_mgh(tf, mgh, format = "mgh")
Expand Down Expand Up @@ -81,15 +81,15 @@ end
@test mgh_re.data[110, 110, 110, 1] == 71
@test mgh_re.data[1, 1, 1, 1] == 0
@test sum(Int32.(mgh_re.data)) == 121035479

end


@testset "fs_mgh.jl: write and re-read MGZ file compressed" begin

MGH_FILE = joinpath(get_testdata_dir(), "subjects_dir/subject1/mri/brain.mgz")
MGH_FILE = joinpath(Base.source_dir(), "data/subjects_dir/subject1/mri/brain.mgz")
mgh = read_mgh(MGH_FILE)

# Write and re-read
tf = tempname()
write_mgh(tf, mgh, format = "mgz")
Expand Down Expand Up @@ -122,6 +122,6 @@ end
@test mgh_re.data[100, 100, 100, 1] == 77 # try on command line: mri_info --voxel 99 99 99 test/data/subjects_dir/subject1/mri/brain.mgz
@test mgh_re.data[110, 110, 110, 1] == 71
@test mgh_re.data[1, 1, 1, 1] == 0
@test sum(Int32.(mgh_re.data)) == 121035479
@test sum(Int32.(mgh_re.data)) == 121035479
end

8 changes: 4 additions & 4 deletions test/test_fs_surface.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

@testset "fs_surface.jl: read brain mesh" begin
BRAIN_MESH_FILE = joinpath(get_testdata_dir(), "subjects_dir/subject1/surf/lh.tinysurface")

BRAIN_MESH_FILE = joinpath(Base.source_dir(), "data/subjects_dir/subject1/surf/lh.tinysurface")
surface = read_surf(BRAIN_MESH_FILE) # a mesh with 5 vertices and 3 faces.

known_num_verts = 5
Expand All @@ -25,8 +25,8 @@ end


@testset "fs_surface.jl: export brain mesh to OBJ file" begin
BRAIN_MESH_FILE = joinpath(get_testdata_dir(), "subjects_dir/subject1/surf/lh.tinysurface")

BRAIN_MESH_FILE = joinpath(Base.source_dir(), "data/subjects_dir/subject1/surf/lh.tinysurface")
surface = read_surf(BRAIN_MESH_FILE) # a mesh with 5 vertices and 3 faces.

tf = tempname()
Expand Down
6 changes: 3 additions & 3 deletions test/test_utils.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

@testset "utils.jl: read a fixed length string from a binary file" begin
BRAIN_MESH_FILE = joinpath(get_testdata_dir(), "subjects_dir/subject1/surf/lh.tinysurface")

BRAIN_MESH_FILE = joinpath(Base.source_dir(), "data/subjects_dir/subject1/surf/lh.tinysurface")
file_io = open(BRAIN_MESH_FILE, "r")

@test Base.position(file_io) == 0

b1 = read(file_io, UInt8)
b2 = read(file_io, UInt8)
b3 = read(file_io, UInt8)
Expand Down
15 changes: 0 additions & 15 deletions test/utils_for_testing.jl

This file was deleted.

0 comments on commit 1f5a4ab

Please sign in to comment.