gmt-beginner

A beginner one‑click installation and mapping tutorial for GMT (Generic Mapping Tools). Automatically detects the operating system (Linux/macOS/Windows) and configures the environment to install GMT. Covers projections, color, and feature drawing. Includes OpenTopography DEM API configuration. All software and tutorial references are from the GMT Chinese community (https://docs.gmt-china.org/latest/).

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "gmt-beginner" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-245c32b6b2e4880ce9a908b22fbf318f711f95610f83bf983c1345a8903a64ad. Verify the upstream source and version against https://skillhub.cn/skills/user_1e091b22/gmt-for-agent before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

skillhub.cn

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

A beginner one‑click installation and mapping tutorial for GMT (Generic Mapping Tools). Automatically detects the operating system (Linux/macOS/Windows) and configures the environment to install GMT. Covers projections, color, and feature drawing. Includes OpenTopography DEM API configuration. All software and tutorial references are from the GMT Chinese community (https://docs.gmt-china.org/latest/).

0 Downloads

Introduction source: third_party · user_1e091b22 · 1.0.0 Reference

SkillPi interpretation

Tasks
Translation pending; see source documentation.
Software, accounts and paid services
conda config --set solver classic 2>/dev/null CONDA_NO_PLUGINS=true conda create -y -n gmt -c conda-forge gmt conda config --set solver libmamba 2>/dev/null
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: gmt-beginner
description: "GMT (Generic Mapping Tools) 零基础一键安装与制图教程。自动检测操作系统 (Linux/macOS/Windows),一键配置环境并安装 GMT。涵盖投影、颜色、要素绘制。附带 OpenTopography DEM API 配置。所有软件和教程引用自 GMT 中文社区 (https://docs.gmt-china.org/latest/)。"

GMT 制图入门 — 一键部署 + 零基础教程

声明:本 skill 中的软件安装方法、绘图语法、示例数据均引用自 GMT 中文社区(https://docs.gmt-china.org/latest/)。本 skill 仅将这些知识封装为 Hermes Agent 可调用的自动化流程。

触发条件

用户提到:GMT、制图、地图绘制、Generic Mapping Tools、地形图、DEM、投影、GMT教程、安装GMT


第零步:自动检测系统并安装 GMT(Agent 必须首先执行)

加载本 skill 后,Agent 必须:

0.1 检测操作系统

# Agent 执行此命令判断 OS
uname -s
# Darwin → macOS
# Linux  → Linux
# MINGW* / MSYS* / CYGWIN* → Windows (Git Bash)

0.2 检测是否已安装 GMT

gmt --version 2>/dev/null || echo "NOT_INSTALLED"

如果已安装,跳过安装步骤。

0.3 一键安装(按 OS 自动选择方案)


▸ Linux 安装

# 方案 A:Conda(推荐,跨平台统一)
# 1. 安装 Miniconda(如果没有)
if ! command -v conda &>/dev/null; then
    curl -sL "https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh" -o /tmp/miniconda.sh
    bash /tmp/miniconda.sh -b -p ~/miniconda3
    export PATH="$HOME/miniconda3/bin:$PATH"
fi

# 2. 配置 conda-forge
conda config --add channels conda-forge 2>/dev/null
conda config --set channel_priority strict 2>/dev/null

# 3. 接受 TOS(conda 26+)
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main 2>/dev/null
conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r 2>/dev/null

# 4. 安装 GMT 到独立环境
conda config --set solver classic 2>/dev/null
CONDA_NO_PLUGINS=true conda create -y -n gmt -c conda-forge gmt
conda config --set solver libmamba 2>/dev/null

# 5. 持久化 PATH
SHELL_RC="$HOME/.bashrc"
grep -q "conda3/envs/gmt/bin" "$SHELL_RC" 2>/dev/null || \
    echo 'export PATH="$HOME/miniconda3/envs/gmt/bin:$PATH"' >> "$SHELL_RC"

# 6. 验证
export PATH="$HOME/miniconda3/envs/gmt/bin:$PATH"
gmt --version

# 方案 B:系统包管理器(备选)
# sudo apt install gmt gmt-dcw gmt-gshhg -y   # Ubuntu/Debian

▸ macOS 安装

# 方案 A:Homebrew(推荐)
if ! command -v brew &>/dev/null; then
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
brew install gmt

# 方案 B:Conda(同 Linux 方案,跨平台一致)

▸ Windows 安装

# 推荐方案:Conda(与 Linux/macOS 统一环境,避免路径问题)
# 前提:需要安装 Git Bash 或 Miniconda Prompt

# 1. 安装 Miniconda for Windows(如果没有)
#    手动下载:https://docs.conda.io/en/latest/miniconda.html
#    或用 curl(在 Git Bash 中):
if ! command -v conda &>/dev/null; then
    curl -sL "https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe" -o /tmp/miniconda.exe
    start /wait "" /tmp/miniconda.exe /InstallationType=JustMe /RegisterPython=0 /S /D=%UserProfile%\miniconda3
    export PATH="$HOME/miniconda3/bin:$HOME/miniconda3/Scripts:$PATH"
fi

# 2. 安装 GMT(同 Linux 流程)
conda config --add channels conda-forge
conda create -y -n gmt -c conda-forge gmt

# 3. 持久化 PATH
#    在 Git Bash 的 ~/.bashrc 中添加:
echo 'export PATH="$HOME/miniconda3/envs/gmt/bin:$PATH"' >> ~/.bashrc

# 4. 验证
export PATH="$HOME/miniconda3/envs/gmt/bin:$PATH"
gmt --version

Windows 特别说明:如果用户没有 Git Bash,Agent 应引导用户先安装 Git for Windows(https://git-scm.com/download/win),然后用 Git Bash 执行上述命令。Conda 方案保证与 Linux/macOS 完全一致的 GMT 6.x 环境。

0.4 安装后验证

gmt begin first_map pdf
    gmt basemap -R0/10/0/10 -JX10c -Baf -B+t"My First GMT Map"
gmt end
# 检查是否生成 first_map.pdf
ls -lh first_map.pdf

第一步:GMT 核心概念

1.1 现代模式(Modern Mode)

gmt begin 输出文件名 格式    # 如 map pdf
    # 所有绘图命令...
gmt end

1.2 三个核心参数:-R -J -B

参数 含义 示例
-R 绘图区域 -R114/123/34/38 (lon1/lon2/lat1/lat2)
-J 投影方式 -JM15c (Mercator, 宽15cm)
-B 边框标注 -B2 -BWSen

每个 GMT 绘图命令都必须包含 -R 和 -J。

1.3 图层模型

第 6 层  gmt text      文字标注      ← 最上面
第 5 层  gmt plot      散点符号
第 4 层  gmt legend    图例
第 3 层  gmt coast     海岸线
第 2 层  gmt grdimage  DEM 底图
第 1 层  gmt basemap   底图框架      ← 最下面

第二步:常用投影速查

投影 -J 写法 场景
Mercator -JM15c 区域地图
Lambert -JL120/36/33/42/15c 中纬度
Hammer -JH120/15c 全球概览
Orthographic -JG120/36/15c 地球视角
线性 -JX10c/8c XY散点图

第三步:颜色选用(CPT)

CPT 效果
-Cterra ★ 地形首选
-Cglobe 卫星图风格
-Crainbow 彩虹色
-Chot 热力色
-Cpolar 两极色
-Cgray 灰度

地形加光照:-I+d(自动光照)


第四步:要素绘制

4.1 海岸线

gmt coast -W0.3p,gray30 -Slightblue -Df
# 关键坑:DEM 上图叠加 coast 不要用 -G,会盖住地形

4.2 散点符号

gmt plot data.txt -Sc0.3c -Gred -W0.5p,black
# -Sc=圆 -Ss=方 -St=三角 -Sd=菱 -Sa=星

4.3 文字标注

gmt text labels.txt -F+f12p,4,black -DJ0.3c/0.2c
# 字体编号: 4=Times-Roman, 5=Times-Bold, 0=Helvetica

4.4 色标

gmt colorbar -Cterra -DJTC+w8c/0.5c+h -Baf+l"Elevation (m)"

4.5 图例

gmt legend -DJTR+o0.3c -F+gwhite+p0.5p << EOF
S 0.3c c 0.3c red  0.5p,black 0.7c  Group A
EOF

第五步:DEM 地形数据获取

方案概览

数据源 分辨率 覆盖 是否需要 API Key 国内可用
中科大 rsync 30弧分~15弧秒 全球 否 ✅
Copernicus S3 30m 全球 否 ✅
OpenTopography 30m/90m 全球 是(免费注册) ✅

5.1 中科大 rsync(低分辨率全球数据)

rsync -av mirrors.ustc.edu.cn::gmtdata/server/earth/earth_relief/earth_relief_30m_g.grd ~/.gmt/cache/

5.2 Copernicus S3(高分辨率区域数据)

wget -O N36E117.tif \
  "https://copernicus-dem-30m.s3.amazonaws.com/Copernicus_DSM_COG_10_N36_00_E117_00_DEM/Copernicus_DSM_COG_10_N36_00_E117_00_DEM.tif"

5.3 OpenTopography API(★ 推荐,最灵活的高分辨率 DEM)

OpenTopography 是全球高分辨率地形数据的开放平台,提供 30m/90m SRTM、ALOS、Copernicus 等数据集的 API 访问。GMT 6 内置了 OpenTopography 数据源支持,配置后可直接用 @earth_relief_01s 语法下载。

第 1 步:注册获取 API Key

  1. 打开 https://portal.opentopography.org/register
  2. 填写邮箱、姓名、机构,注册免费账号
  3. 登录后进入 MyOpenTopo → https://portal.opentopography.org/dashboard
  4. 在 dashboard 页面可以看到你的 API Key

第 2 步:把 API Key 告诉 Agent

用户将 API Key 发给 Agent 后,Agent 执行:

# 方式一:设置环境变量(推荐,不写入配置文件)
export OPENTOPO_API_KEY="你的API_KEY"

# 持久化到 shell 配置
echo 'export OPENTOPO_API_KEY="你的API_KEY"' >> ~/.bashrc
source ~/.bashrc
# 方式二:写入 GMT 配置文件(仅当前会话)
gmt set GMT_DATA_SERVER_OPENTOPO_API_KEY "你的API_KEY"

第 3 步:Agent 自动下载 DEM

配置好 API Key 后,Agent 可以直接用 GMT 内置语法:

# 下载研究区域的 1弧秒 SRTM DEM(自动通过 OpenTopography API)
gmt grdcut @earth_relief_01s -R114/123/34/38 -Gstudy_area.grd

# 直接绘图
gmt begin dem_map pdf
    gmt grdimage study_area.grd -Cterra -I+d -JM15c -Baf
    gmt coast -W0.3p -Swhite
gmt end

支持的 OpenTopography 数据集: | GMT 语法 | 分辨率 | 数据集 | |----------|--------|--------| | @earth_relief_01s | 1弧秒 (~30m) | SRTM GL1 / ALOS World 3D | | @earth_relief_03s | 3弧秒 (~90m) | SRTM GL3 | | @earth_relief_15s | 15弧秒 (~450m) | SRTM15+ | | @srtm_relief_01s | 1弧秒 | SRTM only | | @srtm_relief_03s | 3弧秒 | SRTM only |

Agent 与用户交互流程

Agent: "要使用 OpenTopography 高分辨率 DEM,需要 API Key(免费)。"
Agent: "请访问 https://portal.opentopography.org/register 注册账号,"
Agent: "登录后在 https://portal.opentopography.org/dashboard 查看你的 API Key,"
Agent: "把 API Key 发给我,我会配置好。"

用户: "我的 API Key 是 xxxxxxxxxxxxxxxx"

Agent: 执行 export OPENTOPO_API_KEY="xxx" + echo 到 ~/.bashrc
Agent: 验证: gmt grdcut @earth_relief_01s -R测试区域 -Gtest.grd
Agent: "配置成功!以后画图我自动用 OpenTopography 获取高精度 DEM。"

5.4 DEM 分辨率选择速查

地图范围 推荐分辨率 数据源
全球/半球 30弧分 (~55km) 中科大 rsync
大陆级 15弧秒 (~450m) 中科大 rsync
区域级(省) 30m (1弧秒) OpenTopography / Copernicus
局部(矿区) 30m OpenTopography

第六步:完整示例 — 区域地质样品分布图

将以下脚本保存为 sample_map.sh,修改上方的 REGION 和 PROJ 即可直接使用:

#!/bin/bash
# GMT 区域样品分布图模板
# 使用前改三个地方:
#   1. REGION  改为你的经纬度范围
#   2. PROJ    选择投影和尺寸
#   3. 准备数据文件 samples.txt (格式: lon lat group)

set -e

REGION="115/122/30/36"        # ← 改成你的研究区域
PROJ="M15c"                   # ← 投影:M=Mercator, J=Orthographic, H=Hammer
OUT="sample_map"

# 检查 GMT
if ! command -v gmt &> /dev/null; then
    echo "GMT not found. Run: conda create -n gmt -c conda-forge gmt"
    exit 1
fi

gmt begin ${OUT} pdf

    # 1. 底框
    gmt basemap -R${REGION} -J${PROJ} -Ba2f1 -BWSen -B+t"Sample Distribution"

    # 2. 海岸线
    gmt coast -W0.3p,gray40 -Slightblue -Df

    # 3. 样品点(按组别着色)
    #    数据格式: lon lat group
    if [ -f samples.txt ]; then
        awk '$3=="andesite"'  samples.txt | gmt plot -Sc0.3c -Gred    -W0.5p,black -l"Andesite"
        awk '$3=="granite"'   samples.txt | gmt plot -Sc0.3c -Gblue   -W0.5p,black -l"Granite"
        awk '$3=="basalt"'    samples.txt | gmt plot -St0.3c -Ggreen  -W0.5p,black -l"Basalt"
    else
        echo "No samples.txt — create it with format: lon lat group"
    fi

    # 4. 文字标注(可选)
    # echo "116.4 39.9 Beijing" | gmt text -F+f10p,5,black -DJ0.3c/0.2c

    # 5. 图例
    gmt legend -DJTR+o0.3c -F+gwhite+p0.5p << EOF
S 0.3c c 0.3c red   0.5p,black 0.7c  Andesite
S 0.3c c 0.3c blue  0.5p,black 0.7c  Granite
S 0.3c t 0.3c green 0.5p,black 0.7c  Basalt
EOF

gmt end

echo "Done → ${OUT}.pdf"

运行:

chmod +x sample_map.sh
# 先准备你的 samples.txt,然后:
./sample_map.sh

常见错误排查

问题 原因 解决
gmt: command not found PATH 未设置 export PATH=~/miniconda3/envs/gmt/bin:$PATH
Region ... not correctly specified -R 格式错 必须是 lon1/lon2/lat1/lat2
海岸线盖住 DEM 用了 -G 填色 去掉 -G,仅保留 -S
DEM 下载失败 网络屏蔽 中科大 rsync / Copernicus S3 / OpenTopography
Bad record counter 缓存损坏 rm -f ~/.gmt/gmt_data_server.txt
OpenTopography 403 API Key 未配置 检查 echo $OPENTOPO_API_KEY
中文乱码 字体不支持中文 用英文,或安装中文字体

学习路径

0. 加载本 skill → Agent 自动检测 OS → 一键安装 GMT → 验证 first_map
1. GMT 中文社区入门教程 → https://docs.gmt-china.org/latest/tutorial/started/
2. 跑通上面的完整示例 → 改成自己的数据和区域
3. 配置 OpenTopography API Key → 自动获取高精度 DEM
4. 添加 DEM 地形底图 → gmt grdimage + 光照
5. 进阶:自定义 CPT、等值线、多子图
   → https://docs.gmt-china.org/latest/tutorial/advanced/
6. 看绘图实例找灵感 → https://docs.gmt-china.org/latest/gallery/

参考资源

Current listing version

1.0.0

Verify the source revision ↗

Safety and assessment details

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value92/100

Highlights

  • 提供跨平台 GMT 一键安装方案,解决科研用户环境配置痛点
  • 集成 OpenTopography DEM API 配置,实现高精度地形数据自动化获取
  • 包含完整可执行制图模板,降低零基础用户入门门槛
Trigger Precision95/100

Highlights

  • 触发词覆盖全面且边界清晰,准确匹配 GMT 相关需求场景
Structure and Standards94/100

Highlights

  • 六步式教学结构清晰,从安装到实战完整闭环
  • 提供可直接运行的 sample_map.sh 脚本作为端到端示例
  • frontmatter 完整,文档长度适中
Execution Reliability93/100

Areas to improve

  • 引用文件缺失 Reported severity: Minor

    SKILL.md 末尾引用了 references/gmt-cheatsheet.md 和 references/gmt-dem-sources.md 但未传入

    Recommendation: 请补充这两个引用文件,或移除引用声明

  • Windows 安装兼容性 Reported severity: Minor

    Windows 部分使用 start /wait 执行 .exe 可能不适用于所有 Git Bash 环境

    Recommendation: 建议添加备选方案说明或检测 Git Bash 环境

Highlights

  • 三大操作系统安装路径完整,conda 方案保证环境一致性
  • 多重 DEM 数据源备选(中科大/Copernicus/OpenTopography)提升鲁棒性
  • 关键操作均有前置检测和错误提示
Evidence Verifiability (mean of the first four)94/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

Domains or addresses referenced in the document

These addresses may be documentation links or examples, not an approved network allowlist. Verify actual destinations and outgoing data before use.

  • community.gmt-china.org
  • copernicus-dem-30m.s3.amazonaws.com
  • docs.conda.io
  • docs.generic-mapping-tools.org
  • docs.gmt-china.org
  • git-scm.com
  • portal.opentopography.org
  • raw.githubusercontent.com
  • repo.anaconda.com

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

conda config --set solver classic 2>/dev/null CONDA_NO_PLUGINS=true conda create -y -n gmt -c conda-forge gmt conda config --set solver libmamba 2>/dev/null

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.