-
Notifications
You must be signed in to change notification settings - Fork 3
/
detect_cli_io_backend.py
68 lines (59 loc) · 1.85 KB
/
detect_cli_io_backend.py
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
from enum import Enum
from pathlib import Path
from typing import List
conversion_backends = [("NGFF_ZARR", "ngff_zarr"),
("ZARR_ARRAY", "zarr"),
("ITK", "itk"),
("TIFFFILE", "tifffile"),
("IMAGEIO", "imageio")]
conversion_backends_values = [b[1] for b in conversion_backends]
ConversionBackend = Enum("ConversionBackend", conversion_backends)
def detect_cli_io_backend(input: List[str]) -> ConversionBackend:
if (Path(input[0]) / '.zarray').exists():
return ConversionBackend.ZARR_ARRAY
extension = ''.join(Path(input[0]).suffixes).lower()
ngff_zarr_supported_extensions = (
'.zarr',
)
if extension in ngff_zarr_supported_extensions:
return ConversionBackend.NGFF_ZARR
itk_supported_extensions = (
'.bmp',
'.dcm',
'.gipl',
'.hdf5',
'.jpg',
'.jpeg',
'.iwi',
'.iwi.cbor',
'.lsm',
'.mnc',
'.mnc.gz',
'.mnc2',
'.mgh',
'.mhz',
'.mha',
'.mhd',
'.mrc',
'.nia',
'.nii',
'.nii.gz',
'.hdr',
'.nrrd',
'.nhdr',
'.png',
'.pic',
'.vtk',
'.isq', # Requires pip install itk-ioscanco,
'.fdf', # Requires pip install itk-iofdf
)
if extension in itk_supported_extensions:
return ConversionBackend.ITK
try:
import tifffile
tifffile_supported_extensions = [f".{ext}" for ext in tifffile.TIFF.FILE_EXTENSIONS]
if extension in tifffile_supported_extensions:
return ConversionBackend.TIFFFILE
except ImportError:
console.log('[red]Please install the [i]tifffile[/i] package')
return ConversionBackend.IMAGEIO