-
Notifications
You must be signed in to change notification settings - Fork 16
Conversation
src/eddymotion/estimator.py
Outdated
|
||
""" | ||
|
||
def handle_gradient_ordering(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re: #149 (comment)
All the methods here do not access any instance variable, and any IDE will suggest them becoming static, as they were prior to 8153649. However the actions
dictionary was triggering errors because it was taking static methods. All this could be avoided if these methods were refactored into a utils.py
(or similar) module that takes care of sorting the DWI volumes. In fact, (i) the estimator should not take care of this at all: it should receive the DWI volumes already sorted, and (ii) these methods may be useful elsewhere.
Related to this, the strategies could be put into an enum
so that it becomes clear which are the sorting possibilities, and they are documented and available at a single place. However, I know that using enum
s is not very popular across many major scientific Python packages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like a great idea! I agree, I'll externalize the functions into a new module, util.py. Thanks for the suggestion!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some initial comments
src/eddymotion/utils.py
Outdated
Parameters: | ||
dwdata : :obj:`~eddymotion.dmri.DWI` | ||
DWI dataset, represented by this tool's internal type. | ||
|
||
Returns: | ||
index_order : :obj:`numpy.ndarray` | ||
The sorted index order. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parameters: | |
dwdata : :obj:`~eddymotion.dmri.DWI` | |
DWI dataset, represented by this tool's internal type. | |
Returns: | |
index_order : :obj:`numpy.ndarray` | |
The sorted index order. | |
Parameters | |
---------- | |
size : :obj:`int` | |
Number of volumes in dataset | |
(for instance, number of orientations in a DWI) | |
Returns | |
------- | |
:obj:`list` of :obj:`int` | |
The sorted index order. | |
Examples | |
-------- | |
>>> linear_action(10) | |
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | |
Co-authored-by: Oscar Esteban <[email protected]>
Co-authored-by: Oscar Esteban <[email protected]>
Co-authored-by: Oscar Esteban <[email protected]>
Co-authored-by: Oscar Esteban <[email protected]>
Co-authored-by: Oscar Esteban <[email protected]>
src/eddymotion/utils.py
Outdated
|
||
Examples | ||
-------- | ||
>>> random_iterator(15, seed=0) # seed is 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is failing on my computer locally. I'm getting a different value compared to yours @oesteban . Specifically, I'm getting [2, 11, 3, 10, 0, 4, 7, 5, 14, 12, 6, 9, 13, 8, 1]. Any idea why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea - I might have copied the wrong order.
src/eddymotion/utils.py
Outdated
[12, 2, 7, 8, 14, 4, 9, 13, 6, 3, 5, 0, 1, 10, 11] | ||
>>> random_iterator(15, seed=True) # seed is the default value 20210324 | ||
[13, 2, 8, 12, 10, 4, 9, 3, 0, 1, 14, 6, 11, 7, 5] | ||
>>> random_iterator(15, seed=42) # seed is 42 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, I obtain [6, 7, 9, 3, 0, 11, 14, 10, 5, 2, 4, 12, 1, 13, 8].
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestions to avoid numpy for the time being. Also make the random range iterator a generator.
These for sure will make the test values invalid - we'll need to re-write them. |
Co-authored-by: Oscar Esteban <[email protected]>
I changed them in ed20ca8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, I just have a few suggestions to improve the docstrings.
If you want to make this PR perfect, I'd go for type annotations on the four functions involved.
In the meantime, perhaps open a separate PR (make sure to branch from master, not from here) addressing #151? That PR should be fairly fast to merge and then we can update this one to resolve the ruff complaints.
Co-authored-by: Oscar Esteban <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assistance tool for adding type annotations has introduced some problems (moved the imports to the top, before the license banner) and modified some docstrings that were better before.
src/eddymotion/utils.py
Outdated
import random | ||
from itertools import chain, zip_longest | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert the removal of imports and add the Generation import here:
import random | |
from itertools import chain, zip_longest | |
import random | |
from itertools import chain, zip_longest | |
from typing import Generator |
src/eddymotion/utils.py
Outdated
import random | ||
from itertools import chain, zip_longest | ||
from typing import Generator | ||
|
||
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, be careful, why these four lines here before the header?
import random | |
from itertools import chain, zip_longest | |
from typing import Generator | |
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- | |
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed the imports in 9bda539.
Co-authored-by: Oscar Esteban <[email protected]>
src/eddymotion/utils.py
Outdated
import random | ||
from itertools import chain, zip_longest | ||
from typing import Generator | ||
|
||
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- | ||
# vi: set ft=python sts=4 ts=4 sw=4 et: | ||
# | ||
# Copyright 2024 The NiPreps Developers <[email protected]> | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# We support and encourage derived works from this project, please read | ||
# about our expectations at | ||
# | ||
# https://www.nipreps.org/community/licensing/ | ||
# | ||
"""Iterators to traverse the volumes in a 4D image.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import random | |
from itertools import chain, zip_longest | |
from typing import Generator | |
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- | |
# vi: set ft=python sts=4 ts=4 sw=4 et: | |
# | |
# Copyright 2024 The NiPreps Developers <[email protected]> | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
# | |
# We support and encourage derived works from this project, please read | |
# about our expectations at | |
# | |
# https://www.nipreps.org/community/licensing/ | |
# | |
"""Iterators to traverse the volumes in a 4D image.""" | |
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- | |
# vi: set ft=python sts=4 ts=4 sw=4 et: | |
# | |
# Copyright 2024 The NiPreps Developers <[email protected]> | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
# | |
# We support and encourage derived works from this project, please read | |
# about our expectations at | |
# | |
# https://www.nipreps.org/community/licensing/ | |
# | |
"""Iterators to traverse the volumes in a 4D image.""" | |
import random | |
from itertools import chain, zip_longest | |
from typing import Iterator |
Co-authored-by: Oscar Esteban <[email protected]>
Let's re-sync with main:
|
Introduce iterators to rearrange the indexes used in logo_split. Sorting options include linear, random, in ascending order following gradient magnitude, and central symmetric.
closes #111