Geoskill: Image Composite

Create cloud-masked multi-temporal composites from local Landsat or Sentinel-2 GeoTIFFs using median, mean, maxNDVI, or minRed methods.

ruiduobao

@ruiduobao

Install

$ openclaw skills install @ruiduobao/geoskill-image-composite

Image Composite

Create multi-temporal image composites from local GeoTIFF files. Supports cloud masking and multiple compositing methods. Works with Landsat and Sentinel-2 data.

Features

  • Median, mean, maxNDVI, and minRed compositing
  • Cloud masking via QA band or threshold
  • Landsat and Sentinel-2 band naming support
  • Handles multiple input files with progress reporting

Requirements

pip install rasterio numpy tqdm

Usage

# Median composite of multiple scenes
python scripts\image-composite.py composite --inputs scene1.tif scene2.tif scene3.tif --output composite.tif

# Mean composite
python scripts\image-composite.py composite --inputs *.tif --method mean --output mean_composite.tif

# maxNDVI composite (best vegetation)
python scripts\image-composite.py composite --inputs *.tif --method maxNDVI --output ndvi_composite.tif

# Cloud masking
python scripts\image-composite.py cloud-mask --input scene.tif --threshold 0.3 --output masked.tif

Installation

pip install rasterio numpy tqdm
# Or: pip install -r scripts/requirements.txt

Parameters

composite

ArgumentRequiredDefaultDescription
--inputsYesInput GeoTIFF files (2+)
--outputYesOutput composite path
--methodNomedianCompositing method: median, mean, maxNDVI, minRed
--cloud-maskNoOptional cloud mask file

cloud-mask

ArgumentRequiredDefaultDescription
--inputYesInput GeoTIFF file
--qa-bandNoQA band name or index
--thresholdNo0.3Cloud threshold (0-1)
--outputYesOutput masked file

Data Source

  • Input: Local GeoTIFF files (no download)
  • Processing: 100% local

maxNDVI Pixel Selection

The maxNDVI method selects, for each pixel position, the scene that has the highest NDVI value at that location. This produces a composite with the greenest, healthiest vegetation — ideal for creating cloud-free, maximum vegetation composites. NDVI is calculated as (NIR - Red) / (NIR + Red).

Band Requirements by Method

MethodRequired BandsDescription
medianAnyMedian of all valid pixels
meanAnyMean of all valid pixels
maxNDVIRed + NIRSelects pixel with highest NDVI
minRedRedSelects pixel with lowest red reflectance

Handling Mismatched Extents/Resolutions

  • Same extent, same resolution: Direct compositing (default)
  • Different resolution: Auto-reproject to finest resolution using nearest-neighbor
  • Different extent: Intersection of all extents (output covers overlapping area only)
  • Different CRS: Auto-reproject to first input's CRS
  • Use --target-crs and --target-resolution to override

QA Band Format (Landsat QA_PIXEL)

The QA_PIXEL band uses bit flags for cloud/shadow detection:

BitNameValueDescription
0Fill0/1Fill data
1Dilated Cloud0/1Dilated cloud
2Cirrus0/1Cirrus (Landsat 8/9)
3Cloud0/1Cloud
4Cloud Shadow0/1Cloud shadow
5Snow0/1Snow
6Clear0/1Clear
7Water0/1Water
  • Cloud-free pixels: bits 3-4 are 0
  • Use --qa-bit 3 to mask clouds, --qa-bit 3,4 for cloud + shadow

Memory Management

  • For large scenes (>2GB each), process in sequential mode with --sequential
  • Use --max-memory 4096 to limit RAM usage (MB)
  • Close other applications when compositing many high-res scenes
  • Output is written incrementally to reduce peak memory

Output Data Type

  • Default: preserves source data type (e.g., uint16 stays uint16)
  • Specify with --dtype: uint8, uint16, float32
  • Use --dtype float32 for methods requiring decimal precision (mean, median)

Landsat / Sentinel-2 Band Mapping

BandLandsat 8/9Sentinel-2
BlueSR_B2B2
GreenSR_B3B3
RedSR_B4B4
NIRSR_B5B8
SWIR1SR_B6B11
SWIR2SR_B7B12
QA_PIXELQA_PIXELSCL (Scene Classification)

Nodata Handling

  • Source nodata values are excluded from compositing
  • Output nodata: same as first input's nodata value
  • Use --nodata VALUE to set custom nodata
  • Pixels with nodata in ALL scenes remain nodata in output

