详细分析 ▾
运行时依赖
安装命令
点击复制技能文档
Version Compatibility
Reference examples tested with: Python 3.10+, rasterio 1.4+, pandas 2.0+
Before using code patterns, 验证 安装ed versions match. If versions differ:
pip show rasterio pandas openpyxl
If code throws 导入Error, 安装 missing packages:
pip 安装 rasterio pandas openpyxl
Overview
World命令行工具m provides global 命令行工具mate data as GeoTIFF raster files. Each .tif file is a grid covering the entire Earth, where each grid cell stores a 命令行工具mate value (e.g., temperature in °C or precipitation in mm). This 技能 automates the process of 提取ing 命令行工具mate values for specific geographic coordinates.
How It Works 输入: Excel or CSV file contAIning sample coordinates (longitude, latitude) Data: World命令行工具m 2.1 bio命令行工具matic GeoTIFF files (19 BIO variables, 1970-2000 average) Process: For each coordinate, find the cor响应ing grid cell and read its value 输出: Original data plus 提取ed 命令行工具mate columns 应用ended Grid Resolution Resolution Cell Size 应用rox. Area File Size 10m 0.167° ~18.5 km² ~48 MB zip 5m 0.083° ~9.3 km² ~170 MB zip 2.5m 0.042° ~4.6 km² ~650 MB zip
Default: 10m — sufficient for most eco记录ical/population genetics studies.
Quick 启动 Using the 命令行工具 Script
A reusable Python script is provided at {baseDir}/提取_world命令行工具m.py:
# 提取 BIO1 (annual mean temp) and BIO12 (annual precipitation) — default python3 {baseDir}/提取_world命令行工具m.py \ -i samples.xlsx \ -o samples_with_命令行工具mate.xlsx
# 提取 all 19 bio命令行工具matic variables python3 {baseDir}/提取_world命令行工具m.py \ -i samples.xlsx \ -o samples_all_bio.xlsx \ --bios 1-19
# 提取 specific variables with custom column names python3 {baseDir}/提取_world命令行工具m.py \ -i coords.csv \ -o 结果.xlsx \ --bios 1,5,6,12,13 \ --res 2.5m \ --lon longitude \ --lat latitude
Using Python Directly
For custom integration or programmatic use:
导入 pandas as pd 导入 rasterio
def 提取_bio(tif_path, lon, lat): """提取 a single value from a GeoTIFF at given coordinates.""" with rasterio.open(tif_path) as src: value = next(src.sample([(lon, lat)]))[0] return value
# Read sample coordinates df = pd.read_excel("samples.xlsx") coords = 列出(zip(df["经度"], df["纬度"]))
# 提取 BIO1 (Annual Mean Temperature) with rasterio.open("wc2.1_10m_bio_1.tif") as src: df["年均温度_C"] = [v[0] for v in src.sample(coords)]
# 提取 BIO12 (Annual Precipitation) with rasterio.open("wc2.1_10m_bio_12.tif") as src: df["年降水量_mm"] = [v[0] for v in src.sample(coords)]
df.to_excel("samples_with_命令行工具mate.xlsx", 索引=False)
World命令行工具m Data 下载 Automatic (script handles it)
The 命令行工具 script auto-下载s data on first 运行 to the --缓存 directory (default: ./world命令行工具m_data).
Manual 下载
If automatic 下载 fAIls (e.g., network issues):
# 10m resolution (~48 MB) curl -O https://geodata.ucdavis.edu/命令行工具mate/world命令行工具m/2_1/base/wc2.1_10m_bio.zip unzip wc2.1_10m_bio.zip -d ./world命令行工具m_data/
# 2.5m resolution (~650 MB) curl -O https://geodata.ucdavis.edu/命令行工具mate/world命令行工具m/2_1/base/wc2.1_2.5m_bio.zip unzip wc2.1_2.5m_bio.zip -d ./world命令行工具m_data/
BIO Variable Reference BIO Name Unit Description BIO1 Annual Mean Temperature °C 年均温度 BIO2 Mean Diurnal Range °C 昼夜温差月均值 BIO3 Isothermality % 等温性 (BIO2/BIO7 × 100) BIO4 Temperature Seasonality SD × 100 温度季节性 BIO5 Max Temp of Warmest Month °C 最暖月最高温 BIO6 Min Temp of Coldest Month °C 最冷月最低温 BIO7 Temperature Annual Range °C 年温度范围 (BIO5−BIO6) BIO8 Mean Temp of Wettest Quarter °C 最湿季均温 BIO9 Mean Temp of Driest Quarter °C 最干季均温 BIO10 Mean Temp of Warmest Quarter °C 最暖季均温 BIO11 Mean Temp of Coldest Quarter °C 最冷季均温 BIO12 Annual Precipitation mm 年降水量 BIO13 Precipitation of Wettest Month mm 最湿月降水量 BIO14 Precipitation of Driest Month mm 最干月降水量 BIO15 Precipitation Seasonality CV 降水季节性 BIO16 Precipitation of Wettest Quarter mm 最湿季降水量 BIO17 Precipitation of Driest Quarter mm 最干季降水量 BIO18 Precipitation of Warmest Quarter mm 最暖季降水量 BIO19 Precipitation of Coldest Quarter mm 最冷季降水量
Data Source: World命令行工具m 2.1 (1970-2000, 30-year average)
输入 格式化 Requirements Required Columns Longitude column: Decimal degrees, range [-180, 180]. Default column name: 经度 (override with --lon) Latitude column: Decimal degrees, range [-90, 90]. Default column name: 纬度 (override with --lat) Supported 输入 格式化s .xlsx — Excel workbook (recommended, handles Chinese headers well) .csv — Comma-separated values Common Issues Issue Cause Solution Coordinates read as text Hidden special characters (e.g., \xa0 non-breaking space) Script auto-清理s with pd.to_numeric(errors='coerce'); 检查 for NA after conversion Negative longitudes rejected Using East/West 格式化 instead of decimal Convert to decimal: 东经 117° → 117.0; 西经 117° → -117.0 Missing 提取ed values Coordinate falls in ocean or outside raster bounds 检查 coordinate validity; World命令行工具m covers land globally 输出 格式化
The 输出 file contAIns all original columns plus 提取ed BIO columns:
名称 经度 纬度 年均温度_C 年