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

Get initial traits in place for NeuroCore #1

Merged
merged 15 commits into from
Dec 27, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Using AffineMap instead of 4x4 array now.
- fixed some typos
- bidsdata.jl now contains what could be the beginnings of a BIDS based
datadeps
- traits contains non BIDS entities properties
  • Loading branch information
Tokazama committed Dec 21, 2019
commit 3bda9fa05f659832ecff2834dc2d19c18c4b751a
18 changes: 18 additions & 0 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ git-tree-sha1 = "a2a6a5fea4d6f730ec4c18a76d27ec10e8ec1c50"
uuid = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
version = "1.0.0"

[[CoordinateTransformations]]
deps = ["Compat", "Rotations", "StaticArrays"]
git-tree-sha1 = "47f05d0b7f4999609f92e657147df000818c1f24"
uuid = "150eb455-5306-5404-9cee-2592286d6298"
version = "0.5.0"

[[DataAPI]]
git-tree-sha1 = "674b67f344687a88310213ddfa8a2b3c76cc4252"
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
Expand Down Expand Up @@ -233,6 +239,12 @@ git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0"
uuid = "189a3867-3050-52da-a836-e630ba90ab69"
version = "0.2.0"

[[Rotations]]
deps = ["LinearAlgebra", "StaticArrays", "Statistics"]
git-tree-sha1 = "cb70e13ed3d4b37caf93960676ef415da5979a93"
uuid = "6038ab10-8711-5258-84ad-4b1120ba62dc"
version = "0.12.1"

