Pipeline#

class rapidtools.processing.Pipeline(steps: list[Callable] | None = None, cancel_event: Event | None = None)[source]#

Bases: object

A sequence of processing steps applied to a PhysicalAssetCollection.

The pipeline is order-agnostic during construction. Every step declares the Stage it belongs to, and the steps are sorted by stage right before running, so an analyzer added before the extractor that feeds it still runs after it:

  1. DETECT: find assets (SAM3OrthoFeatureExtractor, MapillaryFeatureExtractor).

  2. EXTRACT_IMAGERY: gather images per asset (AerialImageryExtractor, DroneImageExtractor, …).

  3. REGULARIZE and SEGMENT: clean geometries and masks.

  4. VERIFY: drop false detections and duplicates.

  5. ANALYZE: run a vision-language model (AssetAnalyzer).

  6. EXPORT and anything without a stage.

Steps of the same stage keep the order they were added in. A pipeline with a single step simply runs it.

Parameters:
  • steps (list[Callable] | None, optional) – An optional list of initialized processing steps. Each step must be a callable accepting a PhysicalAssetCollection and returning a PhysicalAssetCollection. Defaults to an empty pipeline.

  • cancel_event (Event | None, optional) – A cooperative cancellation flag. When set (typically from another thread), the pipeline raises OperationCanceled before starting the next step. The event is also handed to every step that has a cancel_event of its own left at None, so the step in progress stops promptly too. Defaults to None.

Example

A detection pipeline needs no input collection, and one cancel event on the pipeline covers every step:

>>> import threading
>>> import rapidtools as rt
>>> stop = threading.Event()
>>> pipeline = rt.Pipeline(cancel_event=stop)
>>> pipeline.add_step(rt.AssetAnalyzer('gemma4', prompt='Damaged? yes/no'))
>>> pipeline.add_step(
...     rt.AerialImageryExtractor('data/ortho.tif', save_directory='crops')
... )
>>> buildings = rt.PhysicalAssetCollection.from_geojson('bldgs.geojson')
>>> processed = pipeline.run(buildings)

Methods

add_step

Add a new processing step to the pipeline.

run

Execute all steps in the pipeline in the correct logical sequence.

add_step(step: Callable) → Pipeline[source]#

Add a new processing step to the pipeline.

Parameters:

step (Callable) – A callable object (like an Extractor or Predictor instance) that accepts and returns a PhysicalAssetCollection.

Returns:

Pipeline – The Pipeline instance itself, allowing for method chaining.

Example

>>> from rapidtools.processing import Pipeline
>>> pipeline = Pipeline()
>>> pipeline.add_step(my_extractor).add_step(my_analyzer)
>>> len(pipeline.steps)
2
run(asset_collection: PhysicalAssetCollection | None = None) → PhysicalAssetCollection[source]#

Execute all steps in the pipeline in the correct logical sequence.

Parameters:

asset_collection (PhysicalAssetCollection | None) – The collection of assets to process. Leave it out for a pipeline that starts with a detection step, which builds the collection itself; an empty collection is used.

Returns:

PhysicalAssetCollection – The fully processed collection. If the pipeline has no steps, a warning is logged and the input is returned unchanged.

Raises:
  • OperationCanceled – If cancel_event is set before any step starts.

  • TypeError – If a step returns something other than a collection.

Example

>>> from rapidtools.processing import Pipeline
>>> pipeline = Pipeline([my_extractor, my_analyzer])
>>> processed = pipeline.run(my_collection)
>>> detected = Pipeline([my_detector, my_cropper]).run()