Visualization

  • Quick preview: rasterio.plot.show(composite, cmap='terrain')
  • RGB composite: stack Red/Green/Blue bands with matplotlib
  • NDVI visualization: plt.imshow(ndvi, cmap='RdYlGn', vmin=-1, vmax=1)
  • Side-by-side comparison: use matplotlib subplots for before/after
  • Export to PNG: rasterio.plot.show(out_file='preview.png')

Troubleshooting

ErrorCauseSolution
ConnectionErrorNetwork issueCheck internet, retry
HTTP 429Rate limitWait 60s, retry
ValueErrorInvalid inputCheck parameter format
Empty outputNo dataTry different parameters
ModuleNotFoundErrorMissing depRun pip install
MemoryErrorToo many scenesUse --sequential or --max-memory
CRSErrorCRS mismatchUse --target-crs to unify
Band not foundWrong namingCheck band mapping table above

Citation

If you use this tool in your research, please cite the input data sources (e.g., USGS Landsat, ESA Sentinel-2) and acknowledge the compositing methodology:

@software{image_composite_2024,
  author = {ruiduobao},
  title = {Image Composite Tool},
  year = {2024},
  note = {Multi-temporal image compositing for Landsat/Sentinel-2}
}

For Landsat data: "Landsat data are provided by the U.S. Geological Survey and/or the National Aeronautics and Space Administration." For Sentinel-2 data: "Copernicus Sentinel data [2024] processed by ESA."


Advanced Usage

Weekly Composite Pipeline

# Composite all scenes from a week
python scripts\image-composite.py composite   --images S2A_20230101.tif S2A_20230105.tif S2A_20230110.tif   --method maxNDVI --sensor sentinel2   --output composite_week1.tif

CI/CD Integration (GitHub Actions)

# .github/workflows/weekly-composite.yml
name: Weekly Image Composite
on:
  schedule:
    - cron: '0 12 * * 1'  # Every Monday at 12:00
