shamo.core.problems.single.components.grid_sampler.CompGridSampler

class shamo.core.problems.single.components.grid_sampler.CompGridSampler(**kwargs)[source]

Bases: shamo.core.problems.single.components.abc.CompABC

Store information about a space grid sampler.

A grid sampler is used to convert outputs from GetDP into a NII file more suitable for neuroimaging studies.

Other Parameters
affinenumpy.ndarray

The affine matrix of the grid.

shapetuple [int]

The shape of the grid.

masknumpy.ndarray

The mask of the grid.

Methods

check

Check is the grid is properly set.

clear

copy

fromkeys

Create a new dictionary with keys from iterable and values set to value.

get

Return the value for key if key is in the dictionary, else default.

items

keys

nii_from_pos

Convert a POS file into a NII file.

pop

If key is not found, d is returned if given, otherwise KeyError is raised

popitem

Remove and return a (key, value) pair as a 2-tuple.

set

Set the grid component.

setdefault

Insert key with a value of default if key is not in the dictionary.

to_pro_param

Return if the grid can be used.

to_py_param

Return the parameters required to render python template.

update

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values

Attributes

affine

Return the affine matrix of the grid.

mask

Return the mask of the grid.

shape

Return the shape of the grid.

use_grid

Return wether or not the grid can be used.

property affine

Return the affine matrix of the grid.

Returns
numpy.ndarray

The affine matrix of the grid.

check(name, **kwargs)[source]

Check is the grid is properly set.

Parameters
namestr

The name of the grid.

Raises
TypeError

If argument affine is not a numpy.ndarray.

ValueError

If argument affine is not (3, 4) or (4, 4) numpy.ndarray. If argument shape is not a 3D shape.

clear() → None. Remove all items from D.
copy() → a shallow copy of D
fromkeys(iterable, value=None, /)

Create a new dictionary with keys from iterable and values set to value.

get(key, default=None, /)

Return the value for key if key is in the dictionary, else default.

items() → a set-like object providing a view on D’s items
keys() → a set-like object providing a view on D’s keys
property mask

Return the mask of the grid.

Returns
numpy.ndarray

The mask of the grid.

nii_from_pos(src, dst)[source]

Convert a POS file into a NII file.

Parameters
srcstr, byte or os.PathLike

The path to the POS file to convert.

dststr, byte or os.PathLike

The path where the generated NII image must be saved.

Returns
——-
nibabel.Nifti1Image

The generated NII image.

pop(k[, d]) → v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised

popitem(/)

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.

set(affine, shape, mask=None, resize=False)[source]

Set the grid component.

Parameters
affinenumpy.ndarray

The affine matrix of the grid.

shametuple [int]

The shape of the grid.

masknumpy.ndarray, optional

The mask of the grid. If set to None, no mask is applied to the resulting data. (The default is None)

resizebool, optional

If set to True, the affine matrix is rescaled from meters to millimeters. (the default is False)

setdefault(key, default=None, /)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

property shape

Return the shape of the grid.

Returns
tuple [int]

The shape of the grid.

to_pro_param(**kwargs)[source]

Return if the grid can be used.

Returns
bool

Return True if the grid is set.

to_py_param(**kwargs)[source]

Return the parameters required to render python template.

Returns
dict [str, str]

The parameters required to render python template.

update([E, ]**F) → None. Update D from dict/iterable E and F.

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

property use_grid

Return wether or not the grid can be used.

Returns
bool

Return True if the grid can be used, False otherwise.

values() → an object providing a view on D’s values