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

Refactor AcqInfo and Trajectory Calculation #560

Open
wants to merge 32 commits into
base: main
Choose a base branch
from

Conversation

fzimmermann89
Copy link
Member

@fzimmermann89 fzimmermann89 commented Nov 26, 2024

Removes fields from AcqInfo only requiered for trajectory calculation.

Trajecotry calculators no longer get the full header as parameters.

TODO: Docstrings could be improved

[ghstack-poisoned]
[ghstack-poisoned]
fzimmermann89 added a commit that referenced this pull request Nov 26, 2024
ghstack-source-id: a4a2be048199eeaa9cf2647606a6e24fd4a4b307
ghstack-comment-id: 2501006700
Pull Request resolved: #560
Copy link
Contributor

github-actions bot commented Nov 26, 2024

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/mrpro/algorithms/csm
   inati.py24196%44
   walsh.py16194%34
src/mrpro/algorithms/dcf
   dcf_voronoi.py53492%15, 48–49, 76
src/mrpro/algorithms/optimizers
   adam.py20195%69
src/mrpro/algorithms/reconstruction
   DirectReconstruction.py281643%51–71, 85
   IterativeSENSEReconstruction.py13192%76
   Reconstruction.py502256%42, 54–56, 80–87, 104–113
   RegularizedIterativeSENSEReconstruction.py411759%96–100, 114–139
src/mrpro/data
   AcqInfo.py146597%51, 55, 59, 229, 267
   CsmData.py29390%15, 82–84
   DcfData.py45882%18, 66, 78–83
   EncodingLimits.py73396%33, 123, 126
   IData.py67987%119, 125, 129, 159–167
   IHeader.py75791%75, 109, 127–131
   KData.py2222788%112–113, 128, 135, 147–158, 167, 175, 184–188, 240–241, 281, 298, 303–304, 326–327, 487, 489, 562, 626, 635
   KHeader.py1391490%24, 109–113, 140, 188, 195–196, 199, 206, 223–230
   KNoise.py311552%39–52, 56–61
   KTrajectory.py81791%108–113, 116–118
   MoveDataMixin.py1401887%15, 113, 129, 143–145, 207, 323–325, 338, 417, 437–438, 440, 455–456, 458
   QData.py39782%42, 65–73
   Rotation.py6743595%100, 198, 335, 433, 477, 495, 581, 583, 592, 626, 628, 691, 768, 773, 776, 791, 808, 813, 889, 1077, 1082, 1085, 1109, 1113, 1240, 1242, 1250–1251, 1315, 1397, 1690, 1846, 1881, 1885, 1996
   SpatialDimension.py2322091%34, 104, 148, 154, 274–276, 289–291, 325, 343, 356, 369, 382, 395, 404–405, 420, 429
   acq_filters.py12192%47
src/mrpro/data/traj_calculators
   KTrajectoryCalculator.py27196%85
   KTrajectoryIsmrmrd.py13285%41, 50
src/mrpro/operators
   CartesianSamplingOp.py89397%118, 157, 280
   ConstraintsOp.py60297%46, 48
   EndomorphOperator.py65297%228, 234
   FiniteDifferenceOp.py27293%40, 105
   FourierOp.py158398%263, 381, 386
   Functional.py71593%20–22, 117, 119
   GridSamplingOp.py136993%72–73, 82–83, 90–91, 94, 96, 98
   LinearOperator.py1681094%55, 91, 190, 220, 261, 270, 278, 287, 295, 320
   LinearOperatorMatrix.py1581690%82, 119, 152, 161, 166, 175–178, 191–194, 203, 215, 304, 331, 359
   MultiIdentityOp.py13285%43, 48
   Operator.py78297%25, 74
   ProximableFunctionalSeparableSum.py39392%50, 103, 110
   SliceProjectionOp.py173895%44, 61, 63, 69, 206, 227, 260, 300
   WaveletOp.py120596%152, 170, 205, 210, 233
   ZeroPadOp.py16194%30
src/mrpro/utils
   filters.py62297%44, 49
   reshape.py60198%191
   slice_profiles.py46687%20, 36, 113–116, 149
   sliding_window.py34197%34
   split_idx.py10280%43, 47
   summarize_tensorvalues.py11282%23, 25
   typing.py181139%8–23
   zero_pad_or_crop.py31681%26, 30, 54, 57, 60, 63
TOTAL490734993% 

Tests Skipped Failures Errors Time
2261 0 💤 2 ❌ 0 🔥 1m 7s ⏱️

[ghstack-poisoned]
fzimmermann89 added a commit that referenced this pull request Nov 27, 2024
ghstack-source-id: 8a5af9ccc79767b8873ef067dcc746bcc6e48f69
ghstack-comment-id: 2501006700
Pull Request resolved: #560
[ghstack-poisoned]
fzimmermann89 added a commit that referenced this pull request Nov 27, 2024
ghstack-source-id: d1ac51bfb1f9c81a7bc7cdbcaf4c0f4e95de0959
ghstack-comment-id: 2501006700
Pull Request resolved: #560
@fzimmermann89 fzimmermann89 changed the title Refactor AcqInfo and Header information Refactor AcqInfo and Trajectory Calculation Nov 27, 2024
[ghstack-poisoned]
[ghstack-poisoned]
@fzimmermann89 fzimmermann89 changed the base branch from gh/fzimmermann89/32/head to gh/fzimmermann89/34/head November 28, 2024 15:50
fzimmermann89 added a commit that referenced this pull request Nov 28, 2024
ghstack-source-id: 1004c06750b10a12ef0e92e22463e872227b5b15
ghstack-comment-id: 2501006700
Pull Request resolved: #560
Copy link
Contributor

