lbm_suite2p_python 1.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,38 @@
1
+ This software license is the 3-clause BSD license plus a fourth clause that
2
+ prohibits redistribution for commercial purposes without further permission.
3
+
4
+ BSD 3-Clause License
5
+
6
+ Copyright (c) 2024, Miller Brain Observatory.
7
+
8
+ Redistribution and use in source and binary forms, with or without
9
+ modification, are permitted provided that the following conditions are met:
10
+
11
+ 1. Redistributions of source code must retain the above copyright notice, this
12
+ list of conditions and the following disclaimer.
13
+
14
+ 2. Redistributions in binary form must reproduce the above copyright notice,
15
+ this list of conditions and the following disclaimer in the documentation
16
+ and/or other materials provided with the distribution.
17
+
18
+ 3. Neither the name of the copyright holder nor the names of its
19
+ contributors may be used to endorse or promote products derived from
20
+ this software without specific prior written permission.
21
+
22
+ 4. Redistributions for commercial purposes are not permitted without the
23
+ written permission of the code owner Kushal Kolar.
24
+ For purposes of this license, commercial purposes is the incorporation of
25
+ mesmerize-core into anything for which you will charge fees or other
26
+ compensation. Contact kushalkolar@alumni.ubc.ca for more information.
27
+
28
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
32
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
34
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38
+
@@ -0,0 +1 @@
1
+ exclude data/*
@@ -0,0 +1,78 @@
1
+ Metadata-Version: 2.4
2
+ Name: lbm_suite2p_python
3
+ Version: 1.0.2
4
+ Summary: Light Beads Microscopy Pipeline using Suite2p
5
+ License-Expression: BSD-3-Clause
6
+ Project-URL: homepage, https://github.com/MillerBrainObservatory/LBM-Suite2p-Python
7
+ Keywords: Pipeline,Numpy,Microscopy,ScanImage,Suite2p,tiff
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Science/Research
10
+ Classifier: Programming Language :: Python :: 3 :: Only
11
+ Requires-Python: <3.13,>=3.11
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE.md
14
+ Requires-Dist: tifffile>=2025.3.30
15
+ Requires-Dist: zarr>=2.18.3
16
+ Requires-Dist: dask>=2025.3.0
17
+ Requires-Dist: mkl-fft>=1.3.13
18
+ Requires-Dist: imageio[ffmpeg]
19
+ Requires-Dist: matplotlib>=3.10.1
20
+ Requires-Dist: h5py
21
+ Requires-Dist: tqdm
22
+ Requires-Dist: mbo_utilities[all]
23
+ Requires-Dist: suite2p_mbo<2.0.0,>=1.0.0
24
+ Provides-Extra: napari
25
+ Requires-Dist: napari; extra == "napari"
26
+ Provides-Extra: all
27
+ Requires-Dist: napari; extra == "all"
28
+ Dynamic: license-file
29
+
30
+ # Light Beads Microscopy (LBM) Pipeline: Suite2p
31
+
32
+ [![PyPI - Version](https://img.shields.io/pypi/v/lbm-suite2p-python)](https://pypi.org/project/lbm-suite2p-python/)
33
+
34
+ [![Documentation](https://img.shields.io/badge/Documentation-blue?style=for-the-badge&logo=readthedocs&logoColor=white)](https://millerbrainobservatory.github.io/LBM-Suite2p-Python/index.html)
35
+
36
+ This package is still in a *beta* stage of development.
37
+
38
+ A pipeline for processing 2-photon Light Beads Microscopy (LBM) datasets.
39
+
40
+ This pipeline uses the following software:
41
+
42
+ - [suite2p](https://github.com/MouseLand/suite2p)
43
+ - [cellpose](https://github.com/MouseLand/cellpose)
44
+ - [rastermap](https://github.com/MouseLand/rastermap)
45
+ - [mbo_utilities](https://github.com/MillerBrainObservatory/mbo_utilities)
46
+ - [scanreader](https://github.com/atlab/scanreader)
47
+
48
+
49
+ [![LBM](https://zenodo.org/badge/DOI/10.1007/978-3-319-76207-4_15.svg)](https://doi.org/10.1038/s41592-021-01239-8)
50
+
51
+ ---
52
+
53
+ ## Installation
54
+
55
+ See the [installation documentation](https://millerbrainobservatory.github.io/LBM-Suite2p-Python/install.html) for more details.
56
+
57
+ This pipeline is fully installable with `pip`.
58
+
59
+ `conda` can still be used for the virual environment, but be mindful to only install packages with `conda install` when absolutely necessary.
60
+
61
+ We recommend cloning the repository, until a more established workflow is available to upload to PyPi.
62
+
63
+ ```
64
+ git clone https://github.com/MillerBrainObservatory/LBM-Suite2p-Python.git
65
+ git clone https://github.com/Suite3D # TODO
66
+ cd LBM-Suite2p-Python
67
+
68
+ # make sure your virtual environment is active
69
+ pip install ".[all]" # optional, contains ".[gui, notebook]"
70
+ ```
71
+
72
+ ---
73
+
74
+ ## Acknowledgements
75
+
76
+ Thank you to the developers of [scanreader](https://github.com/atlab/scanreader), which provides a clean interface to ScanImage metadata using only tifffile and numpy.
77
+
78
+ We vendor this repository because it is not published to an indexable Python package registry like PyPI.
@@ -0,0 +1,49 @@
1
+ # Light Beads Microscopy (LBM) Pipeline: Suite2p
2
+
3
+ [![PyPI - Version](https://img.shields.io/pypi/v/lbm-suite2p-python)](https://pypi.org/project/lbm-suite2p-python/)
4
+
5
+ [![Documentation](https://img.shields.io/badge/Documentation-blue?style=for-the-badge&logo=readthedocs&logoColor=white)](https://millerbrainobservatory.github.io/LBM-Suite2p-Python/index.html)
6
+
7
+ This package is still in a *beta* stage of development.
8
+
9
+ A pipeline for processing 2-photon Light Beads Microscopy (LBM) datasets.
10
+
11
+ This pipeline uses the following software:
12
+
13
+ - [suite2p](https://github.com/MouseLand/suite2p)
14
+ - [cellpose](https://github.com/MouseLand/cellpose)
15
+ - [rastermap](https://github.com/MouseLand/rastermap)
16
+ - [mbo_utilities](https://github.com/MillerBrainObservatory/mbo_utilities)
17
+ - [scanreader](https://github.com/atlab/scanreader)
18
+
19
+
20
+ [![LBM](https://zenodo.org/badge/DOI/10.1007/978-3-319-76207-4_15.svg)](https://doi.org/10.1038/s41592-021-01239-8)
21
+
22
+ ---
23
+
24
+ ## Installation
25
+
26
+ See the [installation documentation](https://millerbrainobservatory.github.io/LBM-Suite2p-Python/install.html) for more details.
27
+
28
+ This pipeline is fully installable with `pip`.
29
+
30
+ `conda` can still be used for the virual environment, but be mindful to only install packages with `conda install` when absolutely necessary.
31
+
32
+ We recommend cloning the repository, until a more established workflow is available to upload to PyPi.
33
+
34
+ ```
35
+ git clone https://github.com/MillerBrainObservatory/LBM-Suite2p-Python.git
36
+ git clone https://github.com/Suite3D # TODO
37
+ cd LBM-Suite2p-Python
38
+
39
+ # make sure your virtual environment is active
40
+ pip install ".[all]" # optional, contains ".[gui, notebook]"
41
+ ```
42
+
43
+ ---
44
+
45
+ ## Acknowledgements
46
+
47
+ Thank you to the developers of [scanreader](https://github.com/atlab/scanreader), which provides a clean interface to ScanImage metadata using only tifffile and numpy.
48
+
49
+ We vendor this repository because it is not published to an indexable Python package registry like PyPI.
@@ -0,0 +1 @@
1
+ 1.0.2
@@ -0,0 +1,35 @@
1
+ from lbm_suite2p_python.utils import *
2
+ from lbm_suite2p_python.volume import *
3
+ from lbm_suite2p_python.run_lsp import *
4
+ from lbm_suite2p_python.zplane import *
5
+ from lbm_suite2p_python.default_ops import default_ops
6
+
7
+ try:
8
+ import suite3d
9
+ except ImportError:
10
+ HAS_S3D = False
11
+ else:
12
+ HAS_S3D = True
13
+
14
+ __version__ = (Path(__file__).parent / "VERSION").read_text().strip()
15
+
16
+ __all__ = [
17
+ "run_volume",
18
+ "run_plane",
19
+ "plot_traces",
20
+ "plot_volume_signal",
21
+ "plot_projection",
22
+ "plot_execution_time",
23
+ "plot_noise_distribution",
24
+ "animate_traces",
25
+ "save_images_to_movie",
26
+ "get_common_path",
27
+ "update_ops_paths",
28
+ "dff_percentile",
29
+ "dff_maxmin",
30
+ "dff_shot_noise",
31
+ "combine_tiffs",
32
+ "load_ops",
33
+ "load_planar_results",
34
+ "default_ops",
35
+ ]
@@ -0,0 +1,91 @@
1
+ import numpy as np
2
+ import argparse
3
+ from pathlib import Path
4
+ from functools import partial
5
+ import lbm_suite2p_python as lsp
6
+ import mbo_utilities as mbo
7
+
8
+ import suite2p
9
+
10
+ print = partial(print, flush=True)
11
+
12
+
13
+ def add_args(parser: argparse.ArgumentParser):
14
+ """
15
+ Add command-line arguments to the parser, dynamically adding arguments
16
+ for each key in the `ops` dictionary.
17
+
18
+ Parameters
19
+ ----------
20
+ parser : argparse.ArgumentParser
21
+ The argument parser to which arguments are added.
22
+
23
+ Returns
24
+ -------
25
+ argparse.ArgumentParser
26
+ The parser with added arguments.
27
+ """
28
+
29
+ parser.add_argument('--version', type=str, help='Print the version of the package.')
30
+ parser.add_argument('--ops', type=str, help='Path to the ops .npy file.')
31
+ parser.add_argument('--data', type=str, help='Path to the data.')
32
+ parser.add_argument('--save', type=str, help='Path to save the results.')
33
+ parser.add_argument('--subdir', type=str, help='Additional subdirectory add to save-path.')
34
+ parser.add_argument('--max-depth', type=int, help='Number of subdirectories to check for files to process.')
35
+ parser.add_argument('--overwrite', action='store_true', help='Overwrite existing files.')
36
+ parser.add_argument('--skip-existing', action='store_true', help='Skip existing files.')
37
+
38
+ return parser
39
+
40
+
41
+ def main():
42
+ """
43
+ The main function that orchestrates the CLI operations.
44
+ """
45
+ print("\n----------- LBM-Suite2p-Pipeline -----------\n")
46
+
47
+ parser = argparse.ArgumentParser(description="LBM-Suite2p-pipeline parameters")
48
+ parser = add_args(parser)
49
+ args = parser.parse_args()
50
+
51
+ if args.version:
52
+ print(f"lbm_suite2p_python v{lsp.__version__}")
53
+ return
54
+
55
+ ops = np.load(args.ops, allow_pickle=True).item() if args.ops else suite2p.default_ops()
56
+
57
+ if not args.data:
58
+ raise ValueError("No input file or directory specified. Use --data")
59
+
60
+ input_path = Path(args.data)
61
+
62
+ # default to data-path / 'results'
63
+ save_path = Path(args.save) if args.save else input_path.parent / "results"
64
+ save_path.mkdir(parents=True, exist_ok=True)
65
+
66
+ # Optional user-defined save folder (e.g., plane_01_runA)
67
+ subdir = Path(args.subdir) if args.subdir else None
68
+
69
+ if input_path.is_file():
70
+ output_ops = lsp.run_plane(
71
+ ops=ops,
72
+ input_tiff=input_path,
73
+ save_path=save_path,
74
+ save_folder=subdir
75
+ )
76
+ elif input_path.is_dir():
77
+ files = mbo.get_files(input_path, "tiff", max_depth=args.max_depth)
78
+ output_ops = lsp.run_volume(
79
+ ops=ops,
80
+ input_file_list=files,
81
+ save_path=save_path,
82
+ save_folder=subdir
83
+ )
84
+ else:
85
+ raise FileNotFoundError(f"Input path does not exist: {input_path}")
86
+
87
+ print("Processing complete -----------")
88
+ return output_ops
89
+
90
+ if __name__ == "__main__":
91
+ main()
@@ -0,0 +1,48 @@
1
+ from suite2p import default_ops as s2p_default_ops
2
+
3
+ def default_ops(metadata=None, ops=None, nplanes=1):
4
+ """
5
+ Returns default ops for Suite2P processing on Light Beads Microscopy datasets.
6
+
7
+ Parameters
8
+ ----------
9
+ metadata : dict, optional
10
+ Metadata dictionary containing information about the dataset.
11
+ ops : dict, str or Path, optional
12
+ Path to or dict of suite2p ops.
13
+ nplanes : int, optional
14
+ Number of z-planes that will be processed by Suite2p, may differ from the number of z-planes in the dataset.
15
+
16
+ Returns
17
+ -------
18
+ dict
19
+ Default ops for Suite2P processing.
20
+
21
+ Examples
22
+ --------
23
+ >>> import lbm_suite2p_python as lsp
24
+ >>> metadata = mbo.get_metadata("D://demo//raw_data//raw_file_00001.tif") # noqa
25
+ >>> ops = lsp.default_ops(metadata=metadata) # noqa
26
+ >>> # No ops are passed, so the default ops are used.
27
+ >>> lsp.run_plane(
28
+ >>> ops=ops,
29
+ >>> input_tiff="D://demo//raw_data//raw_file_00001.tif",
30
+ >>> save_path="D://demo//results",
31
+ >>> save_folder="v1"
32
+ >>> )
33
+ """
34
+ if ops is None:
35
+ ops = s2p_default_ops()
36
+
37
+ # typical neuron ~16 microns
38
+ ops["fs"] = metadata["frame_rate"]
39
+ ops["nplanes"] = 1
40
+ ops["nchannels"] = 1
41
+ ops["do_bidiphase"] = 0
42
+ ops["do_regmetrics"] = True
43
+
44
+ # suite2p iterates each plane and takes ops['dxy'][i] where i is the plane index
45
+ ops["dx"] = [metadata["pixel_resolution"][0]]
46
+ ops["dy"] = [metadata["pixel_resolution"][1]]
47
+
48
+ return ops