airq — CLI Air Quality Checker
Check air quality for any city from the terminal. Merges model data (Open-Meteo) with real citizen science sensors (Sensor.Community). No API keys needed.
Installation
First check if airq is already installed:
CODEBLOCK0
If not installed, detect the user's platform:
macOS (Homebrew)
CODEBLOCK1
Linux (prebuilt binary)
CODEBLOCK2
Any platform (Rust/cargo)
CODEBLOCK3
Configuration (recommended)
If the user mostly checks the same city, set up a config — then just type airq without flags:
CODEBLOCK4
This creates ~/.config/airq/config.toml. Can also add a favorites list to check multiple cities at once:
CODEBLOCK5
CODEBLOCK6
Commands
Current air quality
CODEBLOCK7
Output shows PM2.5, PM10, CO, NO2, O3, SO2, UV index with color-coded AQI.
History (sparkline trend)
airq history --city berlin --days 7
Shows daily AQI with sparkline bars for the past N days.
Rank cities by pollution
airq top --country germany # top 5 cities
airq top --country turkey --count 10 # top 10
Any country in the world — 10,000+ cities built-in. Use
--list to see all countries.
Compare data sources
airq compare --city berlin # model vs area sensors
airq compare --city berlin --sensor-id 72203 # model vs specific sensor
Side-by-side table showing Open-Meteo model vs Sensor.Community readings.
Find nearby sensors
airq nearby --city paris --radius 10
Lists Sensor.Community sensor IDs within the given radius (km).
Single data source
CODEBLOCK12
Pollution front detection
airq front --city hamburg --radius 150 --days 3
airq front --city gazipasa --radius 150 --days 3
Detects pollution fronts moving between cities using:
- - Z-score spike detection on hourly PM2.5 differences
- Cross-correlation with time-lag between city/sensor pairs
- Haversine distance + bearing for speed and direction
- Dual-source: Open-Meteo model + Sensor.Community archive data
- Sensor clustering (~5km zones) with geo-named labels
Shows nearby cities, wind, spikes, fronts with speed/direction, and ETA warnings.
Pollution source attribution (blame)
airq blame --city hamburg --radius 20 --days 7
Identifies which factories, power plants, or highways contribute to pollution using CPF (Conditional Probability Function). Sources auto-discovered from OpenStreetMap via Overpass API. Custom sources can be added in config
[[sources]].
HTML/PDF report with map, heatmap, and source attribution
airq report --city hamburg --radius 150 --pdf
airq report --city delhi --radius 200 --days 3 --pdf
Generates self-contained HTML report with:
- - Leaflet.js map with CartoDB tiles
- PM2.5 heatmap overlay (leaflet.heat)
- Individual sensors colored by air quality level
- Front arrows (green=strong, yellow=medium, orange=weak correlation)
- Pollution source markers on map (⚡ power plants, 🏭 factories, 🛣 highways)
- Source Attribution (CPF) table
- Key Insights, Spikes table, Fronts table, Methodology, AQI reference
- INLINECODE5 exports via Chrome headless or wkhtmltopdf
Data cached in ~/.cache/airq/ (sensor CSV + Overpass responses).
JSON output
All commands support
--json for scripting and piping:
CODEBLOCK16
AQI scale
| AQI | Status | Action |
|---|
| 0-50 | Good | No restrictions |
| 51-100 |
Moderate | Sensitive people limit outdoor |
| 101-150 | Unhealthy for Sensitive Groups | Reduce prolonged outdoor |
| 151-200 | Unhealthy | Everyone limit outdoor |
| 201-300 | Very Unhealthy | Avoid outdoor activity |
| 301-500 | Hazardous | Stay indoors |
How it works
By default airq fetches both sources concurrently and averages PM2.5/PM10:
- - Open-Meteo — atmospheric model (~11km grid, global coverage)
- Sensor.Community — median of real sensors within 5km (filters outliers)
If no sensors are nearby, falls back to model only.
airq — 命令行空气质量检测工具
从终端检查任意城市的空气质量。融合模型数据(Open-Meteo)与真实公民科学传感器(Sensor.Community)。无需API密钥。
安装
首先检查 airq 是否已安装:
bash
airq --version
若未安装,检测用户平台:
macOS(Homebrew)
bash
brew tap fortunto2/tap && brew install airq
Linux(预编译二进制)
bash
curl -LO https://github.com/fortunto2/airq/releases/latest/download/airq-linux-x86_64.tar.gz
tar xzf airq-linux-x86_64.tar.gz
sudo mv airq /usr/local/bin/
任意平台(Rust/cargo)
bash
cargo install airq
配置(推荐)
若用户主要检查同一城市,可设置配置——之后只需输入 airq 而无需附加参数:
bash
airq init --city <城市名称>
这将创建 ~/.config/airq/config.toml。还可添加收藏列表以一次性检查多个城市:
toml
default_city = berlin
cities = [berlin, tokyo, istanbul, new york]
bash
airq # 检查柏林(默认)
airq --all # 检查全部4个城市,按污染程度排序
命令
当前空气质量
bash
airq # 使用配置中的默认城市
airq --city tokyo # 指定城市
airq --lat 55.75 --lon 37.62 # 按坐标查询
输出显示PM2.5、PM10、CO、NO2、O3、SO2、紫外线指数,并带有颜色编码的AQI。
历史数据(迷你趋势图)
bash
airq history --city berlin --days 7
显示过去N天的每日AQI及迷你柱状图。
按污染程度排名城市
bash
airq top --country germany # 前5个城市
airq top --country turkey --count 10 # 前10个城市
支持全球任意国家——内置10,000+城市。使用 --list 查看所有国家。
比较数据源
bash
airq compare --city berlin # 模型 vs 区域传感器
airq compare --city berlin --sensor-id 72203 # 模型 vs 特定传感器
并排表格显示Open-Meteo模型与Sensor.Community读数对比。
查找附近传感器
bash
airq nearby --city paris --radius 10
列出指定半径(公里)内的Sensor.Community传感器ID。
单一数据源
bash
airq --city berlin --provider open-meteo # 仅模型
airq --city berlin --provider sensor-community --sensor-id 72203 # 仅传感器
污染前锋检测
bash
airq front --city hamburg --radius 150 --days 3
airq front --city gazipasa --radius 150 --days 3
检测城市间移动的污染前锋,使用:
- - 基于Z分数的PM2.5小时差异峰值检测
- 城市/传感器对之间的时滞互相关分析
- 哈弗辛距离+方位角计算速度与方向
- 双数据源:Open-Meteo模型 + Sensor.Community存档数据
- 传感器聚类(~5公里区域)并附地理名称标签
显示附近城市、风向、峰值、前锋(含速度/方向)及预计到达时间警告。
污染源归因(溯源)
bash
airq blame --city hamburg --radius 20 --days 7
使用条件概率函数(CPF)识别贡献污染的工厂、发电厂或高速公路。通过Overpass API从OpenStreetMap自动发现污染源。可在配置 [[sources]] 中添加自定义源。
含地图、热力图和源归因的HTML/PDF报告
bash
airq report --city hamburg --radius 150 --pdf
airq report --city delhi --radius 200 --days 3 --pdf
生成自包含HTML报告,包含:
- - 使用CartoDB瓦片的Leaflet.js地图
- PM2.5热力图叠加层(leaflet.heat)
- 按空气质量等级着色的独立传感器
- 前锋箭头(绿色=强相关,黄色=中等,橙色=弱相关)
- 地图上的污染源标记(⚡发电厂、🏭工厂、🛣高速公路)
- 源归因(CPF)表格
- 关键洞察、峰值表格、前锋表格、方法论、AQI参考
- --pdf 通过Chrome无头模式或wkhtmltopdf导出
数据缓存于 ~/.cache/airq/(传感器CSV + Overpass响应)。
JSON输出
所有命令支持 --json 用于脚本和管道操作:
bash
airq --city tokyo --json
airq history --city berlin --days 7 --json
airq top --country usa --json
AQI等级
良 | 敏感人群限制户外活动 |
| 101-150 | 对敏感人群不健康 | 减少长时间户外活动 |
| 151-200 | 不健康 | 所有人限制户外活动 |
| 201-300 | 非常不健康 | 避免户外活动 |
| 301-500 | 危险 | 留在室内 |
工作原理
默认情况下,airq同时获取两个数据源并取PM2.5/PM10的平均值:
- - Open-Meteo — 大气模型(~11公里网格,全球覆盖)
- Sensor.Community — 5公里范围内真实传感器的中位数(过滤异常值)
若附近无传感器,则仅回退使用模型数据。