{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Getting Started with vayuayan\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Importing the Package\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from vayuayan import CPCBHistorical, CPCBLive, PM25Client\n", "import pandas as pd\n", "import json" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1. Exploring Available Data\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Total states available: 32\n", "\n", "First 10 states:\n", " - Andaman and Nicobar\n", " - Andhra Pradesh\n", " - Arunachal Pradesh\n", " - Assam\n", " - Bihar\n", " - Chandigarh\n", " - Chhattisgarh\n", " - Delhi\n", " - Gujarat\n", " - Haryana\n" ] } ], "source": [ "# Initialize the AQI client\n", "aqi_client = CPCBHistorical()\n", "\n", "# Get list of all available states\n", "states = aqi_client.get_state_list()\n", "print(f\"Total states available: {len(states)}\")\n", "print(\"\\nFirst 10 states:\")\n", "for state in states[:10]:\n", " print(f\" - {state}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Getting Cities in a State\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Cities in Maharashtra: 31\n", "\n", "Cities:\n", " - Ahmednagar\n", " - Akola\n", " - Amravati\n", " - Aurangabad\n", " - Badlapur\n", " - Belapur\n", " - Bhiwandi\n", " - Boisar\n", " - Chandrapur\n", " - Dhule\n", " - Jalgaon\n", " - Jalna\n", " - Kalyan\n", " - Kolhapur\n", " - Latur\n", " - Mahad\n", " - Malegaon\n", " - Mira-Bhayandar\n", " - Mumbai\n", " - Nagpur\n", " - Nanded\n", " - Nashik\n", " - Navi Mumbai\n", " - Parbhani\n", " - Pimpri-Chinchwad\n", " - Pune\n", " - Sangli\n", " - Solapur\n", " - Thane\n", " - Ulhasnagar\n", " - Virar\n" ] } ], "source": [ "# Get cities in Maharashtra\n", "cities = aqi_client.get_city_list(\"Maharashtra\")\n", "print(f\"Cities in Maharashtra: {len(cities)}\")\n", "print(\"\\nCities:\")\n", "for city in cities:\n", " print(f\" - {city}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Getting Monitoring Stations in a City\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Monitoring stations in Mumbai: 30\n", "\n", "Stations:\n", " - {'value': 'site_5392', 'label': 'Bandra Kurla Complex, Mumbai - IITM'}\n", " - {'value': 'site_5810', 'label': 'Bandra Kurla Complex, Mumbai - MPCB'}\n", " - {'value': 'site_168', 'label': 'Bandra, Mumbai - MPCB'}\n", " - {'value': 'site_5400', 'label': 'Borivali East, Mumbai - IITM'}\n", " - {'value': 'site_5113', 'label': 'Borivali East, Mumbai - MPCB'}\n", " - {'value': 'site_5960', 'label': 'Byculla, Mumbai - BMC'}\n", " - {'value': 'site_5399', 'label': 'Chakala-Andheri East, Mumbai - IITM'}\n", " - {'value': 'site_5811', 'label': 'Chembur, Mumbai - MPCB'}\n", " - {'value': 'site_5107', 'label': 'Chhatrapati Shivaji Intl. Airport (T2), Mumbai - MPCB'}\n", " - {'value': 'site_5120', 'label': 'Colaba, Mumbai - MPCB'}\n", " - {'value': 'site_5396', 'label': 'Deonar, Mumbai - IITM'}\n", " - {'value': 'site_5964', 'label': 'Ghatkopar, Mumbai - BMC'}\n", " - {'value': 'site_5412', 'label': 'Kandivali East, Mumbai - MPCB'}\n", " - {'value': 'site_5962', 'label': 'Kandivali West, Mumbai - BMC'}\n", " - {'value': 'site_5814', 'label': 'Kherwadi_Bandra East, Mumbai - MPCB'}\n", " - {'value': 'site_5397', 'label': 'Khindipada-Bhandup West, Mumbai - IITM'}\n", " - {'value': 'site_5104', 'label': 'Kurla, Mumbai - MPCB'}\n", " - {'value': 'site_5402', 'label': 'Malad West, Mumbai - IITM'}\n", " - {'value': 'site_5394', 'label': 'Mazgaon, Mumbai - IITM'}\n", " - {'value': 'site_5807', 'label': 'Mindspace-Malad West, Mumbai - MPCB'}\n", " - {'value': 'site_5413', 'label': 'Mulund West, Mumbai - MPCB'}\n", " - {'value': 'site_5398', 'label': 'Navy Nagar-Colaba, Mumbai - IITM'}\n", " - {'value': 'site_5112', 'label': 'Powai, Mumbai - MPCB'}\n", " - {'value': 'site_5963', 'label': 'Sewri, Mumbai - BMC'}\n", " - {'value': 'site_5961', 'label': 'Shivaji Nagar, Mumbai - BMC'}\n", " - {'value': 'site_5403', 'label': 'Siddharth Nagar-Worli, Mumbai - IITM'}\n", " - {'value': 'site_5119', 'label': 'Sion, Mumbai - MPCB'}\n", " - {'value': 'site_5102', 'label': 'Vasai West, Mumbai - MPCB'}\n", " - {'value': 'site_5106', 'label': 'Vile Parle West, Mumbai - MPCB'}\n", " - {'value': 'site_5115', 'label': 'Worli, Mumbai - MPCB'}\n" ] } ], "source": [ "# Get monitoring stations in Mumbai\n", "stations = aqi_client.get_station_list(\"Mumbai\")\n", "print(f\"Monitoring stations in Mumbai: {len(stations)}\")\n", "print(\"\\nStations:\")\n", "for station in stations:\n", " print(f\" - {station}\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 2. Live AQI Data\n" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Your approximate location:\n", "[\n", " 19.0748,\n", " 72.8856\n", "]\n" ] } ], "source": [ "# Initialize Live AQI client\n", "live_client = CPCBLive()\n", "\n", "# Get your current location based on IP\n", "location = live_client.get_system_location()\n", "print(\"Your approximate location:\")\n", "print(json.dumps(location, indent=2))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Finding the Nearest Monitoring Station\n" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Nearest monitoring station:\n", "[\n", " \"site_5104\",\n", " \"Kurla, Mumbai - MPCB\"\n", "]\n" ] } ], "source": [ "# Find nearest monitoring station\n", "nearest_station = live_client.get_nearest_station()\n", "print(\"Nearest monitoring station:\")\n", "print(json.dumps(nearest_station, indent=2))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Getting Current AQI Data\n" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Current Air Quality Data:\n", "{\n", " \"title\": \"Kurla, Mumbai - MPCB\",\n", " \"nOfCom\": 100,\n", " \"down\": \"false\",\n", " \"downmessage\": \"\",\n", " \"date\": \"Wednesday, 08 Oct 2025 12:00 PM\",\n", " \"temp\": \"\",\n", " \"aqi\": {\n", " \"param\": \"PM10\",\n", " \"value\": 77,\n", " \"remark\": \"Satisfactory\",\n", " \"color\": \"#009933\"\n", " },\n", " \"metrics\": [\n", " {\n", " \"name\": \"PM2.5\",\n", " \"avg\": 62,\n", " \"avgDesc\": \"Over the last 24 hours\",\n", " \"min\": 51,\n", " \"max\": 83,\n", " \"pollutantName\": \"PM2.5\"\n", " },\n", " {\n", " \"name\": \"PM10\",\n", " \"avg\": 77,\n", " \"avgDesc\": \"Over the last 24 hours\",\n", " \"min\": 60,\n", " \"max\": 106,\n", " \"pollutantName\": \"PM10\"\n", " },\n", " {\n", " \"name\": \"NO2\",\n", " \"avg\": 5,\n", " \"avgDesc\": \"Over the last 24 hours\",\n", " \"min\": 4,\n", " \"max\": 7,\n", " \"pollutantName\": \"NO2\"\n", " },\n", " {\n", " \"name\": \"NH3\",\n", " \"avg\": 1,\n", " \"avgDesc\": \"Over the last 24 hours\",\n", " \"min\": 1,\n", " \"max\": 2,\n", " \"pollutantName\": \"NH3\"\n", " },\n", " {\n", " \"name\": \"SO2\",\n", " \"avg\": 37,\n", " \"avgDesc\": \"Over the last 24 hours\",\n", " \"min\": 36,\n", " \"max\": 37,\n", " \"pollutantName\": \"SO2\"\n", " },\n", " {\n", " \"name\": \"CO\",\n", " \"avg\": 9,\n", " \"avgDesc\": \"Over the last 8 hours\",\n", " \"min\": 4,\n", " \"max\": 16,\n", " \"pollutantName\": \"CO\"\n", " },\n", " {\n", " \"name\": \"OZONE\",\n", " \"avg\": 28,\n", " \"avgDesc\": \"Over the last 8 hours\",\n", " \"min\": 22,\n", " \"max\": 29,\n", " \"pollutantName\": \"OZONE\"\n", " }\n", " ]\n", "}\n" ] } ], "source": [ "# Get current AQI data for nearest station\n", "current_aqi = live_client.get_live_aqi_data()\n", "current_aqi.pop(\"last_hours\", None)\n", "print(\"Current Air Quality Data:\")\n", "print(json.dumps(current_aqi, indent=2))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3. Downloading Historical Data\n" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Data downloaded to mumbai_aqi_2024.csv\n", "\n", "Dataset shape: (31, 13)\n", "\n", "First few rows:\n", " Day January February March April May June July August September \\\n", "0 1 132.0 93.0 118.0 106.0 102.0 62.0 60.0 41.0 39.0 \n", "1 2 133.0 63.0 71.0 160.0 92.0 50.0 54.0 32.0 45.0 \n", "2 3 117.0 122.0 55.0 128.0 117.0 68.0 61.0 31.0 43.0 \n", "3 4 129.0 158.0 72.0 89.0 89.0 82.0 59.0 36.0 46.0 \n", "4 5 123.0 154.0 109.0 91.0 79.0 69.0 51.0 37.0 36.0 \n", "\n", " October November December \n", "0 66.0 169.0 167.0 \n", "1 101.0 208.0 174.0 \n", "2 58.0 157.0 129.0 \n", "3 54.0 159.0 139.0 \n", "4 54.0 150.0 154.0 \n" ] } ], "source": [ "# Download city-level data for Mumbai in 2024\n", "\n", "output_file = \"mumbai_aqi_2024.csv\"\n", "aqi_client.download_past_year_aqi_data_city_level(\"Mumbai\", \"2024\", output_file)\n", "print(f\"Data downloaded to {output_file}\")\n", "\n", "# # Load and display the data\n", "df = pd.read_csv(output_file)\n", "print(f\"\\nDataset shape: {df.shape}\")\n", "print(\"\\nFirst few rows:\")\n", "print(df.head())" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Data downloaded to site_5104_2024.csv\n", "\n", "Dataset shape: (31, 13)\n", "\n", "First few rows:\n", " Day January February March April May June July August \\\n", "0 1 109.0 88.0 129.0 NaN 96.0 108.0 91.0 90.0 \n", "1 2 107.0 63.0 78.0 204.0 89.0 44.0 91.0 NaN \n", "2 3 116.0 79.0 70.0 134.0 152.0 95.0 92.0 67.0 \n", "3 4 150.0 121.0 43.0 105.0 128.0 96.0 91.0 55.0 \n", "4 5 104.0 130.0 82.0 103.0 151.0 96.0 89.0 60.0 \n", "\n", " September October November December \n", "0 40.0 54.0 133.0 113.0 \n", "1 41.0 NaN 188.0 117.0 \n", "2 37.0 NaN 110.0 103.0 \n", "3 28.0 48.0 121.0 103.0 \n", "4 26.0 43.0 101.0 108.0 \n" ] } ], "source": [ "# Download station-level data for station site_5104 (Kurla, Mumbai - MPCB) in Mumbai in 2024\n", "\n", "output_file = \"site_5104_2024.csv\"\n", "aqi_client.download_past_year_aqi_data_station_level(\"site_5104\", \"2024\", output_file)\n", "print(f\"Data downloaded to {output_file}\")\n", "\n", "# # Load and display the data\n", "df = pd.read_csv(output_file)\n", "print(f\"\\nDataset shape: {df.shape}\")\n", "print(\"\\nFirst few rows:\")\n", "print(df.head())" ] } ], "metadata": { "kernelspec": { "display_name": "venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.1" } }, "nbformat": 4, "nbformat_minor": 4 }