dummy-spatialdata 0.1.8__tar.gz → 0.1.10__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.
- dummy_spatialdata-0.1.10/PKG-INFO +134 -0
- dummy_spatialdata-0.1.10/README.md +110 -0
- {dummy_spatialdata-0.1.8 → dummy_spatialdata-0.1.10}/pyproject.toml +1 -1
- dummy_spatialdata-0.1.10/src/dummy_spatialdata/.gitignore +1 -0
- {dummy_spatialdata-0.1.8 → dummy_spatialdata-0.1.10}/src/dummy_spatialdata/__init__.py +3 -2
- {dummy_spatialdata-0.1.8 → dummy_spatialdata-0.1.10}/src/dummy_spatialdata/generate_dataset.py +9 -1
- {dummy_spatialdata-0.1.8 → dummy_spatialdata-0.1.10}/src/dummy_spatialdata/generate_imagemodel.py +30 -19
- {dummy_spatialdata-0.1.8 → dummy_spatialdata-0.1.10}/src/dummy_spatialdata/generate_labelmodel.py +29 -19
- {dummy_spatialdata-0.1.8 → dummy_spatialdata-0.1.10}/src/dummy_spatialdata/generate_pointmodel.py +9 -8
- {dummy_spatialdata-0.1.8 → dummy_spatialdata-0.1.10}/src/dummy_spatialdata/generate_shapemodel.py +29 -9
- {dummy_spatialdata-0.1.8 → dummy_spatialdata-0.1.10}/src/dummy_spatialdata/generate_tablemodel.py +12 -1
- {dummy_spatialdata-0.1.8 → dummy_spatialdata-0.1.10}/src/dummy_spatialdata/generate_transformations.py +2 -2
- dummy_spatialdata-0.1.10/tests/.gitignore +1 -0
- {dummy_spatialdata-0.1.8 → dummy_spatialdata-0.1.10}/tests/test_basic.py +2 -1
- {dummy_spatialdata-0.1.8 → dummy_spatialdata-0.1.10}/tests/test_models.py +23 -15
- dummy_spatialdata-0.1.8/PKG-INFO +0 -114
- dummy_spatialdata-0.1.8/README.md +0 -90
- {dummy_spatialdata-0.1.8 → dummy_spatialdata-0.1.10}/.gitignore +0 -0
- {dummy_spatialdata-0.1.8 → dummy_spatialdata-0.1.10}/examples/bird-color.png +0 -0
- {dummy_spatialdata-0.1.8 → dummy_spatialdata-0.1.10}/examples/bird.png +0 -0
- {dummy_spatialdata-0.1.8 → dummy_spatialdata-0.1.10}/examples/nuclei.tif +0 -0
- {dummy_spatialdata-0.1.8 → dummy_spatialdata-0.1.10}/src/dummy_spatialdata/utils.py +0 -0
- {dummy_spatialdata-0.1.8 → dummy_spatialdata-0.1.10}/tests/__init__.py +0 -0
- {dummy_spatialdata-0.1.8 → dummy_spatialdata-0.1.10}/tests/test_transformations.py +0 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dummy-spatialdata
|
|
3
|
+
Version: 0.1.10
|
|
4
|
+
Summary: A package for creating arbitrary spatialdata for testing purposes.
|
|
5
|
+
Project-URL: Documentation, https://dummy-spatialdata.readthedocs.io/
|
|
6
|
+
Project-URL: Homepage, https://github.com/BIMSBBioinfo/dummy-spatialdata
|
|
7
|
+
Project-URL: Source, https://github.com/BIMSBBioinfo/dummy-spatialdata
|
|
8
|
+
Author-email: Artür Manukyan <amanukyan.umms@gmail.com>
|
|
9
|
+
License: MIT
|
|
10
|
+
Requires-Python: >=3.12
|
|
11
|
+
Requires-Dist: dummy-anndata>=0.0.3
|
|
12
|
+
Requires-Dist: geopandas
|
|
13
|
+
Requires-Dist: pillow
|
|
14
|
+
Requires-Dist: requests
|
|
15
|
+
Requires-Dist: shapely
|
|
16
|
+
Requires-Dist: spatialdata>=0.5.0
|
|
17
|
+
Provides-Extra: dev
|
|
18
|
+
Requires-Dist: pre-commit; extra == 'dev'
|
|
19
|
+
Requires-Dist: twine>=4.0.2; extra == 'dev'
|
|
20
|
+
Provides-Extra: test
|
|
21
|
+
Requires-Dist: coverage; extra == 'test'
|
|
22
|
+
Requires-Dist: pytest; extra == 'test'
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# dummy-spatialdata
|
|
26
|
+
|
|
27
|
+
Allows generating dummy spatialdata objects, which can be useful for testing purposes.
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install dummy-spatialdata
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Example usage
|
|
36
|
+
|
|
37
|
+
`dummy-spatialdata` is compatible with both spatialdata == 0.5.0 (zarr v2) and 0.7.2 (zarr v3)
|
|
38
|
+
|
|
39
|
+
Thus please use
|
|
40
|
+
|
|
41
|
+
1. `conda create --name dummy_sd_env python==3.12 spatialdata==0.7.2` or
|
|
42
|
+
2. `conda create --name dummy_sd_env_05 python==3.12 spatialdata==0.5.0 setuptools==75.8.0`
|
|
43
|
+
|
|
44
|
+
```{python}
|
|
45
|
+
from dummy_spatialdata import generate_dataset
|
|
46
|
+
import dummy_anndata
|
|
47
|
+
import spatialdata_plot as sdp
|
|
48
|
+
import spatialdata as sd
|
|
49
|
+
import matplotlib.pyplot as plt
|
|
50
|
+
import numpy as np
|
|
51
|
+
import pandas as pd
|
|
52
|
+
import anndata as ad
|
|
53
|
+
import tempfile as tf
|
|
54
|
+
|
|
55
|
+
# generate spatialdata
|
|
56
|
+
sdata = generate_dataset(
|
|
57
|
+
images = [
|
|
58
|
+
{'type': 'rgb', 'scale_factors': [2,2,2], 'shape': {'x': 64, 'y': 64},
|
|
59
|
+
'coordinate_system': ['identity', 'scale', 'mapAxis', 'translation', 'rotation', 'affine', 'sequence']},
|
|
60
|
+
],
|
|
61
|
+
labels = [
|
|
62
|
+
{'n': 12, 'scale_factors': [2,2,2], 'shape': {'x': 64, 'y': 64},
|
|
63
|
+
'coordinate_system': ['identity', 'scale', 'mapAxis', 'translation', 'rotation', 'affine', 'sequence']},
|
|
64
|
+
{'n': 12, 'scale_factors': [2,2,2], 'shape': {'x': 64, 'y': 64},
|
|
65
|
+
'coordinate_system': ['identity', 'scale', 'mapAxis', 'translation', 'rotation', 'affine', 'sequence']},
|
|
66
|
+
],
|
|
67
|
+
shapes = [
|
|
68
|
+
{'n': 12, 'type': 'polygon', 'shape': {'x': 64, 'y': 64},
|
|
69
|
+
'coordinate_system': ['identity', 'scale', 'mapAxis', 'translation', 'rotation', 'affine', 'sequence']},
|
|
70
|
+
{'n': 12, 'type': 'circle', 'shape': {'x': 64, 'y': 64},
|
|
71
|
+
'overlapping': False, 'coordinate_system': ['identity', 'scale', 'mapAxis', 'translation', 'rotation', 'affine', 'sequence']}
|
|
72
|
+
],
|
|
73
|
+
points = [
|
|
74
|
+
{'n': 12, 'coordinate_system': ['identity', 'scale', 'mapAxis', 'translation', 'rotation', 'affine', 'sequence']}
|
|
75
|
+
],
|
|
76
|
+
tables = [
|
|
77
|
+
{'table': dummy_anndata.generate_dataset(n_obs=12, n_vars=20), 'element': 'shape', 'element_index': 0},
|
|
78
|
+
{'table': dummy_anndata.generate_dataset(n_obs=12, n_vars=20), 'element': 'shape', 'element_index': 1},
|
|
79
|
+
{'table': dummy_anndata.generate_dataset(n_obs=12, n_vars=20), 'element': 'label', 'element_index': 0},
|
|
80
|
+
{'table': dummy_anndata.generate_dataset(n_obs=12, n_vars=20), 'element': 'label', 'element_index': 1},
|
|
81
|
+
],
|
|
82
|
+
coordinate_systems = {
|
|
83
|
+
'identity': {'transformations': ['identity']},
|
|
84
|
+
'scale': {'transformations': ['scale']},
|
|
85
|
+
'mapAxis': {'transformations': ['mapAxis']},
|
|
86
|
+
'translation': {'transformations': ['translation']},
|
|
87
|
+
'rotation': {'transformations': ['rotation']},
|
|
88
|
+
'affine': {'transformations': ['affine']},
|
|
89
|
+
'sequence': {'transformations': ['scale', 'mapAxis', 'translation', 'rotation', 'affine']}
|
|
90
|
+
},
|
|
91
|
+
SEED=13
|
|
92
|
+
)
|
|
93
|
+
sdata
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
SpatialData object
|
|
98
|
+
├── Images
|
|
99
|
+
│ └── 'image_0': DataTree[cyx] (3, 64, 64), (3, 32, 32), (3, 16, 16), (3, 8, 8)
|
|
100
|
+
├── Labels
|
|
101
|
+
│ ├── 'label_0': DataTree[yx] (64, 64), (32, 32), (16, 16), (8, 8)
|
|
102
|
+
│ └── 'label_1': DataTree[yx] (64, 64), (32, 32), (16, 16), (8, 8)
|
|
103
|
+
├── Points
|
|
104
|
+
│ └── 'point_0': DataFrame with shape: (<Delayed>, 2) (2D points)
|
|
105
|
+
├── Shapes
|
|
106
|
+
│ ├── 'shape_0': GeoDataFrame shape: (12, 1) (2D shapes)
|
|
107
|
+
│ └── 'shape_1': GeoDataFrame shape: (12, 2) (2D shapes)
|
|
108
|
+
└── Tables
|
|
109
|
+
├── 'table_0': AnnData (12, 20)
|
|
110
|
+
├── 'table_1': AnnData (12, 20)
|
|
111
|
+
├── 'table_2': AnnData (12, 20)
|
|
112
|
+
└── 'table_3': AnnData (12, 20)
|
|
113
|
+
with coordinate systems:
|
|
114
|
+
▸ 'affine', with elements:
|
|
115
|
+
image_0 (Images), label_0 (Labels), label_1 (Labels), point_0 (Points), shape_0 (Shapes), shape_1 (Shapes)
|
|
116
|
+
▸ 'identity', with elements:
|
|
117
|
+
image_0 (Images), label_0 (Labels), label_1 (Labels), point_0 (Points), shape_0 (Shapes), shape_1 (Shapes)
|
|
118
|
+
▸ 'mapAxis', with elements:
|
|
119
|
+
image_0 (Images), label_0 (Labels), label_1 (Labels), point_0 (Points), shape_0 (Shapes), shape_1 (Shapes)
|
|
120
|
+
▸ 'rotation', with elements:
|
|
121
|
+
image_0 (Images), label_0 (Labels), label_1 (Labels), point_0 (Points), shape_0 (Shapes), shape_1 (Shapes)
|
|
122
|
+
...
|
|
123
|
+
image_0 (Images), label_0 (Labels), label_1 (Labels), point_0 (Points), shape_0 (Shapes), shape_1 (Shapes)
|
|
124
|
+
▸ 'sequence', with elements:
|
|
125
|
+
image_0 (Images), label_0 (Labels), label_1 (Labels), point_0 (Points), shape_0 (Shapes), shape_1 (Shapes)
|
|
126
|
+
▸ 'translation', with elements:
|
|
127
|
+
image_0 (Images), label_0 (Labels), label_1 (Labels), point_0 (Points), shape_0 (Shapes), shape_1 (Shapes)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
You can plot the demo data now!
|
|
131
|
+
|
|
132
|
+
```{python}
|
|
133
|
+
sdata.pl.render_images('image_0').pl.render_shapes('shape_0', color='Gene001', table_name = 'table_0', table_layer = 'float_matrix').pl.show(coordinate_systems = 'affine')
|
|
134
|
+
```
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# dummy-spatialdata
|
|
2
|
+
|
|
3
|
+
Allows generating dummy spatialdata objects, which can be useful for testing purposes.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install dummy-spatialdata
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Example usage
|
|
12
|
+
|
|
13
|
+
`dummy-spatialdata` is compatible with both spatialdata == 0.5.0 (zarr v2) and 0.7.2 (zarr v3)
|
|
14
|
+
|
|
15
|
+
Thus please use
|
|
16
|
+
|
|
17
|
+
1. `conda create --name dummy_sd_env python==3.12 spatialdata==0.7.2` or
|
|
18
|
+
2. `conda create --name dummy_sd_env_05 python==3.12 spatialdata==0.5.0 setuptools==75.8.0`
|
|
19
|
+
|
|
20
|
+
```{python}
|
|
21
|
+
from dummy_spatialdata import generate_dataset
|
|
22
|
+
import dummy_anndata
|
|
23
|
+
import spatialdata_plot as sdp
|
|
24
|
+
import spatialdata as sd
|
|
25
|
+
import matplotlib.pyplot as plt
|
|
26
|
+
import numpy as np
|
|
27
|
+
import pandas as pd
|
|
28
|
+
import anndata as ad
|
|
29
|
+
import tempfile as tf
|
|
30
|
+
|
|
31
|
+
# generate spatialdata
|
|
32
|
+
sdata = generate_dataset(
|
|
33
|
+
images = [
|
|
34
|
+
{'type': 'rgb', 'scale_factors': [2,2,2], 'shape': {'x': 64, 'y': 64},
|
|
35
|
+
'coordinate_system': ['identity', 'scale', 'mapAxis', 'translation', 'rotation', 'affine', 'sequence']},
|
|
36
|
+
],
|
|
37
|
+
labels = [
|
|
38
|
+
{'n': 12, 'scale_factors': [2,2,2], 'shape': {'x': 64, 'y': 64},
|
|
39
|
+
'coordinate_system': ['identity', 'scale', 'mapAxis', 'translation', 'rotation', 'affine', 'sequence']},
|
|
40
|
+
{'n': 12, 'scale_factors': [2,2,2], 'shape': {'x': 64, 'y': 64},
|
|
41
|
+
'coordinate_system': ['identity', 'scale', 'mapAxis', 'translation', 'rotation', 'affine', 'sequence']},
|
|
42
|
+
],
|
|
43
|
+
shapes = [
|
|
44
|
+
{'n': 12, 'type': 'polygon', 'shape': {'x': 64, 'y': 64},
|
|
45
|
+
'coordinate_system': ['identity', 'scale', 'mapAxis', 'translation', 'rotation', 'affine', 'sequence']},
|
|
46
|
+
{'n': 12, 'type': 'circle', 'shape': {'x': 64, 'y': 64},
|
|
47
|
+
'overlapping': False, 'coordinate_system': ['identity', 'scale', 'mapAxis', 'translation', 'rotation', 'affine', 'sequence']}
|
|
48
|
+
],
|
|
49
|
+
points = [
|
|
50
|
+
{'n': 12, 'coordinate_system': ['identity', 'scale', 'mapAxis', 'translation', 'rotation', 'affine', 'sequence']}
|
|
51
|
+
],
|
|
52
|
+
tables = [
|
|
53
|
+
{'table': dummy_anndata.generate_dataset(n_obs=12, n_vars=20), 'element': 'shape', 'element_index': 0},
|
|
54
|
+
{'table': dummy_anndata.generate_dataset(n_obs=12, n_vars=20), 'element': 'shape', 'element_index': 1},
|
|
55
|
+
{'table': dummy_anndata.generate_dataset(n_obs=12, n_vars=20), 'element': 'label', 'element_index': 0},
|
|
56
|
+
{'table': dummy_anndata.generate_dataset(n_obs=12, n_vars=20), 'element': 'label', 'element_index': 1},
|
|
57
|
+
],
|
|
58
|
+
coordinate_systems = {
|
|
59
|
+
'identity': {'transformations': ['identity']},
|
|
60
|
+
'scale': {'transformations': ['scale']},
|
|
61
|
+
'mapAxis': {'transformations': ['mapAxis']},
|
|
62
|
+
'translation': {'transformations': ['translation']},
|
|
63
|
+
'rotation': {'transformations': ['rotation']},
|
|
64
|
+
'affine': {'transformations': ['affine']},
|
|
65
|
+
'sequence': {'transformations': ['scale', 'mapAxis', 'translation', 'rotation', 'affine']}
|
|
66
|
+
},
|
|
67
|
+
SEED=13
|
|
68
|
+
)
|
|
69
|
+
sdata
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
SpatialData object
|
|
74
|
+
├── Images
|
|
75
|
+
│ └── 'image_0': DataTree[cyx] (3, 64, 64), (3, 32, 32), (3, 16, 16), (3, 8, 8)
|
|
76
|
+
├── Labels
|
|
77
|
+
│ ├── 'label_0': DataTree[yx] (64, 64), (32, 32), (16, 16), (8, 8)
|
|
78
|
+
│ └── 'label_1': DataTree[yx] (64, 64), (32, 32), (16, 16), (8, 8)
|
|
79
|
+
├── Points
|
|
80
|
+
│ └── 'point_0': DataFrame with shape: (<Delayed>, 2) (2D points)
|
|
81
|
+
├── Shapes
|
|
82
|
+
│ ├── 'shape_0': GeoDataFrame shape: (12, 1) (2D shapes)
|
|
83
|
+
│ └── 'shape_1': GeoDataFrame shape: (12, 2) (2D shapes)
|
|
84
|
+
└── Tables
|
|
85
|
+
├── 'table_0': AnnData (12, 20)
|
|
86
|
+
├── 'table_1': AnnData (12, 20)
|
|
87
|
+
├── 'table_2': AnnData (12, 20)
|
|
88
|
+
└── 'table_3': AnnData (12, 20)
|
|
89
|
+
with coordinate systems:
|
|
90
|
+
▸ 'affine', with elements:
|
|
91
|
+
image_0 (Images), label_0 (Labels), label_1 (Labels), point_0 (Points), shape_0 (Shapes), shape_1 (Shapes)
|
|
92
|
+
▸ 'identity', with elements:
|
|
93
|
+
image_0 (Images), label_0 (Labels), label_1 (Labels), point_0 (Points), shape_0 (Shapes), shape_1 (Shapes)
|
|
94
|
+
▸ 'mapAxis', with elements:
|
|
95
|
+
image_0 (Images), label_0 (Labels), label_1 (Labels), point_0 (Points), shape_0 (Shapes), shape_1 (Shapes)
|
|
96
|
+
▸ 'rotation', with elements:
|
|
97
|
+
image_0 (Images), label_0 (Labels), label_1 (Labels), point_0 (Points), shape_0 (Shapes), shape_1 (Shapes)
|
|
98
|
+
...
|
|
99
|
+
image_0 (Images), label_0 (Labels), label_1 (Labels), point_0 (Points), shape_0 (Shapes), shape_1 (Shapes)
|
|
100
|
+
▸ 'sequence', with elements:
|
|
101
|
+
image_0 (Images), label_0 (Labels), label_1 (Labels), point_0 (Points), shape_0 (Shapes), shape_1 (Shapes)
|
|
102
|
+
▸ 'translation', with elements:
|
|
103
|
+
image_0 (Images), label_0 (Labels), label_1 (Labels), point_0 (Points), shape_0 (Shapes), shape_1 (Shapes)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
You can plot the demo data now!
|
|
107
|
+
|
|
108
|
+
```{python}
|
|
109
|
+
sdata.pl.render_images('image_0').pl.render_shapes('shape_0', color='Gene001', table_name = 'table_0', table_layer = 'float_matrix').pl.show(coordinate_systems = 'affine')
|
|
110
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__pycache__
|
|
@@ -5,7 +5,7 @@ from .generate_imagemodel import generate_imagemodel
|
|
|
5
5
|
from .generate_labelmodel import generate_labelmodel
|
|
6
6
|
from .generate_shapemodel import generate_shapemodel
|
|
7
7
|
from .generate_pointmodel import generate_pointmodel
|
|
8
|
-
from .generate_tablemodel import generate_tablemodel
|
|
8
|
+
from .generate_tablemodel import generate_tablemodel, generate_anndata
|
|
9
9
|
from .generate_transformations import (
|
|
10
10
|
generate_transformations,
|
|
11
11
|
get_basetransformations,
|
|
@@ -18,9 +18,10 @@ __all__ = [
|
|
|
18
18
|
"generate_imagemodel",
|
|
19
19
|
"generate_labelmodel",
|
|
20
20
|
"generate_shapemodel",
|
|
21
|
-
"generate_pointmodel"
|
|
21
|
+
"generate_pointmodel",
|
|
22
22
|
"generate_tablemodel",
|
|
23
23
|
"generate_transformations",
|
|
24
|
+
"generate_anndata",
|
|
24
25
|
"utils"
|
|
25
26
|
]
|
|
26
27
|
|
{dummy_spatialdata-0.1.8 → dummy_spatialdata-0.1.10}/src/dummy_spatialdata/generate_dataset.py
RENAMED
|
@@ -14,6 +14,9 @@ from .generate_pointmodel import generate_pointmodel
|
|
|
14
14
|
from .generate_tablemodel import generate_tablemodel
|
|
15
15
|
from .generate_transformations import generate_transformations
|
|
16
16
|
from spatialdata.models import TableModel
|
|
17
|
+
from spatialdata import get_element_instances
|
|
18
|
+
|
|
19
|
+
from pandas import RangeIndex
|
|
17
20
|
|
|
18
21
|
def generate_dataset(
|
|
19
22
|
images: Optional[list] = None,
|
|
@@ -141,6 +144,11 @@ def generate_dataset(
|
|
|
141
144
|
instance_key = tbl.uns['spatialdata_attrs']['instance_key']
|
|
142
145
|
if region in sdata._shared_keys:
|
|
143
146
|
element = getattr(sdata, element_type + 's')[region]
|
|
144
|
-
|
|
147
|
+
if element_type == 'shape':
|
|
148
|
+
tbl.obs['instance_id'] = element.index
|
|
149
|
+
elif element_type == 'label':
|
|
150
|
+
tbl.obs['instance_id'] = get_element_instances(element)
|
|
151
|
+
else:
|
|
152
|
+
raise ValueError(f"Invalid element type {element_type} in region {region}. Must be either 'shape' or 'label'.")
|
|
145
153
|
|
|
146
154
|
return sdata
|
{dummy_spatialdata-0.1.8 → dummy_spatialdata-0.1.10}/src/dummy_spatialdata/generate_imagemodel.py
RENAMED
|
@@ -6,10 +6,11 @@ from pathlib import Path
|
|
|
6
6
|
from importlib.resources import files, as_file
|
|
7
7
|
from PIL import Image
|
|
8
8
|
from typing import Optional
|
|
9
|
-
from spatialdata.models import Image2DModel
|
|
9
|
+
from spatialdata.models import Image2DModel, Image3DModel
|
|
10
10
|
from spatialdata.transformations import set_transformation, Identity
|
|
11
11
|
from .generate_transformations import generate_transformations, get_basetransformations, get_shape
|
|
12
12
|
from .utils import default_shape
|
|
13
|
+
import zarr
|
|
13
14
|
|
|
14
15
|
def generate_imagemodel(
|
|
15
16
|
input: Optional[dict] = None,
|
|
@@ -46,12 +47,12 @@ def generate_imagemodel(
|
|
|
46
47
|
# check input
|
|
47
48
|
if input is None:
|
|
48
49
|
return None
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
input
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
if 'shape' not in input:
|
|
51
|
+
input.update({'shape': default_shape()})
|
|
52
|
+
if 'scale_factors' not in input:
|
|
53
|
+
input["scale_factors"] = []
|
|
54
|
+
if 'dim' not in input:
|
|
55
|
+
input["dim"] = "2d"
|
|
55
56
|
|
|
56
57
|
# get source
|
|
57
58
|
resource = files('dummy_spatialdata')
|
|
@@ -71,25 +72,35 @@ def generate_imagemodel(
|
|
|
71
72
|
img = img.reshape(1, *img.shape)
|
|
72
73
|
else:
|
|
73
74
|
raise ValueError('Please type either \'rgb\' or \'grayscale\' for the image type.')
|
|
74
|
-
|
|
75
|
+
|
|
75
76
|
# get transformations
|
|
76
77
|
coord_systems = get_basetransformations(coordinate_systems)
|
|
77
78
|
if 'coordinate_system' in input:
|
|
78
79
|
coord_system = input['coordinate_system']
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
trans = {}
|
|
81
|
+
for crd in coord_system:
|
|
82
|
+
if crd in coord_systems:
|
|
83
|
+
# trans = {crd: coord_systems[crd]}
|
|
84
|
+
trans.update({crd: coord_systems[crd]})
|
|
85
|
+
else:
|
|
86
|
+
trans = {key: Identity()}
|
|
83
87
|
else:
|
|
84
88
|
trans = {key: Identity()}
|
|
85
89
|
|
|
86
|
-
#
|
|
87
|
-
if
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
# de
|
|
91
|
+
if "z" not in input["shape"]:
|
|
92
|
+
imagemodel = Image2DModel.parse(data=img,
|
|
93
|
+
scale_factors=input['scale_factors'],
|
|
94
|
+
transformations = trans)
|
|
95
|
+
else:
|
|
96
|
+
depth = input['shape'].get('z', 2)
|
|
97
|
+
img = np.stack([img] * depth, axis=-1)
|
|
98
|
+
img = img.transpose((0, 3, 1, 2))
|
|
99
|
+
imagemodel = Image3DModel.parse(data=img,
|
|
100
|
+
dims = ['c', 'z', 'y', 'x'],
|
|
101
|
+
scale_factors=input['scale_factors'],
|
|
102
|
+
transformations = trans)
|
|
103
|
+
|
|
93
104
|
return imagemodel
|
|
94
105
|
|
|
95
106
|
def resize_image(image: Image, input: dict) -> Image:
|
{dummy_spatialdata-0.1.8 → dummy_spatialdata-0.1.10}/src/dummy_spatialdata/generate_labelmodel.py
RENAMED
|
@@ -4,7 +4,7 @@ import numpy as np
|
|
|
4
4
|
|
|
5
5
|
from importlib.resources import files, as_file
|
|
6
6
|
from typing import Optional
|
|
7
|
-
from spatialdata.models import Labels2DModel
|
|
7
|
+
from spatialdata.models import Labels2DModel, Labels3DModel
|
|
8
8
|
from spatialdata.transformations import set_transformation, Identity
|
|
9
9
|
from .generate_transformations import generate_transformations, get_basetransformations, get_shape
|
|
10
10
|
from .utils import default_shape
|
|
@@ -44,12 +44,12 @@ def generate_labelmodel(
|
|
|
44
44
|
# return None if no input is provided
|
|
45
45
|
if input is None:
|
|
46
46
|
return None
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
input
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
if 'shape' not in input:
|
|
48
|
+
input.update({'shape': default_shape()})
|
|
49
|
+
if 'scale_factors' not in input:
|
|
50
|
+
input["scale_factors"] = []
|
|
51
|
+
if 'dim' not in input:
|
|
52
|
+
input["dim"] = "2d"
|
|
53
53
|
|
|
54
54
|
# generate labels
|
|
55
55
|
# mask for where values should be non-zero
|
|
@@ -58,25 +58,35 @@ def generate_labelmodel(
|
|
|
58
58
|
|
|
59
59
|
arr = np.zeros((rows, cols), dtype=int)
|
|
60
60
|
mask = np.random.rand(rows, cols) < prob_nonzero
|
|
61
|
-
arr[mask] = np.random.randint(1, input['n'], size=mask.sum())
|
|
62
|
-
|
|
61
|
+
arr[mask] = np.random.randint(1, input['n']+1, size=mask.sum())
|
|
62
|
+
|
|
63
63
|
# get transformations
|
|
64
64
|
coord_systems = get_basetransformations(coordinate_systems)
|
|
65
65
|
if 'coordinate_system' in input:
|
|
66
66
|
coord_system = input['coordinate_system']
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
trans = {}
|
|
68
|
+
for crd in coord_system:
|
|
69
|
+
if crd in coord_systems:
|
|
70
|
+
# trans = {crd: coord_systems[crd]}
|
|
71
|
+
trans.update({crd: coord_systems[crd]})
|
|
72
|
+
else:
|
|
73
|
+
trans = {key: Identity()}
|
|
71
74
|
else:
|
|
72
75
|
trans = {key: Identity()}
|
|
73
76
|
|
|
74
|
-
#
|
|
75
|
-
if
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
# define model
|
|
78
|
+
if "z" not in input["shape"]:
|
|
79
|
+
labelmodel = Labels2DModel.parse(data=arr,
|
|
80
|
+
scale_factors=input['scale_factors'],
|
|
81
|
+
transformations = trans)
|
|
82
|
+
else:
|
|
83
|
+
depth = input['shape'].get('z', 2)
|
|
84
|
+
arr = np.stack([arr] * depth, axis=-1)
|
|
85
|
+
arr = arr.transpose((2, 0, 1))
|
|
86
|
+
labelmodel = Labels3DModel.parse(data=arr,
|
|
87
|
+
dims = ['z', 'y', 'x'],
|
|
88
|
+
scale_factors=input['scale_factors'],
|
|
89
|
+
transformations = trans)
|
|
80
90
|
|
|
81
91
|
return labelmodel
|
|
82
92
|
|
{dummy_spatialdata-0.1.8 → dummy_spatialdata-0.1.10}/src/dummy_spatialdata/generate_pointmodel.py
RENAMED
|
@@ -47,10 +47,8 @@ def generate_pointmodel(
|
|
|
47
47
|
return None
|
|
48
48
|
|
|
49
49
|
# get shape
|
|
50
|
-
input
|
|
51
|
-
{'shape':
|
|
52
|
-
input['coordinate_system'] if 'coordinate_system' in input else None)}
|
|
53
|
-
)
|
|
50
|
+
if 'shape' not in input:
|
|
51
|
+
input.update({'shape': default_shape()})
|
|
54
52
|
|
|
55
53
|
# generate points
|
|
56
54
|
RADIUS = 0.08 * min(input['shape']['x'], input['shape']['y'])
|
|
@@ -62,10 +60,13 @@ def generate_pointmodel(
|
|
|
62
60
|
coord_systems = get_basetransformations(coordinate_systems)
|
|
63
61
|
if 'coordinate_system' in input:
|
|
64
62
|
coord_system = input['coordinate_system']
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
trans = {}
|
|
64
|
+
for crd in coord_system:
|
|
65
|
+
if crd in coord_systems:
|
|
66
|
+
# trans = {crd: coord_systems[crd]}
|
|
67
|
+
trans.update({crd: coord_systems[crd]})
|
|
68
|
+
else:
|
|
69
|
+
trans = {key: Identity()}
|
|
69
70
|
else:
|
|
70
71
|
trans = {key: Identity()}
|
|
71
72
|
|
{dummy_spatialdata-0.1.8 → dummy_spatialdata-0.1.10}/src/dummy_spatialdata/generate_shapemodel.py
RENAMED
|
@@ -48,16 +48,21 @@ def generate_shapemodel(
|
|
|
48
48
|
return None
|
|
49
49
|
|
|
50
50
|
# get shape
|
|
51
|
-
input
|
|
52
|
-
{'shape':
|
|
53
|
-
input['coordinate_system'] if 'coordinate_system' in input else None)}
|
|
54
|
-
)
|
|
51
|
+
if 'shape' not in input:
|
|
52
|
+
input.update({'shape': default_shape()})
|
|
55
53
|
|
|
56
54
|
# generate polygons
|
|
57
55
|
RADIUS = 0.08 * min(input['shape']['x'], input['shape']['y'])
|
|
58
56
|
MIN_GAP = 0.01 * min(input['shape']['x'], input['shape']['y'])
|
|
59
57
|
|
|
60
|
-
|
|
58
|
+
if 'overlapping' not in input:
|
|
59
|
+
input['overlapping'] = True
|
|
60
|
+
if input['overlapping']:
|
|
61
|
+
centers = generate_regular_centers(input['shape']['x'], input['shape']['y'], RADIUS, input['n'], SEED)
|
|
62
|
+
else:
|
|
63
|
+
centers = generate_non_overlapping_centers(input['shape']['x'], input['shape']['y'], RADIUS, input['n'], min_gap=MIN_GAP, SEED=SEED)
|
|
64
|
+
# centers = generate_non_overlapping_centers(input['shape']['x'], input['shape']['y'], RADIUS, input['n'], MIN_GAP, SEED)
|
|
65
|
+
# centers = generate_regular_centers(input['shape']['x'], input['shape']['y'], RADIUS, input['n'], SEED)
|
|
61
66
|
if input['type'] == 'polygon':
|
|
62
67
|
polygon_seeds = [SEED + i for i in range(input['n'])]
|
|
63
68
|
polygons = [Polygon(border_polygon_points(c, RADIUS, 10, SEED = seed)) for c, seed in zip(centers, polygon_seeds)]
|
|
@@ -73,10 +78,12 @@ def generate_shapemodel(
|
|
|
73
78
|
coord_systems = get_basetransformations(coordinate_systems)
|
|
74
79
|
if 'coordinate_system' in input:
|
|
75
80
|
coord_system = input['coordinate_system']
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
81
|
+
trans = {}
|
|
82
|
+
for crd in coord_system:
|
|
83
|
+
if crd in coord_systems:
|
|
84
|
+
trans.update({crd: coord_systems[crd]})
|
|
85
|
+
else:
|
|
86
|
+
trans = {key: Identity()}
|
|
80
87
|
else:
|
|
81
88
|
trans = {key: Identity()}
|
|
82
89
|
|
|
@@ -109,6 +116,19 @@ def generate_non_overlapping_centers(width, height, radius, n_circles, min_gap=0
|
|
|
109
116
|
|
|
110
117
|
return np.array(centers)
|
|
111
118
|
|
|
119
|
+
def generate_regular_centers(width, height, radius, n_circles, SEED=1):
|
|
120
|
+
centers = []
|
|
121
|
+
tries = 0
|
|
122
|
+
rng = np.random.default_rng(SEED)
|
|
123
|
+
|
|
124
|
+
for _ in range(n_circles):
|
|
125
|
+
x = rng.uniform(radius, width - radius)
|
|
126
|
+
y = rng.uniform(radius, height - radius)
|
|
127
|
+
candidate = (x, y)
|
|
128
|
+
centers.append(candidate)
|
|
129
|
+
|
|
130
|
+
return np.array(centers)
|
|
131
|
+
|
|
112
132
|
def border_polygon_points(center, radius, n_points, SEED=1):
|
|
113
133
|
cx, cy = center
|
|
114
134
|
rng = np.random.default_rng(SEED)
|
{dummy_spatialdata-0.1.8 → dummy_spatialdata-0.1.10}/src/dummy_spatialdata/generate_tablemodel.py
RENAMED
|
@@ -10,6 +10,9 @@ from spatialdata.models import TableModel
|
|
|
10
10
|
import spatialdata as sd
|
|
11
11
|
from .utils import default_shape
|
|
12
12
|
|
|
13
|
+
import anndata as ad
|
|
14
|
+
import pandas as pd
|
|
15
|
+
|
|
13
16
|
def generate_tablemodel(
|
|
14
17
|
input: Optional[dict] = None
|
|
15
18
|
) -> TableModel:
|
|
@@ -44,4 +47,12 @@ def generate_tablemodel(
|
|
|
44
47
|
'instance_key': 'instance_id',
|
|
45
48
|
}
|
|
46
49
|
|
|
47
|
-
return TableModel.parse(input['table'])
|
|
50
|
+
return TableModel.parse(input['table'])
|
|
51
|
+
|
|
52
|
+
# generate anndata
|
|
53
|
+
def generate_anndata(n_obs=12, n_vars=20):
|
|
54
|
+
obs = pd.DataFrame(index=[f'obs_{i}' for i in range(n_obs)])
|
|
55
|
+
var = pd.DataFrame(index=[f'var_{i}' for i in range(n_vars)])
|
|
56
|
+
X = np.random.rand(n_obs, n_vars)
|
|
57
|
+
adata = ad.AnnData(X=X, obs=obs, var=var)
|
|
58
|
+
return adata
|
|
@@ -59,9 +59,9 @@ def generate_transformations(
|
|
|
59
59
|
elif tr == 'mapAxis':
|
|
60
60
|
tr = MapAxis({"x": "y", "y": "x"})
|
|
61
61
|
elif tr == 'translation':
|
|
62
|
-
tr = Translation([10, 20], axes = ('x', 'y'))
|
|
62
|
+
tr = Translation([10, -20], axes = ('x', 'y'))
|
|
63
63
|
elif tr == 'scale':
|
|
64
|
-
tr = Scale([0.
|
|
64
|
+
tr = Scale([0.3, 1.3], axes = ('x', 'y'))
|
|
65
65
|
elif tr == 'rotation':
|
|
66
66
|
theta = np.deg2rad(15)
|
|
67
67
|
c = np.cos(theta)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__pycache__
|
|
@@ -26,29 +26,29 @@ from spatialdata.transformations import (
|
|
|
26
26
|
def test_shapemodel():
|
|
27
27
|
|
|
28
28
|
# returns GeoDataFrame (circle)
|
|
29
|
-
shp = generate_shapemodel({'n': 12, 'type': 'circle', 'coordinate_system': 'global'}, '
|
|
29
|
+
shp = generate_shapemodel({'n': 12, 'type': 'circle', 'coordinate_system': ['global']}, 'shape')
|
|
30
30
|
assert isinstance(shp, gpd.GeoDataFrame)
|
|
31
31
|
|
|
32
32
|
# returns GeoDataFrame (polygon)
|
|
33
|
-
shp = generate_shapemodel({'n': 12, 'type': 'polygon', 'coordinate_system': 'global'}, '
|
|
33
|
+
shp = generate_shapemodel({'n': 12, 'type': 'polygon', 'coordinate_system': ['global']}, 'shape')
|
|
34
34
|
assert isinstance(shp, gpd.GeoDataFrame)
|
|
35
35
|
|
|
36
36
|
# wrong shape type
|
|
37
37
|
with pytest.raises(ValueError):
|
|
38
|
-
shp = generate_shapemodel({'n': 12, 'type': 'art', 'coordinate_system': 'global'}, '
|
|
38
|
+
shp = generate_shapemodel({'n': 12, 'type': 'art', 'coordinate_system': ['global']}, 'shape')
|
|
39
39
|
|
|
40
40
|
# size is not defined
|
|
41
41
|
with pytest.raises(KeyError):
|
|
42
|
-
shp = generate_shapemodel({'type': 'circle', 'coordinate_system': 'global'}, '
|
|
42
|
+
shp = generate_shapemodel({'type': 'circle', 'coordinate_system': ['global']}, 'shape')
|
|
43
43
|
|
|
44
44
|
# no coordinate system returns element name as coord system and Identity transformation
|
|
45
|
-
shp = generate_shapemodel({'n': 12, 'type': 'circle'}, '
|
|
46
|
-
assert list(shp.attrs['transform'].keys())[0] == '
|
|
47
|
-
assert get_transformation(shp, '
|
|
45
|
+
shp = generate_shapemodel({'n': 12, 'type': 'circle'}, 'shape')
|
|
46
|
+
assert list(shp.attrs['transform'].keys())[0] == 'shape'
|
|
47
|
+
assert get_transformation(shp, 'shape') == Identity()
|
|
48
48
|
|
|
49
49
|
# parses coordinate system
|
|
50
50
|
coord_system = {'global': {'transformations': ['affine'], 'shape': {'x': 2000, 'y': 2000}}}
|
|
51
|
-
shp = generate_shapemodel({'n': 12, 'type': 'polygon', 'coordinate_system': 'global'}, 'image', coord_system)
|
|
51
|
+
shp = generate_shapemodel({'n': 12, 'type': 'polygon', 'coordinate_system': ['global']}, 'image', coord_system)
|
|
52
52
|
assert len(list(shp.attrs['transform'].keys())) == 1
|
|
53
53
|
assert list(shp.attrs['transform'].keys())[0] == 'global'
|
|
54
54
|
assert isinstance(get_transformation(shp, 'global'), Affine)
|
|
@@ -60,12 +60,12 @@ def test_shapemodel():
|
|
|
60
60
|
def test_pointmodel():
|
|
61
61
|
|
|
62
62
|
# returns DataFrame
|
|
63
|
-
pts = generate_pointmodel({'n': 12, 'coordinate_system': 'global'}, 'image')
|
|
63
|
+
pts = generate_pointmodel({'n': 12, 'coordinate_system': ['global']}, 'image')
|
|
64
64
|
assert isinstance(pts, dd.DataFrame)
|
|
65
65
|
|
|
66
66
|
# size is not defined
|
|
67
67
|
with pytest.raises(KeyError):
|
|
68
|
-
pts = generate_pointmodel({'coordinate_system': 'global'}, 'image')
|
|
68
|
+
pts = generate_pointmodel({'coordinate_system': ['global']}, 'image')
|
|
69
69
|
|
|
70
70
|
# no coordinate system returns element name as coord system and Identity transformation
|
|
71
71
|
pts = generate_pointmodel({'n': 12}, 'image')
|
|
@@ -74,7 +74,7 @@ def test_pointmodel():
|
|
|
74
74
|
|
|
75
75
|
# parses coordinate system
|
|
76
76
|
coord_system = {'global': {'transformations': ['affine'], 'shape': {'x': 2000, 'y': 2000}}}
|
|
77
|
-
pts = generate_pointmodel({'n': 12, 'coordinate_system': 'global'}, 'image', coord_system)
|
|
77
|
+
pts = generate_pointmodel({'n': 12, 'coordinate_system': ['global']}, 'image', coord_system)
|
|
78
78
|
assert len(list(pts.attrs['transform'].keys())) == 1
|
|
79
79
|
assert list(pts.attrs['transform'].keys())[0] == 'global'
|
|
80
80
|
assert isinstance(get_transformation(pts, 'global'), Affine)
|
|
@@ -86,16 +86,24 @@ def test_pointmodel():
|
|
|
86
86
|
def test_labelmodel():
|
|
87
87
|
|
|
88
88
|
# returns DataFrame
|
|
89
|
-
lbl = generate_labelmodel({'n': 12, 'scale_factors': [2,2,3], 'coordinate_system': 'global'}, 'image')
|
|
89
|
+
lbl = generate_labelmodel({'n': 12, 'scale_factors': [2,2,3], 'coordinate_system': ['global']}, 'image')
|
|
90
|
+
assert isinstance(lbl, xarray.DataTree)
|
|
91
|
+
assert len(lbl) == 4
|
|
92
|
+
|
|
93
|
+
# returns DataFrame (3d)
|
|
94
|
+
lbl = generate_labelmodel({'n': 12,
|
|
95
|
+
'scale_factors': [2,2,3],
|
|
96
|
+
'shape': {'x': 120, 'y': 120, 'z': 120},
|
|
97
|
+
'coordinate_system': ['global']}, 'image')
|
|
90
98
|
assert isinstance(lbl, xarray.DataTree)
|
|
91
99
|
assert len(lbl) == 4
|
|
92
100
|
|
|
93
101
|
# size is not defined
|
|
94
102
|
with pytest.raises(KeyError):
|
|
95
|
-
lbl = generate_labelmodel({'coordinate_system': 'global'}, 'image')
|
|
103
|
+
lbl = generate_labelmodel({'coordinate_system': ['global']}, 'image')
|
|
96
104
|
|
|
97
105
|
# single scale is returned for no scale factor definition
|
|
98
|
-
lbl = generate_labelmodel({'n': 12, 'coordinate_system': 'global'}, 'image')
|
|
106
|
+
lbl = generate_labelmodel({'n': 12, 'coordinate_system': ['global']}, 'image')
|
|
99
107
|
assert len(lbl) == 1
|
|
100
108
|
|
|
101
109
|
# no coordinate system returns element name as coord system and Identity transformation
|
|
@@ -105,7 +113,7 @@ def test_labelmodel():
|
|
|
105
113
|
|
|
106
114
|
# parses coordinate system
|
|
107
115
|
coord_system = {'global': {'transformations': ['affine'], 'shape': {'x': 2000, 'y': 2000}}}
|
|
108
|
-
lbl = generate_labelmodel({'n': 12, 'coordinate_system': 'global'}, 'image', coord_system)
|
|
116
|
+
lbl = generate_labelmodel({'n': 12, 'coordinate_system': ['global']}, 'image', coord_system)
|
|
109
117
|
assert len(list(dict(lbl["scale0"])["image"].attrs['transform'].keys())) == 1
|
|
110
118
|
assert list(dict(lbl["scale0"])["image"].attrs['transform'].keys())[0] == 'global'
|
|
111
119
|
assert isinstance(get_transformation(lbl, 'global'), Affine)
|
dummy_spatialdata-0.1.8/PKG-INFO
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: dummy-spatialdata
|
|
3
|
-
Version: 0.1.8
|
|
4
|
-
Summary: A package for creating arbitrary spatialdata for testing purposes.
|
|
5
|
-
Project-URL: Documentation, https://dummy-spatialdata.readthedocs.io/
|
|
6
|
-
Project-URL: Homepage, https://github.com/BIMSBBioinfo/dummy-spatialdata
|
|
7
|
-
Project-URL: Source, https://github.com/BIMSBBioinfo/dummy-spatialdata
|
|
8
|
-
Author-email: Artür Manukyan <amanukyan.umms@gmail.com>
|
|
9
|
-
License: MIT
|
|
10
|
-
Requires-Python: >=3.12
|
|
11
|
-
Requires-Dist: dummy-anndata>=0.0.3
|
|
12
|
-
Requires-Dist: geopandas
|
|
13
|
-
Requires-Dist: pillow
|
|
14
|
-
Requires-Dist: requests
|
|
15
|
-
Requires-Dist: shapely
|
|
16
|
-
Requires-Dist: spatialdata>=0.5.0
|
|
17
|
-
Provides-Extra: dev
|
|
18
|
-
Requires-Dist: pre-commit; extra == 'dev'
|
|
19
|
-
Requires-Dist: twine>=4.0.2; extra == 'dev'
|
|
20
|
-
Provides-Extra: test
|
|
21
|
-
Requires-Dist: coverage; extra == 'test'
|
|
22
|
-
Requires-Dist: pytest; extra == 'test'
|
|
23
|
-
Description-Content-Type: text/markdown
|
|
24
|
-
|
|
25
|
-
# dummy-spatialdata
|
|
26
|
-
|
|
27
|
-
Allows generating dummy spatialdata objects, which can be useful for testing purposes.
|
|
28
|
-
|
|
29
|
-
## Installation
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
pip install dummy-spatialdata
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## Example usage
|
|
36
|
-
|
|
37
|
-
`dummy-spatialdata` is compatible with both spatialdata == 0.5.0 (zarr v2) and 0.7.2 (zarr v3)
|
|
38
|
-
|
|
39
|
-
Thus please use
|
|
40
|
-
|
|
41
|
-
1. `conda create --name dummy_sd_env python==3.12 spatialdata==0.7.2` or
|
|
42
|
-
2. `conda create --name dummy_sd_env_05 python==3.12 spatialdata==0.5.0 setuptools==75.8.0`
|
|
43
|
-
|
|
44
|
-
```{python}
|
|
45
|
-
from dummy_spatialdata import generate_dataset
|
|
46
|
-
import dummy_anndata
|
|
47
|
-
import spatialdata_plot as sdp
|
|
48
|
-
import spatialdata as sd
|
|
49
|
-
import matplotlib.pyplot as plt
|
|
50
|
-
import anndata as ad
|
|
51
|
-
|
|
52
|
-
# generate anndata
|
|
53
|
-
adata = dummy_anndata.generate_dataset(n_obs=12, n_vars=20)
|
|
54
|
-
|
|
55
|
-
# generate spatialdata
|
|
56
|
-
sdata = generate_dataset(
|
|
57
|
-
images = [
|
|
58
|
-
{'type': 'rgb', 'scale_factors': [2,2,2], 'coordinate_system': 'global'},
|
|
59
|
-
{'type': 'grayscale', 'coordinate_system': 'global'},
|
|
60
|
-
],
|
|
61
|
-
labels = [
|
|
62
|
-
{'n': 12, 'scale_factors': [2,2,3], 'coordinate_system': 'global2'},
|
|
63
|
-
{'n': 12, 'coordinate_system': 'global2'},
|
|
64
|
-
],
|
|
65
|
-
shapes = [
|
|
66
|
-
{'n': 12, 'type': 'circle', 'coordinate_system': 'global'},
|
|
67
|
-
{'n': 20, 'type': 'circle'},
|
|
68
|
-
],
|
|
69
|
-
points = [
|
|
70
|
-
{'n': 12}
|
|
71
|
-
],
|
|
72
|
-
tables = [
|
|
73
|
-
{'table': adata, 'element': 'shape', 'element_index': 0}
|
|
74
|
-
],
|
|
75
|
-
coordinate_systems = {
|
|
76
|
-
'global': {'transformations': ['affine'], 'shape': {'x': 2000, 'y': 2000}},
|
|
77
|
-
'global2': {'transformations': ['scale', 'translation'], 'shape':{'x': 500, 'y': 500}}
|
|
78
|
-
},
|
|
79
|
-
SEED=13
|
|
80
|
-
)
|
|
81
|
-
sdata
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
```
|
|
85
|
-
SpatialData object
|
|
86
|
-
├── Images
|
|
87
|
-
│ ├── 'image_0': DataTree[cyx] (3, 2000, 2000), (3, 1000, 1000), (3, 500, 500), (3, 250, 250)
|
|
88
|
-
│ └── 'image_1': DataTree[cyx] (1, 2000, 2000)
|
|
89
|
-
├── Labels
|
|
90
|
-
│ ├── 'label_0': DataTree[yx] (500, 500), (250, 250), (125, 125), (41, 41)
|
|
91
|
-
│ └── 'label_1': DataTree[yx] (500, 500)
|
|
92
|
-
├── Points
|
|
93
|
-
│ └── 'point_0': DataFrame with shape: (<Delayed>, 2) (2D points)
|
|
94
|
-
├── Shapes
|
|
95
|
-
│ ├── 'shape_0': GeoDataFrame shape: (12, 2) (2D shapes)
|
|
96
|
-
│ └── 'shape_1': GeoDataFrame shape: (20, 2) (2D shapes)
|
|
97
|
-
└── Tables
|
|
98
|
-
└── 'table_0': AnnData (12, 20)
|
|
99
|
-
with coordinate systems:
|
|
100
|
-
▸ 'global', with elements:
|
|
101
|
-
image_0 (Images), image_1 (Images), shape_0 (Shapes)
|
|
102
|
-
▸ 'global2', with elements:
|
|
103
|
-
label_0 (Labels), label_1 (Labels)
|
|
104
|
-
▸ 'point_0', with elements:
|
|
105
|
-
point_0 (Points)
|
|
106
|
-
▸ 'shape_1', with elements:
|
|
107
|
-
shape_1 (Shapes)
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
You can plot the demo data now!
|
|
111
|
-
|
|
112
|
-
```{python}
|
|
113
|
-
sdata.pl.render_images('image_0').pl.render_shapes('shape_0', color='Gene001', table_name = 'table_0', table_layer = 'float_matrix').pl.show(coordinate_systems = 'global')
|
|
114
|
-
```
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
# dummy-spatialdata
|
|
2
|
-
|
|
3
|
-
Allows generating dummy spatialdata objects, which can be useful for testing purposes.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
pip install dummy-spatialdata
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Example usage
|
|
12
|
-
|
|
13
|
-
`dummy-spatialdata` is compatible with both spatialdata == 0.5.0 (zarr v2) and 0.7.2 (zarr v3)
|
|
14
|
-
|
|
15
|
-
Thus please use
|
|
16
|
-
|
|
17
|
-
1. `conda create --name dummy_sd_env python==3.12 spatialdata==0.7.2` or
|
|
18
|
-
2. `conda create --name dummy_sd_env_05 python==3.12 spatialdata==0.5.0 setuptools==75.8.0`
|
|
19
|
-
|
|
20
|
-
```{python}
|
|
21
|
-
from dummy_spatialdata import generate_dataset
|
|
22
|
-
import dummy_anndata
|
|
23
|
-
import spatialdata_plot as sdp
|
|
24
|
-
import spatialdata as sd
|
|
25
|
-
import matplotlib.pyplot as plt
|
|
26
|
-
import anndata as ad
|
|
27
|
-
|
|
28
|
-
# generate anndata
|
|
29
|
-
adata = dummy_anndata.generate_dataset(n_obs=12, n_vars=20)
|
|
30
|
-
|
|
31
|
-
# generate spatialdata
|
|
32
|
-
sdata = generate_dataset(
|
|
33
|
-
images = [
|
|
34
|
-
{'type': 'rgb', 'scale_factors': [2,2,2], 'coordinate_system': 'global'},
|
|
35
|
-
{'type': 'grayscale', 'coordinate_system': 'global'},
|
|
36
|
-
],
|
|
37
|
-
labels = [
|
|
38
|
-
{'n': 12, 'scale_factors': [2,2,3], 'coordinate_system': 'global2'},
|
|
39
|
-
{'n': 12, 'coordinate_system': 'global2'},
|
|
40
|
-
],
|
|
41
|
-
shapes = [
|
|
42
|
-
{'n': 12, 'type': 'circle', 'coordinate_system': 'global'},
|
|
43
|
-
{'n': 20, 'type': 'circle'},
|
|
44
|
-
],
|
|
45
|
-
points = [
|
|
46
|
-
{'n': 12}
|
|
47
|
-
],
|
|
48
|
-
tables = [
|
|
49
|
-
{'table': adata, 'element': 'shape', 'element_index': 0}
|
|
50
|
-
],
|
|
51
|
-
coordinate_systems = {
|
|
52
|
-
'global': {'transformations': ['affine'], 'shape': {'x': 2000, 'y': 2000}},
|
|
53
|
-
'global2': {'transformations': ['scale', 'translation'], 'shape':{'x': 500, 'y': 500}}
|
|
54
|
-
},
|
|
55
|
-
SEED=13
|
|
56
|
-
)
|
|
57
|
-
sdata
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
```
|
|
61
|
-
SpatialData object
|
|
62
|
-
├── Images
|
|
63
|
-
│ ├── 'image_0': DataTree[cyx] (3, 2000, 2000), (3, 1000, 1000), (3, 500, 500), (3, 250, 250)
|
|
64
|
-
│ └── 'image_1': DataTree[cyx] (1, 2000, 2000)
|
|
65
|
-
├── Labels
|
|
66
|
-
│ ├── 'label_0': DataTree[yx] (500, 500), (250, 250), (125, 125), (41, 41)
|
|
67
|
-
│ └── 'label_1': DataTree[yx] (500, 500)
|
|
68
|
-
├── Points
|
|
69
|
-
│ └── 'point_0': DataFrame with shape: (<Delayed>, 2) (2D points)
|
|
70
|
-
├── Shapes
|
|
71
|
-
│ ├── 'shape_0': GeoDataFrame shape: (12, 2) (2D shapes)
|
|
72
|
-
│ └── 'shape_1': GeoDataFrame shape: (20, 2) (2D shapes)
|
|
73
|
-
└── Tables
|
|
74
|
-
└── 'table_0': AnnData (12, 20)
|
|
75
|
-
with coordinate systems:
|
|
76
|
-
▸ 'global', with elements:
|
|
77
|
-
image_0 (Images), image_1 (Images), shape_0 (Shapes)
|
|
78
|
-
▸ 'global2', with elements:
|
|
79
|
-
label_0 (Labels), label_1 (Labels)
|
|
80
|
-
▸ 'point_0', with elements:
|
|
81
|
-
point_0 (Points)
|
|
82
|
-
▸ 'shape_1', with elements:
|
|
83
|
-
shape_1 (Shapes)
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
You can plot the demo data now!
|
|
87
|
-
|
|
88
|
-
```{python}
|
|
89
|
-
sdata.pl.render_images('image_0').pl.render_shapes('shape_0', color='Gene001', table_name = 'table_0', table_layer = 'float_matrix').pl.show(coordinate_systems = 'global')
|
|
90
|
-
```
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|