harpy.externals.ilastik.run_object_classification

harpy.externals.ilastik.run_object_classification#

harpy.externals.ilastik.run_object_classification(sdata, image_name, labels_name, table_name, output_table_name, path_to_classifier, path_to_ilastik_executable, obs_key='ilastik_label', export_source='Object Predictions', instance_key='cell_ID', region_key='fov_labels', overwrite=False, output_dir=None, runtime_dir=None, lazyflow_threads=8, lazyflow_total_ram_mb=16000, unmapped_label=0, raise_on_unmapped_instance=False)#

Run ilastik headless object classification and add predicted labels to a table element.

Parameters:
  • sdata (SpatialData) – Backed SpatialData object stored as a Zarr v2 store.

  • image_name (str) – Image element used as ilastik raw input.

  • labels_name (str) – Labels element used as ilastik segmentation input and to map predictions back to table instances.

  • table_name (str | None) – Table element from which the annotated cells are selected. If None, a new table is created from the non-zero instance ids in labels_name.

  • output_table_name (str) – Output table element receiving the predicted ilastik labels in adata.obs[obs_key].

  • path_to_classifier (str | Path) – Path to the ilastik project .ilp file.

  • path_to_ilastik_executable (str | Path) – Path to the ilastik executable, or to the app directory containing the executable. Example: ".../ilastik".

  • obs_key (str (default: 'ilastik_label')) – Column name added to adata.obs with the predicted ilastik labels.

  • export_source (Literal['Blockwise Object Predictions', 'Object Predictions'] (default: 'Object Predictions')) – ilastik export source passed to --export_source. This must match the export source configured in the ilastik GUI/project, i.e. choose either "Blockwise Object Predictions" or "Object Predictions" consistently in both places.

  • instance_key (str (default: 'cell_ID')) – Name of the instance id column in adata.obs. Only used if table_name is None.

  • region_key (str (default: 'fov_labels')) – Name of the region column in adata.obs. Only used if table_name is None.

  • overwrite (bool (default: False)) – Whether to overwrite output_table_name if it already exists.

  • output_dir (str | Path | None (default: None)) – Directory for ilastik exported files. If None, a temporary directory is created.

  • runtime_dir (str | Path | None (default: None)) – Directory for ilastik runtime logs. If None, a temporary directory is created.

  • lazyflow_threads (int (default: 8)) – Value for the LAZYFLOW_THREADS environment variable.

  • lazyflow_total_ram_mb (int (default: 16000)) – Value for the LAZYFLOW_TOTAL_RAM_MB environment variable.

  • unmapped_label (int (default: 0)) – Label assigned to table rows whose instance_key is not present in the segmentation-to-prediction mapping. This only applies when raise_on_unmapped_instance is False.

  • raise_on_unmapped_instance (bool (default: False)) – If True, raise when a table instance id is not present in the segmentation mask instead of assigning unmapped_label.

Return type:

SpatialData

Returns:

: The updated SpatialData object.