fishtank.scripts.aggregate_polygons

fishtank.scripts.aggregate_polygons#

fishtank.scripts.aggregate_polygons(input, output='polygons.json', min_size=100, min_ioa=0.2, fovs=None, file_pattern='polygons_{fov}.json', cell_column='cell', z_column=None, x_offset_column='x_offset', y_offset_column='y_offset', positions=None, scale_factor=0.107, tolerance=0.5, save_union=False, flip_horizontal=False, flip_vertical=False, img_size=2304, **kwargs)#

Aggregate polygons from multiple FOVs.

fishtank aggregate-polygons -i input

Parameters:
  • input (str | Path) – Input file directory.

  • output (str | Path (default: 'polygons.json')) – Output file path.

  • min_size (float (default: 100)) – Minimum area/volume for a cell to be kept.

  • min_ioa (float (default: 0.2)) – Minimum intersection over area for merging cells.

  • fovs (Union[list[int], slice, None] (default: None)) – Fields of view to aggregate (e.g., 1 or 1,2,3 or 1:20:5).

  • file_pattern (str (default: 'polygons_{fov}.json')) – Naming pattern for polygon files.

  • cell_column (str (default: 'cell')) – Column containing cell ID.

  • z_column (Optional[str] (default: None)) – Column containing z-slice. None for 2D polygons.

  • x_offset_column (str (default: 'x_offset')) – Column containing x-offset.

  • y_offset_column (str (default: 'y_offset')) – Column containing y-offset.

  • positions (Union[str, Path, None] (default: None)) – Path to a two-column (no header) TSV file with x and y positions for each FOV. Row index corresponds to FOV number. When provided, overrides x_offset_column/y_offset_column.

  • scale_factor (float (default: 0.107)) – Factor for converting pixels to microns.

  • tolerance (float (default: 0.5)) – Tolerance from polygon simplification (microns).

  • save_union (bool (default: False)) – Save polygons flattened (unioned) to 2D.

  • img_size (float (default: 2304)) – Image size in pixels (width and height). Used to correct polygon coordinates after flipping.