Coverage for openhcs/processing/__init__.py: 36.4%

9 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-11-04 02:09 +0000

1""" 

2Image processing module for openhcs. 

3 

4This module provides image processing functionality for openhcs, 

5including image normalization, sharpening, and other operations. 

6 

7It also includes a function registry system that automatically registers 

8functions decorated with memory type decorators (@numpy, @cupy, etc.) for 

9runtime discovery and inspection. 

10 

11Doctrinal Clauses: 

12- Clause 3 — Declarative Primacy: All functions are pure and stateless 

13- Clause 88 — No Inferred Capabilities: Explicit backend requirements 

14- Clause 106-A — Declared Memory Types: All methods specify memory types 

15- Clause 273 — Memory Backend Restrictions: GPU-only implementations are marked 

16""" 

17 

18 

19# Import function registry components (these don't import GPU libs) 

20from openhcs.processing.func_registry import (FUNC_REGISTRY, 

21 get_function_info, 

22 get_functions_by_memory_type, 

23 get_function_by_name, 

24 get_all_function_names, 

25 get_valid_memory_types, 

26 is_registry_initialized) 

27# Import decorators directly from core module (function_registry.py is deprecated) 

28from openhcs.core.memory.decorators import (cupy, jax, numpy, 

29 pyclesperanto, tensorflow, torch) 

30 

31 

32def __getattr__(name: str): 

33 """ 

34 Lazy import of backend subpackages via reflection. 

35 

36 Backend subpackages import GPU libraries (torch, cupy, jax, tensorflow) 

37 at module level, which takes 8+ seconds. We defer these imports until 

38 they're actually needed. 

39 

40 Mathematical property: If name ∈ __all__ ∧ name ∉ globals(), then 

41 name must be a lazy backend subpackage that exists at the derived path. 

42 

43 Args: 

44 name: Attribute name to resolve 

45 

46 Returns: 

47 Imported backend module 

48 

49 Raises: 

50 AttributeError: If attribute is not in __all__ or import fails 

51 """ 

52 # Reflection: Check if name is declared in __all__ (our contract) 

53 if name not in __all__: 

54 raise AttributeError(f"module '{__name__}' has no attribute '{name}'") 

55 

56 # Mathematical derivation: Construct import path from module structure 

57 # __name__ = 'openhcs.processing' 

58 # name = 'enhance' 

59 # ∴ import_path = 'openhcs.processing.backends.enhance' 

60 import_path = f"{__name__}.backends.{name}" 

61 

62 # Import and return the backend module 

63 import importlib 

64 return importlib.import_module(import_path) 

65 

66 

67__all__ = [ 

68 # Image processor components 

69 

70 # Function registry components 

71 "numpy", "cupy", "torch", "tensorflow", "jax", 

72 "FUNC_REGISTRY", "get_functions_by_memory_type", "get_function_info", 

73 "get_valid_memory_types", "is_registry_initialized", 

74 

75 # Backend subpackages (lazy loaded via __getattr__) 

76 "processors", 

77 "enhance", 

78 "pos_gen", 

79 "assemblers", 

80 "analysis", 

81]