Air Quality Index calculator?
09-14-2020, 10:56 AM
Post: #1
 DrD Senior Member Posts: 1,132 Joined: Feb 2014
Air Quality Index calculator?
Is an HP Prime program available to calculate air quality index for use in the United States?

https://en.wikipedia.org/wiki/Air_qualit...omputation

-Dale-
09-14-2020, 08:02 PM (This post was last modified: 09-14-2020 08:25 PM by Didier Lachieze.)
Post: #2
 Didier Lachieze Senior Member Posts: 1,227 Joined: Dec 2013
RE: Air Quality Index calculator?
Here is one based on the table and formula from the Wikipedia article, it's a bit rough (no test for out of range values...) but should work. I suppose you have access to the correct data about the different air pollutants with 1-hour / 8-hour /24-hour average monitoring as required.

Code:
#pragma mode( separator(.,;) integer(h32) ) AQI_bkp:={{0,50},{51,100},{101,150},{151,200},{201,300},{301,400},{401,500}}; AQI_formula(Pol_bkp,C) BEGIN   LOCAL Index, I;   LOCAL Ilow, Ihigh, Clow, Chigh;   FOR I FROM 1 TO 7 DO     IF (C <= Pol_bkp(I,2)) THEN       Ilow:=AQI_bkp(I,1); Ihigh:=AQI_bkp(I,2);       Clow:=Pol_bkp(I,1); Chigh:=Pol_bkp(I,2);       Index:= (Ihigh-Ilow)*(C-Clow)/(Chigh-Clow)+Ilow;       BREAK;     END;   END;   RETURN ROUND(Index,0); END; EXPORT AQI() BEGIN   LOCAL O38hr,O31hr,PM25,PM10,CO,SO2,NO2;   LOCAL O38hr_bkp:={{0,54},{55,70},{71,85},{86,105},{106,200},{0,0},{0,0}};   LOCAL O31hr_bkp:={{0,0},{0,0},{125,164},{165,204},{205,404},{405,504},{505,604}};​   LOCAL PM25_bkp:={{0,12},{12.1,35.4},{35.5,55.4},{55.5,150.4},{150.5,250.4},{250.5​,350.4},{350.5,500.4}};   LOCAL PM10_bkp:={{0,54},{55,154},{155,254},{255,354},{355,424},{425,504},{505,604​}};   LOCAL CO_bkp:={{0.0,4.4},{4.5,9.4},{9.5,12.4},{12.5,15.4},{15.5,30.4},{30.5,40.4}​,{40.5,50.4}};   LOCAL SO2_bkp:={{0,35},{36,75},{76,185},{186,304},{305,604},{605,804},{805,1004}}​;   LOCAL NO2_bkp:={{0,53},{54,100},{101,360},{361,649},{650,1249},{1250,1649},{1650,​2049}};   LOCAL AQI_cat:={{"Good",58368,0},{"Moderate",16776965,0},{"Unhealthy for Sensitive Groups",16743936,0},                   {"Unhealthy",16711680,16777215},{"Very Unhealthy",10027084,16777215},{"Hazardous",8257571,16777215},{"Hazardous",8257571,16777215}};   LOCAL AQI_list:={0,0,0,0,0,0};   LOCAL Category, Color_b, Color_f, Index, I, X;   INPUT({{O38hr,[0],{30,50,0}},{O31hr,[0],{30,50,1}},{PM25,[0],{30,50,2}},{PM10,[0],{30,50,3}},{CO,[0],{30,50,4}},{SO2,[0],{30,50,5}},{NO2,[0],{30,50,6}}},         "AQI - Pollutants", {"O3 8-hr ","O3 1-hr ","PM2.5 ","PM10 ","CO ","SO2 ","NO2 "},         {"8-hour ozone value (ppb)","1-hour ozone value (ppb)","24-hour average fine particle PM2.5 (μg/m3)","24-hour average fine particle PM10 (μg/m3)",          "8-hour carbon monoxide value (ppm)","1 or 24-hour sulfur dioxide value (ppb)","1-hour nitrogen dioxide value (ppb)"});   AQI_list(1):=MAX(AQI_formula(O38hr_bkp,O38hr), IFTE(O31hr>=125,AQI_formula(O31hr_bkp,O31hr),0));   AQI_list(2):=AQI_formula(PM25_bkp,PM25);   AQI_list(3):=AQI_formula(PM10_bkp,PM10);   AQI_list(4):=AQI_formula(CO_bkp,CO);   AQI_list(5):=AQI_formula(SO2_bkp,SO2);   AQI_list(6):=AQI_formula(NO2_bkp,NO2);   Index:=MAX(AQI_list);   FOR I FROM 1 TO 7 DO     IF (Index <= AQI_bkp(I,2)) THEN       Category:=AQI_cat(I,1);       Color_b:=AQI_cat(I,2);       Color_f:=AQI_cat(I,3);       BREAK;     END;   END;   RECT();   X:=TEXTOUT_P("Air Quality Index : "+Index,40,20,0,#FFFFFF);   TEXTOUT_P("Air Quality Index : "+Index,40+(280-X)/2,20);   RECT_P(40,40,280,80,Color_b);   X:=TEXTOUT_P(Category,40,54,0,Color_b);   TEXTOUT_P(Category,40+(280-X)/2,54,0,Color_f);   FREEZE;   RETURN(AQI_list); END;

