Skip to content

Commit 9ab4ca1

Browse files
authored
Merge pull request #1008 from MouseLand/dev
Addresses doc issues and package issues
2 parents 9808eca + 0e98a04 commit 9ab4ca1

File tree

10 files changed

+43
-18
lines changed

10 files changed

+43
-18
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Pachitariu, M., Stringer, C., Schröder, S., Dipoppa, M., Rossi, L. F., Carandin
5252
### <a name="installation_section"></a> Installation for Linux, Windows, and MacOS (intel processors) machines
5353
1. Install an [Anaconda](https://www.anaconda.com/download/) distribution of Python -- Choose **Python 3.8** and your operating system. Note you might need to use an anaconda prompt if you did not add anaconda to the path.
5454
2. Open an anaconda prompt / command prompt with `conda` for **python 3** in the path
55-
3. Create a new environment with `conda create --name suite2p python=3.8`.
55+
3. Create a new environment with `conda create --name suite2p python=3.9`.
5656
4. To activate this new environment, run `conda activate suite2p`
5757
5. (Option 1) You can install the minimal version of suite2p, run `python -m pip install suite2p`.
5858
6. (Option 2) You can install the GUI version with `python -m pip install suite2p[gui]`. If you're on a zsh server, you may need to use `' '` around the suite2p[gui] call: `python -m pip install 'suite2p[gui]'`. This also installs the NWB dependencies.
@@ -76,7 +76,7 @@ pip install --upgrade suite2p
7676
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").
7777
2. Navigate to the iTerm app you will use, right click it, and then select "Get Info". Check "Open using Rosetta".
7878
3. Open up this iTerm app and follow steps 1 & 2 in the installation section [above](#installation_section) to install anaconda.
79-
4. Use the following command `CONDA_SUBDIR=osx-64 conda create --name suite2p python=3.8`
79+
4. Use the following command `CONDA_SUBDIR=osx-64 conda create --name suite2p python=3.9`
8080
5. Follow steps 4-7 in the installation section [above](#installation_section) to install the `suite2p` package.
8181

8282

@@ -102,7 +102,7 @@ The software has been heavily tested on Windows 10 and Ubuntu 18.04, and less we
102102
1. Clone the repository and `cd suite2p` in an anaconda prompt / command prompt with `conda` for **python 3** in the path
103103
2. Run `conda env create --name suite2p`
104104
3. To activate this new environment, run `conda activate suite2p` (you will have to activate every time you want to run suite2p)
105-
4. Install the local version of suite2p into this environment in develop mode with the command `pip install -e .`
105+
4. Install the local version of suite2p into this environment in develop mode with the command `pip install -e .[all]`
106106
5. Run tests: `python setup.py test` or `pytest -vs`, this will automatically download the test data into your `suite2p` folder. The test data is split into two parts: test inputs and expected test outputs which will be downloaded in `data/test_inputs` and `data/test_outputs` respectively. The .zip files for these two parts can be downloaded from these links: [test_inputs](https://www.suite2p.org/static/test_data/test_inputs.zip) and [test_outputs](https://www.suite2p.org/static/test_data/test_outputs.zip).
107107

108108
## Examples

docs/inputs.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,21 +156,21 @@ Suite2p reads nd2 files using the nd2 package and returns a numpy array represen
156156

157157

158158

159-
BinaryRWFile
159+
BinaryFile
160160
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
161161

162-
The ``BinaryRWFile`` is a special class in suite2p that is used to read/write imaging data and acts like a Numpy Array. Inputs of any format listed above will be converted into a ``BinaryRWFile`` before being passed in through the suite2p pipeline. An input file can easily be changed to a ``BinaryRWFile`` in the following way:
162+
The ``BinaryFile`` is a special class in suite2p that is used to read/write imaging data and acts like a Numpy Array. Inputs of any format listed above will be converted into a ``BinaryFile`` before being passed in through the suite2p pipeline. An input file can easily be changed to a ``BinaryFile`` in the following way:
163163

164164
::
165165

166166
import suite2p
167167

168168
fname = "gt1.tif" # Let's say input is of shape (4200, 325, 556)
169169
Lx, Ly = 556, 326 # Lx and Ly are the x and y dimensions of the imaging input
170-
# Read in our input tif and convert it to a BinaryRWFile
171-
f_input = suite2p.io.BinaryRWFile(Ly=Ly, Lx=Lx, filename=fname)
170+
# Read in our input tif and convert it to a BinaryFile
171+
f_input = suite2p.io.BinaryFile(Ly=Ly, Lx=Lx, filename=fname)
172172

173-
``BinaryRWFile`` can work with any of the input formats above. For instance, if you'd like to convert an input binary file, you can do the following:
173+
``BinaryFile`` can work with any of the input formats above. For instance, if you'd like to convert an input binary file, you can do the following:
174174

175175
::
176176

docs/settings.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Suite2p can accomodate many different file formats. Refer to this
7777

7878
- **nwb_series** (*str, default: ''*) Name of TwoPhotonSeries values you wish to retrieve from your NWB file.
7979

80-
- **save_path0** (*list[str], default: empty list*) List containing pathname of where you'd like to save your pipeline results. If list is empty, the first element of ``ops['data_path']`` is used.
80+
- **save_path0** (*str, default: ''*) String containing pathname of where you'd like to save your pipeline results. If no pathname is provided, the first element of ``ops['data_path']`` is used.
8181

8282
- **save_folder** (*list[str], default: empty list*) List containing directory name you'd like results to be saved under. Defaults to ``"suite2p"``.
8383

@@ -247,7 +247,7 @@ ROI detection settings
247247
1.0.
248248

249249
- **high_pass**: (*int, default: 100*) running mean subtraction across
250-
time with window of size 'high_pass'. Values of less than 10 are
250+
bins of frames with window of size 'high_pass'. Values of less than 10 are
251251
recommended for 1P data where there are often large full-field
252252
changes in brightness.
253253

@@ -355,4 +355,4 @@ Channel 2 specific settings
355355
Miscellaneous settings
356356
~~~~~~~~~~~~~~~~~~~~~~
357357

358-
- **suite2p_version**: specifies version of suite2p pipeline that was run with these settings. Changing this parameter will NOT change the version of suite2p used.
358+
- **suite2p_version**: specifies version of suite2p pipeline that was run with these settings. Changing this parameter will NOT change the version of suite2p used.

scripts/generate_test_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def generate_detection_1plane1chan_test_data(ops):
7070
[[Path(ops['data_path'][0]).joinpath('detection/pre_registered.npy')]],
7171
(404, 360)
7272
)
73-
with suite2p.io.BinaryRWFile(Ly = ops[0]['Ly'], Lx = ops[0]['Lx'], filename=ops[0]['reg_file']) as f_reg:
73+
with suite2p.io.BinaryFile(Ly = ops[0]['Ly'], Lx = ops[0]['Lx'], filename=ops[0]['reg_file']) as f_reg:
7474
ops, stat = suite2p.detection.detection_wrapper(f_reg, ops=ops[0])
7575
ops['neuropil_extract'] = True
7676
cell_masks, neuropil_masks = masks.create_masks(stat, ops['Ly'], ops['Lx'], ops=ops)
@@ -107,7 +107,7 @@ def generate_detection_2plane2chan_test_data(ops):
107107
two_plane_ops[1]['meanImg_chan2'] = np.load(detection_dir.joinpath('meanImg_chan2p1.npy'))
108108
for i in range(len(two_plane_ops)):
109109
op = two_plane_ops[i]
110-
with suite2p.io.BinaryRWFile(Ly = op['Ly'], Lx = op['Lx'], filename=op['reg_file']) as f_reg:
110+
with suite2p.io.BinaryFile(Ly = op['Ly'], Lx = op['Lx'], filename=op['reg_file']) as f_reg:
111111
# Neuropil_masks are later needed for extraction test data step
112112
op['neuropil_extract'] = True
113113
op, stat = suite2p.detection.detection_wrapper(f_reg, ops=op)

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@
3636
"pytest",
3737
"tenacity",
3838
"tqdm",
39+
"pynwb>=2.3.2", #this is needed as test_io contains a test with nwb
3940
"pytest-qt>3.3.0",
40-
]
41+
]
4142

4243
all_deps = gui_deps + nwb_deps + test_deps + io_deps
4344

suite2p/default_ops.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def default_ops():
2525
"nwb_driver": "", # driver for nwb file (nothing if file is local)
2626
"nwb_series":
2727
"", # TwoPhotonSeries name, defaults to first TwoPhotonSeries in nwb file
28-
"save_path0": [], # stores results, defaults to first item in data_path
28+
"save_path0": '', # pathname where you'd like to store results, defaults to first item in data_path
2929
"save_folder": [], # directory you"d like suite2p results to be saved to
3030
"subfolders": [
3131
], # subfolders you"d like to search through when look_one_level_down is set to True
@@ -120,7 +120,7 @@ def default_ops():
120120
"max_overlap":
121121
0.75, # cells with more overlap than this get removed during triage, before refinement
122122
"high_pass":
123-
100, # running mean subtraction with window of size "high_pass" (use low values for 1P)
123+
100, # running mean subtraction across bins with a window of size "high_pass" (use low values for 1P)
124124
"spatial_hp_detect":
125125
25, # window for spatial high-pass filtering for neuropil subtraction before detection
126126
"denoise": False, # denoise binned movie for cell detection in sparse_mode

suite2p/gui/visualize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from PyQt5.QtWidgets import QStyle
1111
from PyQt5.QtWidgets import QWidget, QSlider, QMainWindow, QGridLayout, QStyleOptionSlider, QApplication, QLabel, QLineEdit, QPushButton, QComboBox, QCheckBox
1212
from matplotlib import cm
13-
from rastermap.mapping import Rastermap
13+
from rastermap.rastermap import Rastermap
1414
from scipy.ndimage import gaussian_filter1d
1515
from scipy.stats import zscore
1616

suite2p/io/binary.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"""
44
from typing import Optional, Tuple, Sequence
55
from contextlib import contextmanager
6+
from tifffile import TiffWriter
7+
68
import os
79

810
import numpy as np
@@ -191,6 +193,24 @@ def bin_movie(self, bin_size: int, x_range: Optional[Tuple[int, int]] = None,
191193
mov = np.stack(batches)
192194
return mov
193195

196+
def write_tiff(self, fname, range_dict={}):
197+
"Writes BinaryFile's contents using selected ranges from range_dict into a tiff file."
198+
n_frames, Ly, Lx = self.shape
199+
frame_range, y_range, x_range = (0,n_frames), (0, Ly), (0, Lx)
200+
with TiffWriter(fname, bigtiff=True) as f:
201+
# Iterate through current data and write each frame to a tiff
202+
# All ranges should be Tuples(int,int)
203+
if 'frame_range' in range_dict:
204+
frame_range = range_dict['frame_range']
205+
if 'x_range' in range_dict:
206+
x_range = range_dict['x_range']
207+
if 'y_range' in range_dict:
208+
y_range = range_dict['y_range']
209+
print('Frame Range: {}, y_range: {}, x_range{}'.format(frame_range, y_range, x_range))
210+
for i in range(frame_range[0], frame_range[1]):
211+
curr_frame = np.floor(self.file[i, y_range[0]:y_range[1], x_range[0]:x_range[1]]).astype(np.int16)
212+
f.write(curr_frame)
213+
print('Tiff has been saved to {}'.format(fname))
194214

195215
def from_slice(s: slice) -> Optional[np.ndarray]:
196216
"""Creates an np.arange() array from a Python slice object. Helps provide numpy-like slicing interfaces."""

suite2p/io/tiff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def generate_tiff_filename(functional_chan: int, align_by_chan: int, save_path:
6060
wchan = 0
6161
if not os.path.isdir(tifroot):
6262
os.makedirs(tifroot)
63-
fname = "file%0.3d_chan%d.tif" % (k, wchan)
63+
fname = "file00%0.3d_chan%d.tif" % (k, wchan)
6464
fname = os.path.join(tifroot, fname)
6565
return fname
6666

tests/instructions.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Instructions on generating new test data
2+
1. Make sure you are in the `suite2p/scripts` directory instead of `suite2p/tests` where this `instructions.md` file is located. Run `python generate_test_data.py`.
3+
2. All the generated test data will be placed in the directory
4+
`suite2p/scripts/test_data`. These directories will correspond to the expected outputs for our tests.

0 commit comments

Comments
 (0)