pykrait 0.1.0__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.

Potentially problematic release.


This version of pykrait might be problematic. Click here for more details.

@@ -0,0 +1,183 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+
110
+ # pdm
111
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112
+ #pdm.lock
113
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114
+ # in version control.
115
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116
+ .pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121
+ __pypackages__/
122
+
123
+ # Celery stuff
124
+ celerybeat-schedule
125
+ celerybeat.pid
126
+
127
+ # SageMath parsed files
128
+ *.sage.py
129
+
130
+ # Environments
131
+ .env
132
+ .venv
133
+ env/
134
+ venv/
135
+ ENV/
136
+ env.bak/
137
+ venv.bak/
138
+
139
+ # Spyder project settings
140
+ .spyderproject
141
+ .spyproject
142
+
143
+ # Rope project settings
144
+ .ropeproject
145
+
146
+ # mkdocs documentation
147
+ /site
148
+
149
+ # mypy
150
+ .mypy_cache/
151
+ .dmypy.json
152
+ dmypy.json
153
+
154
+ # Pyre type checker
155
+ .pyre/
156
+
157
+ # pytype static type analyzer
158
+ .pytype/
159
+
160
+ # Cython debug symbols
161
+ cython_debug/
162
+
163
+ # PyCharm
164
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
167
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
168
+ #.idea/
169
+
170
+ # Ruff stuff:
171
+ .ruff_cache/
172
+
173
+ # PyPI configuration file
174
+ .pypirc
175
+ .venv/
176
+ __pycache__/
177
+ *.pyc
178
+ .DS_Store
179
+ uv.lock
180
+
181
+ /cellpose_models/
182
+ notebooks/developing.ipynb
183
+ notebooks/benchmark_adjacency_matrix.ipynb
pykrait-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Pentabyteman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
pykrait-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,56 @@
1
+ Metadata-Version: 2.4
2
+ Name: pykrait
3
+ Version: 0.1.0
4
+ Summary: Python Calcium Recording Analysis and Inference Toolbox
5
+ Author-email: Pentabyteman <22663502+Pentabyteman@users.noreply.github.com>
6
+ License: MIT
7
+ License-File: LICENSE
8
+ Requires-Python: >=3.10
9
+ Requires-Dist: aicspylibczi>=3.1.1
10
+ Requires-Dist: cellpose>=4.0.5
11
+ Requires-Dist: dask>=2025.5.1
12
+ Requires-Dist: fsspec>=2022.8.0
13
+ Requires-Dist: imagecodecs>=2025.3.30
14
+ Requires-Dist: lxml>=5.4.0
15
+ Requires-Dist: matplotlib>=3.10.3
16
+ Requires-Dist: numpy<2
17
+ Requires-Dist: ome-types>=0.5.3
18
+ Requires-Dist: ome-zarr>=0.10.2
19
+ Requires-Dist: pip>=25.1.1
20
+ Requires-Dist: pydantic<2
21
+ Requires-Dist: pyyaml>=6.0.2
22
+ Requires-Dist: resource-backed-dask-array>=0.1.0
23
+ Requires-Dist: scikit-image>=0.25.2
24
+ Requires-Dist: scipy>=1.15.3
25
+ Requires-Dist: tifffile<2023.3.15,>=2021.8.30
26
+ Requires-Dist: wrapt>=1.17.2
27
+ Requires-Dist: xarray>2025
28
+ Requires-Dist: xmlschema>=4.0.1
29
+ Requires-Dist: zarr<2.16.0,>=2.6
30
+ Description-Content-Type: text/markdown
31
+
32
+ # pyKrait - Python Calcium Recording Analysis and Inference Toolbox
33
+
34
+ ![Logo](docs/logo.png)
35
+
36
+ ## Overview
37
+
38
+ **pyKrait** is a Python package designed to facilitate automated analysis of calcium imaging data.
39
+
40
+ ## Installation
41
+
42
+ ```bash
43
+ pip install pykrait
44
+ ```
45
+
46
+ ## Documentation
47
+
48
+ See the [docs](docs/) folder for detailed guides and API reference.
49
+
50
+ ## License
51
+
52
+ This project is licensed under the GNU Lesser General Public License (GLP). See the [LICENSE](LICENSE) file for details.
53
+
54
+ ## Contributing
55
+
56
+ Contributions are welcome! Please open issues or submit pull requests.
@@ -0,0 +1,25 @@
1
+ # pyKrait - Python Calcium Recording Analysis and Inference Toolbox
2
+
3
+ ![Logo](docs/logo.png)
4
+
5
+ ## Overview
6
+
7
+ **pyKrait** is a Python package designed to facilitate automated analysis of calcium imaging data.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ pip install pykrait
13
+ ```
14
+
15
+ ## Documentation
16
+
17
+ See the [docs](docs/) folder for detailed guides and API reference.
18
+
19
+ ## License
20
+
21
+ This project is licensed under the GNU Lesser General Public License (GLP). See the [LICENSE](LICENSE) file for details.
22
+
23
+ ## Contributing
24
+
25
+ Contributions are welcome! Please open issues or submit pull requests.
@@ -0,0 +1,71 @@
1
+ [project]
2
+ name = "pykrait"
3
+ version = "0.1.0"
4
+ description = "Python Calcium Recording Analysis and Inference Toolbox"
5
+ readme = { file = "README.md", content-type = "text/markdown" }
6
+ license = { text = "MIT" }
7
+ authors = [
8
+ { name = "Pentabyteman", email = "22663502+Pentabyteman@users.noreply.github.com" }
9
+ ]
10
+ requires-python = ">=3.10"
11
+ dependencies = [
12
+ "aicspylibczi>=3.1.1",
13
+ "cellpose>=4.0.5",
14
+ "dask>=2025.5.1",
15
+ "fsspec>=2022.8.0",
16
+ "imagecodecs>=2025.3.30",
17
+ "lxml>=5.4.0",
18
+ "matplotlib>=3.10.3",
19
+ "numpy<2",
20
+ "ome-types>=0.5.3",
21
+ "ome-zarr>=0.10.2",
22
+ "pip>=25.1.1",
23
+ "pydantic<2",
24
+ "pyyaml>=6.0.2",
25
+ "resource-backed-dask-array>=0.1.0",
26
+ "scikit-image>=0.25.2",
27
+ "scipy>=1.15.3",
28
+ "tifffile>=2021.8.30,<2023.3.15",
29
+ "wrapt>=1.17.2",
30
+ "xarray>2025",
31
+ "xmlschema>=4.0.1",
32
+ "zarr>=2.6,<2.16.0",
33
+ ]
34
+
35
+ [build-system]
36
+ requires = ["hatchling"]
37
+ build-backend = "hatchling.build"
38
+
39
+ [tool.hatch.build.targets.sdist]
40
+ include = ["src/**", "pyproject.toml", "README.md"]
41
+
42
+ [tool.hatch.build.targets.wheel]
43
+ only-include = ["src"]
44
+
45
+ [tool.hatch.metadata]
46
+ allow-direct-references = true
47
+
48
+ [tool.pytest.ini_options]
49
+ pythonpath = ["src"]
50
+ testpaths = ["tests"]
51
+
52
+ [tool.coverage.run]
53
+ source = ["stavromueller_beta"]
54
+
55
+ [tool.coverage.report]
56
+ show_missing = true
57
+ skip_covered = true
58
+
59
+ [dependency-groups]
60
+ dev = [
61
+ "build>=1.2.2.post1",
62
+ "hatch>=1.14.1",
63
+ "ipywidgets>=8.1.7",
64
+ "pydata-sphinx-theme>=0.16.1",
65
+ "ruff>=0.11.13",
66
+ "sphinx>=8.1.3",
67
+ "sphinx-autoapi>=3.6.0",
68
+ "sphinx-favicon>=1.0.1",
69
+ "tomli>=2.2.1",
70
+ "twine>=6.1.0",
71
+ ]
@@ -0,0 +1 @@
1
+
File without changes
@@ -0,0 +1,117 @@
1
+ import os
2
+ import xml.etree.ElementTree as ET
3
+ import dask.array as da
4
+ import warnings
5
+ import re
6
+ from aicsimageio import AICSImage
7
+
8
+ ALLOWED_IMAGE_EXTENSIONS =[".czi", ".tif", ".tiff"]
9
+
10
+ def load_timelapse_lazy(
11
+ file_path: str,
12
+ ) -> list[da.Array, float, float, float]:
13
+ """Load a timelapse image file lazily using AICSImageIO, returning a Dask array of the image data along with the frame interval and pixel sizes.
14
+
15
+ Currently supports CZI and TIF/TIFF files. The image data is returned as a Dask array with shape (T, C, Y, X) where T is time, C is channels, Y is height, and X is width. The Z dimension is dropped if it has only one slice.
16
+
17
+ :param file_path: input file path to the timelapse image file
18
+ :type file_path: str
19
+ :raises TypeError: if filepath is not a string
20
+ :raises FileNotFoundError: if the file does not exist
21
+ :raises ValueError: if the extension is not supported
22
+ :raises ValueError: if the image does not have the expected 5D shape (TCZYX)
23
+ :raises ValueError: if the image has more than one Z slice and Z cannot be automatically dropped
24
+ :return: returns a list of a Dask array containing the image data, the frame interval in seconds, and pixel sizes in micrometers (Y, X)
25
+ :rtype: list[da.Array, float, float, float]
26
+ """
27
+ if not isinstance(file_path, str):
28
+ raise TypeError("file_path must be a string")
29
+
30
+ if not os.path.exists(file_path):
31
+ raise FileNotFoundError(f"File not found: {file_path}")
32
+
33
+ ext = os.path.splitext(file_path)[-1].lower()
34
+ if ext not in ALLOWED_IMAGE_EXTENSIONS:
35
+ raise ValueError(f"Image to load has the unsupported file format '{ext}'. Supported file formats are: {ALLOWED_IMAGE_EXTENSIONS}")
36
+
37
+ # Load with AICSImage using Dask
38
+ img = AICSImage(file_path, reconstruct_mosaic=False)
39
+
40
+ # extract the relevant metadata
41
+ pixel_sizes = img.physical_pixel_sizes # Units are in micrometers (µm)
42
+ y_um = round(pixel_sizes.Y, 2) if pixel_sizes else None
43
+ x_um = round(pixel_sizes.X, 2) if pixel_sizes else None
44
+
45
+ frame_interval = None
46
+
47
+ # accessing frame interval from tif/tiff meadata
48
+ if ext == ".tiff" or ext == ".tif":
49
+ try:
50
+ match = re.search(r"finterval=([0-9.]+)", img.metadata)
51
+ raw_finterval = float(match.group(1))
52
+ frame_interval = round(raw_finterval, 2) # Output: 1.26
53
+ except Exception as e:
54
+ warnings.warn(
55
+ f"Failed to extract frame interval from TIFF/TIF metadata: {type(e).__name__}: {e}",
56
+ UserWarning
57
+ )
58
+
59
+ # accessing frame interval from czi metadata
60
+ elif ext == ".czi":
61
+ try:
62
+ frame_time_elem = img.metadata.findall(".//FrameTime")
63
+ # select the last FrameTime element if there are multiple and round to 2 decimal places
64
+ frame_interval = round(float(frame_time_elem[-1].text), 2)
65
+ except Exception as e:
66
+ warnings.warn(
67
+ f"Failed to extract frame interval from CZI metadata: {type(e).__name__}: {e}",
68
+ UserWarning
69
+ )
70
+
71
+ # trying to extract frame interval from OME-XML metadata
72
+ else:
73
+ try:
74
+ root = ET.fromstring(img.ome_metadata)
75
+ namespace = {'ome': 'http://www.openmicroscopy.org/Schemas/OME/2016-06'}
76
+ pixels_elem = root.find('.//ome:Pixels', namespaces=namespace)
77
+ if pixels_elem is not None and 'TimeIncrement' in pixels_elem.attrib:
78
+ frame_interval = float(pixels_elem.attrib['TimeIncrement'])
79
+ except Exception as e:
80
+ warnings.warn(
81
+ f"Failed to extract frame interval from OME-XML: {type(e).__name__}: {e}",
82
+ UserWarning
83
+ )
84
+
85
+ dask_img = img.dask_data # TCZYX
86
+
87
+ if dask_img.ndim != 5:
88
+ raise ValueError(f"Expected 5D image (TCZYX), but got shape {dask_img.shape}")
89
+
90
+ T, C, Z, Y, X = dask_img.shape
91
+
92
+ if Z == 1:
93
+ dask_img = dask_img[:, :, 0, :, :] # shape: (T, C, Z, Y, X)
94
+ else:
95
+ raise ValueError(f"Cannot drop Z dimension automatically: Z={Z}. Consider handling it explicitly.")
96
+
97
+ print(f"Returning lazy array of shape {dask_img.shape} (T, C, Y, X)")
98
+ return dask_img, frame_interval, y_um, x_um
99
+
100
+ def get_files_from_folder(
101
+ folder: str,
102
+ extension: str = ".czi",
103
+ ) -> list[str]:
104
+ """returns all files from a folder with specified extensions.
105
+
106
+ :param folder: path to the folder
107
+ :type folder: str
108
+ :param extensions: str of file extension (default is ".czi")
109
+ :type extensions: str
110
+ :return: list of file paths with the specified extensions
111
+ :rtype: list[str]
112
+ """
113
+ if not os.path.isdir(folder):
114
+ raise NotADirectoryError(f"Provided path is not a directory: {folder}")
115
+
116
+ files = [os.path.join(folder, f) for f in os.listdir(folder) if os.path.isfile(os.path.join(folder, f)) and os.path.splitext(f)[-1].lower() == extension]
117
+ return files