def _map_global_to_filtered(self, k):
"""
map global (unfiltered) ND key to local (filtered) 2D key
Parameters
----------
k: tuple
Labels associated with the modified element of the non-filtered array.
Returns
-------
tuple
Positional index (row, column) of the modified data cell.
"""
assert isinstance(k, tuple) and len(k) == self.la_data.ndim
dkey = {axis_id: axis_key for axis_key, axis_id in zip(k, self.la_data.axes.ids)}
# transform global dictionary key to "local" (filtered) key by removing
# the parts of the key which are redundant with the filter
for axis_id, axis_filter in self.current_filter.items():
axis_key = dkey[axis_id]
if np.isscalar(axis_filter) and axis_key == axis_filter:
del dkey[axis_id]
elif not np.isscalar(axis_filter) and axis_key in axis_filter:
pass
else:
# that key is invalid for/outside the current filter
return None
# transform (axis:label) dict key to positional ND key
try:
index_key = self.filtered_data._translated_key(dkey)
except ValueError:
return None
# transform positional ND key to positional 2D key
strides = np.append(1, np.cumprod(self.filtered_data.shape[1:-1][::-1], dtype=int))[::-1]
return (index_key[:-1] * strides).sum(), index_key[-1]
评论列表
文章目录