Skip to content

Commit bd8f29f

Browse files
Implement conversion for raw file WIP
1 parent 80de1f7 commit bd8f29f

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

flamingo_tools/data_conversion.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,23 @@ def _write_missing_views(out_path):
207207
tree.write(xml_path)
208208

209209

210+
def _load_data(file_path):
211+
# TODO how do we read the raw data.
212+
if Path(file_path).suffix == ".raw":
213+
pass
214+
else:
215+
try:
216+
data = tifffile.memmap(file_path, mode="r")
217+
except ValueError:
218+
print(f"Could not memmap the data from {file_path}. Fall back to load it into memory.")
219+
data = tifffile.imread(file_path)
220+
return data
221+
222+
210223
def convert_lightsheet_to_bdv(
211224
root: str,
212225
out_path: str,
226+
ext: str = ".tif",
213227
attribute_parser: callable = flamingo_filename_parser,
214228
attribute_names: Optional[Dict[str, Dict[int, str]]] = None,
215229
metadata_file_name_pattern: Optional[str] = None,
@@ -233,6 +247,8 @@ def convert_lightsheet_to_bdv(
233247
root: Folder that contains the image data stored as tifs.
234248
This function will take into account all tif files in folders beneath this root directory.
235249
out_path: Output path where the converted data is saved.
250+
ext: The name of the file extension. By default assumes tif files (.tif).
251+
Change to '.raw' to read files stored in raw format instead.
236252
attribute_parser: TODO
237253
metadata_file_name_pattern: The pattern for the names of files that contain the metadata.
238254
For flamingo metadata the following pattern should work: '*_Settings.txt'.
@@ -264,7 +280,11 @@ def convert_lightsheet_to_bdv(
264280
elif ext == ".zarr":
265281
convert_to_ome_zarr = True
266282

267-
files = sorted(glob(os.path.join(root, "**/*.tif"), recursive=True))
283+
files = sorted(glob(os.path.join(root, f"**/*{ext}"), recursive=True))
284+
# Raise an error if we could not find any files.
285+
if len(files) == 0:
286+
raise ValueError(f"Could not find any files in {root} with extension {ext}.")
287+
268288
if metadata_file_name_pattern is None:
269289
metadata_files = [None] * len(files)
270290
offset = None
@@ -316,12 +336,7 @@ def convert_lightsheet_to_bdv(
316336
)
317337

318338
print(f"Converting tp={timepoint}, channel={attributes['channel']}, tile={attributes['tile']}")
319-
try:
320-
data = tifffile.memmap(file_path, mode="r")
321-
except ValueError:
322-
print(f"Could not memmap the data from {file_path}. Fall back to load it into memory.")
323-
data = tifffile.imread(file_path)
324-
339+
data = _load_data(file_path)
325340
if scale_factors is None:
326341
scale_factors = derive_scale_factors(data.shape)
327342

scripts/convert_raw_cochlea_sample.py

Whitespace-only changes.

scripts/data_transfer/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ Current approach to the data transfer:
1515
- mget *
1616
- Copy this to HLRN by logging into it and running
1717
$ rsync pape41:/scratch1/projects/cca/data/moser/<NAME>
18-
$ rsync -e "ssh -i ~/.ssh/id_rsa_hlrn" -avz [email protected]:/scratch1/projects/cca/data/mose
19-
r/<NAME> /mnt/lustre-grete/usr/u12086/moser/lightsheet/<NAME>
18+
$ rsync -e "ssh -i ~/.ssh/id_rsa_hlrn" -avz [email protected]:/scratch1/projects/cca/data/moser/<NAME> /mnt/lustre-grete/usr/u12086/moser/lightsheet/<NAME>
2019
- Remove on SCC
2120

2221
## Next files

0 commit comments

Comments
 (0)