xuxing123 commited on
Commit
243d23f
·
verified ·
1 Parent(s): 608165f

Upload AirQualityBench.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. AirQualityBench.py +95 -0
AirQualityBench.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """AirQualityBench dataset loading script for Hugging Face datasets."""
2
+
3
+ import os
4
+ import h5py
5
+ import numpy as np
6
+ import datasets
7
+
8
+
9
+ _CITATION = """@article{airqualitybench2025,
10
+ title={AirQualityBench: A Global-Scale Air Quality Forecasting Benchmark
11
+ for Spatio-Temporal Graph Neural Networks},
12
+ author={...},
13
+ journal={arXiv preprint arXiv:2605.05854},
14
+ year={2025}
15
+ }"""
16
+
17
+ _DESCRIPTION = """AirQualityBench is a global-scale air quality forecasting benchmark
18
+ featuring 3,720 monitoring stations across the world with **authentic missing patterns**
19
+ and physical-scale evaluation. The dataset spans 5 years (2021–2025) of hourly
20
+ measurements across 6 primary pollutants: PM2.5, PM10, NO2, O3, SO2, CO.
21
+ """
22
+
23
+ _HOMEPAGE = "https://github.com/Star-Learning/AirQualityBench"
24
+ _LICENSE = "MIT"
25
+
26
+ NUM_STATIONS = 3720
27
+ NUM_POLLUTANTS = 6
28
+
29
+
30
+ class AirQualityBench(datasets.GeneratorBasedBuilder):
31
+ VERSION = datasets.Version("1.0.0")
32
+
33
+ BUILDER_CONFIGS = [
34
+ datasets.BuilderConfig(name="train", description="Training set (2021–2023)"),
35
+ datasets.BuilderConfig(name="validation", description="Validation set (2024)"),
36
+ datasets.BuilderConfig(name="test", description="Test set (2025)"),
37
+ datasets.BuilderConfig(name="2021", description="Year 2021 hourly data"),
38
+ datasets.BuilderConfig(name="2022", description="Year 2022 hourly data"),
39
+ datasets.BuilderConfig(name="2023", description="Year 2023 hourly data"),
40
+ datasets.BuilderConfig(name="2024", description="Year 2024 hourly data"),
41
+ datasets.BuilderConfig(name="2025", description="Year 2025 hourly data"),
42
+ ]
43
+
44
+ DEFAULT_CONFIG_NAME = "train"
45
+
46
+ def _info(self):
47
+ return datasets.DatasetInfo(
48
+ description=_DESCRIPTION,
49
+ features=datasets.Features({
50
+ "timestamp_idx": datasets.Value("int32"),
51
+ "values": datasets.Array2D(
52
+ shape=(NUM_STATIONS, NUM_POLLUTANTS), dtype="float32"
53
+ ),
54
+ "masks": datasets.Array2D(
55
+ shape=(NUM_STATIONS, NUM_POLLUTANTS), dtype="int8"
56
+ ),
57
+ }),
58
+ homepage=_HOMEPAGE,
59
+ license=_LICENSE,
60
+ citation=_CITATION,
61
+ )
62
+
63
+ def _split_generators(self, dl_manager):
64
+ data_dir = os.path.dirname(__file__) or "."
65
+ return [
66
+ datasets.SplitGenerator(
67
+ name=datasets.Split.TRAIN,
68
+ gen_kwargs={"data_dir": data_dir, "config": self.config.name},
69
+ )
70
+ ]
71
+
72
+ def _generate_examples(self, data_dir, config):
73
+ config_year_map = {
74
+ "2021": [2021], "2022": [2022], "2023": [2023],
75
+ "2024": [2024], "2025": [2025],
76
+ "train": [2021, 2022, 2023],
77
+ "validation": [2024],
78
+ "test": [2025],
79
+ }
80
+ years = config_year_map[config]
81
+
82
+ global_idx = 0
83
+ for year in years:
84
+ file_path = os.path.join(data_dir, f"aq_compact_{year}.h5")
85
+ with h5py.File(file_path, "r") as f:
86
+ values = f["values"][:]
87
+ masks = f["masks"][:]
88
+
89
+ for t in range(values.shape[0]):
90
+ yield global_idx, {
91
+ "timestamp_idx": t,
92
+ "values": values[t].astype(np.float32),
93
+ "masks": masks[t].astype(np.int8),
94
+ }
95
+ global_idx += 1