Skip to content

Add unified MaskBuilder class replacing mixin-based factory pattern#30

Draft
Copilot wants to merge 2 commits intofeature/refactor-maskbuilder-for-xaifrom
copilot/simplify-mask-builders
Draft

Add unified MaskBuilder class replacing mixin-based factory pattern#30
Copilot wants to merge 2 commits intofeature/refactor-maskbuilder-for-xaifrom
copilot/simplify-mask-builders

Conversation

Copy link
Contributor

Copilot AI commented Feb 23, 2026

The mask builder system required composing 12+ mixin classes via MaskBuilderFactory to get a usable builder — opaque, fragile, and hard to type correctly.

Changes

  • New MaskBuilder class (mask_builders/builder.py): Single concrete class with explicit, typed init arguments. No mixins, no factory. Implements all pipeline stages (storage allocation, coordinate scaling, scalar expansion, edge clipping, aggregation) directly.

    • storage: Literal["memmap", "in-memory"]
    • aggregation: Literal["mean", "max"]
    • auto_scale: bool — auto-computes mask extents and scales coordinates from source to mask space
    • expand_scalars: bool — GCD-compressed per-tile scalar expansion
    • StorageType and AggregationType type aliases exported for annotations
  • __init__.py: Exports MaskBuilder, StorageType, AggregationType alongside existing symbols (fully backward-compatible; all mixin classes and MaskBuilderFactory preserved).

Usage

from ratiopath.masks.mask_builders import MaskBuilder

builder = MaskBuilder(
    storage="memmap",       # "memmap" | "in-memory"
    aggregation="mean",     # "mean" | "max"
    auto_scale=True,
    source_extents=source_extents,
    source_tile_extents=tile_extents,
    source_tile_strides=tile_strides,
    mask_tile_extents=tile_extents,
    channels=3,
    px_to_clip=2,
    dtype=np.float32,
)

builder.update_batch(data_batch, coords_batch)
assembled, overlap = builder.finalize()
Original prompt

Simplify the mask builders. Do not use mixins but instead use proper init arguments and classes. The output should be a single MaskBuilder class with arguments such as storage="mammap" | "in-memory". Everything should be properly typed.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: matejpekar <69220871+matejpekar@users.noreply.github.com>
Copilot AI force-pushed the copilot/simplify-mask-builders branch from 6dcea26 to 2224b62 Compare February 23, 2026 20:24
Copilot AI changed the title [WIP] Simplify mask builders to a single class Add unified MaskBuilder class replacing mixin-based factory pattern Feb 23, 2026
Copilot AI requested a review from matejpekar February 23, 2026 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants