Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MRIBuilder.jl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michiel Cottaar
MRIBuilder.jl
Commits
a8078c7b
Unverified
Commit
a8078c7b
authored
9 months ago
by
Michiel Cottaar
Browse files
Options
Downloads
Patches
Plain Diff
Document variables and @defvar
parent
1027e0ef
No related branches found
No related tags found
1 merge request
!2
Define variables through new @defvar macro
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/variables.jl
+51
-0
51 additions, 0 deletions
src/variables.jl
with
51 additions
and
0 deletions
src/variables.jl
+
51
−
0
View file @
a8078c7b
...
@@ -91,6 +91,20 @@ struct _Variables
...
@@ -91,6 +91,20 @@ struct _Variables
variables
::
Dict
{
Symbol
,
AnyVariable
}
variables
::
Dict
{
Symbol
,
AnyVariable
}
end
end
"""
Main interface to all the MRIBuilder sequence variables.
All variables are available as members of this object, e.g.
`variables.echo_time` returns the echo time variable.
New variables can be defined using [`@defvar`](@ref).
Set constraints on variables by passing them on as keywords during the sequence generation,
e.g., `seq=SpinEcho(echo_time=70)`.
After sequence generation you can get the variable values by calling
`variables.echo_time(seq)`.
For the sequence defined above this would return 70. (or a number very close to that).
"""
variables
=
_Variables
(
Dict
{
Symbol
,
AnyVariable
}())
variables
=
_Variables
(
Dict
{
Symbol
,
AnyVariable
}())
Base
.
getindex
(
v
::
_Variables
,
i
::
Symbol
)
=
getfield
(
v
,
:
variables
)[
i
]
Base
.
getindex
(
v
::
_Variables
,
i
::
Symbol
)
=
getfield
(
v
,
:
variables
)[
i
]
...
@@ -102,6 +116,43 @@ Base.propertynames(v::_Variables) = Tuple(keys(getfield(v, :variables)))
...
@@ -102,6 +116,43 @@ Base.propertynames(v::_Variables) = Tuple(keys(getfield(v, :variables)))
Base
.
getproperty
(
v
::
_Variables
,
s
::
Symbol
)
=
v
[
s
]
Base
.
getproperty
(
v
::
_Variables
,
s
::
Symbol
)
=
v
[
s
]
"""
@defvar([getter, ], function(s))
Defines new [`variables`](@ref).
Each variable is defined as regular Julia functions embedded within a `@defvar` macro.
For example, to define a `variables.echo_time` variable for a `SpinEcho` sequence, one can use:
```julia
@defvar echo_time(ge::SpinEcho) = 2 * (variables.effective_time(ge, :refocus) - variables.effective_time(ge, :excitation))
```
Multiple variables can be defined in a single `@defvar` by including them in a code block:
```julia
@defvar begin
function var1(seq::SomeSequenceType)
...
end
function var2(seq::SomeSequenceType)
...
end
end
```
Before the variable function definitions one can include a `getter`.
This `getter` defines the type of the sequence component for which the variables will be defined.
If the variable is not defined for the sequence, the variable will be extracted for those type of sequence components instead.
The following sequence component types are provided:
- `pulse`: use [`get_pulse`](@ref)
- `gradient`: use [`get_gradient`](@ref)
- `readout`: use [`get_readout`](@ref)
- `pathway`: use [`get_pathway`](@ref)
e.g. the following defines a `flip_angle` variable, which is marked as a property of an RF pulse.
```julia
@defvar pulse flip_angle(...) = ...
```
If after this definition, `flip_angle` is not explicitly defined for any sequence, it will be extracted for the RF pulses in that sequence instead.
"""
macro
defvar
(
func_def
)
macro
defvar
(
func_def
)
return
_defvar
(
func_def
,
nothing
)
return
_defvar
(
func_def
,
nothing
)
end
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment