Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, voxel_thresh=0.001, n_iters=10000, n_cores=-1, ijk=None,
kernel_estimator=ALEKernel, **kwargs):
kernel_args = {k.split('kernel__')[1]: v for k, v in kwargs.items()
if k.startswith('kernel__')}
if not issubclass(kernel_estimator, KernelTransformer):
raise ValueError('Argument "kernel_estimator" must be a '
'KernelTransformer')
kwargs = {k: v for k, v in kwargs.items() if not k.startswith('kernel__')}
for k in kwargs.keys():
LGR.warning('Keyword argument "{0}" not recognized'.format(k))
self.mask = None
self.dataset = None
self.kernel_estimator = kernel_estimator(**kernel_args)
self.voxel_thresh = voxel_thresh
self.ijk = ijk
self.n_iters = n_iters
self.results = None
def __init__(self, prior=0.5, kernel_estimator=MKDAKernel, **kwargs):
kernel_args = {k.split('kernel__')[1]: v for k, v in kwargs.items()
if k.startswith('kernel__')}
if not issubclass(kernel_estimator, KernelTransformer):
raise ValueError('Argument "kernel_estimator" must be a '
'KernelTransformer')
kwargs = {k: v for k, v in kwargs.items() if not k.startswith('kernel__')}
for k in kwargs.keys():
LGR.warning('Keyword argument "{0}" not recognized'.format(k))
self.kernel_estimator = kernel_estimator(**kernel_args)
self.prior = prior
__all__ = ['ALEKernel', 'MKDAKernel', 'KDAKernel', 'Peaks2MapsKernel']
class KernelTransformer(Transformer):
"""Base class for modeled activation-generating methods.
Coordinate-based meta-analyses leverage coordinates reported in
neuroimaging papers to simulate the thresholded statistical maps from the
original analyses. This generally involves convolving each coordinate with
a kernel (typically a Gaussian or binary sphere) that may be weighted based
on some additional measure, such as statistic value or sample size.
"""
pass
class ALEKernel(KernelTransformer):
"""
Generate ALE modeled activation images from coordinates and sample size.
Parameters
----------
fwhm : :obj:`float`, optional
Full-width half-max for Gaussian kernel, if you want to have a
constant kernel across Contrasts. Mutually exclusive with ``n``.
n : :obj:`int`, optional
Sample size, used to derive FWHM for Gaussian kernel based on
formulae from Eickhoff et al. (2012). This sample size overwrites
the Contrast-specific sample sizes in the dataset, in order to hold
kernel constant across Contrasts. Mutually exclusive with ``fwhm``.
"""
def __init__(self, fwhm=None, n=None):
if fwhm is not None and n is not None:
sphere = sphere[idx, :].astype(int)
kernel_data[tuple(sphere.T)] = self.value
if not masked:
kernel_data *= mask_data
img = nib.Nifti1Image(kernel_data, mask.affine)
else:
img = kernel_data[mask_data]
imgs.append(img)
if masked:
imgs = np.vstack(imgs)
return imgs
class KDAKernel(KernelTransformer):
"""
Generate KDA modeled activation images from coordinates.
Parameters
----------
r : :obj:`int`, optional
Sphere radius, in mm.
value : :obj:`int`, optional
Value for sphere.
"""
def __init__(self, r=6, value=1):
self.r = float(r)
self.value = value
def transform(self, dataset, mask=None, masked=False):
"""
idx = (np.min(sphere, 1) >= 0) & (np.max(np.subtract(sphere, dims), 1) <= -1)
sphere = sphere[idx, :].astype(int)
kernel_data[tuple(sphere.T)] += self.value
if not masked:
kernel_data *= mask_data
img = nib.Nifti1Image(kernel_data, mask.affine)
else:
img = kernel_data[mask_data]
imgs.append(img)
if masked:
imgs = np.vstack(imgs)
return imgs
class Peaks2MapsKernel(KernelTransformer):
"""
Generate peaks2maps modeled activation images from coordinates.
"""
def __init__(self, resample_to_mask=True):
self.resample_to_mask = resample_to_mask
def transform(self, dataset, mask=None, masked=False):
"""
Generate peaks2maps modeled activation images for each Contrast in dataset.
Parameters
----------
ids : :obj:`list`
A list of Contrast IDs for which to generate modeled activation
images.
masked : :obj:`boolean`
kern = kernels[n_subjects]
kernel_data = compute_ma(mask.shape, ijk, kern)
if not masked:
kernel_data *= mask_data
img = nib.Nifti1Image(kernel_data, mask.affine)
else:
img = kernel_data[mask_data]
imgs.append(img)
if masked:
imgs = np.vstack(imgs)
return imgs
class MKDAKernel(KernelTransformer):
"""
Generate MKDA modeled activation images from coordinates.
Parameters
----------
r : :obj:`int`, optional
Sphere radius, in mm.
value : :obj:`int`, optional
Value for sphere.
"""
def __init__(self, r=10, value=1):
self.r = float(r)
self.value = value
def transform(self, dataset, mask=None, masked=False):
"""