catalystneuro / lazy_ops

Lazy transposing and slicing of h5py and Zarr Datasets
BSD 3-Clause "New" or "Revised" License
3 stars 3 forks source link

cannot index with list of ints #22

Open bendichter opened 4 years ago

alejoe91 commented 4 years ago

To reproduce the error you can use this minimal example (using this commit of roiextractors: https://github.com/catalystneuro/roiextractors/commit/6a3c9c425b8f5e275177ee799981fda30841b69f)

import roiextractors as re

imag, seg = re.example_datasets.toy_example(duration=30, num_rois=10, 
                                            mode='gaussian', decay_time=0.5, sampling_frequency=30)
re.Hdf5ImagingExtractor.write_imaging(imag, "write_test.h5", verbose=True, chunk_size=None,
                                      chunk_mb=10, overwrite=True)
imag_load = re.Hdf5ImagingExtractor("write_test.h5")
video = imag_load.get_video()

Traceback:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~/anaconda3/envs/imaging/lib/python3.7/site-packages/lazy_ops/lazy_loading.py in _slice_composition(self, new_slice)
    256                         if new_slice[i].dtype.kind != 'b':
--> 257                             raise ValueError("Indices must be either integers or booleans")
    258                         else:

ValueError: Indices must be either integers or booleans

During handling of the above exception, another exception occurred:

IndexError                                Traceback (most recent call last)
<ipython-input-8-9ffa7d668817> in <module>
----> 1 im0 = imag_load.get_video()

~/Documents/Codes/imaging/roiinterface/roiextractors/roiextractors/extraction_tools.py in corrected_args(imaging, start_frame, end_frame, channel)
    123         start_frame, end_frame = cast_start_end_frame(start_frame, end_frame)
    124         channel = int(channel)
--> 125         get_videos_correct_arg = func(imaging, start_frame=start_frame, end_frame=end_frame, channel=channel)
    126 
    127         return get_videos_correct_arg

~/Documents/Codes/imaging/roiinterface/roiextractors/roiextractors/imagingextractor.py in get_video(self, start_frame, end_frame, channel)
     57     @check_get_videos_args
     58     def get_video(self, start_frame: int = None, end_frame: int = None, channel: int = 0) -> NumpyArray:
---> 59         return self.get_frames(range(start_frame, end_frame), channel)
     60 
     61     @staticmethod

~/Documents/Codes/imaging/roiinterface/roiextractors/roiextractors/extraction_tools.py in corrected_args(imaging, frame_idxs, channel)
     93             frame_idxs = np.array(frame_idxs)
     94             assert np.all(frame_idxs < imaging.get_num_frames()), "'frame_idxs' exceed number of frames"
---> 95         get_frames_correct_arg = func(imaging, frame_idxs, channel)
     96 
     97         if len(frame_idxs) == 1:

~/Documents/Codes/imaging/roiinterface/roiextractors/roiextractors/extractors/hdf5imagingextractor/hdf5imagingextractor.py in get_frames(self, frame_idxs, channel)
     73     def get_frames(self, frame_idxs, channel=0):
     74         if frame_idxs.size > 1 and np.all(np.diff(frame_idxs) > 0) or frame_idxs.size == 1:
---> 75             return lazy_ops.DatasetView(self._video).lazy_slice[channel, frame_idxs]
     76         else:
     77             # unsorted multiple frame idxs

~/anaconda3/envs/imaging/lib/python3.7/site-packages/lazy_ops/lazy_loading.py in __getitem__(self, new_slice)
    168           lazy object
    169         """
--> 170         key_reinit = self._slice_composition(new_slice)
    171         if self._lazy_slice_call:
    172             self._lazy_slice_call = False

~/anaconda3/envs/imaging/lib/python3.7/site-packages/lazy_ops/lazy_loading.py in _slice_composition(self, new_slice)
    274                         slice_result += (new_slice_i,)
    275                 except:
--> 276                     raise IndexError("Indices must be either integers, iterators of integers, slice objects, or numpy boolean arrays")
    277         slice_result += self.key[len(new_slice):]
    278 

IndexError: Indices must be either integers, iterators of integers, slice objects, or numpy boolean arrays