Getting Started with vayuayan

Importing the Package

from vayuayan import CPCBHistorical, CPCBLive, PM25Client
import pandas as pd
import json

1. Exploring Available Data

# Initialize the AQI client
aqi_client = CPCBHistorical()

# Get list of all available states
states = aqi_client.get_state_list()
print(f"Total states available: {len(states)}")
print("\nFirst 10 states:")
for state in states[:10]:
    print(f"  - {state}")
Total states available: 32

First 10 states:
  - Andaman and Nicobar
  - Andhra Pradesh
  - Arunachal Pradesh
  - Assam
  - Bihar
  - Chandigarh
  - Chhattisgarh
  - Delhi
  - Gujarat
  - Haryana

Getting Cities in a State

# Get cities in Maharashtra
cities = aqi_client.get_city_list("Maharashtra")
print(f"Cities in Maharashtra: {len(cities)}")
print("\nCities:")
for city in cities:
    print(f"  - {city}")
Cities in Maharashtra: 31

Cities:
  - Ahmednagar
  - Akola
  - Amravati
  - Aurangabad
  - Badlapur
  - Belapur
  - Bhiwandi
  - Boisar
  - Chandrapur
  - Dhule
  - Jalgaon
  - Jalna
  - Kalyan
  - Kolhapur
  - Latur
  - Mahad
  - Malegaon
  - Mira-Bhayandar
  - Mumbai
  - Nagpur
  - Nanded
  - Nashik
  - Navi Mumbai
  - Parbhani
  - Pimpri-Chinchwad
  - Pune
  - Sangli
  - Solapur
  - Thane
  - Ulhasnagar
  - Virar

Getting Monitoring Stations in a City

# Get monitoring stations in Mumbai
stations = aqi_client.get_station_list("Mumbai")
print(f"Monitoring stations in Mumbai: {len(stations)}")
print("\nStations:")
for station in stations:
    print(f"  - {station}")
Monitoring stations in Mumbai: 30

Stations:
  - {'value': 'site_5392', 'label': 'Bandra Kurla Complex, Mumbai - IITM'}
  - {'value': 'site_5810', 'label': 'Bandra Kurla Complex, Mumbai - MPCB'}
  - {'value': 'site_168', 'label': 'Bandra, Mumbai - MPCB'}
  - {'value': 'site_5400', 'label': 'Borivali East, Mumbai - IITM'}
  - {'value': 'site_5113', 'label': 'Borivali East, Mumbai - MPCB'}
  - {'value': 'site_5960', 'label': 'Byculla, Mumbai - BMC'}
  - {'value': 'site_5399', 'label': 'Chakala-Andheri East, Mumbai - IITM'}
  - {'value': 'site_5811', 'label': 'Chembur, Mumbai - MPCB'}
  - {'value': 'site_5107', 'label': 'Chhatrapati Shivaji Intl. Airport (T2), Mumbai - MPCB'}
  - {'value': 'site_5120', 'label': 'Colaba, Mumbai - MPCB'}
  - {'value': 'site_5396', 'label': 'Deonar, Mumbai - IITM'}
  - {'value': 'site_5964', 'label': 'Ghatkopar, Mumbai - BMC'}
  - {'value': 'site_5412', 'label': 'Kandivali East, Mumbai - MPCB'}
  - {'value': 'site_5962', 'label': 'Kandivali West, Mumbai - BMC'}
  - {'value': 'site_5814', 'label': 'Kherwadi_Bandra East, Mumbai - MPCB'}
  - {'value': 'site_5397', 'label': 'Khindipada-Bhandup West, Mumbai - IITM'}
  - {'value': 'site_5104', 'label': 'Kurla, Mumbai - MPCB'}
  - {'value': 'site_5402', 'label': 'Malad West, Mumbai - IITM'}
  - {'value': 'site_5394', 'label': 'Mazgaon, Mumbai - IITM'}
  - {'value': 'site_5807', 'label': 'Mindspace-Malad West, Mumbai - MPCB'}
  - {'value': 'site_5413', 'label': 'Mulund West, Mumbai - MPCB'}
  - {'value': 'site_5398', 'label': 'Navy Nagar-Colaba, Mumbai - IITM'}
  - {'value': 'site_5112', 'label': 'Powai, Mumbai - MPCB'}
  - {'value': 'site_5963', 'label': 'Sewri, Mumbai - BMC'}
  - {'value': 'site_5961', 'label': 'Shivaji Nagar, Mumbai - BMC'}
  - {'value': 'site_5403', 'label': 'Siddharth Nagar-Worli, Mumbai - IITM'}
  - {'value': 'site_5119', 'label': 'Sion, Mumbai - MPCB'}
  - {'value': 'site_5102', 'label': 'Vasai West, Mumbai - MPCB'}
  - {'value': 'site_5106', 'label': 'Vile Parle West, Mumbai - MPCB'}
  - {'value': 'site_5115', 'label': 'Worli, Mumbai - MPCB'}

2. Live AQI Data

# Initialize Live AQI client
live_client = CPCBLive()

