Skip to content
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

[Bug]: ROI extractor returns error "tuple index out of range" #1109

Open
2 tasks done
laurelrr opened this issue Oct 9, 2024 · 4 comments
Open
2 tasks done

[Bug]: ROI extractor returns error "tuple index out of range" #1109

laurelrr opened this issue Oct 9, 2024 · 4 comments
Assignees
Labels

Comments

@laurelrr
Copy link

laurelrr commented Oct 9, 2024

What happened?

I am working with this code base to convert 6 subjects:
https://github.com/catalystneuro/tye-lab-to-nwb/tree/main/src/tye_lab_to_nwb/ast_ophys
I created individual convert_session.py files for each subject. Three of them are working correctly and convert my data as expected.
However, one subject returned an error, and I am not sure what to look for in my data in order to correct it.

Steps to Reproduce

git clone https://github.com/catalystneuro/tye-lab-to-nwb
cd tye-lab-to-nwb
conda env create --file make_env.yml
conda activate tye-lab-to-nwb-env
python  ~/tye-lab-to-nwb/src/tye_lab_to_nwb/ast_ophys/convert_session_jackalope.py

Traceback

Source data is valid!
/home/lkeyes/anaconda3/envs/tye_lab_to_nwb_env/lib/python3.11/site-packages/pymatreader/utils.py:238: UserWarning: Complex objects (like classes) are not supported. They are importedeffort base but your mileage will vary.
  warn('Complex objects (like classes) are not supported. '
Traceback (most recent call last):
  File "/home/lkeyes/Projects/GIT/tye-lab-to-nwb/src/tye_lab_to_nwb/ast_ophys/convert_session_jackalope.py", line 207, in <module>
    session_to_nwb(
  File "/home/lkeyes/Projects/GIT/tye-lab-to-nwb/src/tye_lab_to_nwb/ast_ophys/convert_session_jackalope.py", line 107, in session_to_nwb
    converter = AStOphysNWBConverter(source_data=source_data)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lkeyes/anaconda3/envs/tye_lab_to_nwb_env/lib/python3.11/site-packages/neuroconv/nwbconverter.py", line 65, in __init__
    self.data_interface_objects = {
                                  ^
  File "/home/lkeyes/anaconda3/envs/tye_lab_to_nwb_env/lib/python3.11/site-packages/neuroconv/nwbconverter.py", line 66, in <dictcomp>
    name: data_interface(**source_data[name])
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nadata/snlkt/home/lkeyes/Projects/GIT/tye-lab-to-nwb/src/tye_lab_to_nwb/ast_ophys/interfaces/cnmfe_matlab_segmentationinterface.py", line 12, in __init__
    super().__init__(file_path=file_path)
  File "/home/lkeyes/anaconda3/envs/tye_lab_to_nwb_env/lib/python3.11/site-packages/neuroconv/datainterfaces/ophys/basesegmentationextractorinterface.py", line 20, in __init__
    self.segmentation_extractor = self.get_extractor()(**source_data)
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nadata/snlkt/home/lkeyes/Projects/GIT/tye-lab-to-nwb/src/tye_lab_to_nwb/ast_ophys/extractors/cnmfe_matlab_segmentationextractor.py", line 42, in __init__
    self._image_masks = self._transform_image_masks()
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nadata/snlkt/home/lkeyes/Projects/GIT/tye-lab-to-nwb/src/tye_lab_to_nwb/ast_ophys/extractors/cnmfe_matlab_segmentationextractor.py", line 71, in _transform_image_masks
    num_rois = self.get_num_rois()
               ^^^^^^^^^^^^^^^^^^^
  File "/home/lkeyes/anaconda3/envs/tye_lab_to_nwb_env/lib/python3.11/site-packages/roiextractors/segmentationextractor.py", line 278, in get_num_rois
    return trace.shape[1]
           ~~~~~~~~~~~^^^
IndexError: tuple index out of range

Operating System

Linux

Python Executable

Conda

Python Version

3.8

Package Versions

environment_for_issue.txt

Code of Conduct

@laurelrr laurelrr added the bug label Oct 9, 2024
@h-mayorquin
Copy link
Collaborator

It seems that the trace for that example does not have two dimensions, maybe only one roi? I think that @weiglszonja is the one that worked with that code base, could you take a look?

@weiglszonja
Copy link
Contributor

It seems that the trace for that example does not have two dimensions, maybe only one roi? I think that @weiglszonja is the one that worked with that code base, could you take a look?

That would be my first guess too. @laurelrr can you check the shape of the traces in the extractor?

from tye_lab_to_nwb.ast_ophys.extractors.cnmfe_matlab_segmentationextractor import CnmfeMatlabSegmentationExtractor

extractor = CnmfeMatlabSegmentationExtractor(file_path="path/to/problematic_file.mat")
# Check the original trace shape, should be [num_rois x num_frames]
print(extractor._dataset_file["C"].shape)
print(len(extractor._dataset_file["C"].shape))

If this returns a one dimensional array then we have to fix the code in the custom extractor .

Let me know if this is the case and I'll help to fix it.

@laurelrr
Copy link
Author

I ran into the same error at the extractor line:

Python 3.11.2 (main, Mar 27 2023, 23:42:44) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from tye_lab_to_nwb.ast_ophys.extractors.cnmfe_matlab_segmentationextractor import CnmfeMatlabSegmentationExtractor
>>> extractor = CnmfeMatlabSegmentationExtractor("/snlkt/ast/Miniscope/expAnalysis/20211206_CACO_ALL_DISC/CACO3_DISC6/analysis/msCam_MC/G2B1_C4-6886_L_jackalope_DISC6UNP+TONES_neuron.mat")
/home/lkeyes/anaconda3/envs/tye_lab_to_nwb_env/lib/python3.11/site-packages/pymatreader/utils.py:238: UserWarning: Complex objects (like classes) are not supported. They are imported on a best effort base but your mileage will vary.
  warn('Complex objects (like classes) are not supported. '
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/nadata/snlkt/home/lkeyes/Projects/GIT/tye-lab-to-nwb/src/tye_lab_to_nwb/ast_ophys/extractors/cnmfe_matlab_segmentationextractor.py", line 42, in __init__
    self._image_masks = self._transform_image_masks()
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nadata/snlkt/home/lkeyes/Projects/GIT/tye-lab-to-nwb/src/tye_lab_to_nwb/ast_ophys/extractors/cnmfe_matlab_segmentationextractor.py", line 71, in _transform_image_masks
    num_rois = self.get_num_rois()
               ^^^^^^^^^^^^^^^^^^^
  File "/home/lkeyes/anaconda3/envs/tye_lab_to_nwb_env/lib/python3.11/site-packages/roiextractors/segmentationextractor.py", line 278, in get_num_rois
    return trace.shape[1]
           ~~~~~~~~~~~^^^
IndexError: tuple index out of range

Not sure if this is helpful or not but I loaded the file into Matlab and here is what is in it:


  struct with fields:

                    A: [90240×1 double]
               A_prev: [90240×6 double]
                    C: [0.3787 0.3574 0.4006 0.3782 0.3933 0.4259 0.3824 0.3880 0.4590 0.3978 0.3650 0.4191 0.4809 0.3841 0.3219 0.3921 0.3981 0.3856 0.3413 0.3595 0.4127 0.3992 … ]
               C_prev: [6×15218 double]
                C_raw: [0.3787 0.3574 0.4006 0.3782 0.3933 0.4259 0.3824 0.3880 0.4590 0.3978 0.3650 0.4191 0.4809 0.3841 0.3219 0.3921 0.3981 0.3856 0.3413 0.3595 0.4127 0.3992 … ]
                    S: [1×15218 double]
               kernel: [1×1 struct]
                    b: {3×4 cell}
                    f: {3×4 cell}
                    W: {3×4 cell}
                   b0: {3×4 cell}
               b0_new: [240×376 double]
              options: [1×1 struct]
                    P: [1×1 struct]
                   Fs: 15
                 file: '/nadata/snlkt/ast/Miniscope/expAnalysis/20211206_CACO_ALL_DISC/CACO3_DISC6/analysis/msCam_MC/G2B1_C4-6886_L_jackalope_DISC6UNP+TONES_msCamComb_MC.mat'
          frame_range: [1 15218]
                  ids: 2
                 tags: 0
                   Cn: [240×376 double]
                  PNR: [240×376 double]
                 Coor: {4×1 cell}
    neurons_per_patch: []
                   Df: []
                 C_df: []
                 S_df: []
              batches: {}
              file_id: []

@weiglszonja
Copy link
Contributor

Thank you @laurelrr, this is helpful indeed. I opened catalystneuro/tye-lab-to-nwb#57 to fix this, can you check if this works for your data? Feel free to comment on the pull request if you have any questions. I can also test it if you share this file with me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants