Skip to content

Commit

Permalink
Fix illumination correction test (ref #116)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcompa committed Jul 22, 2022
1 parent 153742a commit 254a272
Show file tree
Hide file tree
Showing 31 changed files with 231 additions and 4 deletions.
80 changes: 78 additions & 2 deletions tests/data/generate_zarr_ones.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
import json
import os
import shutil

import dask.array as da
import numpy as np
import pandas as pd
import zarr
from anndata.experimental import write_elem

from fractal.tasks.lib_regions_of_interest import prepare_FOV_ROI_table


num_C = 2
num_Z = 1
num_Y = 2
num_X = 1
num_levels = 5
cxy = 2


x = da.ones(
(num_C, num_Z, num_Y * 2160, num_X * 2560), chunks=(1, 1, 2160, 2560)
).astype(np.uint16)


zarrurl = "plate_ones.zarr/"

if os.path.isdir(zarrurl):
shutil.rmtree(zarrurl)
component = "B/03/0/"

for ind_level in range(num_levels):
Expand All @@ -27,14 +39,78 @@
zarrurl, component=f"{component}{ind_level}", dimension_separator="/"
)

pxl_x = 0.1625
pxl_y = 0.1625
pxl_z = 1.0

axes = [
{"name": "c", "type": "channel"},
{"name": "z", "type": "space", "unit": "micrometer"},
{"name": "y", "type": "space", "unit": "micrometer"},
{"name": "x", "type": "space", "unit": "micrometer"},
]

cT = "coordinateTransformations"
zattrs = {
"multiscales": [
{
"axes": [],
"datasets": [{"path": level} for level in range(num_levels)],
"axes": axes,
"datasets": [
{
"path": level,
cT: [
{
"type": "scale",
"scale": [
pxl_z,
pxl_y * cxy**level,
pxl_x * cxy**level,
],
}
],
}
for level in range(num_levels)
],
"version": "0.3",
}
]
}
with open(f"{zarrurl}{component}.zattrs", "w") as jsonfile:
json.dump(zattrs, jsonfile)


pixel_size_z = 1.0
pixel_size_y = 0.1625
pixel_size_x = 0.1625

df = pd.DataFrame(np.zeros((2, 10)), dtype=int)
df.index = ["FOV1", "FOV2"]
df.columns = [
"x_micrometer",
"y_micrometer",
"z_micrometer",
"x_pixel",
"y_pixel",
"z_pixel",
"pixel_size_x",
"pixel_size_y",
"pixel_size_z",
"bit_depth",
]
df["x_micrometer"] = [0.0, 0.0]
df["y_micrometer"] = [0.0, 351.0]
df["z_micrometer"] = [0.0, 0.0]
df["x_pixel"] = [2560] * 2
df["y_pixel"] = [2160] * 2
df["z_pixel"] = [num_Z] * 2
df["pixel_size_x"] = [pxl_x] * 2
df["pixel_size_y"] = [pxl_y] * 2
df["pixel_size_z"] = [pxl_z] * 2
df["bit_depth"] = [16.0, 16.0]


FOV_ROI_table = prepare_FOV_ROI_table(df)
print(FOV_ROI_table.to_df())

group_tables = zarr.group(f"{zarrurl}{component}/tables")
write_elem(group_tables, "FOV_ROI_table", FOV_ROI_table)
2 changes: 1 addition & 1 deletion tests/data/plate_ones.zarr/B/03/0/.zattrs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"multiscales": [{"axes": [], "datasets": [{"path": 0}, {"path": 1}, {"path": 2}, {"path": 3}, {"path": 4}], "version": "0.3"}]}
{"multiscales": [{"axes": [{"name": "c", "type": "channel"}, {"name": "z", "type": "space", "unit": "micrometer"}, {"name": "y", "type": "space", "unit": "micrometer"}, {"name": "x", "type": "space", "unit": "micrometer"}], "datasets": [{"path": 0, "coordinateTransformations": [{"type": "scale", "scale": [1.0, 0.1625, 0.1625]}]}, {"path": 1, "coordinateTransformations": [{"type": "scale", "scale": [1.0, 0.325, 0.325]}]}, {"path": 2, "coordinateTransformations": [{"type": "scale", "scale": [1.0, 0.65, 0.65]}]}, {"path": 3, "coordinateTransformations": [{"type": "scale", "scale": [1.0, 1.3, 1.3]}]}, {"path": 4, "coordinateTransformations": [{"type": "scale", "scale": [1.0, 2.6, 2.6]}]}], "version": "0.3"}]}
3 changes: 3 additions & 0 deletions tests/data/plate_ones.zarr/B/03/0/tables/.zgroup
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"zarr_format": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"encoding-type": "anndata",
"encoding-version": "0.1.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"zarr_format": 2
}
22 changes: 22 additions & 0 deletions tests/data/plate_ones.zarr/B/03/0/tables/FOV_ROI_table/X/.zarray
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"chunks": [
2,
6
],
"compressor": {
"blocksize": 0,
"clevel": 5,
"cname": "lz4",
"id": "blosc",
"shuffle": 1
},
"dtype": "<f4",
"fill_value": 0.0,
"filters": null,
"order": "C",
"shape": [
2,
6
],
"zarr_format": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"encoding-type": "array",
"encoding-version": "0.2.0"
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"encoding-type": "dict",
"encoding-version": "0.1.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"zarr_format": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"_index": "_index",
"column-order": [],
"encoding-type": "dataframe",
"encoding-version": "0.2.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"zarr_format": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"chunks": [
2
],
"compressor": {
"blocksize": 0,
"clevel": 5,
"cname": "lz4",
"id": "blosc",
"shuffle": 1
},
"dtype": "|O",
"fill_value": 0,
"filters": [
{
"id": "vlen-utf8"
}
],
"order": "C",
"shape": [
2
],
"zarr_format": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"encoding-type": "string-array",
"encoding-version": "0.2.0"
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"encoding-type": "dict",
"encoding-version": "0.1.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"zarr_format": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"encoding-type": "dict",
"encoding-version": "0.1.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"zarr_format": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"encoding-type": "dict",
"encoding-version": "0.1.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"zarr_format": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"_index": "_index",
"column-order": [],
"encoding-type": "dataframe",
"encoding-version": "0.2.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"zarr_format": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"chunks": [
6
],
"compressor": {
"blocksize": 0,
"clevel": 5,
"cname": "lz4",
"id": "blosc",
"shuffle": 1
},
"dtype": "|O",
"fill_value": 0,
"filters": [
{
"id": "vlen-utf8"
}
],
"order": "C",
"shape": [
6
],
"zarr_format": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"encoding-type": "string-array",
"encoding-version": "0.2.0"
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"encoding-type": "dict",
"encoding-version": "0.1.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"zarr_format": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"encoding-type": "dict",
"encoding-version": "0.1.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"zarr_format": 2
}
1 change: 0 additions & 1 deletion tests/test_unit_illumination_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


@pytest.mark.parametrize("overwrite", [True, False])
@pytest.mark.skip("Missing ROIs table in test data")
def test_illumination_correction(
overwrite: bool,
tmp_path: pathlib.Path,
Expand Down

0 comments on commit 254a272

Please sign in to comment.