Skip to content

Commit 4407ad4

Browse files
committed
WIP: fix tests
1 parent a95fa8f commit 4407ad4

4 files changed

Lines changed: 89 additions & 87 deletions

File tree

src/vitessce/data_utils/entities.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,6 @@ def __init__(self, f, profile_paths, assembly='hg38', starting_resolution=5000,
196196

197197
num_profiles = len(profile_paths)
198198

199-
compressor = 'default'
200-
201199
chromosomes = [str(chr_name) for chr_name in nc.get_chromorder(
202200
assembly)[:25]] # TODO: should more than chr1-chrM be used?
203201
chroms_length_arr = np.array(
@@ -217,8 +215,8 @@ def __init__(self, f, profile_paths, assembly='hg38', starting_resolution=5000,
217215
# Create each resolution group.
218216
for resolution in resolutions:
219217
chr_shape = (num_profiles, math.ceil(chr_len / resolution))
220-
chr_group.create_dataset(str(
221-
resolution), shape=chr_shape, dtype="f4", fill_value=np.nan, compressor=compressor)
218+
chr_group.create_array(str(
219+
resolution), shape=chr_shape, dtype="f4", fill_value=np.nan)
222220

223221
# f.attrs should contain the properties required for HiGlass's "tileset_info" requests.
224222
f.attrs['row_infos'] = [

src/vitessce/data_utils/ome.py

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def multiplex_img_to_ome_tiff(img_arr, channel_names, output_path, axes="CYX"):
6767
tiff_writer.close()
6868

6969

70-
def rgb_img_to_ome_zarr(img_arr, output_path, img_name="Image", chunks=(1, 256, 256), axes="cyx", **kwargs):
70+
def rgb_img_to_ome_zarr(img_arr, output_path, img_name="Image", chunks=(1, 256, 256), axes="cyx", **write_image_kwargs):
7171
"""
7272
Convert an RGB image to OME-Zarr v0.3.
7373
@@ -94,35 +94,36 @@ def rgb_img_to_ome_zarr(img_arr, output_path, img_name="Image", chunks=(1, 256,
9494
group=z_root,
9595
axes=axes,
9696
storage_options=dict(chunks=chunks),
97-
**kwargs,
98-
)
99-
z_root.attrs["omero"] = {
100-
"name": img_name,
101-
"version": "0.3",
102-
"rdefs": {
103-
"model": "color",
104-
},
105-
"channels": [
106-
{
107-
"label": "R",
108-
"color": "FF0000",
109-
"window": default_window
110-
},
111-
{
112-
"label": "G",
113-
"color": "00FF00",
114-
"window": default_window
115-
},
116-
{
117-
"label": "B",
118-
"color": "0000FF",
119-
"window": default_window
97+
**write_image_kwargs,
98+
metadata={
99+
"omero": {
100+
"name": img_name,
101+
"rdefs": {
102+
"model": "color",
103+
},
104+
"channels": [
105+
{
106+
"label": "R",
107+
"color": "FF0000",
108+
"window": default_window
109+
},
110+
{
111+
"label": "G",
112+
"color": "00FF00",
113+
"window": default_window
114+
},
115+
{
116+
"label": "B",
117+
"color": "0000FF",
118+
"window": default_window
119+
}
120+
]
120121
}
121-
]
122-
}
122+
}
123+
)
123124

124125

125-
def multiplex_img_to_ome_zarr(img_arr, channel_names, output_path, img_name="Image", chunks=(1, 256, 256), axes="cyx", channel_colors=None):
126+
def multiplex_img_to_ome_zarr(img_arr, channel_names, output_path, img_name="Image", chunks=(1, 256, 256), axes="cyx", channel_colors=None, **write_image_kwargs):
126127
"""
127128
Convert a multiplexed image to OME-Zarr v0.3.
128129
@@ -153,21 +154,23 @@ def multiplex_img_to_ome_zarr(img_arr, channel_names, output_path, img_name="Ima
153154
image=img_arr,
154155
group=z_root,
155156
axes=axes,
156-
storage_options=dict(chunks=chunks)
157-
)
158-
z_root.attrs["omero"] = {
159-
"name": img_name,
160-
"version": "0.3",
161-
"rdefs": {
162-
"model": "greyscale",
163-
},
164-
"channels": [
165-
{
166-
"label": channel_name,
167-
"color": channel_colors[channel_name] if channel_colors is not None else "FFFFFF",
168-
"window": default_window
157+
storage_options=dict(chunks=chunks),
158+
**write_image_kwargs,
159+
metadata={
160+
"omero": {
161+
"name": img_name,
162+
"rdefs": {
163+
"model": "greyscale",
164+
},
165+
"channels": [
166+
{
167+
"label": channel_name,
168+
"color": channel_colors[channel_name] if channel_colors is not None else "FFFFFF",
169+
"window": default_window
170+
}
171+
for channel_name
172+
in channel_names
173+
]
169174
}
170-
for channel_name
171-
in channel_names
172-
]
173-
}
175+
}
176+
)

src/vitessce/data_utils/spatialdata_points_zorder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import pandas as pd
77
import numpy as np
88

9-
109
from spatialdata import get_element_annotators
10+
from spatialdata.models import PointsModel
1111
import dask.dataframe as dd
1212
import zarr
1313

@@ -157,7 +157,7 @@ def sdata_morton_sort_points(sdata, element):
157157
sorted_ddf = ddf.sort_values(by="morton_code_2d", ascending=True)
158158
else:
159159
sorted_ddf = ddf.sort_values(by="morton_code_2d", ascending=True)
160-
sdata.points[element] = sorted_ddf
160+
sdata.points[element] = PointsModel.parse(sorted_ddf)
161161

162162
# annotating_tables = get_element_annotators(sdata, element)
163163

tests/test_ome_utils.py

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -50,49 +50,50 @@ def setUp(self):
5050
def test_rgb_img_to_ome_zarr(self):
5151
img_arr = self.img_arr
5252
out_path = data_path / "rgb_out.ome.zarr"
53-
rgb_img_to_ome_zarr(img_arr, out_path, img_name="Test", axes="cyx", chunks=(1, 3, 3), scaler=None)
53+
rgb_img_to_ome_zarr(img_arr, out_path, img_name="Test", axes="cyx", chunks=(1, 3, 3), scale_factors=[])
5454

5555
z_root = zarr.open(out_path, mode="r")
5656

5757
assert dict(z_root.attrs) == {
58-
'multiscales': [
59-
{
60-
'axes': [
61-
{'name': 'c', 'type': 'channel'},
62-
{'name': 'y', 'type': 'space'},
63-
{'name': 'x', 'type': 'space'}
64-
],
65-
'datasets': [
66-
{
67-
'coordinateTransformations': [
68-
{'scale': [1.0, 1.0, 1.0], 'type': 'scale'}
69-
],
70-
'path': '0'
58+
'ome': {
59+
'version': '0.5',
60+
'multiscales': [
61+
{
62+
'axes': [
63+
{'name': 'c', 'type': 'channel'},
64+
{'name': 'y', 'type': 'space'},
65+
{'name': 'x', 'type': 'space'}
66+
],
67+
'datasets': [
68+
{
69+
'coordinateTransformations': [
70+
{'scale': [1.0, 1.0, 1.0], 'type': 'scale'}
71+
],
72+
'path': 's0'
73+
}
74+
],
75+
'name': '/',
76+
}
77+
],
78+
'omero': {
79+
'channels': [
80+
{'color': 'FF0000',
81+
'label': 'R',
82+
'window': {'end': 255, 'max': 255, 'min': 0, 'start': 0}
83+
},
84+
{'color': '00FF00',
85+
'label': 'G',
86+
'window': {'end': 255, 'max': 255, 'min': 0, 'start': 0}
87+
},
88+
{'color': '0000FF',
89+
'label': 'B',
90+
'window': {'end': 255, 'max': 255, 'min': 0, 'start': 0}
7191
}
7292
],
73-
'name': '/',
74-
'version': '0.4'
93+
'name': 'Test',
94+
'rdefs': {
95+
"model": "color",
96+
}
7597
}
76-
],
77-
'omero': {
78-
'channels': [
79-
{'color': 'FF0000',
80-
'label': 'R',
81-
'window': {'end': 255, 'max': 255, 'min': 0, 'start': 0}
82-
},
83-
{'color': '00FF00',
84-
'label': 'G',
85-
'window': {'end': 255, 'max': 255, 'min': 0, 'start': 0}
86-
},
87-
{'color': '0000FF',
88-
'label': 'B',
89-
'window': {'end': 255, 'max': 255, 'min': 0, 'start': 0}
90-
}
91-
],
92-
'name': 'Test',
93-
'rdefs': {
94-
"model": "color",
95-
},
96-
'version': '0.3'
9798
}
9899
}

0 commit comments

Comments
 (0)