Install
openclaw skills install @ruiduobao/netcdf-toolkitConvert NetCDF/HDF files to GeoTIFF, extract variables, subset by time and spatial bbox, and inspect file metadata. All processing is local — no data is uploaded.
openclaw skills install @ruiduobao/netcdf-toolkitProcess NetCDF and HDF files locally: convert to GeoTIFF, extract variables, subset by time range and spatial bounding box, and inspect file metadata.
pip install netCDF4 rasterio numpy
# 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
pip install netCDF4 rasterio numpy
# Or: pip install -r scripts/requirements.txt
info| Argument | Required | Default | Description |
|---|---|---|---|
--input | Yes | — | Input NetCDF/HDF file path |
--json | No | false | Output as JSON |
convert| Argument | Required | Default | Description |
|---|---|---|---|
--input | Yes | — | Input file path |
--variable | Yes | — | Variable name to convert |
--output | Yes | — | Output GeoTIFF path |
--time-index | No | 0 | Time step index |
extract| Argument | Required | Default | Description |
|---|---|---|---|
--input | Yes | — | Input file path |
--variables | Yes | — | Comma-separated variable names |
--output | Yes | — | Output NetCDF path |
subset| Argument | Required | Default | Description |
|---|---|---|---|
--input | Yes | — | Input file path |
--variable | Yes | — | Variable name |
--bbox | No | — | minlon,minlat,maxlon,maxlat |
--start | No | — | Start date (YYYY-MM-DD) |
--end | No | — | End date (YYYY-MM-DD) |
--output | Yes | — | Output file path |
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 EPSG:XXXX to override output CRSgdalwarp for reprojection--dtype: float32, float64, int16, int32--dtype int16 to reduce file size (with appropriate scaling)--nodata VALUE to set a custom nodata value--chunk to process in tiles--chunk 1024 processes 1024×1024 tilesinfo command first to assess file size and dimensionsinfo to list available subdatasets--subdataset PATH (e.g., /science/grids/data/temperature)info OutputFile: 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
YYYY-MM-DDTHH:MM:SSdays since 1900-01-01 or seconds since 1970-01-01--start and --end with YYYY-MM-DD format for subsettingrasterio.plot.show(): single-band visualizationmatplotlib subplots for different time stepsmatplotlib colormaps: cmap='viridis' for temperature, cmap='Blues' for precipitationmatplotlib.animation or xarray| Error | Cause | Solution |
|---|---|---|
ConnectionError | Network issue | Check internet, retry |
HTTP 429 | Rate limit | Wait 60s, retry |
ValueError | Invalid input | Check parameter format |
| Empty output | No data | Try different parameters |
ModuleNotFoundError | Missing dep | Run pip install |
MemoryError | File too large | Use --chunk for tiled processing |
KeyError | Variable not found | Check variable name with info |
| HDF subdataset error | Wrong path | Use info to list subdatasets |
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}
}
# 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
# .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
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
--subset with --bbox to extract only the area of interest (reduces memory)--sequential mode to limit memory usageh5netcdf engine; check availability with python scripts\netcdf-toolkit.py info --input file.hdf在本地处理 NetCDF 和 HDF 文件:转换为 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
使用 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
--crs EPSG:XXXX 覆盖输出 CRSgdalwarp 进行重投影--dtype 指定: float32, float64, int16, int32--dtype int16 减小文件大小(需适当缩放)--nodata VALUE 设置自定义 nodata 值--chunk 分块处理--chunk 1024 处理 1024×1024 瓦片info 命令评估文件大小和维度info 列出可用子数据集--subdataset PATH 访问子数据集(如 /science/grids/data/temperature)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
YYYY-MM-DDTHH:MM:SSdays since 1900-01-01 或 seconds since 1970-01-01--start 和 --end,格式为 YYYY-MM-DDrasterio.plot.show() 快速绘图: 单波段可视化matplotlib subplots 显示不同时间步matplotlib 色标: 温度用 cmap='viridis',降水用 cmap='Blues'matplotlib.animation 或 xarray 制作时间序列动画| 错误 | 原因 | 解决方案 |
|---|---|---|
ConnectionError | 网络问题 | 检查网络,重试 |
HTTP 429 | 速率限制 | 等待 60 秒后重试 |
ValueError | 无效输入 | 检查参数格式 |
| 空输出 | 无数据 | 尝试不同参数 |
ModuleNotFoundError | 缺少依赖 | 运行 pip install |
MemoryError | 文件过大 | 使用 --chunk 分块处理 |
KeyError | 变量未找到 | 使用 info 检查变量名 |
| HDF 子数据集错误 | 路径错误 | 使用 info 列出子数据集 |