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

Automatic mask creation for MRS shimming based on voxel position #509

Open
wants to merge 22 commits into
base: master
Choose a base branch
from

Conversation

behrouzvia
Copy link
Contributor

@behrouzvia behrouzvia commented Jan 22, 2024

Checklist

  • I've given this PR a concise, self-descriptive, and meaningful title
  • I've applied the relevant labels to this PR
  • I've added relevant tests for my contribution
  • I've updated the documentation and/or added correct docstrings
  • I've assigned a reviewer

Description

A new functionality is added to masking for creating a mask that corresponds to the MRS voxel. The mask is created by reading the MRS voxel position from Siemens' MRS raw data. This mask can be used subsequently to shim the voxel position. The functionality is available through st_mask cli.

Linked issues

@behrouzvia behrouzvia added the feature Introduces a new functionality label Jan 22, 2024
@behrouzvia behrouzvia requested a review from po09i January 22, 2024 18:30
shimmingtoolbox/cli/mask.py Outdated Show resolved Hide resolved
shimmingtoolbox/cli/mask.py Outdated Show resolved Hide resolved
shimmingtoolbox/cli/mask.py Outdated Show resolved Hide resolved
shimmingtoolbox/cli/mask.py Outdated Show resolved Hide resolved
shimmingtoolbox/masking/mask_mrs.py Outdated Show resolved Hide resolved
shimmingtoolbox/masking/mask_mrs.py Outdated Show resolved Hide resolved
shimmingtoolbox/masking/mask_mrs.py Outdated Show resolved Hide resolved
shimmingtoolbox/masking/mask_mrs.py Outdated Show resolved Hide resolved
shimmingtoolbox/masking/mask_mrs.py Outdated Show resolved Hide resolved
shimmingtoolbox/masking/mask_mrs.py Outdated Show resolved Hide resolved
shimmingtoolbox/cli/mask.py Outdated Show resolved Hide resolved
@behrouzvia behrouzvia requested a review from po09i January 24, 2024 03:40
Copy link
Member

@po09i po09i left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have tried keeping the number of characters for each line below 120 characters. Some of the lines are too long.

Nice job on the last changes!

shimmingtoolbox/cli/mask.py Outdated Show resolved Hide resolved
shimmingtoolbox/cli/mask.py Outdated Show resolved Hide resolved
shimmingtoolbox/masking/mask_mrs.py Outdated Show resolved Hide resolved
shimmingtoolbox/masking/mask_mrs.py Outdated Show resolved Hide resolved
shimmingtoolbox/masking/mask_mrs.py Outdated Show resolved Hide resolved
shimmingtoolbox/masking/mask_mrs.py Outdated Show resolved Hide resolved
shimmingtoolbox/masking/mask_mrs.py Outdated Show resolved Hide resolved
shimmingtoolbox/masking/mask_mrs.py Outdated Show resolved Hide resolved
shimmingtoolbox/masking/mask_mrs.py Outdated Show resolved Hide resolved
shimmingtoolbox/masking/mask_mrs.py Outdated Show resolved Hide resolved
@behrouzvia
Copy link
Contributor Author

We have tried keeping the number of characters for each line below 120 characters. Some of the lines are too long.

Nice job on the last changes!

Thanks for the review and comments! I applied the suggestions.

@behrouzvia behrouzvia requested a review from po09i January 26, 2024 16:03
Copy link
Member

@po09i po09i left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Add tests for your new function
  • I'm not sure if you are using an editor, but most of the comments I am making are simply underlined in my editor to respect PEP conventions. If you are not using an editor, I suggests you do, if not, I suggest familiarizing yourself wit PEP conventions.
  • You can add my suggestions directly in GitHub rather than copying what I propose.

shimmingtoolbox/cli/mask.py Outdated Show resolved Hide resolved
shimmingtoolbox/cli/mask.py Outdated Show resolved Hide resolved
shimmingtoolbox/cli/mask.py Outdated Show resolved Hide resolved
shimmingtoolbox/masking/mask_mrs.py Outdated Show resolved Hide resolved
shimmingtoolbox/masking/mask_mrs.py Outdated Show resolved Hide resolved
shimmingtoolbox/masking/mask_mrs.py Outdated Show resolved Hide resolved
shimmingtoolbox/masking/mask_mrs.py Outdated Show resolved Hide resolved
shimmingtoolbox/masking/mask_mrs.py Outdated Show resolved Hide resolved
shimmingtoolbox/masking/mask_mrs.py Outdated Show resolved Hide resolved
shimmingtoolbox/masking/mask_mrs.py Outdated Show resolved Hide resolved
behrouzvia and others added 3 commits February 14, 2024 12:06
Correcting typos in the code

Co-authored-by: Alex Dastous <47249340+po09i@users.noreply.github.com>
@po09i
Copy link
Member

po09i commented Feb 27, 2024

Once a test has been implemented to automatically figure out the center location of MRS data, we can merge this PR

@behrouzvia behrouzvia requested a review from po09i June 15, 2024 22:14
@po09i
Copy link
Member

po09i commented Jun 17, 2024

Tests are failing, I'll review when all tests pass :)

@click.option('-i', '--input', 'fname_input', type=click.Path(), required=True,
help="Input path of the fieldmap to be shimmed.")
@click.option('-r', '--raw_data', type=click.Path(),
help="Input path of the of the siemens raw-data (supported extention .rda)")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
help="Input path of the of the siemens raw-data (supported extention .rda)")
help="Input path of the siemens raw-data (supported extention .rda)")

Comment on lines +318 to +319
show_default=True, help="Name of the output mask. Supported extensions are .nii or .nii.gz. (default: "
"(os.curdir, 'mask_mrs.nii.gz'))")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to tell what the default is in the description. You already see it with the option "show_default"

Suggested change
show_default=True, help="Name of the output mask. Supported extensions are .nii or .nii.gz. (default: "
"(os.curdir, 'mask_mrs.nii.gz'))")
show_default=True, help="Name of the output mask. Supported extensions are .nii or .nii.gz.")

Comment on lines +194 to +206
run_subprocess(['spec2nii', 'rda', mrs_raw_data, '-o', tmp])
name_nii, ext = os.path.splitext(mrs_raw_data)
nii_path = os.path.join(tmp, 'sub-1_acq-press-siemens-shim_nuc-H_echo-135_svs.nii.gz')
nii = nib.load(nii_path)
header_raw_data = nii.header
position_sag = header_raw_data['qoffset_x']
position_cor = header_raw_data['qoffset_y']
position_tra = header_raw_data['qoffset_z']

mrs_center = np.array([position_sag, position_cor, position_tra])
mrs_voxel_size = header_raw_data['pixdim'][1:4]
mrs_voxel_size_str = ' '.join(map(str, mrs_voxel_size))
mrs_center_str = ' '.join(map(str, mrs_center))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not reimplement mask_mrs in the test. Just use what mrs_center_str and what mrs_voxel_size_str contain. The idea is giving a know input and verify that the output is the same across versions of the code. If you include all or some of the implementation of the API, we might not catch these differences.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test where you give the .rda file as an input

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Introduces a new functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants