aqi

package module
v0.0.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2023 License: MIT Imports: 4 Imported by: 0

README

go-aqi tests godev

Calculate the air quality index (AQI) from different particulate concentrations. The method for calculating AQI is based on the Environmental Protection Agency's (United States) table method for calculating AQI. Other countries' AQI calculation methods might come in the future, but this might require some rethinking of how this library is currently written.

Currently this library supports the following measurements:

  • PM2.5
  • PM10
  • Carbon Monoxide
  • Sulfur Dioxide
  • Nitrogen Dioxide

Ozone is another measurement that I would like to add, but calculating AQI from ozone is slightly more complicated compared to the other particulate measures.

Installation

go get -u github.com/lildude/go-aqi

Documentation

Documentation for this library can be found here.

Example

Here is an example for calculating AQI from multiple particulate measurements.

package main

import (
	"fmt"

	"github.com/lildude/go-aqi"
)

func main() {
	results, err := aqi.Calculate(aqi.PM25{Concentration: 20.2}, aqi.CO{Concentration: 4.1}, aqi.NO2{Concentration: 67.6})
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Printf("The air quality is %s with an AQI of %.3f\n", results.Index.Name, results.AQI)
}

A toy CLI application can be found in the examples/ folder.

Contributing

Contributions are welcome. Create a pull request and I'll take a look at it whenever I have some time.

Make sure to include unit tests in your pull requests.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Good = Index{
		Name:  "Good",
		Key:   "Good",
		Color: color.RGBA{0, 228, 0, 255},
		Low:   goodBreakpointLow,
		High:  goodBreakpointHigh,
	}
	Moderate = Index{
		Name:  "Moderate",
		Key:   "Moderate",
		Color: color.RGBA{255, 255, 0, 255},
		Low:   moderateBreakpointLow,
		High:  moderateBreakpointHigh,
	}
	Sensitive = Index{
		Name:  "Unhealthy for Sensitive Groups",
		Key:   "Sensitive",
		Color: color.RGBA{255, 126, 0, 255},
		Low:   sensitiveBreakpointLow,
		High:  sensitiveBreakpointHigh,
	}
	Unhealthy = Index{
		Name:  "Unhealthy",
		Key:   "Unhealthy",
		Color: color.RGBA{255, 0, 0, 255},
		Low:   unhealthyBreakpointLow,
		High:  unhealthyBreakpointHigh,
	}
	VeryUnhealthy = Index{
		Name:  "Very Unhealthy",
		Key:   "VeryUnhealthy",
		Color: color.RGBA{153, 0, 76, 255},
		Low:   veryUnhealthyBreakpointLow,
		High:  veryUnhealthyBreakpointHigh,
	}
	Hazardous = Index{
		Name:  "Hazardous",
		Key:   "Hazardous",
		Color: color.RGBA{125, 0, 35, 255},
		Low:   hazardousBreakpointLow,
		High:  hazardousBreakpointHigh,
	}
	VeryHazardous = Index{
		Name:  "Very Hazardous",
		Key:   "VeryHazardous",
		Color: color.RGBA{128, 64, 10, 255},
		Low:   veryHazardousBreakpointLow,
		High:  veryHazardousBreakpointHigh,
	}
)

Default indices for all EPA AQI levels, each containing their level's respective metadata.

Functions

This section is empty.

Types

type CO

type CO struct {
	Concentration float64
}

CO contains concentration measurements for carbon monoxide in air in parts per million.

type Index

type Index struct {
	Name  string
	Key   string
	Color color.RGBA
	Low   int
	High  int
}

Index represents the different levels of AQI (i.e good, moderate, etc.) with associated metadata.

type Measurement

type Measurement interface {
	// contains filtered or unexported methods
}

Measurement type are the functions require to calculate the AQI value.

type NO2

type NO2 struct {
	Concentration float64
}

NO2 contains concentration measurements for nitrogen dioxide in air in parts per billion.

type PM10

type PM10 struct {
	Concentration float64
}

PM10 contains concentration measurements for PM10 particulates in air in micrograms per meter cubed.

type PM25

type PM25 struct {
	Concentration float64
}

PM25 contains concentration measurements for PM2.5 particulates in air in micrograms per meter cubed.

type Result

type Result struct {
	AQI   float64
	Index Index
}

Result contains the AQI one of the predefined Index values.

func Calculate

func Calculate(ms ...Measurement) (Result, error)

Calculate determines the AQI from the given measurements. The largest AQI value is always returned.

type SO2

type SO2 struct {
	Concentration float64
}

SO2 ontains concentration measurements for sulfur dioxide measurements in air in parts per billion.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL