Skip to content

Commit

Permalink
Update to use full 'data' dir from head phantom
Browse files Browse the repository at this point in the history
  • Loading branch information
astewartau committed Jan 2, 2024
1 parent 3130c91 commit 77c414f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dist/
head-phantom-maps/
data/
qsm_forward.egg-info/
*.nii*
*__pycache__*
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ Some repesentative images including the mask, first and last-echo phase image, a

## Example using head phantom data

In this example, we generate a BIDS-compliant dataset based on head phantom maps. You must provide these maps yourself by gaining access to the QSM Challenge 2.0 head phantom data or generating your own realistic maps:
In this example, we generate a BIDS-compliant dataset based on the [realistic in-silico head phantom](https://doi.org/10.34973/m20r-jt17). If you have access to the head phantom, you need to retain the `data` directory which provides relevant tissue parameters:

```python
import qsm_forward
import numpy as np

if __name__ == "__main__":
tissue_params = qsm_forward.TissueParams("../head-phantom-maps")
tissue_params = qsm_forward.TissueParams(root_dir="~/data")

recon_params_all = [
qsm_forward.ReconParams(voxel_size=voxel_size, peak_snr=100, session=session)
Expand Down Expand Up @@ -179,7 +179,7 @@ import qsm_forward
import numpy as np

if __name__ == "__main__":
tissue_params = qsm_forward.TissueParams("../head-phantom-maps", chi="ChiModelMIX.nii.gz")
tissue_params = qsm_forward.TissueParams(root_dir="~/data", chi="ChiModelMIX.nii.gz")

recon_params_all = [
qsm_forward.ReconParams(voxel_size=voxel_size, session=session, TEs=TEs, TR=TR, flip_angle=flip_angle, suffix=suffix, export_phase=export_phase)
Expand Down
5 changes: 3 additions & 2 deletions qsm_forward/examples/head_phantom_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
The simulations are carried out with various reconstruction parameters
(which include different voxel sizes), and the results are saved in the "bids" directory.
The tissue parameters are loaded from the directory "../head-phantom-maps".
The tissue parameters are loaded from the directory "../data". The data directory can
be downloaded from https://doi.org/10.34973/m20r-jt17.
Author: Ashley Stewart ([email protected])
"""
Expand All @@ -16,7 +17,7 @@
import numpy as np

if __name__ == "__main__":
tissue_params = qsm_forward.TissueParams("~/head-phantom-maps", chi="ChiModelMIX.nii.gz")
tissue_params = qsm_forward.TissueParams(root_dir="~/data")

recon_params_all = [
qsm_forward.ReconParams(voxel_size=voxel_size, TEs=TEs, TR=TR, flip_angle=flip_angle, suffix=suffix, export_phase=export_phase)
Expand Down
6 changes: 3 additions & 3 deletions qsm_forward/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def main():

# Create subcommands
subparsers = parser.add_subparsers(dest='mode')
headphantom_parser = subparsers.add_parser('head', help='Use head phantom maps for simulation')
headphantom_parser = subparsers.add_parser('head', help='Use realistic in-silico head phantom for simulation')
simplephantom_parser = subparsers.add_parser('simple', help='Generate simple susceptibility sources for simulation')

def argparse_bool(user_in):
Expand All @@ -23,7 +23,7 @@ def argparse_bool(user_in):
if user_in in ['off', 'false', 'no']: return False
raise ValueError(f"Invalid boolean value {user_in}; use on/yes/true or off/false/no")# Arguments specific to phantom simulation

headphantom_parser.add_argument('maps', help='Head phantom maps directory')
headphantom_parser.add_argument('data', help='Head phantom data directory (download from https://doi.org/10.34973/m20r-jt17)')

# Arguments common to both subcommands
for sub_parser in [headphantom_parser, simplephantom_parser]:
Expand Down Expand Up @@ -60,7 +60,7 @@ def argparse_bool(user_in):
args = parser.parse_args()

if args.mode == 'head':
tissue_params = qsm_forward.TissueParams(args.maps)
tissue_params = qsm_forward.TissueParams(args.data)

elif args.mode == 'simple':
tissue_params = qsm_forward.TissueParams(
Expand Down
14 changes: 8 additions & 6 deletions qsm_forward/qsm_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class TissueParams:
Attributes
----------
root_dir : str or None
The path to the root directory containing the tissue parameter files.
chi_path : str or ndarray
The path to the Chi file or a 3D numpy array containing Chi values.
M0_path : str or ndarray
Expand All @@ -34,12 +36,12 @@ class TissueParams:
def __init__(
self,
root_dir = "",
chi = "ChiModelMIX_noCalc.nii.gz",
M0 = "M0.nii.gz",
R1 = "R1.nii.gz",
R2star = "R2star.nii.gz",
mask = "BrainMask.nii.gz",
seg = "SegmentedModel.nii.gz",
chi = "chimodel/ChiModelMIX.nii",
M0 = "maps/M0.nii.gz",
R1 = "maps/R1.nii.gz",
R2star = "maps/R2star.nii.gz",
mask = "masks/BrainMask.nii.gz",
seg = "masks/SegmentedModel.nii.gz",
apply_mask = False
):
if isinstance(chi, str) and not os.path.exists(os.path.join(root_dir, chi)):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='qsm-forward',
version='0.18',
version='0.19',
packages=find_packages(),
url='https://github.com/astewartau/qsm-forward',
author='Ashley Stewart',
Expand Down

0 comments on commit 77c414f

Please sign in to comment.