19
19
"/media/starfish/Storage/metacell/converted/Isl1-GFP_E13-5_F129-3_CMN-R-L_02052024-GLC-stitched"
20
20
)
21
21
OUTPUT_PATH .mkdir (exist_ok = True , parents = True )
22
+ OVERWRITE = False
22
23
23
24
# %% Load the data
24
25
br = BioReader (str (FILEPATH ), backend = "bioformats" )
54
55
num_channels = br .shape [- 1 ]
55
56
data_type = "uint16"
56
57
chunk_size = [256 , 256 , 128 , 1 ]
58
+ volume_size = [br .shape [1 ], br .shape [0 ], br .shape [2 ]] # XYZ
57
59
58
60
# %% Setup the cloudvolume info
59
61
info = CloudVolume .create_new_info (
64
66
resolution = [size_x , size_y , size_z ],
65
67
voxel_offset = [0 , 0 , 0 ],
66
68
chunk_size = chunk_size [:- 1 ],
67
- volume_size = [ br . shape [ 0 ], br . shape [ 1 ], br . shape [ 2 ]] ,
69
+ volume_size = volume_size ,
68
70
)
69
71
vol = CloudVolume ("file://" + str (OUTPUT_PATH ), info = info )
70
72
vol .provenance .description = "Example data conversion"
77
79
78
80
79
81
# %% Functions for moving data
80
- shape = np .array (br .shape )
82
+ shape = np .array ([ br .shape [ 1 ], br . shape [ 0 ], br . shape [ 2 ], br . shape [ 3 ]] )
81
83
chunk_shape = np .array ([1024 , 1024 , 512 , 1 ]) # this is for reading data
82
84
num_chunks_per_dim = np .ceil (shape / chunk_shape ).astype (int )
83
85
@@ -88,24 +90,34 @@ def chunked_reader(x_i, y_i, z_i, c):
88
90
z_start , z_end = z_i * chunk_shape [2 ], min ((z_i + 1 ) * chunk_shape [2 ], shape [2 ])
89
91
90
92
# Read the chunk from the BioReader
91
- chunk = br .read (X = (x_start , x_end ), Y = (y_start , y_end ), Z = (z_start , z_end ), C = (c ,))
92
- return np .expand_dims (chunk , axis = - 1 )
93
+ chunk = br .read (
94
+ X = (x_start , x_end ), Y = (y_start , y_end ), Z = (z_start , z_end ), C = (c ,)
95
+ )
96
+ # Keep expanding dims until it is the same length as chunk_shape
97
+ while len (chunk .shape ) < len (chunk_shape ):
98
+ chunk = np .expand_dims (chunk , axis = - 1 )
99
+ # Return the chunk
100
+ return chunk .swapaxes (0 , 1 )
93
101
94
102
95
103
def process (args ):
96
104
x_i , y_i , z_i , c = args
97
- rawdata = chunk = chunked_reader (x_i , y_i , z_i , c )
98
105
start = [x_i * chunk_shape [0 ], y_i * chunk_shape [1 ], z_i * chunk_shape [2 ]]
99
106
end = [
100
107
min ((x_i + 1 ) * chunk_shape [0 ], shape [0 ]),
101
108
min ((y_i + 1 ) * chunk_shape [1 ], shape [1 ]),
102
109
min ((z_i + 1 ) * chunk_shape [2 ], shape [2 ]),
103
110
]
104
- vol [start [0 ] : end [0 ], start [1 ] : end [1 ], start [2 ] : end [2 ], c ] = rawdata
105
- touch (
111
+ f_name = (
106
112
progress_dir
107
113
/ f"{ start [0 ]} -{ end [0 ]} _{ start [1 ]} -{ end [1 ]} _{ start [2 ]} -{ end [2 ]} _{ c } .done"
108
114
)
115
+ if f_name .exists () and not OVERWRITE :
116
+ return
117
+ print ("Working on" , f_name )
118
+ rawdata = chunk = chunked_reader (x_i , y_i , z_i , c )
119
+ vol [start [0 ] : end [0 ], start [1 ] : end [1 ], start [2 ] : end [2 ], c ] = rawdata
120
+ touch (f_name )
109
121
110
122
111
123
# %% Try with a single chunk to see if it works
@@ -122,6 +134,9 @@ def process(args):
122
134
range (num_chunks_per_dim [2 ]),
123
135
range (num_channels ),
124
136
)
137
+ # Do it in reverse order because the last chunks are most likely to error
138
+ reversed_coords = list (coords )
139
+ reversed_coords .reverse ()
125
140
126
141
# %% Move the data across with multiple workers
127
142
# max_workers = 8
@@ -130,7 +145,7 @@ def process(args):
130
145
# executor.map(process, coords)
131
146
132
147
# %% Move the data across with a single worker
133
- for coord in coords :
148
+ for coord in reversed_coords :
134
149
process (coord )
135
150
136
151
# %% Serve the dataset to be used in neuroglancer
0 commit comments