Coverage for src/cell_abm_pipeline/flows/generate_voronoi_tessellation.py: 0%

32 statements  

« prev     ^ index     » next       coverage.py v7.1.0, created at 2024-06-05 19:14 +0000

1""" 

2Workflow for generating Voronoi tessellation images. 

3 

4For each condition, a Voronoi tessellation is applied to the nuclear 

5segmentation to approximate the cell shape. The number of iterations and the 

6target height can be used to refine the tessellation to produce realistic cell 

7volumes. 

8""" 

9 

10from dataclasses import dataclass 

11 

12from abm_initialization_collection.image import create_voronoi_image 

13from io_collection.keys import make_key 

14from io_collection.load import load_image 

15from io_collection.save import save_image 

16from prefect import flow 

17 

18 

19@dataclass 

20class ParametersConfig: 

21 """Parameter configuration for generate voronoi tessellation flow.""" 

22 

23 channel: int 

24 """Image channel.""" 

25 

26 iterations: int 

27 """Number of boundary estimation steps.""" 

28 

29 target_height: int 

30 """Target height in voxels.""" 

31 

32 

33@dataclass 

34class ContextConfig: 

35 """Context configuration for generate voronoi tessellation flow.""" 

36 

37 working_location: str 

38 """Location for input and output files (local path or S3 bucket).""" 

39 

40 

41@dataclass 

42class SeriesConfig: 

43 """Series configuration for generate voronoi tessellation flow.""" 

44 

45 name: str 

46 """Name of the simulation series.""" 

47 

48 conditions: list[dict] 

49 """List of series condition dictionaries (must include unique condition "key").""" 

50 

51 

52@flow(name="generate-voronoi-tessellation") 

53def run_flow(context: ContextConfig, series: SeriesConfig, parameters: ParametersConfig) -> None: 

54 """Main generate voronoi tessellation flow.""" 

55 

56 for key in series.conditions: 

57 image_key = make_key(series.name, "images", f"{series.name}_{key['key']}.tiff") 

58 image = load_image(context.working_location, image_key, "ZYX") 

59 

60 voronoi = create_voronoi_image( 

61 image, parameters.channel, parameters.iterations, parameters.target_height 

62 ) 

63 

64 voronoi_key = make_key( 

65 series.name, 

66 "images", 

67 f"{series.name}_{key['key']}_C{parameters.channel:02}_voronoi.ome.tiff", 

68 ) 

69 save_image(context.working_location, voronoi_key, voronoi)