Skip to content

Commit e127bcc

Browse files
authored
Merge pull request #910 from MouseLand/refactor
Fixes bugs with badframes and nonrigid registration.
2 parents d7915fa + afca634 commit e127bcc

File tree

6 files changed

+40
-34
lines changed

6 files changed

+40
-34
lines changed

.github/workflows/test_and_deploy.yml

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ jobs:
3232
with:
3333
python-version: ${{ matrix.python-version }}
3434

35+
3536
# these libraries, along with pytest-xvfb (added in the `deps` in tox.ini),
3637
# enable testing on Qt on linux
3738
- name: Install Linux libraries
3839
if: runner.os == 'Linux'
3940
run: |
41+
sudo apt-get update
4042
sudo apt-get install -y libdbus-1-3 libxkbcommon-x11-0 libxcb-icccm4 \
4143
libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 \
4244
libxcb-xinerama0 libxcb-xinput0 libxcb-xfixes0 pkg-config libhdf5-103 libhdf5-dev
@@ -54,25 +56,24 @@ jobs:
5456
run: |
5557
python -m pip install --upgrade pip
5658
pip install wheel setuptools tox tox-gh-actions
57-
pip install dvc==1.11.0 pydrive2
58-
# For debugging purposes, allows one to ssh into host machine.
59-
# Follow instructions in https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account
60-
# to add your ssh keys.
61-
# MAKE SURE TO COMMENT OUT IF NOT DEBUGGING!
62-
# - name: Setup upterm session
63-
# if: runner.os == 'macOS'
64-
# uses: lhotari/action-upterm@v1
65-
# with:
66-
# ## limits ssh access and adds the ssh public key for the user which triggered the workflow
67-
# limit-access-to-actor: true
68-
# ## limits ssh access and adds the ssh public keys of the listed GitHub users
69-
# limit-access-to-users: chriski777, carsen-stringer
59+
pip install pydrive2 py # Added py due to pytest tox issues requiring py module.
7060
7161
- name: Test with tox
7262
run: tox
7363
env:
74-
PLATFORM: ${{ matrix.platform }}
75-
64+
PLATFORM: ${{ matrix.platform }}
65+
# ONLY UNCOMMENT SECTION BELOW FOR DEBUGGING PURPOSES: allows one to ssh into host machine.
66+
# Follow instructions in https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account
67+
# to add your ssh keys.
68+
# - name: Job failed. Activating debugging mode via up-term.
69+
# if: ${{ failure() }}
70+
# uses: lhotari/action-upterm@v1
71+
# with:
72+
# ## limits ssh access and adds the ssh public key for the user which triggered the workflow
73+
# limit-access-to-actor: true
74+
# ## limits ssh access and adds the ssh public keys of the listed GitHub users
75+
# limit-access-to-users: chriski777, carsen-stringera
76+
7677
- name: Coverage
7778
# Only run coverage once
7879
if: runner.os == 'Linux'

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,11 @@ pip install --upgrade suite2p
6262
~~~~
6363