It displays the overall Air Quality Index, and returns a list of the Air Quality Index calculated for each pollutant (O3, PM2.5, PM10, CO, SO2, NO2).
09-14-2020, 09:53 PM
Post: #3
 DrD Senior Member Posts: 1,132 Joined: Feb 2014
RE: Air Quality Index calculator?
Thank you very much, Didier! I sure wasn't expecting you to create one for me, or (us)! I did search around and didn't see anything, so I asked here, thinking that if nothing existed I would give it a try myself.

In Washington, USA, we are experiencing significant smoke from fires all up and down the west coast, but, in particular, Oregon fires are creating huge amounts of smoke pollution for us. I have access to pollution data, and wanted to use the Prime for a handheld way to process it.

So, again, thank you very much. I hope you found the programming effort fun, and maybe even worthwhile for your own use.

-Dale-
09-15-2020, 05:40 AM (This post was last modified: 09-15-2020 05:46 AM by Didier Lachieze.)
Post: #4
 Didier Lachieze Senior Member Posts: 1,227 Joined: Dec 2013
RE: Air Quality Index calculator?
Yes it was fun to program and I learned how this index is calculated in the US. You can use it as a baseline and adapt it to fit how your data are entered (for example they may be stored in a spreadsheet) and how you want to get the results.

I've seen the fires on the west coast in the news. They are huge and casualties seems to be significant unfortunately. Smoke particules from these fires have even reached the north of Europe :

I hope for you and all people in California and Oregon that the air quality will improve soon.
09-15-2020, 10:13 PM
Post: #5
 Benjer Junior Member Posts: 39 Joined: Apr 2017
RE: Air Quality Index calculator?
About an hour east of here (Corvallis, OR) the Beachie Creek fire really blew up 9/7 and 9/8, forcing evacuations from many small communities. One of these, Mill City, was where I was interning this Summer with a company on a project to expand and improve two schools. The fire ended up damaging many structures in the northern part of this town but spared the new construction we were working on.

Meanwhile, the air quality in this region took a nosedive around 9/8 and has only recently begun to improve. At some points the AQI was over 500 and there was visible smoke inside my drafty apartment. Yesterday was the first time I saw any hint of sky since 9/8 and I'm hoping for further improvements over the next few days.

South of where I live in the Rogue Valley, the Almeda Fire damaged parts of Ashland, and significant parts of Phoenix and Talent. In Ashland, the first place I ever worked burned down, and an apartment I used to live in in Talent also burned down. The downtown portions of both Talent and Phoenix were significantly damaged, and entire neighborhoods were destroyed. Probably one of the worst things to ever happen in the state of Oregon.
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)