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: Input array broadcast error when th_badframes = 0 #930

Closed
evanpc opened this issue Mar 6, 2023 · 13 comments
Closed

BUG: Input array broadcast error when th_badframes = 0 #930

evanpc opened this issue Mar 6, 2023 · 13 comments
Assignees

Comments

@evanpc
Copy link

evanpc commented Mar 6, 2023

Describe the issue:

Hi, I’m sorry if I’m missing something simple, but it seems anytime I have my ops th_badframes = 0, I get an error in ROI detection.

I’ve tried many different ops settings and many different datasets (including ones that worked well previously).

The error is always the same and persists even when all of the ops are default except tau = 0.7, fs = 30, and th_badframes = 0

Reproduce the code example:

** Found 3 tifs - converting to binary **
time 1.25 sec. Wrote 1200 frames per binary for 1 planes
>>>>>>>>>>>>>>>>>>>>> PLANE 0 <<<<<<<<<<<<<<<<<<<<<<
NOTE: not registered / registration forced with ops['do_registration']>1
      (no previous offsets to delete)
NOTE: applying default /Users/evancampbell/.suite2p/classifiers/classifier_user.npy
----------- REGISTRATION
Reference frame, 15.78 sec.
Registered 400/1200 in 7.46s
Registered 800/1200 in 14.98s
Registered 1200/1200 in 22.37s
----------- Total 45.80 sec
----------- ROI DETECTION
Binning movie in chunks of length 21
>>>ERROR<<<
Traceback (most recent call last):
  File "/Users/evancampbell/miniconda3/envs/suite2p/lib/python3.8/runpy.py", line 194, in _run_module_as_main
