Skip to main content

AirPy Tool

A Python package for cleaning and processing CPCB (Central Pollution Control Board) air quality data for official government and research use.

Python 3.8+ License: MIT

Features

  • Flexible Input: Process single files or entire directories
  • Multiple Formats: Supports CSV and Excel (XLSX/XLS) files
  • Auto-detection: Automatically detects filename format and extracts metadata
  • Data Cleaning: Removes outliers, consecutive repeats, and corrects unit inconsistencies
  • Unit Standardization: Converts all nitrogen compounds to µg/m³
  • Debug-friendly: Verbose mode for troubleshooting

Installation

From PyPI

pip install airpy-tool

From GitHub

pip install git+https://github.com/chandankr014/airpy-tool.git

Local Development

git clone https://github.com/chandankr014/airpy-tool.git
cd airpy-tool
pip install -e .

Quick Start

Command Line (CLI)

# Process a single file
airpy --input data/raw/site_5112_2024.csv --output data/clean/

# Process all files in a folder
airpy --input data/raw/ --output data/clean/

# With verbose output for debugging
airpy --input data/raw/ --output data/clean/ --verbose

# Process specific pollutants only
airpy --input data/raw/ --output data/clean/ --pollutants PM25 PM10

# Filter by city
airpy --input data/raw/ --output data/clean/ --city Delhi

# Overwrite existing files
airpy --input data/raw/ --output data/clean/ --overwrite

Python API

from airpy.core.processor import process_data

# Process a single file
df = process_data(
    input_path="data/raw/site_5112_2024.csv",
    output_path="data/clean/"
)

# Process all files in a folder
process_data(
    input_path="data/raw/",
    output_path="data/clean/"
)

# With all options
process_data(
    input_path="data/raw/",
    output_path="data/clean/",
    city="Delhi",                          # Filter by city
    pollutants=["PM25", "PM10", "NO2"],     # Specific pollutants
    verbose=True,                           # Debug output
    overwrite=True                          # Replace existing files
)

CLI Arguments Reference

Argument Short Description
--input -i Path to input file or directory (required)
--output -o Path to output file or directory (required)
--city Filter processing to a specific city
--live Process live data format filenames
--pollutants List of pollutants to process
--siteid-position Custom site ID position [start, end]
--overwrite Overwrite existing output files
--verbose -v Enable verbose/debug output
--version Show version number

Supported File Formats

AirPy automatically detects these filename formats:

Format Example
Site format site_5112_2024.csv
Numeric format 5112_2024.csv
15min format 15Min_2020_site_5111_station_name.csv
Raw data format Raw_data_15Min_2020_site_5111_name.csv
Live format site_5111202012251200000.xlsx

Output Columns

After processing, the cleaned data includes:

Standard Cleaned Columns

  • PM25_clean - PM2.5 concentrations (µg/m³)
  • PM10_clean - PM10 concentrations (µg/m³)
  • Ozone_clean - Ozone concentrations (µg/m³)

Unit-Corrected Nitrogen Compounds

  • NO_CPCB - Nitric oxide (µg/m³)
  • NO2_CPCB - Nitrogen dioxide (µg/m³)
  • NOx_CPCB - Total nitrogen oxides (µg/m³)

Data Cleaning Process

  1. Data Formatting: Standardizes column names and timestamps
  2. Consecutive Repeat Detection: Removes stuck sensor readings
  3. Outlier Detection: Uses IQR and MAD methods
  4. Unit Correction: Standardizes NO/NO2/NOx to µg/m³
  5. Gap Interpolation: Fills small gaps in data

For detailed documentation, see Documentation.md.

CPCB Data Access

Download CPCB state and city-wise air quality data: CPCB Data Repository

Troubleshooting

Common Issues

No files found

# Check if your files have supported extensions (.csv, .xlsx, .xls, .txt)
# Use verbose mode to see what's happening
airpy --input data/raw/ --output data/clean/ --verbose

Metadata extraction fails

# Use custom site ID position if your filename format is non-standard
airpy --input data/raw/ --output data/clean/ --siteid-position 1 2

Missing pollutant data

# Check which pollutants exist in your data
# Process specific available pollutants only
airpy --input data/raw/ --output data/clean/ --pollutants PM25 PM10

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Citation

If you use this tool in your research, please cite:

AirPy - CPCB Air Quality Data Processing Tool
https://github.com/chandankr014/airpy-tool

Metadata

Release files for airpy-tool 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for airpy-tool 2.0.0
File Size Uploaded Provenance Actions
airpy_tool-2.0.0.tar.gz 40.3 kB Without provenance Details for airpy_tool-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for airpy-tool 2.0.0
File Interpreter ABI Platform Actions
airpy_tool-2.0.0-py3-none-any.whl Python 3 none any Details for airpy_tool-2.0.0-py3-none-any.whl

Total release size: 80.2 kB

Release files / airpy_tool-2.0.0.tar.gz

Download URL airpy_tool-2.0.0.tar.gz
Size 40.3 kB
Tags Source
SHA-256 checksum
How to use checksums
afaf40e8b4650d5dd5f5681acca40c815c136ac1b4453d21139023d863216813
BLAKE2b-256 checksum
How to use checksums
0d79f76207a2635e699007cc6fb4f6a42aac2bb3cdb02594553d58dc0a90dee1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.19

Release files / airpy_tool-2.0.0-py3-none-any.whl

Download URL airpy_tool-2.0.0-py3-none-any.whl
Size 39.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
501d3d589382727982c175a1fff068cd4676d84ea0106db3fac78901d9368217
BLAKE2b-256 checksum
How to use checksums
415b824654d255e4d07082cdafe4b193264ecb3abf8f532c6da1bc5a4f64f409
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.19

Security for airpy-tool 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page