From 77c414fedbdc6e4349775734f868f3638a8aa1ec Mon Sep 17 00:00:00 2001 From: Ashley Stewart Date: Tue, 2 Jan 2024 14:47:29 +1000 Subject: [PATCH] Update to use full 'data' dir from head phantom --- .gitignore | 2 +- README.md | 6 +++--- qsm_forward/examples/head_phantom_maps.py | 5 +++-- qsm_forward/main.py | 6 +++--- qsm_forward/qsm_forward.py | 14 ++++++++------ setup.py | 2 +- 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index a9fa552..e423b82 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ dist/ -head-phantom-maps/ +data/ qsm_forward.egg-info/ *.nii* *__pycache__* diff --git a/README.md b/README.md index d4a268f..4860c50 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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) diff --git a/qsm_forward/examples/head_phantom_maps.py b/qsm_forward/examples/head_phantom_maps.py index 06638fc..dd182b2 100755 --- a/qsm_forward/examples/head_phantom_maps.py +++ b/qsm_forward/examples/head_phantom_maps.py @@ -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 (a.stewart.au@gmail.com) """ @@ -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) diff --git a/qsm_forward/main.py b/qsm_forward/main.py index 7a4404c..3207590 100644 --- a/qsm_forward/main.py +++ b/qsm_forward/main.py @@ -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): @@ -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]: @@ -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( diff --git a/qsm_forward/qsm_forward.py b/qsm_forward/qsm_forward.py index 89f71f3..b3835d7 100644 --- a/qsm_forward/qsm_forward.py +++ b/qsm_forward/qsm_forward.py @@ -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 @@ -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)): diff --git a/setup.py b/setup.py index c390438..f57414e 100644 --- a/setup.py +++ b/setup.py @@ -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',