Coverage for openhcs/constants/constants.py: 100.0%

87 statements  

« prev     ^ index     » next       coverage.py v7.10.3, created at 2025-08-14 05:57 +0000

1""" 

2Consolidated constants for OpenHCS. 

3 

4This module defines all constants related to backends, defaults, I/O, memory, and pipeline. 

5These constants are governed by various doctrinal clauses. 

6""" 

7 

8from enum import Enum 

9from typing import Any, Callable, Dict, List, Set, TypeVar 

10 

11class VariableComponents(Enum): 

12 SITE = "site" 

13 CHANNEL = "channel" 

14 Z_INDEX = "z_index" 

15 WELL = "well" 

16 

17class Microscope(Enum): 

18 AUTO = "auto" 

19 OPENHCS = "openhcs" # Added for the OpenHCS pre-processed format 

20 IMAGEXPRESS = "ImageXpress" 

21 OPERAPHENIX = "OperaPhenix" 

22 

23class GroupBy(Enum): 

24 CHANNEL = VariableComponents.CHANNEL.value # Will be "channel" 

25 Z_INDEX = VariableComponents.Z_INDEX.value # Will be "z_index" 

26 SITE = VariableComponents.SITE.value # Will be "site" 

27 WELL = VariableComponents.WELL.value # Will be "well" 

28 NONE = "" # Added for allow_blank in Select 

29 

30class OrchestratorState(Enum): 

31 """Simple orchestrator state tracking - no complex state machine.""" 

32 CREATED = "created" # Object exists, not initialized 

33 READY = "ready" # Initialized, ready for compilation 

34 COMPILED = "compiled" # Compilation complete, ready for execution 

35 EXECUTING = "executing" # Execution in progress 

36 COMPLETED = "completed" # Execution completed successfully 

37 INIT_FAILED = "init_failed" # Initialization failed 

38 COMPILE_FAILED = "compile_failed" # Compilation failed (implies initialized) 

39 EXEC_FAILED = "exec_failed" # Execution failed (implies compiled) 

40 

41# I/O-related constants 

42DEFAULT_IMAGE_EXTENSION = ".tif" 

43DEFAULT_IMAGE_EXTENSIONS: Set[str] = {".tif", ".tiff", ".TIF", ".TIFF"} 

44DEFAULT_SITE_PADDING = 3 

45DEFAULT_RECURSIVE_PATTERN_SEARCH = False 

46DEFAULT_VARIABLE_COMPONENTS: List[VariableComponents] = [VariableComponents.SITE] 

47DEFAULT_GROUP_BY: GroupBy = GroupBy.CHANNEL 

48DEFAULT_MICROSCOPE: Microscope = Microscope.AUTO 

49 

50 

51 

52# Backend-related constants 

53class Backend(Enum): 

54 DISK = "disk" 

55 MEMORY = "memory" 

56 ZARR = "zarr" 

57 

58class FileFormat(Enum): 

59 TIFF = list(DEFAULT_IMAGE_EXTENSIONS) 

60 NUMPY = [".npy"] 

61 TORCH = [".pt", ".torch", ".pth"] 

62 JAX = [".jax"] 

63 CUPY = [".cupy",".craw"] 

64 TENSORFLOW = [".tf"] 

65 TEXT = [".txt",".csv",".json",".py",".md"] 

66 

67DEFAULT_BACKEND = Backend.MEMORY 

68REQUIRES_DISK_READ = "requires_disk_read" 

69REQUIRES_DISK_WRITE = "requires_disk_write" 

70FORCE_DISK_WRITE = "force_disk_write" 

71READ_BACKEND = "read_backend" 

72WRITE_BACKEND = "write_backend" 

73 

74# Default values 

75DEFAULT_TILE_OVERLAP = 10.0 

76DEFAULT_MAX_SHIFT = 50 

77DEFAULT_MARGIN_RATIO = 0.1 

78DEFAULT_PIXEL_SIZE = 1.0 

79DEFAULT_ASSEMBLER_LOG_LEVEL = "INFO" 

80DEFAULT_INTERPOLATION_MODE = "nearest" 

81DEFAULT_INTERPOLATION_ORDER = 1 

82DEFAULT_CPU_THREAD_COUNT = 4 

83DEFAULT_PATCH_SIZE = 128 

84DEFAULT_SEARCH_RADIUS = 20 

85# Consolidated definition for CPU thread count 

86 

87 

88# Memory-related constants 

89T = TypeVar('T') 

90ConversionFunc = Callable[[Any], Any] 

91 

92class MemoryType(Enum): 

93 NUMPY = "numpy" 

94 CUPY = "cupy" 

95 TORCH = "torch" 

96 TENSORFLOW = "tensorflow" 

97 JAX = "jax" 

98 PYCLESPERANTO = "pyclesperanto" 

99 

100CPU_MEMORY_TYPES: Set[MemoryType] = {MemoryType.NUMPY} 

101GPU_MEMORY_TYPES: Set[MemoryType] = { 

102 MemoryType.CUPY, 

103 MemoryType.TORCH, 

104 MemoryType.TENSORFLOW, 

105 MemoryType.JAX, 

106 MemoryType.PYCLESPERANTO 

107} 

108SUPPORTED_MEMORY_TYPES: Set[MemoryType] = CPU_MEMORY_TYPES | GPU_MEMORY_TYPES 

109 

110VALID_MEMORY_TYPES = {mt.value for mt in MemoryType} 

111VALID_GPU_MEMORY_TYPES = {mt.value for mt in GPU_MEMORY_TYPES} 

112 

113# Memory type constants for direct access 

114MEMORY_TYPE_NUMPY = MemoryType.NUMPY.value 

115MEMORY_TYPE_CUPY = MemoryType.CUPY.value 

116MEMORY_TYPE_TORCH = MemoryType.TORCH.value 

117MEMORY_TYPE_TENSORFLOW = MemoryType.TENSORFLOW.value 

118MEMORY_TYPE_JAX = MemoryType.JAX.value 

119MEMORY_TYPE_PYCLESPERANTO = MemoryType.PYCLESPERANTO.value 

120 

121DEFAULT_NUM_WORKERS = 1 

122# Consolidated definition for number of workers 

123DEFAULT_OUT_DIR_SUFFIX = "_out" 

124DEFAULT_POSITIONS_DIR_SUFFIX = "_positions" 

125DEFAULT_STITCHED_DIR_SUFFIX = "_stitched" 

126DEFAULT_WORKSPACE_DIR_SUFFIX = "_workspace"