# Get your current location based on IP
location = live_client.get_system_location()
print("Your approximate location:")
print(json.dumps(location, indent=2))
Your approximate location:
[
  19.0748,
  72.8856
]

Finding the Nearest Monitoring Station

# Find nearest monitoring station
nearest_station = live_client.get_nearest_station()
print("Nearest monitoring station:")
print(json.dumps(nearest_station, indent=2))
Nearest monitoring station:
[
  "site_5104",
  "Kurla, Mumbai - MPCB"
]

Getting Current AQI Data

# Get current AQI data for nearest station
current_aqi = live_client.get_live_aqi_data()
current_aqi.pop("last_hours", None)
print("Current Air Quality Data:")
print(json.dumps(current_aqi, indent=2))
Current Air Quality Data:
{
  "title": "Kurla, Mumbai - MPCB",
  "nOfCom": 100,
  "down": "false",
  "downmessage": "",
  "date": "Wednesday, 08 Oct 2025 12:00 PM",
  "temp": "",
  "aqi": {
    "param": "PM10",
    "value": 77,
    "remark": "Satisfactory",
    "color": "#009933"
  },
  "metrics": [
    {
      "name": "PM2.5",
      "avg": 62,
      "avgDesc": "Over the last 24 hours",
      "min": 51,
      "max": 83,
      "pollutantName": "PM2.5"
    },
    {
      "name": "PM10",
      "avg": 77,
      "avgDesc": "Over the last 24 hours",
      "min": 60,
      "max": 106,
      "pollutantName": "PM10"
    },
    {
      "name": "NO2",
      "avg": 5,
      "avgDesc": "Over the last 24 hours",
      "min": 4,
      "max": 7,
      "pollutantName": "NO2"
    },
    {
      "name": "NH3",
      "avg": 1,
      "avgDesc": "Over the last 24 hours",
      "min": 1,
      "max": 2,
      "pollutantName": "NH3"
    },
    {
      "name": "SO2",
      "avg": 37,
      "avgDesc": "Over the last 24 hours",
      "min": 36,
      "max": 37,
      "pollutantName": "SO2"
    },
    {
      "name": "CO",
      "avg": 9,
      "avgDesc": "Over the last 8 hours",
      "min": 4,
      "max": 16,
      "pollutantName": "CO"
    },
    {
      "name": "OZONE",
      "avg": 28,
      "avgDesc": "Over the last 8 hours",
      "min": 22,
      "max": 29,
      "pollutantName": "OZONE"
    }
  ]
}

3. Downloading Historical Data

# Download city-level data for Mumbai in 2024

output_file = "mumbai_aqi_2024.csv"
aqi_client.download_past_year_aqi_data_city_level("Mumbai", "2024", output_file)
print(f"Data downloaded to {output_file}")

# # Load and display the data
df = pd.read_csv(output_file)
print(f"\nDataset shape: {df.shape}")
print("\nFirst few rows:")
print(df.head())
Data downloaded to mumbai_aqi_2024.csv

Dataset shape: (31, 13)

First few rows:
   Day  January  February  March  April    May  June  July  August  September  \
0    1    132.0      93.0  118.0  106.0  102.0  62.0  60.0    41.0       39.0   
1    2    133.0      63.0   71.0  160.0   92.0  50.0  54.0    32.0       45.0   
2    3    117.0     122.0   55.0  128.0  117.0  68.0  61.0    31.0       43.0   
3    4    129.0     158.0   72.0   89.0   89.0  82.0  59.0    36.0       46.0   
4    5    123.0     154.0  109.0   91.0   79.0  69.0  51.0    37.0       36.0   

   October  November  December  
0     66.0     169.0     167.0  
1    101.0     208.0     174.0  
2     58.0     157.0     129.0  
3     54.0     159.0     139.0  
4     54.0     150.0     154.0  
# Download station-level data for station site_5104 (Kurla, Mumbai - MPCB) in Mumbai in 2024

output_file = "site_5104_2024.csv"
aqi_client.download_past_year_aqi_data_station_level("site_5104", "2024", output_file)
print(f"Data downloaded to {output_file}")

# # Load and display the data
df = pd.read_csv(output_file)
print(f"\nDataset shape: {df.shape}")
print("\nFirst few rows:")
print(df.head())
Data downloaded to site_5104_2024.csv

Dataset shape: (31, 13)

First few rows:
   Day  January  February  March  April    May   June  July  August  \
0    1    109.0      88.0  129.0    NaN   96.0  108.0  91.0    90.0   
1    2    107.0      63.0   78.0  204.0   89.0   44.0  91.0     NaN   
2    3    116.0      79.0   70.0  134.0  152.0   95.0  92.0    67.0   
3    4    150.0     121.0   43.0  105.0  128.0   96.0  91.0    55.0   
4    5    104.0     130.0   82.0  103.0  151.0   96.0  89.0    60.0   

   September  October  November  December  
0       40.0     54.0     133.0     113.0  
1       41.0      NaN     188.0     117.0  
2       37.0      NaN     110.0     103.0  
3       28.0     48.0     121.0     103.0  
4       26.0     43.0     101.0     108.0