Raw values often need additional processing before they represent useful data. One example is how PM2.5 particulate values can be processed into Air Quality Index values.
The PM2.5 AQI is an index developed by various governmental agencies; the exact formula used for AQI calculation varies depending on the regulatory jurisdiction, but in this example we will translate the computations used by the US-EPA into process code. The AQI is divided into six categories. Each category corresponds to a different level of health concern, and has a specific color:
Daily AQI Color | Levels of Concern | Values of Index | Description of Air Quality |
---|---|---|---|
Green | Good | 0 to 50 | Air quality is satisfactory, and air pollution poses little or no risk. |
Yellow | Moderate | 51 to 100 | Air quality is acceptable. However, there may be a risk for some people, particularly those who are unusually sensitive to air pollution. |
Orange | Unhealthy for Sensitive Groups | 101 to 150 | Members of sensitive groups may experience health effects. The general public is less likely to be affected. |
Red | Unhealthy | 151 to 200 | Some members of the general public may experience health effects; members of sensitive groups may experience more serious health effects. |
Purple | Very Unhealthy | 201 to 300 | Health alert: The risk of health effects is increased for everyone. |
Maroon | Hazardous | 301 and higher | Health warning of emergency conditions: everyone is more likely to be affected. |
Unlike direct PM measurements, AQI is a unitless number that varies from 0 to more than 500. PM2.5 AQI is a midnight-to-midnight 24-hour value based on 1-hour measured values. The PM2.5 AQI is computed from the following formula where Ip = AQI:
To apply the formula, it is necessary to know the breakpoints between the AQI categories. These are given below in Table 1.
.
The following process code translates the breakpoints into a series of if statements. The raw 24-hour PM2.5 is an input parameter named pm2.5:
pm = NODE( "pm2.5" );
function aqiFromPm( pm ) {
if ( pm > 350.5 ) {
return calcAqi( pm, 500, 401, 500.4, 350.5 ); // Hazardous
} else if ( pm > 250.5 ) {
return calcAqi( pm, 400, 301, 350.4, 250.5 ); // Hazardous
} else if ( pm > 150.5 ) {
return calcAqi( pm, 300, 201, 250.4, 150.5 ); // Very Unhealthy
} else if ( pm > 55.5 ) {
return calcAqi( pm, 200, 151, 150.4, 55.5 ); // Unhealthy
} else if ( pm > 35.5 ) {
return calcAqi( pm, 150, 101, 55.4, 35.5 ); // Unhealthy for Sensitive Groups
} else if ( pm > 12.1 ) {
return calcAqi( pm, 100, 51, 35.4, 12.1 ); // Moderate
} else if ( pm >= 0 ) {
return calcAqi( pm, 50, 0, 12, 0 ); // Good
} else {
return null;
}
}
function calcAqi( Cp, Ih, Il, BPh, BPl ) {
var a = ( Ih - Il );
var b = ( BPh - BPl );
var c = ( Cp - BPl );
return Math.round( (a/b) * c + Il );
}
return aqiFromPm( pm );
Note that additional error checking code is omitted for clarity but may be advisable.
Comments
0 comments
Article is closed for comments.