# Pansharpening Operation
#
# Fuses low-resolution multispectral imagery with high-resolution
# panchromatic imagery to produce high-resolution multispectral output.
#
# Common use cases:
# - Sentinel-2: 20m bands → 10m using 10m bands
# - Landsat: 30m multispectral → 15m using panchromatic
# - WorldView/Pleiades: multispectral → panchromatic resolution

id: imagery_pansharpening
name: Pansharpening
description: >
  Combine low-resolution multispectral image with high-resolution
  panchromatic image to produce high-resolution multispectral output.
  Uses spectral injection to preserve color while gaining spatial detail.
version: 1.0.0
category: imagery
type: raster-to-raster
default_implementation: otb

inputs:
  - name: panchromatic
    type: raster
    format: cog
    description: >
      High-resolution panchromatic image (single band).
      Should cover similar spectral range as multispectral bands.
    required: true

  - name: multispectral
    type: raster
    format: cog
    description: >
      Low-resolution multispectral image (multiple bands).
      Must be co-registered with panchromatic image.
    required: true

# Needs a panchromatic band + at least RGB multispectral. The classic
# pansharpening pipeline (RCS / LMVM / Bayes) injects pan-detail into the
# visible bands; rededge/NIR may also be present but are not strictly
# required. Listed bands are the op-level rollup across both inputs.
requires:
  bands: [pan, red, green, blue]

outputs:
  - name: pansharpened
    type: raster
    format: cog
    # concept: omitted — output is the input multispectral concept at
    # higher (panchromatic) resolution; the concept itself is preserved.
    description: >
      High-resolution multispectral image at panchromatic resolution.
      Same number of bands as multispectral input.

params:
  method:
    type: enum
    enum: [rcs, lmvm, bayes]
    default: rcs
    description: >
      Pansharpening algorithm:
      - rcs: RCS (default) - fast, good color preservation
      - lmvm: Local Mean Variance Matching - better edge preservation
      - bayes: Bayesian - best quality, slowest

execution:
  realtime_max_km2: 100
  cost_per_km2: 0.005
  time_per_km2_sec: 2.0
  memory_profile: high

# backends: audited 2026-08-14 (defect 50). A key means a runtime that DISPATCHES this op —
# folia-engine `dispatch_op` (products/sdk/folia-engine/src/lib.rs), a `registerOp`/OP_TABLE
# entry in packages/compute, `_BUILTIN_OP_MAP` in folia/compute.py, or a backend manifest
# (folia/backends/*/backend.yaml).
backends:
  python:
    function: geo.otb.pansharpening
    dispatch: folia/compute.py _BUILTIN_OP_MAP

display_hints:
  map:
    renderer: maplibre

cache_policy:
  ttl_days: 30
  invalidate_on: [source_update]

examples:
  - name: Sentinel-2 pansharpening
    description: Sharpen 20m bands using 10m bands
    inputs:
      panchromatic: "s2_B08_10m.tif"
      multispectral: "s2_B05_B06_B07_20m.tif"
    params:
      method: rcs
