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

Make PeaksAndMetrics pickle-able #1195

Merged
merged 14 commits into from Mar 22, 2017
32 changes: 17 additions & 15 deletions dipy/direction/peaks.py
Expand Up @@ -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)
Copy link
Contributor

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.



def _pam_from_attrs(sphere, peak_indices, peak_values, peak_dirs,
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

class PeaksAndMetrics(PeaksAndMetricsDirectionGetter): pass

Why not use PeaksAndMetricsDirectionGetter directly?

gfa, qa, shm_coeff, B, odf):
gfa, qa, shm_coeff, B, odf, klass=PeaksAndMetrics):
"""
Construct a PeaksAndMetrics object from its attributes.

Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down