6464
### Installation for Macs with Apple Silicon chips (e.g., M1)
65-
1. Set up a Rosetta terminal following step 1 in this [link](https://dev.to/courier/tips-and-tricks-to-setup-your-apple-m1-for-development-547g).
66-
2. Open up the newly created Rosetta terminal and follow steps 1 & 2 in the installation section [above](#installation_section) to install anaconda.
67-
3. Use the following command `CONDA_SUBDIR=osx-64 conda create --name suite2p python=3.8`
68-
4. Follow steps 4-7 in the installation section [above](#installation_section) to install the `suite2p` package.
65+
1. Download an iTerm2 terminal from this [link](https://iterm2.com/). Install it into your /Applications folder. If you already have downloaded iTerm, duplicate it and give it whatever name you'd like (e.g., "iterm2Rosetta").
66+
2. Navigate to the iTerm app you will use, right click it, and then select "Get Info". Check "Open using Rosetta".
67+
3. Open up this iTerm app and follow steps 1 & 2 in the installation section [above](#installation_section) to install anaconda.
68+
4. Use the following command `CONDA_SUBDIR=osx-64 conda create --name suite2p python=3.8`
69+
5. Follow steps 4-7 in the installation section [above](#installation_section) to install the `suite2p` package.
6970

7071

7172
### Installing the latest github version of the code

suite2p/detection/detect.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ def bin_movie(f_reg, bin_size, yrange=None, xrange=None, badframes=None):
3535
batch_size = min(good_frames.sum(), 500)
3636
Lyc = yrange[1] - yrange[0]
3737
Lxc = xrange[1] - xrange[0]
38-
mov = np.zeros((n_frames//bin_size, Lyc, Lxc), np.float32)
38+
# Need to adjust binned movie size after calculating bad frames
39+
num_good_frames = good_frames.sum()
40+
mov = np.zeros((num_good_frames//bin_size, Lyc, Lxc), np.float32)
3941
ik = 0
40-
4142
t0 = time.time()
4243
for k in np.arange(0, n_frames, batch_size):
4344
data = f_reg[k : min(k + batch_size, n_frames)]
@@ -61,7 +62,6 @@ def bin_movie(f_reg, bin_size, yrange=None, xrange=None, badframes=None):
6162
ik += n_bins
6263

6364
print('Binned movie of size [%d,%d,%d] created in %0.2f sec.' % (mov.shape[0], mov.shape[1], mov.shape[2], time.time() - t0))
64-
6565
return mov
6666

6767

suite2p/io/nwb.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,14 +359,14 @@ def save_nwb(save_folder):
359359
grid_spacing=([2.0, 2.0, 30.0] if multiplane else [2.0, 2.0]),
360360
grid_spacing_unit="microns",
361361
)
362-
363362
# link to external data
363+
external_data = ops["filelist"] if "filelist" in ops else [""]
364364
image_series = TwoPhotonSeries(
365365
name="TwoPhotonSeries",
366366
dimension=[ops["Ly"], ops["Lx"]],
367-
external_file=(ops["filelist"] if "filelist" in ops else [""]),
367+
external_file=external_data,
368368
imaging_plane=imaging_plane,
369-
starting_frame=[0],
369+
starting_frame=[0 for i in range(len(external_data))],
370370
format="external",
371371
starting_time=0.0,
372372
rate=ops["fs"] * ops["nplanes"],

suite2p/registration/register.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ def compute_reference_masks(refImg, ops=default_ops()):
179179
smooth_sigma=ops['smooth_sigma'],
180180
)
181181
Ly, Lx = refImg.shape
182+
blocks = []
182183
if ops.get('nonrigid'):
183184
blocks = nonrigid.make_blocks(Ly=Ly, Lx=Lx, block_size=ops['block_size'])
184185

@@ -190,7 +191,7 @@ def compute_reference_masks(refImg, ops=default_ops()):
190191
xblock=blocks[1],
191192
)
192193
else:
193-
maskMulNR, maskOffsetNR, cfRefImgNR, blocks = [], [], [], []
194+
maskMulNR, maskOffsetNR, cfRefImgNR = [], [], []
194195

195196
return maskMul, maskOffset, cfRefImg, maskMulNR, maskOffsetNR, cfRefImgNR, blocks
196197

@@ -464,7 +465,8 @@ def shift_frames_and_write(f_alt_in, f_alt_out=None, yoff=None, xoff=None, yoff1
464465
raise ValueError('no rigid registration offsets provided')
465466
elif yoff.shape[0] != n_frames or xoff.shape[0] != n_frames:
466467
raise ValueError('rigid registration offsets are not the same size as input frames')
467-
468+
# Overwrite blocks if nonrigid registration is activated
469+
blocks = None
468470
if ops.get('nonrigid'):
469471
if yoff1 is None or xoff1 is None:
470472
raise ValueError('nonrigid registration is activated but no nonrigid shifts provided')
@@ -636,16 +638,17 @@ def registration_wrapper(f_reg, f_raw=None, f_reg_chan2=None, f_raw_chan2=None,
636638

637639

638640
# compute valid region
639-
# ignore user-specified bad_frames.npy
640641
badframes = np.zeros(n_frames, 'bool')
641642
if 'data_path' in ops and len(ops['data_path']) > 0:
642643
badfrfile = path.abspath(path.join(ops['data_path'][0], 'bad_frames.npy'))
644+
# Check if badframes file exists
643645
if path.isfile(badfrfile):
644646
print('bad frames file path: %s'%badfrfile)
645-
badframes = np.load(badfrfile)
646-
badframes = badframes.flatten().astype(int)
647-
badframes = True
648-
print('number of badframes: %d'%ops['badframes'].sum())
647+
bf_indices = np.load(badfrfile)
648+
bf_indices = bf_indices.flatten().astype(int)
649+
# Set indices of badframes to true
650+
badframes[bf_indices] = True
651+
print('number of badframes: %d'%badframes.sum())
649652

650653
# return frames which fall outside range
651654
badframes, yrange, xrange = compute_crop(

tox.ini

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ platform =
2121
passenv =
2222
CI
2323
GITHUB_ACTIONS
24-
DISPLAY XAUTHORITY
24+
DISPLAY,XAUTHORITY
2525
NUMPY_EXPERIMENTAL_ARRAY_FUNCTION
2626
PYVISTA_OFF_SCREEN
2727
extras = all
2828
deps =
2929
.[all]
30+
py # Needed for py-test import error
3031
pytest # https://docs.pytest.org/en/latest/contents.html
3132
pytest-cov # https://pytest-cov.readthedocs.io/en/latest/
3233
pytest-xvfb ; sys_platform == 'linux'
33-
commands = pytest -v --color=yes --cov=suite2p --cov-report=xml
34+
commands = pytest -v --color=yes --cov=suite2p --cov-report=xml

0 commit comments

Comments
 (0)