BaseGrid

class sofia_redux.toolkit.resampling.BaseGrid(*grid, scale_factor=None, scale_offset=None, build_tree=False, tree_shape=None, dtype=None, **kwargs)[source]

Bases: object

Define and initialize a resampling grid.

The resampling grid is used to specify a set of output coordinates for the resampling objects. The grid coordinates may be either arranged as a typical grid or as a set of irregularly spaced coordinates. Here, a typical grid implies that all output coordinates are aligned across all dimensions.

The resampling grid contains its own Tree object that is used to quickly map arbitrary coordinates onto grid positions (see BaseTree for further details). A scaling factor and offset may exist between supplied coordinates and grid coordinates if necessary, which are applied according to scale_coordinates().

Parameters:
gridtuple or numpy.ndarray, optional

Either an n-dimensional tuple containing the grid coordinates for each feature, or a single array of shape (n_features, n) that may be used to specify irregular grid coordinates.

scale_factornumpy.ndarray (float), optional

The scaling factor between the actual coordinates and grid coordinates. Must be supplied in conjunction with scale_offset. Should be an array of shape (n_features,).

scale_offsetnumpy.ndarray (float), optional

The scaling offset between the actual coordinates and grid coordinates. Must be supplied in conjunction with scale_factor. Should be an array of shape (n_features,).

build_treebool, optional

If True, build the associated tree for this grid.

tree_shapetuple or numpy.ndarray (int), optional

The shape of the tree blocks. If not supplied, defaults to maximum grid coordinates in each dimension.

dtypetype, optional

The type of the grid coordinates. If not supplied, defaults to the type of the provided grid coordinates. If neither grid nor dtype is provided, defaults to float.

kwargsdict, optional

Optional keyword arguments passed into the set_indexer method. These parameters will be applied during tree initialization.

Attributes Summary

features

Return the number of grid dimensions.

regular

Return whether the grid contains feature aligned grid coordinates.

scale_factor

Return the scaling factor between actual and grid coordinates.

scale_offset

Return the scaling offset between actual and grid coordinates.

shape

Return the shape of the grid.

singular

Return whether the grid consists of only a single output coordinate.

size

Return the number of grid vertices.

tree_class

Return the relevant tree class for this grid.

Methods Summary

__call__()

Returns the grid.

get_class_for(thing)

Return a Grid class specific to a given tree, resampler, or name.

get_class_for_name(name)

Return a Grid class of the given name.

get_tree_class()

Return the relevant tree class for the grid.

rescale()

Re-apply the previous scaling factors and offsets if removed.

reshape_data(data)

Reshape data to the grid dimensions.

scale(factor, offset)

Apply a scaling factor and offset to the grid coordinates.

set_indexer([shape, build_tree, build_type])

Calculate the indexing mapping the grid coordinates to the tree.

unscale()

Unscale the grid coordinates.

Attributes Documentation

features

Return the number of grid dimensions.

Returns:
int
regular

Return whether the grid contains feature aligned grid coordinates.

Returns:
bool
scale_factor

Return the scaling factor between actual and grid coordinates.

Returns:
numpy.ndarray (float)
scale_offset

Return the scaling offset between actual and grid coordinates.

Returns:
numpy.ndarray (float)
shape

Return the shape of the grid.

Returns:
tuple (int)
singular

Return whether the grid consists of only a single output coordinate.

Returns:
bool
size

Return the number of grid vertices.

Returns:
int
tree_class

Return the relevant tree class for this grid.

Returns:
BaseTree subclass

Methods Documentation

__call__()[source]

Returns the grid.

Returns:
numpy.ndarray

The resampling grid of shape (n_features, m) where m is the number of grid vertices.

static get_class_for(thing)[source]

Return a Grid class specific to a given tree, resampler, or name.

Parameters:
thingBaseTree or ResampleBase or str

Either a sub-class of a BaseTree, ResampleBase, or a string.

Returns:
BaseTree subclass
static get_class_for_name(name)[source]

Return a Grid class of the given name.

Parameters:
namestr

The name of the grid.

Returns:
BaseGrid subclass
get_tree_class()[source]

Return the relevant tree class for the grid.

Returns:
BaseGrid subclass
rescale()[source]

Re-apply the previous scaling factors and offsets if removed.

Returns:
None
reshape_data(data)[source]

Reshape data to the grid dimensions.

Note that this will only reshape data if the grid is regular.

Parameters:
datanumpy.ndarray

Data of the shape (n_sets, grid.size) or (grid.size,).

Returns:
reshaped_datanumpy.ndarray

Data of shape (grid.shape).

scale(factor, offset)[source]

Apply a scaling factor and offset to the grid coordinates.

Parameters:
factornumpy.ndarray

A scaling factor of shape (n_features,).

offsetnumpy.ndarray

A scaling offset of shape (n_features,).

Returns:
None
set_indexer(shape=None, build_tree=False, build_type='hood', **kwargs)[source]

Calculate the indexing mapping the grid coordinates to the tree.

Parameters:
shapetuple (int), optional

The shape of the grid. If not supplied, uses the maximum internal grid coordinates + 1 in each dimension.

build_treebool, optional

If True, builds a neighborhood tree of the type build_type.

build_typestr, optional

Must be one of {‘hood’, ‘balltree’, ‘all’, None}. Please see BaseTree for further details. The default type necessary for resampling is ‘hood’.

kwargsdict, optional

Optional keyword arguments passed into the tree initialization.

Returns:
None
unscale()[source]

Unscale the grid coordinates.

Remove a scaling factor and offset if previously applied.

Returns:
None