[[SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"

Expand Down Expand Up @@ -268,6 +280,12 @@ git-tree-sha1 = "268052ee908b2c086cc0011f528694f02f3e2408"
uuid = "276daf66-3868-5448-9aa4-cd146d93841b"
version = "0.9.0"

[[StaticArrays]]
deps = ["InteractiveUtils", "LinearAlgebra", "Random", "Statistics", "Test"]
git-tree-sha1 = "3841b39ed5f047db1162627bf5f80a9cd3e39ae2"
uuid = "90137ffa-7385-5640-81b9-e52037218182"
version = "0.10.3"

[[Statistics]]
deps = ["LinearAlgebra", "SparseArrays"]
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Expand Down
3 changes: 3 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ authors = ["Tokazama <zchristensen7@gmail.com>"]
version = "0.1.0"

[deps]
CoordinateTransformations = "150eb455-5306-5404-9cee-2592286d6298"
ImageAxes = "2803e5a7-5153-5ecf-9a86-9b4c37f5f5ac"
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
ImageMetadata = "bc367c6b-8a6b-528e-b4bd-a4b897500b49"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
Rotations = "6038ab10-8711-5258-84ad-4b1120ba62dc"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
48 changes: 25 additions & 23 deletions src/NeuroCore.jl
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
module NeuroCore

using ImageCore, ImageAxes, Unitful, ImageMetadata, Markdown
using StaticArrays, Rotations, CoordinateTransformations

export NeuroMetadata,
NeuroMetaArray,
BIDSMetadata,
neurohelp
#=
# methods
calmax,
calmax!,
calmin,
calmin!,
magic_bytes,
magic_bytes!
=#
description,
freqdim,
is_anatomical,
is_functional,
is_electrophysiology,
neurohelp,
phasedim,
stream_offset,
slicedim,
slice_end,
slice_start,
spatial_offset,
spatial_units,
time_units


const OneF64Sec = 1.0u"s"
const F64Sec = typeof(OneF64Sec)
Expand All @@ -29,33 +39,25 @@ const IntDeg = typeof(OneIntDeg)

const CoordinateList = Dict{Symbol,NTuple{3,Float64}}

const NeuroAffine{R} = AffineMap{R,SArray{Tuple{3},Float64,1,3}}

include("enums.jl")
include("properties.jl")
include("coordinates.jl")
include("bids_entities.jl")
include("modalities.jl")
include("modality_agnostic.jl")
include("event_table.jl")
include("bidsdata.jl")
include("getproperty.jl")
include("bidsmetadata.jl")
include("metadata.jl")
include("array.jl")
include("traits.jl")

"""
neurohelp(func[; extended = false])

For help on a specific function's arguments, type `help_arguments(function_name)`.
neurohelp(func[;])

For help on a specific function's attributes, type `help_attributes(plot_Type)`.

Use the optional `extended = true` keyword argument to see more details.
"""
neurohelp(func; kw_args...) = neurohelp(stdout, func; kw_args...) #defaults to STDOUT

function neurohelp(io::IO, input::Symbol; extended = false)
return neurohelp(io, getproperty(NeuroCore, input); extended=extended)
end
function neurohelp(io::IO, input; extended = false)
neurohelp(func) = neurohelp(stdout, func)
neurohelp(io::IO, input::Symbol) = neurohelp(io, getproperty(NeuroCore, input))
function neurohelp(io::IO, input)
buffer = IOBuffer()
println(buffer, Base.Docs.doc(input))
Markdown.parse(String(take!(buffer)))
Expand Down
99 changes: 0 additions & 99 deletions src/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,102 +7,3 @@ NeuroMetaArray(x::AbstractArray, p::AbstractDict) = NeuroMetaArray(x, NeuroMetad
NeuroMetaArray(x; kwargs...) = NeuroMetaArray(x, NeuroMetadata(; kwargs...))

Base.getproperty(x::NeuroMetaArray, s::Symbol) = getproperty(properties(x), s)

"""
spatial_offset(img)

Provides the offset of each dimension (i.e., where each spatial axis starts).
"""
spatial_offset(x) = first.(coords_indices(x))


"""
spatial_units(img)

Returns the units (i.e. Unitful.unit) that each spatial axis is measured in. If not
available `nothing` is returned for each spatial axis.
"""
spatial_units(x) = unit.(eltype.(spatial_indices(x)))

"""
freqdim(x) -> Int

Which spatial dimension (1, 2, or 3) corresponds to phase acquisition. If not
applicable to scan type defaults to `0`.
"""
freqdim(x) = getter(x, :freqdim, Int, 0)
freqdim!(x, val) = setter!(x, :freqdim, Int, val)

"""
slicedim(x) -> Int

Which dimension slices where acquired at throughout MRI acquisition.
"""
slicedim(x) = getter(x, :slicedim, Int, i -> 0)
slicedim!(x, val) = setter!(x, :slicedim, Int, val)

"""
phasedim(x) -> Int

Which spatial dimension (1, 2, or 3) corresponds to phase acquisition.
"""
phasedim(x) = getter(x, :phasedim, Int, i -> 0)
phasedim!(x, val) = setter!(x, :phasedim, Int, val)

"""
slice_start(x) -> Int

Which slice corresponds to the first slice acquired during MRI acquisition
(i.e. not padded slices). Defaults to `1`.
"""
slice_start(x) = getter(x, :slice_start, Int, i -> 1)
slice_start!(x, val) = setter!(x, :slice_start, Int, val)

"""
slice_end(x) -> Int

Which slice corresponds to the last slice acquired during MRI acquisition
(i.e. not padded slices).
"""
slice_end(x) = getter(x, :slice_end, Int, i -> 1)
slice_end!(x, val) = setter!(x, :slice_end, Int, val)

"""
time_units(img)

Returns the units (i.e. Unitful.unit) the time axis is measured in. If not available
`nothing` is returned.
"""
time_units(x) = unit(eltype(timeaxis(x)))

"""
start_time(x) -> F64Sec

Returns start time in seconds in relation to the start of acquisition of the first
data sample in the corresponding neural dataset (negative values are allowed).
"""
start_time(x) = first(timeaxis(x))

"""
calmax(x)

Specifies maximum element for display puproses. Defaults to the maximum of `x`.
"""
calmax(x::Any) = getter(x, :calmax, i -> _caltype(x), i -> _calmax(i))
calmax!(x::Any, val::Any) = setter!(x, :calmax, val, i -> _caltype(i))

"""
calmin(x)

Specifies minimum element for display puproses. Defaults to the minimum of `x`.
"""
calmin(x) = getter(x, :calmin, i -> _caltype(i), i -> _calmin(i))
calmin!(x, val) = setter!(x, :calmin, val, i -> _caltype(i))

###
_caltype(x::AbstractArray{T}) where {T} = T
_caltype(x::Any) = Float64
_calmax(x::AbstractArray) = maximum(x)
_calmax(x::Any) = one(Float64)
_calmin(x::AbstractArray) = minimum(x)
_calmin(x::Any) = one(Float64)
2 changes: 1 addition & 1 deletion src/bids_entities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
AcquisitionDuration(x) -> F64Sec

Duration (in seconds) of volume acquisition. This field is REQUIRED for
sequences that are described with the VolumeTimingfield and that not have the
sequences that are described with the VolumeTimingfield and that do not have the
SliceTiming field set to allowed for accurate calculation of "acquisition time".
This field is mutually exclusive with RepetitionTime.
"""
Expand Down
34 changes: 34 additions & 0 deletions src/event_table.jl → src/bidsdata.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
"""
BIDSMetadata

Metadata for describing a BIDS dataset.


* `name::String`: The name of the dataset
* `bids_version::String`: The version of the BIDS standard that was used.
* `license::Union{String,Nothing}`: Returns the license that a given dataset is
distributed under? The use of license name abbreviations is suggested for
specifying a license (e.g., PD, PDDL, CCO).
* `authors::Union{Vector{String},Nothing}`: list of individuals who contributed
to the creation/curation of the dataset.
* `acknowledgedgements::Union{String,Nothing}`: Returns the text acknowledging
contributions of individuals or institutions beyond those listed in Authors or Funding.
* `how_to_acknowledge::Union{String,Nothing}`: Instructions how researchers using
this dataset should acknowledge the original authors. This field can also be used
to define a publication that should be cited in publications that use the dataset.
* `funding::Union{Vector{String},Nothing}`: List of sources of funding (grant numbers)
* `references::Union{Vector{String},Nothing}`: List of references to publication
that contain information on the dataset, or links.
* `doi::Union{String,Nothing}`: Returns the Document Object Identifier of the dataset (not the corresponding paper)
"""
Base.@kwdef struct BIDSMetadata
name::String
bids_version::String
license::Union{String,Nothing}=nothing
authors::Union{Vector{String},Nothing}=nothing
acknowledgedgements::Union{String,Nothing}=nothing
how_to_acknowledge::Union{String,Nothing}=nothing
funding::Union{Vector{String},Nothing}=nothing
references::Union{Vector{String},Nothing}=nothing
doi::Union{String,Nothing}=nothing
end

# TODO FileIO integration
# TODO HED format should probably involve its own package
Expand Down
32 changes: 0 additions & 32 deletions src/bidsmetadata.jl

This file was deleted.

Loading