-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprep_cellpose_dataset.py
More file actions
83 lines (67 loc) · 2.13 KB
/
Copy pathprep_cellpose_dataset.py
File metadata and controls
83 lines (67 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python3
import argparse
import harpy as hp
from pathlib import Path
from spatialdata import read_zarr
import dask.array as da
import math
import numpy as np
def create_cellpose_dataset(
path: str | Path,
y_dim: int = 10000,
x_dim: int = 10000,
chunksize: int = 4096,
img_layer: str = "image_tiled",
dtype: str = np.float32, # sopa only accepts np.uint
):
# Generate the example spatial data
sdata = hp.datasets.vectra_example()
sdata.write(path, overwrite=False)
sdata = read_zarr(sdata.path)
orig_shape = sdata["image"].data.shape
# Compute the minimum number of repetitions required along each axis
repeat_y = math.ceil(y_dim / orig_shape[1])
repeat_x = math.ceil(x_dim / orig_shape[2])
# Tile the array
tiled = da.tile(sdata["image"].data, (1, repeat_y, repeat_x))
# take channel at index 6 and 8, this is a DAPI stain, and some cell specific stain.
tiled = tiled[6:8, ...]
tiled = tiled[:, :y_dim, :x_dim].rechunk((tiled.shape[0], chunksize, chunksize))
hp.im.add_image_layer(
sdata, arr=tiled.astype(dtype), output_layer=img_layer, overwrite=True
)
return sdata
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Generate vectra example spatial data and write it to a zarr file."
)
parser.add_argument(
"output_path",
type=str,
help="The output path where the zarr file will be saved.",
)
parser.add_argument(
"--y_dim",
type=int,
default=10000,
help="The target size along the y-axis (second axis). Default is 10000.",
)
parser.add_argument(
"--x_dim",
type=int,
default=10000,
help="The target size along the x-axis (third axis). Default is 10000.",
)
parser.add_argument(
"--chunksize",
type=int,
default=4096,
help="Chunksize in y and x. Chunksize in c is c_dim.",
)
args = parser.parse_args()
create_cellpose_dataset(
path=args.output_path,
y_dim=args.y_dim,
x_dim=args.x_dim,
chunksize=args.chunksize,
)