Geoskill: NetCDF Toolkit

Process NetCDF/HDF files locally by converting variables to GeoTIFF, extracting variables, subsetting by time and spatial bbox, and inspecting metadata.

ruiduobao

@ruiduobao

What This Skill Does

Local command-line tool to convert NetCDF/HDF files to GeoTIFF, extract specific variables, subset by time range and spatial bounding box, and inspect file metadata. All processing happens on your machine with no data uploaded.

Replaces manual scripting with GDAL or Python libraries by providing a single CLI for common NetCDF/HDF geospatial operations.

When to Use It

  • Convert a NetCDF variable to GeoTIFF for use in GIS software
  • Extract specific variables from a multi-variable NetCDF file
  • Subset a NetCDF file by spatial bounding box and date range
  • Inspect metadata, dimensions, and attributes of a NetCDF/HDF file
  • Batch-process multiple NetCDF files into GeoTIFFs with a shell loop

Install

$ openclaw skills install @ruiduobao/netcdf-toolkit

NetCDF Toolkit

Process NetCDF and HDF files locally: convert to GeoTIFF, extract variables, subset by time range and spatial bounding box, and inspect file metadata.

Features

  • Show file metadata (variables, dimensions, attributes)
  • Convert any variable to GeoTIFF
  • Extract specific variables from multi-variable files
  • Subset by time range and spatial bbox
  • Batch-friendly design

Requirements

pip install netCDF4 rasterio numpy

Usage

# Show file info
python scripts\netcdf-toolkit.py info --input data.nc

# Convert a variable to GeoTIFF
python scripts\netcdf-toolkit.py convert --input data.nc --variable temperature --output temp.tif

# Extract variables
python scripts\netcdf-toolkit.py extract --input data.nc --variables temp,pressure --output subset.nc

# Subset spatially and temporally
python scripts\netcdf-toolkit.py subset --input data.nc --variable temp --bbox 73,18,135,54 --output subset.tif

Installation

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

Parameters

info

ArgumentRequiredDefaultDescription
--inputYesInput NetCDF/HDF file path
--jsonNofalseOutput as JSON

convert

ArgumentRequiredDefaultDescription
--inputYesInput file path
--variableYesVariable name to convert
--outputYesOutput GeoTIFF path
--time-indexNo0Time step index

extract

ArgumentRequiredDefaultDescription
--inputYesInput file path
--variablesYesComma-separated variable names
--outputYesOutput NetCDF path

subset

ArgumentRequiredDefaultDescription
--inputYesInput file path
--variableYesVariable name
--bboxNominlon,minlat,maxlon,maxlat
--startNoStart date (YYYY-MM-DD)
--endNoEnd date (YYYY-MM-DD)
--outputYesOutput file path

Data Source

  • Input: Local NetCDF/HDF files (no download)
  • Output: GeoTIFF, NetCDF
  • Processing: 100% local

Batch Processing

Loop over multiple files with a shell script:

