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

KomaMRIIO subpackage #231

Merged
merged 41 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
3ca7139
Update phantom section with pelvis example in docs
beorostica Nov 22, 2023
1bd5ee7
Add simple contributing guidelines
beorostica Nov 22, 2023
f7d0fcc
Create simple KomaMRIIO subpackage
beorostica Nov 27, 2023
d69698e
Update ci.yml and minor dependency changes for KomaMRIIO
beorostica Nov 28, 2023
210c517
Remove MRI dependencies from KomaMRIIO
beorostica Nov 28, 2023
bb696e9
Update ci.yml to include codecov for KomaMRIIO
beorostica Nov 28, 2023
3eaace2
Merge branch 'master' into komaio
beorostica Nov 28, 2023
93dc116
Reexport ISMRMRDFile from KomaMRIIO
beorostica Nov 28, 2023
2150390
Use functions from KomaMRIIO and reduce number of dependencies
beorostica Nov 29, 2023
80ec68c
Use descriptive names for folders in KomaMRIIO
beorostica Nov 29, 2023
f65c8fc
Add KomaMRIIO version in UI
beorostica Nov 29, 2023
a4dbfdf
Update CONTRIBUTING.md
beorostica Nov 29, 2023
66e65f3
Merge branch 'master' into komaio
beorostica Nov 29, 2023
1e81082
Update ci.yml to consider develop environment of KomaMRIIO
beorostica Nov 29, 2023
5f8cb28
Consider KomaMRIIO in docs generation
beorostica Nov 29, 2023
072f361
Update contributing guidelines
beorostica Nov 29, 2023
721fef5
Include a Contributing section in README.md
beorostica Nov 29, 2023
094243f
Remove KomaMRIIO from KomaMRIPlots
beorostica Nov 29, 2023
9ca5957
Remove the unnecessary KomaMRIIO prefix from function calls
beorostica Nov 29, 2023
5ad188e
Update README.md with information about KomaMRIIO
beorostica Nov 29, 2023
36fd490
Update README.md
beorostica Nov 29, 2023
f425357
Update README.md
beorostica Nov 29, 2023
a7145d6
Use KomaMRIIO for testing KomaMRICore
beorostica Nov 30, 2023
f9e5e84
Utilize multiple-dispatching for simulation output
beorostica Nov 30, 2023
d9b7b2a
Change InteractiveUtils compat
beorostica Nov 30, 2023
1bef1df
Change name of simulation output structs
beorostica Nov 30, 2023
97640b1
Add consistent names for simulation output structs
beorostica Nov 30, 2023
8ff77bb
Move signal_to_raw_data() to KomaMRICore
beorostica Nov 30, 2023
dfda824
Remove simulation output functions
beorostica Nov 30, 2023
091441d
Remove InteractiveUtils package
beorostica Nov 30, 2023
2597f59
Remove show() tests
beorostica Nov 30, 2023
c85b5df
Simple tests for show() function
beorostica Nov 30, 2023
f42277c
Create a function to update encoding parameters for RawAcquisitionData
beorostica Dec 1, 2023
2115656
Fix XML saving
beorostica Dec 1, 2023
f624ab4
Rewrite insertNode function
beorostica Dec 1, 2023
2194121
Remove import for EncodingEncounters
beorostica Dec 1, 2023
7f48a03
Explicit types in ISMRMRD
cncastillo Dec 1, 2023
0a24ee5
Remove unnecessary KomaMRICore from test environment of KomaMRIIO
beorostica Dec 1, 2023
21e472e
Merge branch 'komaio' of github.com:cncastillo/KomaMRI.jl into komaio
beorostica Dec 1, 2023
7348532
Removes off-resonance from default UI phantom
cncastillo Dec 1, 2023
435f8f8
Merge branch 'master' into komaio
cncastillo Dec 1, 2023
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
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,26 @@ jobs:
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- name: "KomaMRICore dev setup"
shell: bash
run: |
julia --color=yes --project="KomaMRICore" -e "using Pkg; Pkg.develop(PackageSpec(; path=\"./KomaMRIIO\"));"
- uses: julia-actions/julia-buildpkg@v1
with:
project: KomaMRICore
- uses: julia-actions/julia-runtest@v1
with:
project: KomaMRICore
- name: "KomaMRIIO dev setup"
shell: bash
run: |
julia --color=yes --project="KomaMRIIO" -e "using Pkg; Pkg.develop(PackageSpec(; path=\"./KomaMRICore\"));"
- uses: julia-actions/julia-buildpkg@v1
with:
project: KomaMRIIO
- uses: julia-actions/julia-runtest@v1
with:
project: KomaMRIIO
cncastillo marked this conversation as resolved.
Show resolved Hide resolved
- name: "KomaMRIPlots dev setup"
shell: bash
run: |
Expand All @@ -61,6 +75,7 @@ jobs:
shell: julia --color=yes --project {0}
run: |
using Pkg
Pkg.develop(PackageSpec(path=pwd(), subdir="KomaMRIIO"))
Pkg.develop(PackageSpec(path=pwd(), subdir="KomaMRICore"))
Pkg.develop(PackageSpec(path=pwd(), subdir="KomaMRIPlots"))
- uses: julia-actions/julia-buildpkg@v1
Expand Down Expand Up @@ -88,6 +103,13 @@ jobs:
with:
files: lcov.info
flags: plots
- uses: julia-actions/julia-processcoverage@v1
with:
directories: KomaMRIIO/src
- uses: codecov/codecov-action@v3
with:
files: lcov.info
flags: io
docs:
name: Documentation
runs-on: ubuntu-latest
Expand All @@ -99,6 +121,9 @@ jobs:
- run: |
julia --project=docs -e '
using Pkg
Pkg.develop(PackageSpec(path=pwd(), subdir="KomaMRIIO"))
Pkg.develop(PackageSpec(path=pwd(), subdir="KomaMRICore"))
Pkg.develop(PackageSpec(path=pwd(), subdir="KomaMRIPlots"))
Pkg.develop(PackageSpec(path=pwd()))
Pkg.instantiate()'
- run: |
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*.jl.cov
*.jl.mem
.DS_Store
*Manifest.toml
**/Manifest.toml
/test/Manifest.toml
/dev/
.vscode/settings.json
Expand Down
64 changes: 64 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Contributing Guidelines