jobs:
  composite:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: '3.11'
      - run: pip install numpy rasterio
      - run: |
          python scripts\image-composite.py composite \
            --images data/scenes/*.tif \
            --method maxNDVI --sensor sentinel2 \
            --output data/composite_$(date +%Y%m%d).tif

Zonal Statistics with rasterio + GeoPandas

import rasterio
import geopandas as gpd
from rasterio.features import geometry_mask

with rasterio.open('composite.tif') as src:
    img = src.read(1)
    profile = src.profile

# Compute zonal stats for polygons
gdf = gpd.read_file('aoi.gdf')

Performance Tips

  • Use --max-memory to limit RAM usage for large scenes
  • --sequential mode reads one band at a time (slower but memory-safe)
  • Mismatched extents are handled by intersection; use --reference to control output grid

中文说明

从本地 GeoTIFF 文件创建多时相影像合成。支持云掩膜和多种合成方法。兼容 Landsat 和 Sentinel-2 数据。

功能

  • 中位数、平均值、最大 NDVI、最小红波段合成
  • 通过 QA 波段或阈值进行云掩膜
  • 支持 Landsat 和 Sentinel-2 波段命名
  • 多文件输入带进度报告

依赖

pip install rasterio numpy tqdm

使用方法

# 中位数合成
python scripts\image-composite.py composite --inputs scene1.tif scene2.tif scene3.tif --output composite.tif

# 平均值合成
python scripts\image-composite.py composite --inputs *.tif --method mean --output mean_composite.tif

# 最大 NDVI 合成(最佳植被)
python scripts\image-composite.py composite --inputs *.tif --method maxNDVI --output ndvi_composite.tif

# 云掩膜
python scripts\image-composite.py cloud-mask --input scene.tif --threshold 0.3 --output masked.tif

数据来源

  • 输入: 本地 GeoTIFF 文件(无下载)
  • 处理: 完全本地

maxNDVI 像素选择说明

maxNDVI 方法在每个像素位置选择 NDVI 值最高 的场景。这样生成的合成影像具有最绿、最健康的植被——适合创建无云、最大植被覆盖的合成影像。NDVI 计算公式: (NIR - Red) / (NIR + Red)

各合成方法的波段需求

方法所需波段描述
median任意所有有效像素的中位数
mean任意所有有效像素的平均值
maxNDVI红 + 近红外选择 NDVI 最高的像素
minRed红波段选择红反射率最低的像素

不匹配范围/分辨率的处理

  • 相同范围、相同分辨率: 直接合成(默认)
  • 不同分辨率: 使用最近邻法自动重投影到最高分辨率
  • 不同范围: 所有范围的交集(输出仅覆盖重叠区域)
  • 不同坐标系: 自动重投影到第一个输入的 CRS
  • 使用 --target-crs--target-resolution 覆盖默认行为

QA 波段格式 (Landsat QA_PIXEL)

QA_PIXEL 波段使用位标志进行云/阴影检测:

名称描述
0Fill0/1填充数据
1Dilated Cloud0/1膨胀云
2Cirrus0/1卷云(Landsat 8/9)
3Cloud0/1
4Cloud Shadow0/1云阴影
5Snow0/1
6Clear0/1晴空
7Water0/1水体
  • 无云像素: 位 3-4 为 0
  • 使用 --qa-bit 3 掩膜云,--qa-bit 3,4 掩膜云+阴影

内存管理

  • 大场景(>2GB/个)使用 --sequential 顺序处理
  • 使用 --max-memory 4096 限制内存使用(MB)
  • 合成多个高分辨率场景时关闭其他应用程序
  • 输出增量写入以降低峰值内存

输出数据类型

  • 默认: 保留源数据类型(如 uint16 保持 uint16)
  • 使用 --dtype 指定: uint8, uint16, float32
  • 需要小数精度的方法(mean, median)使用 --dtype float32

Landsat / Sentinel-2 波段映射表

波段Landsat 8/9Sentinel-2
SR_B2B2
绿SR_B3B3
SR_B4B4
近红外SR_B5B8
短波红外1SR_B6B11
短波红外2SR_B7B12
QA_PIXELQA_PIXELSCL (场景分类)

无数据值处理

  • 合成时排除源 nodata 值
  • 输出 nodata: 与第一个输入的 nodata 值相同
  • 使用 --nodata VALUE 设置自定义 nodata
  • 所有场景中均为 nodata 的像素在输出中仍为 nodata

可视化

  • 快速预览: rasterio.plot.show(composite, cmap='terrain')
  • RGB 合成: 使用 matplotlib 堆叠 Red/Green/Blue 波段
  • NDVI 可视化: plt.imshow(ndvi, cmap='RdYlGn', vmin=-1, vmax=1)
  • 并排比较: 使用 matplotlib subplots 显示前后对比
  • 导出 PNG: rasterio.plot.show(out_file='preview.png')

故障排除

错误原因解决方案
ConnectionError网络问题检查网络,重试
HTTP 429速率限制等待 60 秒后重试
ValueError无效输入检查参数格式
空输出无数据尝试不同参数
ModuleNotFoundError缺少依赖运行 pip install
MemoryError场景过多使用 --sequential--max-memory
CRSError坐标系不匹配使用 --target-crs 统一
波段未找到命名错误查看上方波段映射表

Top skills in this category

Using Superpowers

@zlc000190

Use when starting any conversation - establishes how to find and use skills, requiring Skill tool invocation before ANY response including clarifying questions

6336k

Marketing Skills

@jchopard69

Access 23 marketing modules offering checklists, frameworks, and ready-to-use deliverables for CRO, SEO, copywriting, analytics, launches, ads, and social me...

11519k

diagram-generator

@matthewyin

Generate and edit diagrams with the mcp-diagram-generator MCP server. Use this skill for new diagrams, existing .drawio/.mmd/.excalidraw edits, network topology, architecture, flowchart, swimlane, sequence, class, ER, and Excalidraw whiteboard work. Always use this skill when the user asks to draw,

4731k

Openclaw Command Center

@jontsai

Mission control dashboard for OpenClaw - real-time session monitoring, LLM usage tracking, cost intelligence, and system vitals. View all your AI agents in o...

7913k

novel-generator 是一个中文爽文小说生成技能。用户只需提供一句话方向(如"写个都市重生爽文"),AI 代理即可自动完善提示词、规划大纲、逐章创作并输出为独立 Markdown 文件。 核心特性: 智能提示词生成:从一句话方向自动补全世界观、人设、冲突、爽点设计 分章节创作:每章 2000-3000 字,层层递进,章章有爽点 记忆系统:通过 .learnings/ 记录角色、地点、情节、世界观,确保故事前后一致 情节图解:关键战斗、人物关系、势力分布自动生成 Mermaid 图 失败记录:穿帮、矛盾、崩塌等问题自动记录,持续优化 多题材支持:都市、修仙、玄幻、重生、系统流、末世、科幻、游戏 兼容 Claude Code、Cursor、OpenAI Codex、GitHub Copilot 等所有支持 Agent Skills 的工具。

@ityhg

根据用户提供的内容方向自动生成提示词并创作爽文小说。适用场景:(1) 用户提供小说方向/题材/关键词,(2) 需要生成章节连贯的长篇爽文,(3) 需要维护角色、地点、情节的连续性,(4) 需要为关键情节生成图解,(5) 需要记录生成失败场景以优化后续创作。支持都市、修仙、玄幻、重生、系统流等多种题材。Use wh...

7110k