# catalog/operations/raster/resample.yaml

id: raster_resample
name: Resample
description: >
  Resample raster to a new resolution while maintaining the same CRS.
  Useful for changing resolution without reprojecting.
version: 1.0.0
category: raster
type: raster-to-raster
default_implementation: native

inputs:
  - name: raster
    type: raster
    format: geotiff
    description: Input raster to resample
    required: true

requires: {}  # structural — operates on any raster

outputs:
  - name: resampled
    type: raster
    format: cog
    description: Resampled raster at target resolution

params:
  resolution:
    type: number
    required: true
    description: Target resolution in the raster's CRS units
    min: 0.0001
    max: 100000
  method:
    type: enum
    default: bilinear
    enum: [nearest, bilinear, cubic, average, mode]
    description: >
      Resampling method:
      - nearest: fast, preserves categorical values
      - bilinear: good for continuous data upsampling
      - cubic: smoother, may overshoot
      - average: good for downsampling continuous data
      - mode: good for downsampling categorical data

granularity:
  min_resolution_m: 0.1
  max_resolution_m: 100000
  output_resolution: fixed
  requires_continuous: false
  suitable_aoi_km2:
    min: 0.001
    max: 1000000
  realtime_max_km2: 1000

uncertainty:
  error_model: additive
  factors:
    - name: resampling_artifacts
      description: "Downsampling loses detail; upsampling invents detail"
      severity: medium
      mitigations:
        - "Use 'average' for downsampling continuous data"
        - "Use 'mode' for downsampling categorical data"
        - "Use 'nearest' to preserve exact values"
  limitations:
    - "Upsampling beyond 2x source resolution adds no real information"

execution:
  realtime_max_km2: 1000
  cost_per_km2: 0.0003
  time_per_km2_sec: 0.1
  memory_profile: medium
  profile:
    cpu: low
    memory: medium
    io: high
  scaling:
    model: linear
    parallelizable: true
    min_chunk_km2: 1

cache_policy:
  ttl_days: 365
  invalidate_on: [source_update, param_change]

# 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:
  rust-wasm:
    handle_function: h_raster_resample
  js:
    function: raster_resample
  python:
    function: geo.raster.resample
    dispatch: folia/compute.py _BUILTIN_OP_MAP

display_hints:
  map:
    renderer: maplibre

ui:
  icon: maximize
  color: "#4682B4"