github-actions bot commented Nov 28, 2024

📚 Documentation

📁 Download as zip
🔍 View online

@fzimmermann89 fzimmermann89 marked this pull request as ready for review November 28, 2024 16:01
src/mrpro/data/AcqInfo.py Outdated Show resolved Hide resolved
src/mrpro/data/AcqInfo.py Outdated Show resolved Hide resolved
discard_post=tensor_2d(headers['discard_post']),
discard_pre=tensor_2d(headers['discard_pre']),
encoding_space_ref=tensor_2d(headers['encoding_space_ref']),
acquisition_time_stamp=tensor_2d(headers['acquisition_time_stamp']).double(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think casting to double is a good idea here and for the PhysiologyTimestamps, because these parameters are very likely to be used in signal models leading than to the whole signal model being evaluated in double precision. I would probably leave it as int - this might be another indicator for users that these are not times in [s] but discrete timesteps

Copy link
Member Author

Choose a reason for hiding this comment

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

we should come up with a solution here.
it it is int, it is quite easy to make the mistake "acquisition_time_stamp*2.5" which will not work as expected..

also, if i am not mistaken, we would anyways assume it is in 2.5ms steps when we use it in signal models.
so maybe we can just convert it when loading from ismrmrd to seconds, assuming 2.5ms steps.
if there ever is another source for ismrmrd files that uses a different step, we should handle that case separately.

So i would change the documentation to
"usually in seconds since midnight (Siemens). For other vendors, this will be the vendor time stamp times 2.5e-3"

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think seconds makes most sense but we should check the vendor and print a warning if not Siemens. Soon we will hopefully have similar data from the low-field scanner and it would be nice to have a higher resolution than 2.5ms...

src/mrpro/data/traj_calculators/KTrajectoryCalculator.py Outdated Show resolved Hide resolved
src/mrpro/data/traj_calculators/KTrajectoryCalculator.py Outdated Show resolved Hide resolved
src/mrpro/data/traj_calculators/KTrajectoryPulseq.py Outdated Show resolved Hide resolved
src/mrpro/data/traj_calculators/KTrajectoryRpe.py Outdated Show resolved Hide resolved
src/mrpro/data/traj_calculators/KTrajectoryRpe.py Outdated Show resolved Hide resolved
src/mrpro/data/traj_calculators/KTrajectoryRpe.py Outdated Show resolved Hide resolved
This was referenced Dec 16, 2024
@PTB-MR PTB-MR deleted a comment from ckolbPTB Dec 16, 2024
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@fzimmermann89 fzimmermann89 mentioned this pull request Dec 23, 2024
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@fzimmermann89 fzimmermann89 mentioned this pull request Dec 29, 2024
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
ismrmrd_header.acquisitionSystemInformation is None
or ismrmrd_header.acquisitionSystemInformation.systemVendor is None
):
warnings.warn('No vendor information found. Assuming Siemens time stamp format.', stacklevel=1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think here you are missing another convert_time_stamp = convert_time_stamp_siemens # 2.5ms time steps but I would actually suggest to add another converter which interprets the integer time stamps as time in ms and use that if there is no vendor information or if the vendor is unknown.

note = 'discard_pre and post were applied.'
else:
note = 'discard_pre and discard_post were empty.'
warnings.warn(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be moved out of the else statement?

reversed_readout_mask: torch.Tensor | None = None,
**_,
) -> KTrajectory:
"""Calculate radial phase encoding trajectory for given KHeader.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"""Calculate radial phase encoding trajectory for given KHeader.
"""Calculate radial phase encoding trajectory for given header information.

k2_idx: torch.Tensor,
reversed_readout_mask: torch.Tensor | None = None,
**_,
) -> KTrajectory:
"""Calculate radial phase encoding trajectory for given KHeader.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"""Calculate radial phase encoding trajectory for given KHeader.
"""Calculate radial phase encoding trajectory for given header information.

k1_idx: torch.Tensor,
reversed_readout_mask: torch.Tensor | None = None,
**_,
) -> KTrajectory:
"""Calculate radial 2D trajectory for given KHeader.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"""Calculate radial 2D trajectory for given KHeader.
"""Calculate radial 2D trajectory for given header information.

k2_idx
indices of k2
reversed_readout_mask
boolean tensor indicating reversed readout

Returns
-------
radial phase encoding trajectory for given KHeader
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
radial phase encoding trajectory for given KHeader
radial phase encoding trajectory for given header information

@ckolbPTB
Copy link
Collaborator

ckolbPTB commented Jan 7, 2025

The doc string here is IMO also wrong/outdated:

The value range of the trajectory in the ISMRMRD file is not well defined. Here we simple normalize everything

@ckolbPTB ckolbPTB linked an issue Jan 7, 2025 that may be closed by this pull request
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
Base automatically changed from gh/fzimmermann89/34/head to main January 7, 2025 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Channel mask
4 participants