neurokernel.pm.PortMapper¶
-
class
neurokernel.pm.
PortMapper
(selector, data=None, portmap=None, make_copy=True)[source]¶ Maps a numpy array to/from path-like port identifiers.
Examples
>>> data = np.array([1, 0, 3, 2, 5, 2]) >>> pm = PortMapper('/d[0:5]', data) >>> print pm['/d[1]'] array([0]) >>> print pm['/d[2:4]'] array([3, 2])
Parameters: - selector (str, unicode, or sequence) – Selector string (e.g., ‘/foo[0:2]’) or sequence of token sequences (e.g., [[‘foo’, (0, 2)]]) to map to data.
- data (numpy.ndarray) – 1D data array to map to ports. If no data array is specified, port identifiers will still be mapped to their sequential indices but __getitem__() and __setitem__() will raise exceptions if invoked.
- portmap (sequence of int) – Integer indices to map to port identifiers. If no map is specified, it is assumed to be an array of consecutive integers from 0 through one less than the number of ports.
- make_copy (bool) – If True, map a copy of the specified data array to the specified port identifiers.
-
data
¶ numpy.ndarray – Data that has been mapped to ports.
-
dtype
¶ numpy.dtype – Type of mapped data.
-
index
¶ pandas.MultiIndex – Index of port identifiers.
-
portmap
¶ pandas.Series – Map of port identifiers to integer indices into data.
Notes
The selectors may not contain any ‘*’ or ‘[:]’ characters.
-
__init__
(selector, data=None, portmap=None, make_copy=True)[source]¶ x.__init__(…) initializes x; see help(type(x)) for signature
Methods
__init__
(selector[, data, portmap, make_copy])x.__init__(…) initializes x; see help(type(x)) for signature copy
()Return copy of this port mapper. equals
(other)Check whether this mapper is equivalent to another mapper. from_index
(idx, data[, portmap])Create port mapper from a Pandas index and a sequence of integer indices. from_pm
(pm)Create a new port mapper instance given an existing instance. get
(selector)Retrieve mapped data specified by given selector. get_by_inds
(inds)Retrieve mapped data specified by integer index. get_inds_nonzero
()Select indices of ports with nonzero data. get_map
(selector)Retrieve integer indices associated with selector. get_ports
(f)Select ports using a data selection function. get_ports_as_inds
(f)Select integer indices corresponding to ports in map. get_ports_nonzero
()Select ports with nonzero data. inds_to_ports
(inds)Convert list of integer indices to port identifiers. ports_to_inds
(selector)Convert port selector to list of integer indices. set
(selector, data)Set mapped data specified by given selector. set_by_inds
(inds, data)Set mapped data by integer indices. set_map
(selector, portmap)Set mapped integer index associated with selector. Attributes
data
Data associated with ports. dtype
Port mapper data type. index
Port mapper index.