>>>ERROR<<<
    return _run_code(code, main_globals, None,
  File "/Users/evancampbell/miniconda3/envs/suite2p/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/evancampbell/miniconda3/envs/suite2p/lib/python3.8/site-packages/suite2p/__main__.py", line 78, in <module>
    main()
  File "/Users/evancampbell/miniconda3/envs/suite2p/lib/python3.8/site-packages/suite2p/__main__.py", line 71, in main
    run_s2p(ops, db)
  File "/Users/evancampbell/miniconda3/envs/suite2p/lib/python3.8/site-packages/suite2p/run_s2p.py", line 443, in run_s2p
    op = run_plane(op, ops_path=ops_path)
  File "/Users/evancampbell/miniconda3/envs/suite2p/lib/python3.8/site-packages/suite2p/run_s2p.py", line 296, in run_plane
    ops = pipeline(f_reg, f_raw, f_reg_chan2, f_raw_chan2, run_registration, ops, stat=stat)
  File "/Users/evancampbell/miniconda3/envs/suite2p/lib/python3.8/site-packages/suite2p/run_s2p.py", line 129, in pipeline
    ops, stat = detection.detection_wrapper(f_reg,
  File "/Users/evancampbell/miniconda3/envs/suite2p/lib/python3.8/site-packages/suite2p/detection/detect.py", line 112, in detection_wrapper
    mov = bin_movie(f_reg, bin_size, yrange=yrange, 
  File "/Users/evancampbell/miniconda3/envs/suite2p/lib/python3.8/site-packages/suite2p/detection/detect.py", line 61, in bin_movie
    mov[ik : ik + n_bins] = data
ValueError: could not broadcast input array from shape (11,492,508) into shape (0,492,508)
Interrupted by error (not finished)

Error message:

No response

Version information:

suite2p v0.12.0

Context for the issue:

I use an M1 macbook, and had previously installed and used suit2p for ~ 5-6 months (though I am still a total novice).

I recently needed the display replaced and the machine came back with a factory reset and the newest Ventura OS installed. After re-install of iterm2, python3.8, miniconda (python 3.8), and suite2p v0.12.0, I have run into this error with every dataset I’ve tried.

I am curious if my problem may be a software incompatibility?

Although, I have also encountered the same error using suite2p v0.11.1 (the version I ran before my macbook was reset).

@evanpc
Copy link
Author

evanpc commented Mar 7, 2023

Quick correction - when running suite2p v0.11.1 (instead of v0.12.0), if ops are default except tau = 0.7, fs = 30, and th_badframes = 0 suite2p will run and open GUI, however will not save an NWB file.

If I add save_NWB = 1 to ops, I encounter an error following save in NWB format, error message below:

ERROR<<<
Traceback (most recent call last):
File "/Users/evancampbell/miniconda3/envs/suite2p/lib/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/Users/evancampbell/miniconda3/envs/suite2p/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/Users/evancampbell/miniconda3/envs/suite2p/lib/python3.8/site-packages/suite2p/main.py", line 78, in
main()
File "/Users/evancampbell/miniconda3/envs/suite2p/lib/python3.8/site-packages/suite2p/main.py", line 71, in main
run_s2p(ops, db)
File "/Users/evancampbell/miniconda3/envs/suite2p/lib/python3.8/site-packages/suite2p/run_s2p.py", line 443, in run_s2p
io.save_nwb(save_folder)
File "/Users/evancampbell/miniconda3/envs/suite2p/lib/python3.8/site-packages/suite2p/io/nwb.py", line 307, in save_nwb
image_series = TwoPhotonSeries(
File "/Users/evancampbell/miniconda3/envs/suite2p/lib/python3.8/site-packages/hdmf/utils.py", line 645, in func_call
return func(args[0], **pargs)
File "/Users/evancampbell/miniconda3/envs/suite2p/lib/python3.8/site-packages/pynwb/ophys.py", line 232, in init
super().init(**kwargs)
File "/Users/evancampbell/miniconda3/envs/suite2p/lib/python3.8/site-packages/hdmf/utils.py", line 645, in func_call
return func(args[0], **pargs)
File "/Users/evancampbell/miniconda3/envs/suite2p/lib/python3.8/site-packages/pynwb/image.py", line 112, in init
self._error_on_new_warn_on_construct(
File "/Users/evancampbell/miniconda3/envs/suite2p/lib/python3.8/site-packages/pynwb/core.py", line 46, in _error_on_new_warn_on_construct
ERROR<<<
raise ValueError(error_msg)
ValueError: TwoPhotonSeries 'TwoPhotonSeries': The number of frame indices in 'starting_frame' should have the same length as 'external_file'.
Interrupted by error (not finished)

@lizard1111
Copy link

I'm getting the same input array error on about half of the datasets I've tried so far,
They're all single-channel tiffs, exported from the same program, so I wonder why some work and others don't.
I'm using s2p v012.0 on Ubuntu 20.04.

@jmdelahanty
Copy link

jmdelahanty commented Mar 21, 2023

I just ran into this error as well running v0.12.0 on Debian 11. Going to try re-install/clear my conda environment in case something strange has happened after I removed and reinstalled to update.

EDIT:
No luck with re-installing/cleaning up conda environments for me quite yet. Has happened to me on 2 separate datasets so far. Several others in the lab using the most recent version of suite2p aren't having trouble as far as I'm aware, so there's gotta be something else specific to me.

@juhuntenburg
Copy link

Hi,

I also get this error (the original one)
Ubuntu 20.04 , suite2p 0.12.0

We have analyzed the same dataset using the GUI but running it through the python function gives this error.
Any help appreciated

@chriski777 chriski777 self-assigned this Apr 2, 2023
@chriski777
Copy link
Collaborator

Thanks for letting us know about this. Can someone provide a dropbox link to a dataset such that this can be reproduced? We are having trouble replicating this on our end.

@jmdelahanty
Copy link

I can provide a dataset this evening, but need to pare it down to something a lot smaller. It's currently about 60k individual tiffs acquired from a Bruker 2p scope. If it still throws this error with a smaller number of tiffs I'll update this comment with the link for you. I'll also include my conda environment and the info about the machine I've run it on most recently (it's happened across several different machines).

I can also put it into H5 or whatever else you'd like if that's easier for you.

@chriski777
Copy link
Collaborator

Yep, that'd be great! It'd be best if it's as small as possible and can reproduce this error. Any format is fine. Thanks a bunch!

@lizard1111
Copy link

I can also upload a dataset if it might be helpful. Also, I don't know if this is a clue but sometimes it seems like registration runs fine on the initial analysis, but if I try to open the session up later on and/or tweak parameters, things "break" and I wind up with OP's error message.

I'm a bit confused as to whether I should be saving the ops.npy from the initial run-through and reloading those ops when I reopen the session to avoid any conflicts with the default values?

I am using the GUI to change ops values, btw.

@chriski777
Copy link
Collaborator

Yes, @lizard1111, if you could that would be greatly appreciated.

@jmdelahanty
Copy link

Somehow since Monday evening I have been unable to reproduce this with any of my troublesome datasets of any size... Really unsure what I did... Trying to break it again though!

@lizard1111
Copy link

That's funny, @jmdelahanty - same deal here. I've been loading in much smaller datasets than usual though, so I will see what happens with one of my regular-sized ones.

@RandallJEllis
Copy link

I am having this issue as well, and from looking at the bin_movie function from detect.py where the error is coming from, it appears to be an incompatibility between the number of frames in f_reg, bin_size, and the dimensionality of mov. The code below replicates the error. The error does not occur if bin_size=10 instead of 20 as in this example, or if f_reg has 6040 frames instead of 6020.

import numpy as np
import time


f_reg = np.random.rand(6020,10,10)
badframes=None
n_frames = f_reg.shape[0]
good_frames = ~badframes if badframes is not None else np.ones(n_frames, dtype=bool)
batch_size = min(good_frames.sum(), 500)
Lyc=9
Lxc=9
xrange = (1,10)
yrange = (1,10)
num_good_frames = good_frames.sum()
bin_size=20
mov = np.zeros((num_good_frames//bin_size, Lyc, Lxc), np.float32)
ik = 0
t0 = time.time()


for k in np.arange(0, n_frames, batch_size):
	data = f_reg[k : min(k + batch_size, n_frames)]

	# exclude badframes
	good_indices = good_frames[k : min(k + batch_size, n_frames)]
	if good_indices.mean() > 0.5:
		data = data[good_indices]

	# crop to valid region
	if yrange is not None and xrange is not None:
		data = data[:, slice(*yrange), slice(*xrange)]

	# bin in time
	if data.shape[0] > bin_size:
		n_d = data.shape[0]
		data = data[:(n_d // bin_size) * bin_size]
		data = data.reshape(-1, bin_size, Lyc, Lxc).astype(np.float32).mean(axis=1)
	n_bins = data.shape[0]
	mov[ik : ik + n_bins] = data
	ik += n_bins

Output:

Traceback (most recent call last):
  File "<stdin>", line 16, in <module>
ValueError: could not broadcast input array from shape (20,9,9) into shape (1,9,9)

chriski777 added a commit that referenced this issue Apr 27, 2023
…ich the current batch has fewer frames than the bin_size
@chriski777
Copy link
Collaborator

Hi @RandallJEllis, thanks for providing this code! Seems this error was caused by a particular edge case in which the last batch (frames 6000-6020) happened to have the same number of frames as the bin_size. This error seems to have also occurred when the number of bad_frames in a given batch made it such that the filtered batch had fewer frames than bin_size.

We've updated the code to cover these edge cases but without the data that caused the errors in the first place, we can't say for sure if this was the problem @lizard1111 and @jmdelahanty faced above. I'll close this for now since the commit above fixes the bug @RandallJEllis mentioned but you all can feel free to create another issue if it still persists after pulling the commit 83d4ebb.

tbabola added a commit to tbabola/suite2p that referenced this issue Jun 19, 2024
* add get_nd2_list method

* remove comment

* support pipelining nd2 files

* support pipelining nd2 files

* fix docstring and whitespaces

* bug fix

* final touch

* Modified README to contain updated suite2p installation instructions for mac Ventura OS. Addresses issue MouseLand#897.

* Fixed issue MouseLand#908 regarding badframes for register.py. Detection module was fixed to properly bin movies AFTEr taking into account bad frames.

* Fix blocks issue for nonrigid registration in MouseLand#907

* Update test_and_deploy.yml

* Removed whitespace from display xauthority line in tox.ini.

* Update test_and_deploy.yml

Add apt-get update for linux runner and remove dvc requirement.

* Update test_and_deploy.yml

Added py import to workflow file and added debugging only during job failures

* Update test_and_deploy.yml

* Update tox.ini

* Update test_and_deploy.yml

Remove the up-term step.

* Updated TwophotonSeries initialization for save_nwb in io

* Bump torch from 1.11.0 to 1.13.1

Bumps [torch](https://github.com/pytorch/pytorch) from 1.11.0 to 1.13.1.
- [Release notes](https://github.com/pytorch/pytorch/releases)
- [Changelog](https://github.com/pytorch/pytorch/blob/master/RELEASE.md)
- [Commits](pytorch/pytorch@v1.11.0...v1.13.1)

---
updated-dependencies:
- dependency-name: torch
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>

* Update issue templates

* Update installation-issues.yml for issues

* Rename installation-issues.yml to installation-issue.yml

* Update installation issue.yml

* Update bug_report.yml

* Added bug_report.yml issue template

* Update all issue templates

* Update feature_request issue

* Update feature_request.yml

* Fixes issue MouseLand#914 for saving news ops parameters

* Update documentation_issue.yml

* Update documentation_issue.yml

* Fixes multiplane issue MouseLand#905 with save_nwb

* Fixes issue MouseLand#904 for 2 channel manual labeling

* Update .readthedocs.yml

* remove spaces

* conform to function signature and usage pattern a few lines above

* add nd2 in requirements

* minor revision

* new logic

* refactor dim sorting

* revert to previous code

* Fixes the from_stat_dict bug mentioned in MouseLand#935.

* Update run suite2p jupyter notebook to fix issue MouseLand#935

* Addresses MouseLand#930 in which bin_data has trouble dealing with cases in which the current batch has fewer frames than the bin_size

* removed ops assignment

* removed deprecated np.bool

* Update the version of the dependencies for suite2p

* Update np.bool to 'bool' to account for numpy deprecation with latest version

* Add Sparse detection to gui as a setting for running suite2p

* Addresses MouseLand#951 and adds nd2 as an input to gui

* Fix issue with np.asanyarray being changed in numpy 1.24.4

* addressed IndexError

* Update README.md

* Update README.md

* fixing skip torch if version 2.0

* adding pep8 style to repo

* fixing dictionary splitting

* modifying imports

* converting to "" from ''

* converting binaryfile to memmap

* rewriting binarycombined

* removing scanimage-tiff-reader for now

* fixing dragging in gui and linewidth=88

* removing old testing yml

* adding py39, updating readme

* adding option for MouseLand#955

* fixing bug in docstring  (MouseLand#902)

* adding iplane to saved manual ROIs (MouseLand#789)

* fixing MouseLand#747 saving to mat

* making nd2 and scanimage-tiff-reader optional (MouseLand#950)

* removing bruker dependency on scanimage-tiff-reader

* Create codecov.yml

* Update README.md

* Update README.md

* Update README.md

* Update README.md

* Update BinaryRWFile name usage to BinaryFile

* Add instructions on how to use test_data generation script

* Added instructions on generating new test data

* Add method for writing tiff for binaryFile class

* Update write_tiff for binary.py to crop frames, x, and y too

* fix frame range issue with write_Tiff for binary

* added debugging logs

* removed debugging logs

* removed print statement

* removed unnecessary space

* Fixes MouseLand#943 to address documentation issue with high_pass

* adding copyright to every py file

* Delete .dvc directory

* fixing import error with h5py and paramiko MouseLand#987

* Update README.md

* Add pynwb package to setup.py as tests needs pynwb for one of the io_tests

* Update readme.md to be for python version 3.9

* Addresses MouseLand#944  leading zero issue with tiff filename.

* Addresses MouseLand#944  leading zero issue with tiff filename.

* Update save_path0 to close MouseLand#991.

* Update save_path0 to close MouseLand#991.

* update visualize.py to import rastermap properly

* Re-add connected to GUI options

* Update README.md

Remove note about scanimage-tiff-reader mac incompatibility

* Update README.md

Simplify mac os instructions

* Update setup.py

Update rastermap requirement based on issue ticket suggestions

* Update setup.py

* Updated jupyter notebook to work with new binaryFile class in suite2p.io

* Updated jupyter notebook name

* Update colab 2023 to fully fix MouseLand#1011 and update some comments on notebook

* Updated jupyter notebook to work with new binaryFile class in suite2p.io

* Updated jupyter notebook name

* Update colab 2023 to fully fix MouseLand#1011 and update some comments on notebook

* adding pyqt6 and switching to qtpy

* updating readme and fixing spelling error in copyright

* adding license notice

* adding check in setup.py for installation of a pyqt version

* adding tutorial

* Update tutorial.md with additional comments

* Update suite2p gui to work with QFileDialog.Options() not working with pyqt6

* Update binary.py write_tiff to add all frames to a single series

* Updated tiff.py to use contiguous parameter

* Update README.md

* checking h5py key to open binaries before data_path

* fixing bug in code

* adding new data type

* adding support for binary and mp4/avi files

* enabling ops.json loading in reggui and binary-only processing

* increase tolerance on classification regression test

* add more tolerance

* increasing tolerance again

* increasing tolerance again

* Update README.md

* Add explanation for how to apply classifiers

* CheckState Fix

* Fix conda environment creation for developers

* Update utils.py

* Update README.md to fix MouseLand#1060.

Updates badge links for tests and docs

* Update merge.py of gui subpackage to not use deprecated np.bool

* Update merge.py of gui subpackage to not use deprecated np.bool

* Add import to gui/io.py

* Update gui.rst to have clearer instructions for MouseLand#1002.

* bug in h5py key option

* adding support for multipage bruker ome tiffs

* Update inputs.rst to include multipage bruker instructions

* Update inputs.rst

* Added support for Thorlabs RAW files (io.raw)

* Added xmltodict

* Update raw.py- todo verified

* safe import for xmltodict

* fixing bug with multiplane registration

* allowing reg_file input to compute_zpos

* fixing bug with multi-plane nonrigid ops

* add support for Hamamatsu DCIMG format

* add support for Hamamatsu DCIMG format

* add dcimg_deps to all_deps and restrict cellpose to <3.0

* Addresses MouseLand#1093 with cellpose method having too many arguments

* Addresses MouseLand#1093 with cellpose method having too many arguments

* remove cellpose<3.0 restriction

* Fixes issue MouseLand#1101 with older version of cellpose

* Update zalign.py

Made sure that if a reg_file is given to the zalign function it uses it, rather than the ops reg_file

* Update setup.py

* adding dcimg

* removing dcimg extra

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: tdincer <[email protected]>
Co-authored-by: Chris Ki <[email protected]>
Co-authored-by: Chris Ki <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: carsen-stringer <[email protected]>
Co-authored-by: Kabilar Gunalan <[email protected]>
Co-authored-by: itsb <[email protected]>
Co-authored-by: Sidharth Hulyalkar <[email protected]>
Co-authored-by: Ahmed Morsi <[email protected]>
Co-authored-by: Marius Pachitariu <[email protected]>
Co-authored-by: Heather Ratigan <[email protected]>
Co-authored-by: Ryan Ly <[email protected]>
Co-authored-by: Arielle Leon <[email protected]>
Co-authored-by: Andrew Landau <[email protected]>
Co-authored-by: arielleleon <[email protected]>
Co-authored-by: yaelpri <[email protected]>
Co-authored-by: yaelpri <[email protected]>
Co-authored-by: Yael Prilutski <[email protected]>
Co-authored-by: nguyemi5 <[email protected]>
Co-authored-by: nguyemi5 <[email protected]>
Co-authored-by: liadJB <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants