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

Remove index entry from parsed CSA header elements #15

Open
matthew-brett opened this issue Apr 22, 2023 · 5 comments
Open

Remove index entry from parsed CSA header elements #15

matthew-brett opened this issue Apr 22, 2023 · 5 comments

Comments

@matthew-brett
Copy link
Contributor

Am I right in thinking that the index elements in a CSA header are always sequential?

For example, from the README:

{
    'NumberOfPrescans': {'index': 1, 'VR': 'IS', 'VM': 1, 'value': 0},
    'TransmitterCalibration': {'index': 2, 'VR': 'DS', 'VM': 1, 'value': 247.102},
    'PhaseGradientAmplitude': {'index': 3, 'VR': 'DS', 'VM': 1, 'value': 0.0},
    'ReadoutGradientAmplitude': {'index': 4, 'VR': 'DS', 'VM': 1, 'value': 0.0},
    'SelectionGradientAmplitude': {'index': 5, 'VR': 'DS', 'VM': 1, 'value': 0.0},
...
}

Are these index entries necessary? I realize they are in the CSA header structure, but, given Python dictionary insertion order, does:

indices = [v['index'] for k, v in parsed_csa.items()]

ever differ from np.arange(len(parsed_csa))?

@ZviBaratz
Copy link
Contributor

Yeah, they definitely don't seem to be necessary. However, it might be a good idea to use OrderedDict to make sure order is preserved.

@matthew-brett
Copy link
Contributor Author

Does OrderedDict preserve order better than dict in Python >= 3.7?

@ZviBaratz
Copy link
Contributor

AFAIK, yes. OrderedDict still guarantees the order of the dictionary items in ways that dict does not.

@matthew-brett
Copy link
Contributor Author

This page lists the advantages of OrderedDict as:

  • OrderedDict makes it clear that the order of items in the dictionary is important.
  • Features for control over the order of items - you can use .move_to_end and .popitem(last=False)
  • Compare equal iff elements are in same order.

@ZviBaratz
Copy link
Contributor

I see. Well, in that case, I guess dict would be good enough.

@ZviBaratz ZviBaratz changed the title Need for index entry in CSA header elements? Remove index entry from parsed CSA header elements Apr 22, 2023
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

No branches or pull requests

2 participants