Thanks for taking the time to contribute to KomaMRI! ❤️

We appreciate your interest in improving this project. Before you start contributing, please take a moment to review the following guidelines.


## Reporting Issues

First off, we assume that you have read the available [Documentation](https://cncastillo.github.io/KomaMRI.jl).

Before you report an issue, it is best to search for existing [Issues](https://github.com/cncastillo/KomaMRI.jl/issues) that might help you. In case you have found a suitable issue and still need clarification, you can write your question in this issue.

If you then still feel the need to report an issue, we recommend the following:

- Open an [Issue](https://github.com/cncastillo/KomaMRI.jl/issues/new).
- Provide as much context as you can about what you're running into.
- Provide project and platform versions, depending on what seems relevant.

We will then take care of the issue as soon as possible.


## How to Contribute

1. **Fork KomaMRI Repository**: Fork the [KomaMRI.jl repository](https://github.com/cncastillo/KomaMRI.jl) to your GitHub account to create a personal copy.

2. **Clone Fork to Local Machine**: Clone your fork of the repository to your local machine using the following Git command:

```bash
git clone [email protected]:<your-username>/KomaMRI.jl.git
```

3. **Create Contribution Branch**: Create a new branch dedicated to your contribution within the cloned repository.

```bash
git checkout -b feature/your-feature
```

4. **Implement Code Changes**: Introduce your modifications, ensuring adherence to the [Julia Blue Style Guidelines](https://github.com/invenia/BlueStyle). For new features, include informative comments, docstrings, and consider enriching the documentation with relevant examples.

5. **Validate Changes with Tests**: Execute existing tests to verify the compatibility of your alterations with the current functionality. If applicable, incorporate additional tests to validate your new contributions.

6. **Commit Code Changes**: Commit your modifications with a precise and descriptive commit message using the following Git command:

```bash
git commit -m "Add a concise summary of your changes"
```

7. **Push Changes to Your Fork**: Push your committed changes to the corresponding branch on your forked repository:

```bash
git push origin feature/your-feature
```

8. **Initiate Pull Request (PR)**: Propose your changes by creating a pull request against the `master` branch of the KomaMRI repository. Provide a clear title and a detailed description of your modifications. Ensure that your pull request is linked to an issue by including its #ID in the description.

9. **Undergo Code Review**: Subject your code to review by maintainers, who will provide feedback and may request further adjustments before merging.


## License

By contributing to KomaMRI, you agree that your contributions will be licensed under the [MIT License](https://github.com/cncastillo/KomaMRI.jl/blob/master/LICENSE).

Thank you for contributing to KomaMRI! 🌟
8 changes: 0 additions & 8 deletions KomaMRICore/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ version = "0.7.7"
[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
Functors = "d9f16b24-f501-4c13-a1f2-28368ffc5196"
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
MAT = "23992714-dd62-5051-b70f-ba57cb901cac"
MRIBase = "f7771a9a-6e57-4e71-863b-6e4b6a2f17df"
MRIFiles = "5a6f062f-bf45-497d-b654-ad17aae2a530"
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
Expand All @@ -24,14 +20,10 @@ ThreadsX = "ac1d9e8a-700a-412c-b207-f0111f4b6c0d"
[compat]
Adapt = "3"
CUDA = "3, 4, 5"
FileIO = "1"
Functors = "0.4"
HDF5 = "0.16, 0.17"
Interpolations = "0.13, 0.14"
JLD2 = "0.4"
MAT = "0.10"
MRIBase = "0.3, 0.4"
MRIFiles = "0.1, 0.2"
Parameters = "0.12"
Pkg = "1.4"
ProgressMeter = "1"
Expand Down
22 changes: 8 additions & 14 deletions KomaMRICore/src/KomaMRICore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ using Parameters
using Interpolations
using CUDA
#Reconstruction
using MRIBase, MRIFiles
@reexport using MRIBase: Profile, RawAcquisitionData, AcquisitionData, AcquisitionHeader
@reexport using MRIFiles: ISMRMRDFile
#IO
using FileIO, HDF5, MAT, JLD2
using MRIBase
@reexport using MRIBase: EncodingCounters, Profile, RawAcquisitionData, AcquisitionData, AcquisitionHeader
using MAT # For loading example phantoms

global γ = 42.5774688e6; #Hz/T gyromagnetic constant for H1, JEMRIS uses 42.5756 MHz/T

Expand All @@ -29,11 +27,10 @@ include("datatypes/sequence/ADC.jl")
include("simulation/KeyValuesCalculation.jl")
include("datatypes/Sequence.jl")
include("datatypes/sequence/Delay.jl")
include("io/Pulseq.jl")
#Phantom
include("datatypes/Phantom.jl")
include("io/JEMRIS.jl")
include("io/MRiLab.jl")
#Rawdata
include("rawdata/ISMRMRD.jl")
#Simulator
include("datatypes/simulation/DiscreteSequence.jl")
include("datatypes/simulation/Spinor.jl")
Expand All @@ -43,23 +40,20 @@ include("simulation/GPUFunctions.jl")
# include("simulation/other/OffResonanceModel.jl")
include("simulation/TrapezoidalIntegration.jl")
include("simulation/SimulatorCore.jl")
include("io/ISMRMRD.jl")

#Main
export γ #gyro-magnetic ratio [Hz/T]
export Scanner, Sequence, Phantom
export Grad, RF, ADC, Delay
export Mag, dur
#Pulseq
export read_seq
#ISMRMRD
export signal_to_raw_data
#Phantom
export brain_phantom2D, brain_phantom3D, read_phantom_jemris, read_phantom_MRiLab
export brain_phantom2D, brain_phantom3D
#Spinors
export Spinor, Rx, Ry, Rz, Q, Un
#Secondary
export get_kspace, rotx, roty, rotz
#ISMRMRD
export signal_to_raw_data
#Simulator
export simulate, simulate_slice_profile

Expand Down
76 changes: 76 additions & 0 deletions KomaMRICore/src/datatypes/Phantom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,79 @@
)
return obj
end

"""
obj = pelvis_phantom2D(; ss=4)

Creates a two-dimensional pelvis Phantom struct.

# Keywords
- `ss`: (`::Integer`, `=4`) subsampling parameter

# Returns
- `obj`: (`::Phantom`) Phantom struct

# Examples
```julia-repl
julia> obj = pelvis_phantom2D(; ss=1)

julia> pelvis_phantom2D(obj, :ρ)
```
"""
function pelvis_phantom2D(; ss=4)

Check warning on line 412 in KomaMRICore/src/datatypes/Phantom.jl

View check run for this annotation

Codecov / codecov/patch

KomaMRICore/src/datatypes/Phantom.jl#L412

Added line #L412 was not covered by tests

# Get data from .mat file
path = @__DIR__
data = MAT.matread(path*"/phantom/pelvis2D.mat")
class = data["pelvis3D_slice"][1:ss:end,1:ss:end]

Check warning on line 417 in KomaMRICore/src/datatypes/Phantom.jl

View check run for this annotation

Codecov / codecov/patch

KomaMRICore/src/datatypes/Phantom.jl#L415-L417

Added lines #L415 - L417 were not covered by tests

# Define spin position vectors
Δx = .5e-3*ss
M, N = size(class)
FOVx = (M-1)*Δx # [m]
FOVy = (N-1)*Δx # [m]
x = -FOVx/2:Δx:FOVx/2 # spin coordinates
y = -FOVy/2:Δx:FOVy/2 # spin coordinates
x, y = x .+ y'*0, x*0 .+ y' # grid points

Check warning on line 426 in KomaMRICore/src/datatypes/Phantom.jl

View check run for this annotation

Codecov / codecov/patch

KomaMRICore/src/datatypes/Phantom.jl#L420-L426

Added lines #L420 - L426 were not covered by tests

# Define spin property vectors
ρ = (class.==51)*.001 .+ # Air

Check warning on line 429 in KomaMRICore/src/datatypes/Phantom.jl

View check run for this annotation

Codecov / codecov/patch

KomaMRICore/src/datatypes/Phantom.jl#L429

Added line #L429 was not covered by tests
(class.==102)*.86 .+ # Fat
(class.==153)*.9 .+ # SoftTissue
(class.==204)*.4 .+ # SpongyBone
(class.==255)*.2 # CorticalBone
T1 = (class.==51)*.001 .+ # Air

Check warning on line 434 in KomaMRICore/src/datatypes/Phantom.jl

View check run for this annotation

Codecov / codecov/patch

KomaMRICore/src/datatypes/Phantom.jl#L434

Added line #L434 was not covered by tests
(class.==102)*366 .+ # Fat
(class.==153)*1200 .+ # SoftTissue
(class.==204)*381 .+ # SpongyBone
(class.==255)*100 # CorticalBone
T2 = (class.==51)*.001 .+ # Air

Check warning on line 439 in KomaMRICore/src/datatypes/Phantom.jl

View check run for this annotation

Codecov / codecov/patch

KomaMRICore/src/datatypes/Phantom.jl#L439

Added line #L439 was not covered by tests
(class.==102)*70 .+ # Fat
(class.==153)*80 .+ # SoftTissue
(class.==204)*52 .+ # SpongyBone
(class.==255)*.3 # CorticalBone
T2s = (class.==51)*.001 .+ # Air

Check warning on line 444 in KomaMRICore/src/datatypes/Phantom.jl

View check run for this annotation

Codecov / codecov/patch

KomaMRICore/src/datatypes/Phantom.jl#L444

Added line #L444 was not covered by tests
(class.==102)*70 .+ # Fat
(class.==153)*80 .+ # SoftTissue
(class.==204)*52 .+ # SpongyBone
(class.==255)*.3 # CorticalBone
Δw_fat = -220 * 2π
Δw = (class.==102) * Δw_fat # FAT1
T1 = T1*1e-3
T2 = T2*1e-3
T2s = T2s*1e-3

Check warning on line 453 in KomaMRICore/src/datatypes/Phantom.jl

View check run for this annotation

Codecov / codecov/patch

KomaMRICore/src/datatypes/Phantom.jl#L449-L453

Added lines #L449 - L453 were not covered by tests

# Define and return the Phantom struct
obj = Phantom{Float64}(

Check warning on line 456 in KomaMRICore/src/datatypes/Phantom.jl

View check run for this annotation

Codecov / codecov/patch

KomaMRICore/src/datatypes/Phantom.jl#L456

Added line #L456 was not covered by tests
name = "pelvis2D",
x = y[ρ.!=0],
y = x[ρ.!=0],
z = 0*x[ρ.!=0],
ρ = ρ[ρ.!=0],
T1 = T1[ρ.!=0],
T2 = T2[ρ.!=0],
T2s = T2s[ρ.!=0],
Δw = Δw[ρ.!=0],
)
return obj

Check warning on line 467 in KomaMRICore/src/datatypes/Phantom.jl

View check run for this annotation

Codecov / codecov/patch

KomaMRICore/src/datatypes/Phantom.jl#L467

Added line #L467 was not covered by tests
end
Binary file added KomaMRICore/src/datatypes/phantom/pelvis2D.mat
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
"""
It is the same as defined in MRIFiles without the need to import MRIFiles
"""
struct Limit
minimum::Int
maximum::Int
center::Int
end

cncastillo marked this conversation as resolved.
Show resolved Hide resolved
"""
raw = signal_to_raw_data(signal, seq; phantom_name, sys, sim_params)

Expand Down Expand Up @@ -79,7 +88,7 @@ function signal_to_raw_data(
"reconFOV" => [FOVx, FOVy, 1.0], #reconSpace>fieldOfView_mm
"encodedSize" => [Nx, Ny, 1], #encodedSpace>matrixSize
"reconSize" => [Nx+Nx%2, Ny+Ny%2, 1], #reconSpace>matrixSize
#encodingLimits>
#encoding limits
"enc_lim_kspace_encoding_step_1" => Limit(0, Nx-1, ceil(Int, Nx / 2)), #min, max, center, e.g. phase encoding line number
"enc_lim_kspace_encoding_step_2" => Limit(0, 0, 0), #min, max, center, e.g. partition encoding number
"enc_lim_average" => Limit(0, 0, 0), #min, max, center, e.g. signal average number
Expand All @@ -99,7 +108,7 @@ function signal_to_raw_data(

#Then, we define the Profiles
profiles = Profile[]
t_acq = get_adc_sampling_times(seq)
t_acq = KomaMRICore.get_adc_sampling_times(seq)
Nadcs = sum(is_ADC_on.(seq))
NadcsPerImage = floor(Int, Nadcs / Nz)
scan_counter = 0
Expand Down
2 changes: 1 addition & 1 deletion KomaMRICore/src/simulation/SimulatorCore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@
seq::Sequence;
z=range(-2.e-2, 2.e-2, 200), sim_params=Dict{String,Any}("Δt_rf" => 1e-6)
)
sim_params["return_type"] = "state"
sim_params["return_type"] = SpinsStateSimOutput()

Check warning on line 265 in KomaMRICore/src/simulation/SimulatorCore.jl

View check run for this annotation

Codecov / codecov/patch

KomaMRICore/src/simulation/SimulatorCore.jl#L265

Added line #L265 was not covered by tests
sys = Scanner()
obj = Phantom{Float64}(x=zeros(size(z)), z=Array(z))
mag = simulate(obj, seq, sys; sim_params)
Expand Down
1 change: 1 addition & 0 deletions KomaMRICore/test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[deps]
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
KomaMRIIO = "fcf631a6-1c7e-4e88-9e64-b8888386d9dc"
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
Expand Down
Loading