Pipeline#
- class rapidtools.processing.Pipeline(steps: list[Callable] | None = None, cancel_event: Event | None = None)[source]#
Bases:
objectA sequence of processing steps applied to a PhysicalAssetCollection.
The pipeline is order-agnostic during construction. Every step declares the
Stageit 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:DETECT: find assets (SAM3OrthoFeatureExtractor,MapillaryFeatureExtractor).EXTRACT_IMAGERY: gather images per asset (AerialImageryExtractor,DroneImageExtractor, …).REGULARIZEandSEGMENT: clean geometries and masks.VERIFY: drop false detections and duplicates.ANALYZE: run a vision-language model (AssetAnalyzer).EXPORTand 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
PhysicalAssetCollectionand returning aPhysicalAssetCollection. Defaults to an empty pipeline.cancel_event (Event | None, optional) – A cooperative cancellation flag. When set (typically from another thread), the pipeline raises
OperationCanceledbefore starting the next step. The event is also handed to every step that has acancel_eventof its own left atNone, so the step in progress stops promptly too. Defaults toNone.
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 a new processing step to the pipeline.
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_eventis 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()