Tomorrow.io's Resilience Platform is Here. Learn More.

X

How to Find Air Quality Data

Air quality data is essential for planning outdoor activities in a commercial space. Here's the simplest way to get air quality data with Tomorrow.io

Filip Dimkovski
By Filip Dimkovski

Published April 7, 2024.

A person typing on a laptop with HTML and CSS coding overlaying the image

Nowadays, environmental concerns are at the forefront of global discussions, and the importance of reliable air quality can't be overstated. Air quality affects everything—from individual health and lifestyle choices to much broader issues like climate change and public safety.

By accessing accurate weather data through user-friendly weather APIs like Tomorrow.io, individuals, businesses, and policymakers can obtain valuable information for making informed decisions. Now, with the basics out of the way, let's go over the different types of air quality data and see what's covered in the REST weather API.



Air Quality Data Types

Air quality data encompasses a wide range of measurements critical to understanding the health of our environment and its impact on public well-being.

Among the key types of air quality data available through a REST weather API such as Tomorrow.io, the most important ones are particulate matter concentrations (tiny particles in the air that cause health problems), specifically PM2.5 and PM10.

Other important data fields under air quality include:

  • pollutantO3: Tracks ground-level ozone, one of the key components of smog.
  • pollutantNO2: Monitors nitrogen dioxide levels, a pollutant primarily emitted from vehicle exhaust and industrial activities.
  • pollutantCO: Details carbon monoxide levels, a colorless, odorless gas produced by burning carbon-based fuels.
  • pollutantSO2: Measures sulfur dioxide concentrations, which primarily come from the burning of fossil fuels by power plants and other industrial facilities.
  • mepIndex: Provides an overall score representing the air quality at a specific location per China's MEP standard.

To see the full list of data fields under Air Quality, consider visiting the Tomorrow.io documentation referencing weather data layers (air).

Accessing Air Quality Data in JavaScript

Now that we've covered the different data fields under air quality, let's take a look at how to find air quality data and fetch it in JavaScript. Provided you've already created a Tomorrow.io account and gotten your API key, the next step is to head out to the weather timelines API where you can access different data fields, including air quality.

Simply put, the Weather Timelines API allows you to query weather conditions with a startTime and an endTime.

Once you've taken a look at the Timelines API, the next step is to create a ".js" file. Let's name it "airQuality.js". Then, copy the code snippet below and paste it into your file:

const options = {
    method: 'POST',
    headers: {
      accept: 'application/json',
      'Accept-Encoding': 'gzip',
      'content-type': 'application/json'
    },
    body: JSON.stringify({
      location: '42.3478, -71.0466',
      fields: ['particulateMatter25'],
      units: 'metric',
      timesteps: ['1h'],
      startTime: 'now',
      endTime: 'nowPlus6h'
    })
  };
  
  fetch('https://api.tomorrow.io/v4/timelines?apikey=YOUR_API_KEY', options)
    .then(response => response.json())
    .then(response => console.log(JSON.stringify(response, null, 2)))
    .catch(err => console.error(err));

Before you run it, remember to replace "YOUR_API_KEY" with the API key you'll get in your Tomorrow.io account.

In the code snippet above, we're fetching information for the field "particulateMatter25", which calculates the concentration of PM matter with a 2.5-micrometer diameter. Keep in mind that you can fetch information for any one of the fields under air quality.

» Prefer other languages? Learn how to get weather data in Python and React.js

Breaking Down the Response

{
  "data": {
    "timelines": [
      {
        "timestep": "1h",
        "endTime": "2024-03-29T15:00:00Z",
        "startTime": "2024-03-29T09:00:00Z",
        "intervals": [
          {
            "startTime": "2024-03-29T09:00:00Z",
            "values": {
              "particulateMatter25": 15.38
            }
          },
          {
            "startTime": "2024-03-29T10:00:00Z",
            "values": {
              "particulateMatter25": 4.28
            }
          },
          {
            "startTime": "2024-03-29T11:00:00Z",
            "values": {
              "particulateMatter25": 2.47
            }
          },
          {
            "startTime": "2024-03-29T12:00:00Z",
            "values": {
              "particulateMatter25": 2.88
            }
          },
          {
            "startTime": "2024-03-29T13:00:00Z",
            "values": {
              "particulateMatter25": 3.53
            }
          },
          {
            "startTime": "2024-03-29T14:00:00Z",
            "values": {
              "particulateMatter25": 3.44
            }
          },
          {
            "startTime": "2024-03-29T15:00:00Z",
            "values": {
              "particulateMatter25": 3.72
            }
          }
        ]
      }
    ]
  }
}

As you can see, the response provides detailed data on the PM2.5 field, spanning from 09:00 to 15:00 on March 29, 2024, starting with initially high levels of 15.38, and then stabilizing within the range of 2.88 to 3.72.

Simplified Air Quality Data With Tomorrow.io

With a robust weather API, we can analyze valuable insights for specific locations, providing us with information that can be useful in outdoor activities, planning, environmental monitoring, and public health in numerous industries, including aviation and agriculture.

By accessing accurate weather data with an API such as Tomorrow.io, we can make informed decisions about when and where to schedule outdoor events, manage air quality alerts, or implement measures to protect vulnerable populations.