# Convert all NetCDF files in a directory
for f in data/*.nc; do
  python scripts\netcdf-toolkit.py convert \
    --input "$f" \
    --variable temperature \
    --output "output/$(basename "$f" .nc).tif"
done

CRS Handling

  • Source CRS is preserved in output GeoTIFF (embedded in GeoTIFF tags)
  • If source CRS is missing, assumes WGS84 (EPSG:4326)
  • Use --crs EPSG:XXXX to override output CRS
  • Reprojection is not performed; use gdalwarp for reprojection

Output Data Type

  • Default: preserves source data type (e.g., float32 stays float32)
  • Specify with --dtype: float32, float64, int16, int32
  • Use --dtype int16 to reduce file size (with appropriate scaling)

Nodata Handling

  • Source nodata value is preserved in output
  • Use --nodata VALUE to set a custom nodata value
  • If source has no nodata attribute, output will also lack one

Memory / Large File Guidance

  • For files > 2GB, use --chunk to process in tiles
  • Chunk size specified in pixels: --chunk 1024 processes 1024×1024 tiles
  • Use info command first to assess file size and dimensions
  • Close other memory-intensive applications when processing large files

HDF Subdatasets

  • HDF5 files may contain multiple subdatasets
  • Use info to list available subdatasets
  • Access subdatasets with --subdataset PATH (e.g., /science/grids/data/temperature)
  • Common in NASA HDF-EOS (MODIS, AIRS) products

Example info Output

File: data.nc
Dimensions: time(365), lat(721), lon(1440)
Variables:
  temperature (float32): K, dims=(time, lat, lon)
  pressure (float32): Pa, dims=(time, lat, lon)
CRS: EPSG:4326
Bounds: -180.0, -90.0, 180.0, 90.0

Time Format

  • Time values follow ISO 8601: YYYY-MM-DDTHH:MM:SS
  • Time units attribute: days since 1900-01-01 or seconds since 1970-01-01
  • Use --start and --end with YYYY-MM-DD format for subsetting

Visualization

  • Quick plot with rasterio.plot.show(): single-band visualization
  • Multi-panel time series: use matplotlib subplots for different time steps
  • Use matplotlib colormaps: cmap='viridis' for temperature, cmap='Blues' for precipitation
  • Animate time series with matplotlib.animation or xarray

Troubleshooting

ErrorCauseSolution
ConnectionErrorNetwork issueCheck internet, retry
HTTP 429Rate limitWait 60s, retry
ValueErrorInvalid inputCheck parameter format
Empty outputNo dataTry different parameters
ModuleNotFoundErrorMissing depRun pip install
MemoryErrorFile too largeUse --chunk for tiled processing
KeyErrorVariable not foundCheck variable name with info
HDF subdataset errorWrong pathUse info to list subdatasets

Citation

If you use this tool in your research, please cite the input data source (e.g., NASA, NOAA, ECMWF) and acknowledge this tool:

@software{netcdf_toolkit_2024,
  author = {ruiduobao},
  title = {NetCDF Toolkit},
  year = {2024},
  note = {NetCDF/HDF to GeoTIFF conversion and subsetting}
}

Advanced Usage

Batch Convert Multiple Files

# Convert all NetCDF files in a directory to GeoTIFF
for f in data/*.nc; do
  python scripts\netcdf-toolkit.py convert     --input "$f" --variable Band1 --output "${f%.nc}.tif"
done

CI/CD Integration (GitHub Actions)

# .github/workflows/convert-netcdf.yml
name: Convert NetCDF Batch
on:
  push:
    paths: ['data/*.nc']
jobs:
  convert:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: '3.11'
      - run: pip install numpy h5netcdf rasterio
      - run: |
          for f in data/*.nc; do
            python scripts\netcdf-toolkit.py convert \
              --input "$f" --variable Band1 --output "${f%.nc}.tif"
          done

PostgreSQL/PostGIS Raster Import

python scripts\netcdf-toolkit.py convert   --input temperature.nc --variable t2m --output t2m.tif

raster2pgsql -s 4326 -I -C t2m.tif public.t2m_raster | psql -d gis_db

Performance Tips

  • Use --subset with --bbox to extract only the area of interest (reduces memory)
  • For large files, use --sequential mode to limit memory usage
  • HDF4 files require h5netcdf engine; check availability with python scripts\netcdf-toolkit.py info --input file.hdf

中文说明

在本地处理 NetCDF 和 HDF 文件:转换为 GeoTIFF、提取变量、按时间和空间子集、查看文件元数据。

功能

  • 查看文件元数据(变量、维度、属性)
  • 将任意变量转换为 GeoTIFF
  • 从多变量文件中提取指定变量
  • 按时间范围和空间边界子集
  • 支持批量处理

依赖

pip install netCDF4 rasterio numpy

使用方法

# 查看文件信息
python scripts\netcdf-toolkit.py info --input data.nc

# 转换变量为 GeoTIFF
python scripts\netcdf-toolkit.py convert --input data.nc --variable temperature --output temp.tif

# 提取变量
python scripts\netcdf-toolkit.py extract --input data.nc --variables temp,pressure --output subset.nc

# 空间和时间子集
python scripts\netcdf-toolkit.py subset --input data.nc --variable temp --bbox 73,18,135,54 --output subset.tif

数据来源

  • 输入: 本地 NetCDF/HDF 文件(无下载)
  • 输出: GeoTIFF, NetCDF
  • 处理: 完全本地

批量处理

使用 shell 脚本循环处理多个文件:

# 转换目录中所有 NetCDF 文件
for f in data/*.nc; do
  python scripts\netcdf-toolkit.py convert \
    --input "$f" \
    --variable temperature \
    --output "output/$(basename "$f" .nc).tif"
done

坐标系处理

  • 输出 GeoTIFF 中保留源 CRS(嵌入 GeoTIFF 标签)
  • 如果源 CRS 缺失,假定为 WGS84 (EPSG:4326)
  • 使用 --crs EPSG:XXXX 覆盖输出 CRS
  • 不执行重投影;使用 gdalwarp 进行重投影

输出数据类型

  • 默认: 保留源数据类型(如 float32 保持 float32)
  • 使用 --dtype 指定: float32, float64, int16, int32
  • 使用 --dtype int16 减小文件大小(需适当缩放)

无数据值处理

  • 输出中保留源 nodata 值
  • 使用 --nodata VALUE 设置自定义 nodata 值
  • 如果源没有 nodata 属性,输出也将缺少该属性

内存/大文件指南

  • 对于 > 2GB 的文件,使用 --chunk 分块处理
  • 块大小以像素指定: --chunk 1024 处理 1024×1024 瓦片
  • 先用 info 命令评估文件大小和维度
  • 处理大文件时关闭其他内存密集型应用程序

HDF 子数据集

  • HDF5 文件可能包含多个子数据集
  • 使用 info 列出可用子数据集
  • 使用 --subdataset PATH 访问子数据集(如 /science/grids/data/temperature
  • 常见于 NASA HDF-EOS (MODIS, AIRS) 产品

info 输出示例

File: data.nc
Dimensions: time(365), lat(721), lon(1440)
Variables:
  temperature (float32): K, dims=(time, lat, lon)
  pressure (float32): Pa, dims=(time, lat, lon)
CRS: EPSG:4326
Bounds: -180.0, -90.0, 180.0, 90.0

时间格式

  • 时间值遵循 ISO 8601: YYYY-MM-DDTHH:MM:SS
  • 时间单位属性: days since 1900-01-01seconds since 1970-01-01
  • 子集操作使用 --start--end,格式为 YYYY-MM-DD

可视化

  • 使用 rasterio.plot.show() 快速绘图: 单波段可视化
  • 多面板时间序列: 使用 matplotlib subplots 显示不同时间步
  • 使用 matplotlib 色标: 温度用 cmap='viridis',降水用 cmap='Blues'
  • 使用 matplotlib.animationxarray 制作时间序列动画

故障排除

错误原因解决方案
ConnectionError网络问题检查网络,重试
HTTP 429速率限制等待 60 秒后重试
ValueError无效输入检查参数格式
空输出无数据尝试不同参数
ModuleNotFoundError缺少依赖运行 pip install
MemoryError文件过大使用 --chunk 分块处理
KeyError变量未找到使用 info 检查变量名
HDF 子数据集错误路径错误使用 info 列出子数据集

Top skills in this category

PollyReach

@pollyreach

PollyReach gives every AI agent a phone number and the ability to get things done over the phone — finding contacts, making calls, and completing tasks. Just...

55101k

Proactive Agent Lite

@bestrocky

Transform AI agents from task-followers into proactive partners with memory architecture, reverse prompting, and self-healing patterns. Lightweight version f...

6241k

Planning with files

@othmanadi

Manus-style persistent file-based planning for AI coding agents: keeps task_plan.md, findings.md, and progress.md on disk so work survives context loss and /clear. Use when asked to plan out, break down, or organize a multi-step project, research task, or any work requiring 5+ tool calls. Supports a

5440k

Productivity

@ivangdavila

Diagnoses and repairs personal productivity: overwhelm, procrastination, scattered priorities, collapsed habits, busywork that never finishes. Use when someone is overwhelmed or behind; when they cannot start, cannot stop, or keep replanning instead of working; when everything feels urgent and the list is no longer trusted; when goals never turn into shipped work; when meetings and messages eat the day; when a habit keeps breaking; when they want a weekly review, a shutdown routine, or one trusted home for goals, projects and commitments; and when the constraint is a situation — student, manager, executive, parent, freelancer, founder, creative, remote work, ADHD, burnout, or guilt about resting. Covers capacity math, estimation, WIP limits, delegation and saying no. Not for calendar-API automation (`calendar-planner`), running the day-to-day list (`task-list`), or the narrower tools: time blocking (`time-management`), habit streaks (`habits`), deep-work rituals (`deep-work`).

6926k

Agent Autonomy Kit

@ryancampbell

Stop waiting for prompts. Keep working.

7020k