spatialproteomics 0.4.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.
- spatialproteomics-0.4.0/LICENSE +21 -0
- spatialproteomics-0.4.0/PKG-INFO +22 -0
- spatialproteomics-0.4.0/pyproject.toml +40 -0
- spatialproteomics-0.4.0/setup.py +47 -0
- spatialproteomics-0.4.0/spatialproteomics/__init__.py +95 -0
- spatialproteomics-0.4.0/spatialproteomics/base_logger.py +4 -0
- spatialproteomics-0.4.0/spatialproteomics/constants.py +178 -0
- spatialproteomics-0.4.0/spatialproteomics/container.py +71 -0
- spatialproteomics-0.4.0/spatialproteomics/ext/__init__.py +5 -0
- spatialproteomics-0.4.0/spatialproteomics/ext/external.py +445 -0
- spatialproteomics-0.4.0/spatialproteomics/la/__init__.py +5 -0
- spatialproteomics-0.4.0/spatialproteomics/la/label.py +626 -0
- spatialproteomics-0.4.0/spatialproteomics/la/utils.py +16 -0
- spatialproteomics-0.4.0/spatialproteomics/pl/__init__.py +10 -0
- spatialproteomics-0.4.0/spatialproteomics/pl/plot.py +1030 -0
- spatialproteomics-0.4.0/spatialproteomics/pl/spectra.py +192 -0
- spatialproteomics-0.4.0/spatialproteomics/pl/utils.py +127 -0
- spatialproteomics-0.4.0/spatialproteomics/pp/__init__.py +25 -0
- spatialproteomics-0.4.0/spatialproteomics/pp/intensity.py +201 -0
- spatialproteomics-0.4.0/spatialproteomics/pp/preprocessing.py +1062 -0
- spatialproteomics-0.4.0/spatialproteomics/pp/utils.py +261 -0
- spatialproteomics-0.4.0/spatialproteomics/tl/__init__.py +5 -0
- spatialproteomics-0.4.0/spatialproteomics/tl/gaussian.py +181 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Harald Vöhringer, Matthias Meyer-Bender
|
|
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.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: spatialproteomics
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary:
|
|
5
|
+
Author: Harald Vohringer
|
|
6
|
+
Requires-Python: >=3.8,<4.0
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Provides-Extra: docs
|
|
13
|
+
Requires-Dist: Sphinx (==4.2.0) ; extra == "docs"
|
|
14
|
+
Requires-Dist: matplotlib (>=3.5.3,<4.0.0)
|
|
15
|
+
Requires-Dist: nbsphinx (==0.8.9) ; extra == "docs"
|
|
16
|
+
Requires-Dist: scikit-image (>=0.19.3,<0.20.0)
|
|
17
|
+
Requires-Dist: scikit-learn (>=1.2.2,<2.0.0)
|
|
18
|
+
Requires-Dist: sphinx-rtd-theme (==1.0.0) ; extra == "docs"
|
|
19
|
+
Requires-Dist: sphinxcontrib-napoleon (==0.7) ; extra == "docs"
|
|
20
|
+
Requires-Dist: tqdm (>=4.64.0,<5.0.0)
|
|
21
|
+
Requires-Dist: xarray (>=2022.6.0,<2023.0.0)
|
|
22
|
+
Requires-Dist: zarr (>=2.14.2,<3.0.0)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "spatialproteomics"
|
|
3
|
+
packages = [
|
|
4
|
+
{ include = "spatialproteomics" },
|
|
5
|
+
]
|
|
6
|
+
version = "0.4.0"
|
|
7
|
+
description = ""
|
|
8
|
+
authors = ["Harald Vohringer", "Matthias Meyer-Bender"]
|
|
9
|
+
|
|
10
|
+
[tool.poetry.dependencies]
|
|
11
|
+
python = ">=3.8,<4.0"
|
|
12
|
+
xarray = "^2022.6.0"
|
|
13
|
+
scikit-image = "^0.19.3"
|
|
14
|
+
matplotlib = "^3.5.3"
|
|
15
|
+
Sphinx = { version = "4.2.0", optional = true }
|
|
16
|
+
sphinx-rtd-theme = { version = "1.0.0", optional = true }
|
|
17
|
+
sphinxcontrib-napoleon = { version = "0.7", optional = true }
|
|
18
|
+
nbsphinx = { version = "0.8.9", optional = true }
|
|
19
|
+
tqdm = "^4.64.0"
|
|
20
|
+
scikit-learn = "^1.2.2"
|
|
21
|
+
zarr = "^2.14.2"
|
|
22
|
+
|
|
23
|
+
[tool.poetry.dev-dependencies]
|
|
24
|
+
pytest = "^7.1.2"
|
|
25
|
+
pytest-cov = "^3.0.0"
|
|
26
|
+
black = "^22.6.0"
|
|
27
|
+
isort = "^5.10.1"
|
|
28
|
+
flake8 = "^5.0.4"
|
|
29
|
+
bandit = "^1.7.4"
|
|
30
|
+
safety = "^2.1.1"
|
|
31
|
+
|
|
32
|
+
[tool.poetry.extras]
|
|
33
|
+
docs = ["Sphinx", "sphinx-rtd-theme", "sphinxcontrib-napoleon", "nbsphinx"]
|
|
34
|
+
|
|
35
|
+
[build-system]
|
|
36
|
+
requires = ["poetry-core>=1.0.0"]
|
|
37
|
+
build-backend = "poetry.core.masonry.api"
|
|
38
|
+
|
|
39
|
+
[tool.black]
|
|
40
|
+
line-length = 120
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from setuptools import setup
|
|
3
|
+
|
|
4
|
+
packages = \
|
|
5
|
+
['spatialproteomics',
|
|
6
|
+
'spatialproteomics.ext',
|
|
7
|
+
'spatialproteomics.la',
|
|
8
|
+
'spatialproteomics.pl',
|
|
9
|
+
'spatialproteomics.pp',
|
|
10
|
+
'spatialproteomics.tl']
|
|
11
|
+
|
|
12
|
+
package_data = \
|
|
13
|
+
{'': ['*']}
|
|
14
|
+
|
|
15
|
+
install_requires = \
|
|
16
|
+
['matplotlib>=3.5.3,<4.0.0',
|
|
17
|
+
'scikit-image>=0.19.3,<0.20.0',
|
|
18
|
+
'scikit-learn>=1.2.2,<2.0.0',
|
|
19
|
+
'tqdm>=4.64.0,<5.0.0',
|
|
20
|
+
'xarray>=2022.6.0,<2023.0.0',
|
|
21
|
+
'zarr>=2.14.2,<3.0.0']
|
|
22
|
+
|
|
23
|
+
extras_require = \
|
|
24
|
+
{'docs': ['Sphinx==4.2.0',
|
|
25
|
+
'sphinx-rtd-theme==1.0.0',
|
|
26
|
+
'sphinxcontrib-napoleon==0.7',
|
|
27
|
+
'nbsphinx==0.8.9']}
|
|
28
|
+
|
|
29
|
+
setup_kwargs = {
|
|
30
|
+
'name': 'spatialproteomics',
|
|
31
|
+
'version': '0.4.0',
|
|
32
|
+
'description': '',
|
|
33
|
+
'long_description': 'None',
|
|
34
|
+
'author': 'Harald Vohringer',
|
|
35
|
+
'author_email': 'None',
|
|
36
|
+
'maintainer': 'None',
|
|
37
|
+
'maintainer_email': 'None',
|
|
38
|
+
'url': 'None',
|
|
39
|
+
'packages': packages,
|
|
40
|
+
'package_data': package_data,
|
|
41
|
+
'install_requires': install_requires,
|
|
42
|
+
'extras_require': extras_require,
|
|
43
|
+
'python_requires': '>=3.8,<4.0',
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
setup(**setup_kwargs)
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
from .constants import (
|
|
2
|
+
Apricot,
|
|
3
|
+
Beige,
|
|
4
|
+
Black,
|
|
5
|
+
Blue,
|
|
6
|
+
Brown,
|
|
7
|
+
Cyan,
|
|
8
|
+
Dims,
|
|
9
|
+
Features,
|
|
10
|
+
Green,
|
|
11
|
+
Grey,
|
|
12
|
+
Lavender,
|
|
13
|
+
Layers,
|
|
14
|
+
Lime,
|
|
15
|
+
Magenta,
|
|
16
|
+
Maroon,
|
|
17
|
+
Mint,
|
|
18
|
+
Navy,
|
|
19
|
+
Olive,
|
|
20
|
+
Orange,
|
|
21
|
+
Pink,
|
|
22
|
+
Props,
|
|
23
|
+
Purple,
|
|
24
|
+
Red,
|
|
25
|
+
Teal,
|
|
26
|
+
White,
|
|
27
|
+
Yellow,
|
|
28
|
+
)
|
|
29
|
+
from .container import load_image_data
|
|
30
|
+
from .ext import ExternalAccessor
|
|
31
|
+
from .la import LabelAccessor
|
|
32
|
+
from .pl import PlotAccessor
|
|
33
|
+
from .pp import (
|
|
34
|
+
PreprocessingAccessor,
|
|
35
|
+
arcsinh_mean_intensity,
|
|
36
|
+
arcsinh_median_intensity,
|
|
37
|
+
arcsinh_sum_intensity,
|
|
38
|
+
arcsinh_var_intensity,
|
|
39
|
+
detect_peaks_num,
|
|
40
|
+
is_positive,
|
|
41
|
+
mean_intensity,
|
|
42
|
+
percentage_positive,
|
|
43
|
+
sum_intensity,
|
|
44
|
+
)
|
|
45
|
+
from .tl import TwoComponentGaussianMixture
|
|
46
|
+
|
|
47
|
+
__all__ = [
|
|
48
|
+
"load_image_data",
|
|
49
|
+
"PreprocessingAccessor",
|
|
50
|
+
"LabelAccessor",
|
|
51
|
+
"PlotAccessor",
|
|
52
|
+
"SegmentationAccessor",
|
|
53
|
+
"ExternalAccessor",
|
|
54
|
+
"Layers",
|
|
55
|
+
"Dims",
|
|
56
|
+
"Features",
|
|
57
|
+
"Props",
|
|
58
|
+
"sum_intensity",
|
|
59
|
+
"mean_intensity",
|
|
60
|
+
"arcsinh_sum_intensity",
|
|
61
|
+
"arcsinh_mean_intensity",
|
|
62
|
+
"arcsinh_var_intensity",
|
|
63
|
+
"arcsinh_median_intensity",
|
|
64
|
+
"merge_segmentation",
|
|
65
|
+
"detect_peaks_num",
|
|
66
|
+
"percentage_positive",
|
|
67
|
+
"is_positive",
|
|
68
|
+
"TwoComponentGaussianMixture",
|
|
69
|
+
"Apricot",
|
|
70
|
+
"Beige",
|
|
71
|
+
"Black",
|
|
72
|
+
"Blue",
|
|
73
|
+
"Brown",
|
|
74
|
+
"Cyan",
|
|
75
|
+
"Dims",
|
|
76
|
+
"Features",
|
|
77
|
+
"Green",
|
|
78
|
+
"Grey",
|
|
79
|
+
"Lavender",
|
|
80
|
+
"Layers",
|
|
81
|
+
"Lime",
|
|
82
|
+
"Magenta",
|
|
83
|
+
"Maroon",
|
|
84
|
+
"Mint",
|
|
85
|
+
"Navy",
|
|
86
|
+
"Olive",
|
|
87
|
+
"Orange",
|
|
88
|
+
"Pink",
|
|
89
|
+
"Props",
|
|
90
|
+
"Purple",
|
|
91
|
+
"Red",
|
|
92
|
+
"Teal",
|
|
93
|
+
"White",
|
|
94
|
+
"Yellow",
|
|
95
|
+
]
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
Red = "#e6194B"
|
|
2
|
+
Green = "#3cb44b"
|
|
3
|
+
Yellow = "#ffe119"
|
|
4
|
+
Blue = "#4363d8"
|
|
5
|
+
Orange = "#f58231"
|
|
6
|
+
Purple = "#911eb4"
|
|
7
|
+
Cyan = "#42d4f4"
|
|
8
|
+
Magenta = "#f032e6"
|
|
9
|
+
Lime = "#bfef45"
|
|
10
|
+
Pink = "#fabed4"
|
|
11
|
+
Teal = "#469990"
|
|
12
|
+
Lavender = "#dcbeff"
|
|
13
|
+
Brown = "#9A6324"
|
|
14
|
+
Beige = "#fffac8"
|
|
15
|
+
Maroon = "#800000"
|
|
16
|
+
Mint = "#aaffc3"
|
|
17
|
+
Olive = "#808000"
|
|
18
|
+
Apricot = "#ffd8b1"
|
|
19
|
+
Navy = "#000075"
|
|
20
|
+
Grey = "#a9a9a9"
|
|
21
|
+
White = "#ffffff"
|
|
22
|
+
Black = "#000000"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class Layers(object):
|
|
26
|
+
IMAGE = "_image"
|
|
27
|
+
SEGMENTATION = "_segmentation"
|
|
28
|
+
COORDINATES = "_coordinates"
|
|
29
|
+
LABELS = "_labels"
|
|
30
|
+
DATA = "_data"
|
|
31
|
+
PLOT = "_plot"
|
|
32
|
+
OBS = "_obs"
|
|
33
|
+
NEIGHBORS = "_neighbors"
|
|
34
|
+
INTENSITY = "_intensity"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class Dims(object):
|
|
38
|
+
CHANNELS = "channels"
|
|
39
|
+
X = "x"
|
|
40
|
+
Y = "y"
|
|
41
|
+
RGBA = "rgba"
|
|
42
|
+
CELLS = "cells"
|
|
43
|
+
COORDINATES = "coordinates"
|
|
44
|
+
LABELS = "labels"
|
|
45
|
+
FEATURES = "features"
|
|
46
|
+
PROPS = "props"
|
|
47
|
+
NEIGHBORS = "neighbors"
|
|
48
|
+
IMAGE = ["channels", "x", "y"]
|
|
49
|
+
COLORED_IMAGE = ["channels", "x", "y", "rgba"]
|
|
50
|
+
SEGMENTATION = ["x", "y"]
|
|
51
|
+
DATA = ["cell_idx", "channels"]
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class Attrs(object):
|
|
55
|
+
IMAGE_COLORS = "image_colors"
|
|
56
|
+
LABEL_COLORS = "label_colors"
|
|
57
|
+
LABEL_NAMES = "label_names"
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class Props(object):
|
|
61
|
+
COLOR = "_color"
|
|
62
|
+
NAME = "_name"
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class Features(object):
|
|
66
|
+
LABELS = "_labels"
|
|
67
|
+
X = "centroid-1"
|
|
68
|
+
Y = "centroid-0"
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class Labels(object):
|
|
72
|
+
UNLABELED = "Unlabeled"
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
COLORS = [
|
|
76
|
+
"#FFFF00",
|
|
77
|
+
"#1CE6FF",
|
|
78
|
+
"#FF34FF",
|
|
79
|
+
"#FF4A46",
|
|
80
|
+
"#008941",
|
|
81
|
+
"#006FA6",
|
|
82
|
+
"#A30059",
|
|
83
|
+
"#FFDBE5",
|
|
84
|
+
"#7A4900",
|
|
85
|
+
"#0000A6",
|
|
86
|
+
"#63FFAC",
|
|
87
|
+
"#B79762",
|
|
88
|
+
"#004D43",
|
|
89
|
+
"#8FB0FF",
|
|
90
|
+
"#997D87",
|
|
91
|
+
"#5A0007",
|
|
92
|
+
"#809693",
|
|
93
|
+
"#6A3A4C",
|
|
94
|
+
"#1B4400",
|
|
95
|
+
"#4FC601",
|
|
96
|
+
"#3B5DFF",
|
|
97
|
+
"#4A3B53",
|
|
98
|
+
"#FF2F80",
|
|
99
|
+
"#61615A",
|
|
100
|
+
"#BA0900",
|
|
101
|
+
"#6B7900",
|
|
102
|
+
"#00C2A0",
|
|
103
|
+
"#FFAA92",
|
|
104
|
+
"#FF90C9",
|
|
105
|
+
"#B903AA",
|
|
106
|
+
"#D16100",
|
|
107
|
+
"#DDEFFF",
|
|
108
|
+
"#000035",
|
|
109
|
+
"#7B4F4B",
|
|
110
|
+
"#A1C299",
|
|
111
|
+
"#0AA6D8",
|
|
112
|
+
"#013349",
|
|
113
|
+
"#00846F",
|
|
114
|
+
"#372101",
|
|
115
|
+
"#FFB500",
|
|
116
|
+
"#C2FFED",
|
|
117
|
+
"#A079BF",
|
|
118
|
+
"#CC0744",
|
|
119
|
+
"#C0B9B2",
|
|
120
|
+
"#C2FF99",
|
|
121
|
+
"#00489C",
|
|
122
|
+
"#6F0062",
|
|
123
|
+
"#0CBD66",
|
|
124
|
+
"#EEC3FF",
|
|
125
|
+
"#456D75",
|
|
126
|
+
"#B77B68",
|
|
127
|
+
"#7A87A1",
|
|
128
|
+
"#788D66",
|
|
129
|
+
"#885578",
|
|
130
|
+
"#FAD09F",
|
|
131
|
+
"#FF8A9A",
|
|
132
|
+
"#D157A0",
|
|
133
|
+
"#BEC459",
|
|
134
|
+
"#456648",
|
|
135
|
+
"#0086ED",
|
|
136
|
+
"#886F4C",
|
|
137
|
+
"#34362D",
|
|
138
|
+
"#B4A8BD",
|
|
139
|
+
"#00A6AA",
|
|
140
|
+
"#452C2C",
|
|
141
|
+
"#636375",
|
|
142
|
+
"#A3C8C9",
|
|
143
|
+
"#FF913F",
|
|
144
|
+
"#938A81",
|
|
145
|
+
"#575329",
|
|
146
|
+
"#00FECF",
|
|
147
|
+
"#B05B6F",
|
|
148
|
+
"#8CD0FF",
|
|
149
|
+
"#3B9700",
|
|
150
|
+
"#04F757",
|
|
151
|
+
"#C8A1A1",
|
|
152
|
+
"#1E6E00",
|
|
153
|
+
"#7900D7",
|
|
154
|
+
"#A77500",
|
|
155
|
+
"#6367A9",
|
|
156
|
+
"#A05837",
|
|
157
|
+
"#6B002C",
|
|
158
|
+
"#772600",
|
|
159
|
+
"#D790FF",
|
|
160
|
+
"#9B9700",
|
|
161
|
+
"#549E79",
|
|
162
|
+
"#FFF69F",
|
|
163
|
+
"#72418F",
|
|
164
|
+
"#BC23FF",
|
|
165
|
+
"#99ADC0",
|
|
166
|
+
"#3A2465",
|
|
167
|
+
"#922329",
|
|
168
|
+
"#5B4534",
|
|
169
|
+
"#FDE8DC",
|
|
170
|
+
"#404E55",
|
|
171
|
+
"#0089A3",
|
|
172
|
+
"#CB7E98",
|
|
173
|
+
"#A4E804",
|
|
174
|
+
"#324E72",
|
|
175
|
+
]
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
PROPS_DICT = {"centroid-1": Features.X, "centroid-0": Features.Y}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
from typing import List, Union
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
import pandas as pd
|
|
5
|
+
import xarray as xr
|
|
6
|
+
|
|
7
|
+
from .constants import Dims, Layers
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def load_image_data(
|
|
11
|
+
image: np.ndarray,
|
|
12
|
+
channel_coords: Union[str, List[str]],
|
|
13
|
+
segmentation: Union[None, np.ndarray] = None,
|
|
14
|
+
labels: Union[None, pd.DataFrame] = None,
|
|
15
|
+
cell_col: str = "cell",
|
|
16
|
+
label_col: str = "label",
|
|
17
|
+
copy_segmentation: bool = False,
|
|
18
|
+
copy_image: bool = False,
|
|
19
|
+
):
|
|
20
|
+
"""Creates a image container.
|
|
21
|
+
|
|
22
|
+
Creates an Xarray dataset with images, segmentation, and
|
|
23
|
+
coordinate fields.
|
|
24
|
+
|
|
25
|
+
Parameters
|
|
26
|
+
----------
|
|
27
|
+
image : np.ndarray
|
|
28
|
+
np.ndarray with image.shape = (n, x, y)
|
|
29
|
+
channel_coords: str | List[str]
|
|
30
|
+
list with the names for each channel
|
|
31
|
+
|
|
32
|
+
Returns
|
|
33
|
+
-------
|
|
34
|
+
xr.Dataset
|
|
35
|
+
An X-array dataset with all fields.
|
|
36
|
+
"""
|
|
37
|
+
if copy_image:
|
|
38
|
+
image = image.copy()
|
|
39
|
+
|
|
40
|
+
if type(channel_coords) is str:
|
|
41
|
+
channel_coords = [channel_coords]
|
|
42
|
+
|
|
43
|
+
if image.ndim == 2:
|
|
44
|
+
image = np.expand_dims(image, 0)
|
|
45
|
+
|
|
46
|
+
channel_dim, y_dim, x_dim = image.shape
|
|
47
|
+
|
|
48
|
+
assert len(channel_coords) == channel_dim, "Length of channel_coords must match image.shape[0]."
|
|
49
|
+
|
|
50
|
+
if labels is not None:
|
|
51
|
+
assert segmentation is not None, "Labels may only be provided in conjunction with a segmentation."
|
|
52
|
+
|
|
53
|
+
im = xr.DataArray(
|
|
54
|
+
image,
|
|
55
|
+
coords=[channel_coords, range(y_dim), range(x_dim)],
|
|
56
|
+
dims=[Dims.CHANNELS, Dims.Y, Dims.X],
|
|
57
|
+
name=Layers.IMAGE,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
dataset = xr.Dataset(data_vars={Layers.IMAGE: im})
|
|
61
|
+
|
|
62
|
+
if segmentation is not None:
|
|
63
|
+
dataset = dataset.pp.add_segmentation(segmentation, copy=copy_segmentation)
|
|
64
|
+
|
|
65
|
+
if labels is not None:
|
|
66
|
+
dataset = dataset.pp.add_labels(labels, cell_col=cell_col, label_col=label_col)
|
|
67
|
+
|
|
68
|
+
else:
|
|
69
|
+
dataset = xr.Dataset(data_vars={Layers.IMAGE: im})
|
|
70
|
+
|
|
71
|
+
return dataset
|