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
Make PeaksAndMetrics pickle-able #1195
Merged
Merged
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7d53841
Add get_state, set_state methods to PeaksAndMetrics.
arokem 399ac2e
Don't implement set_state.
arokem 2de6ca7
Test pickling of PAM objects.
arokem bcbdeac
Implement pickling of PAM objects as a reduce operation instead.
arokem d4bed65
Documentation and a bit more testing.
arokem 9743fdb
Rename to `_pam_from_attrs`, use to reduce boilerplate.
arokem cec60bc
Implement `from_attrs` as an alternative constructor classmethod.
arokem 0cef31f
Reimplement _pam_from_attrs as a free-standing function.
arokem 116cd0e
Add optional argument to use other classes (e.g., when subclassing).
arokem a2d49bc
Make the klass input obligatory.
arokem 8f221a0
Whitespace.
arokem f47076a
Correct docstring: this is not optional!
arokem ec3ac55
Whitespace.
arokem 02c4ee7
Prettify the if statements.
arokem File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,8 +157,20 @@ def peak_directions(odf, sphere, relative_peak_threshold=.5, | |
return directions, values, indices | ||
|
||
|
||
class PeaksAndMetrics(PeaksAndMetricsDirectionGetter): | ||
def __reduce__(self): return _pam_from_attrs, (self.sphere, | ||
self.peak_indices, | ||
self.peak_values, | ||
self.peak_dirs, | ||
self.gfa, | ||
self.qa, | ||
self.shm_coeff, | ||
self.B, | ||
self.odf) | ||
|
||
|
||
def _pam_from_attrs(sphere, peak_indices, peak_values, peak_dirs, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding class as first argument? Or as optional argument at end? In case we need to sub-class? Sorry to ask, but why do we need this otherwise empty sub-class?
Why not use |
||
gfa, qa, shm_coeff, B, odf): | ||
gfa, qa, shm_coeff, B, odf, klass=PeaksAndMetrics): | ||
""" | ||
Construct a PeaksAndMetrics object from its attributes. | ||
|
||
|
@@ -187,12 +199,14 @@ def _pam_from_attrs(sphere, peak_indices, peak_values, peak_dirs, | |
coefficients. | ||
odf : ndarray | ||
The orientation distribution function on the sphere in each voxel. | ||
klass : class, optional | ||
The class of object to be created. Default: PeaksAndMetrics | ||
|
||
Returns | ||
------- | ||
PeaksAndMetrics class instance. | ||
pam : Instance of the class `klass`. | ||
""" | ||
this_pam = PeaksAndMetrics() | ||
this_pam = klass() | ||
this_pam.sphere = sphere | ||
this_pam.peak_dirs = peak_dirs | ||
this_pam.peak_values = peak_values | ||
|
@@ -205,18 +219,6 @@ def _pam_from_attrs(sphere, peak_indices, peak_values, peak_dirs, | |
return this_pam | ||
|
||
|
||
class PeaksAndMetrics(PeaksAndMetricsDirectionGetter): | ||
def __reduce__(self): return _pam_from_attrs, (self.sphere, | ||
self.peak_indices, | ||
self.peak_values, | ||
self.peak_dirs, | ||
self.gfa, | ||
self.qa, | ||
self.shm_coeff, | ||
self.B, | ||
self.odf) | ||
|
||
|
||
def _peaks_from_model_parallel(model, data, sphere, relative_peak_threshold, | ||
min_separation_angle, mask, return_odf, | ||
return_sh, gfa_thr, normalize_peaks, sh_order, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Add
self.__class__
as argument to allow sub-classing? Maybe, it would be better as first argument.