-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accessing non-scalar, non-innate features in RTDC_Hierarchy objects leads to Error #165
Comments
One option to solve this issue is changing the boolean mask, used in This can be done by changing: item = self.hparent[key]
return item[self.hparent.filter.all] to item = self.hparent[key]
idxs = np.where(self.hparent.filter.all)
return item[idxs] The "only" downside of that is, that the loaded non-scalar features are not loaded as HDF5-dataset (like other non-scalar features), but as np.ndarray instead. This implies that the array is loaded completely into memory. |
While running the tests, I had the feeling that it might have taken a bit longer than normally. I will run the tests for the original and the new coda and compare the time. I don't want to introduce inefficient code here. |
Another option would be to introduce a wrapper class that returns a lazy object which can then be indexed via EDIT: I think you would want to (a) generalize the ChildImage, ChildImageBG and ChildMask classes (pass feature name to I did this for data export like so: https://github.com/ZELLMECHANIK-DRESDEN/dclab/blob/0.39.14/dclab/rtdc_dataset/writer.py#L180-L207 |
Ok, so I implemented a generalized ChildNonScalar class, including non-scalar PluginFeatures, TemporaryFeatures and "image", "image_bg" and "mask". def __getitem__(self, key):
# contour, image, and traces are added automatically
# to `self._events` in `self.apply_filter`.
if key in self._events:
return self._events[key]
elif key in self.features_scalar or key in dfn.FEATURES_NON_SCALAR:
item = self.hparent[key]
return item[self.hparent.filter.all]
else:
self._events.setdefault(key, ChildNonScalar(self, key))
return self[key] Where I feel not 100% happy with the solution, because I basically had to add |
For completeness sake, here the implementation of class ChildNonScalar(ChildBase):
def __init__(self, child, key):
super(ChildNonScalar, self).__init__(child)
self.key = key
def __getitem__(self, idx):
pidx = map_indices_child2parent(child=self.child,
child_indices=idx)
hp = self.child.hparent
return hp[self.key][pidx]
@property
def shape(self):
hp = self.child.hparent
return tuple([len(self)] + list(hp[self.key][0].shape)) Other suggestions for the name are more than welcome! |
Maybe The tdms thing looks like a bug and should probably be handled in a separate new issue. It might make sense to extend that not-100%-clean case you added by checking that the root parent of the hierarchy child is a tmds dataset and link to the new issue (until that is fixed).
|
ChildNDArray sounds good, I will use it instead. Regarding the registration of features happening in two different places ( |
When registering a non-scalar feature (i.e. temporary feature or plugin feature) and creating a RTDC_Hierarchy object, leads to
*** TypeError: Boolean indexing array has incompatible shape
.This seems to be due to the indexing behaviour of RTDC_Hierarchy instances in its
__getitem__()
-functionThis is caused by more complex indexing behaviour of higher-dimensional np.ndarrays.
The text was updated successfully, but these errors were encountered: