Last active
December 30, 2020 23:44
-
-
Save OilSlick/8d56f288b7ed030c801a4b7feb4f93ad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void aqiStats::calculatenowCast() | |
{ | |
// nowCast Calculation, step 1: https://forum.airnowtech.org/t/the-nowcast-for-pm2-5-and-pm10/172 | |
float twelveHourRangePM25{0.0}; | |
float twelveHourRangePM10{0.0}; | |
twelveHourRangePM25 = twelveHourMaxPM25 - twelveHourMinPM25; | |
twelveHourRangePM10 = twelveHourMaxPM10 - twelveHourMinPM10; | |
#ifdef DEBUG | |
if ( outputLVL == 3 && Serial ) | |
{ | |
Serial.print("twelveHourRangePM25: "); Serial.println(twelveHourRangePM25); | |
Serial.print("twelveHourRangePM10: "); Serial.println(twelveHourRangePM10); | |
} | |
#endif | |
// nowCast Calculation, step 2: | |
float scaledRoCPM25{0.0}; | |
float scaledRoCPM10{0.0}; | |
scaledRoCPM25 = twelveHourRangePM25 / twelveHourMaxPM25; | |
scaledRoCPM10 = twelveHourRangePM10 / twelveHourMaxPM10; | |
#ifdef DEBUG | |
if ( outputLVL == 3 && Serial ) | |
{ | |
Serial.print("scaledRoCPM25: "); Serial.println(scaledRoCPM25); | |
Serial.print("scaledRoCPM10: "); Serial.println(scaledRoCPM10); | |
} | |
#endif | |
// nowCast Calculation, step 3: | |
float weightFactorPM25{0.0}; | |
float weightFactorPM10{0.0}; | |
weightFactorPM25 = 1 - scaledRoCPM25; | |
if ( weightFactorPM25 < .5 ) weightFactorPM25 = .5; //weight factor must be between .5 and 1. | |
weightFactorPM10 = 1 - scaledRoCPM10; | |
if ( weightFactorPM10 < .5 ) weightFactorPM10 = .5; | |
#ifdef DEBUG | |
if ( outputLVL == 3 && Serial ) | |
{ | |
Serial.print("weightFactorPM25: "); Serial.println(weightFactorPM25); | |
Serial.print("weightFactorPM10: "); Serial.println(weightFactorPM10); | |
} | |
#endif | |
// nowCast Calculation, step 4: | |
float scaledWeightedSummedObsPM25{0.0}; | |
float scaledWeightedSummedObsPM10{0.0}; | |
for ( int i = 0; i < hoursCount; i++ ) //#DEBUG calc needs to know the number of hourlyobs stored in twentyfourHourHistory array!! | |
{ | |
scaledWeightedSummedObsPM25 += ( twentyfourHourHistoryPM25[i] * pow(weightFactorPM25,i) ); | |
scaledWeightedSummedObsPM10 += ( twentyfourHourHistoryPM10[i] * pow(weightFactorPM10,i) ); | |
} | |
#ifdef DEBUG | |
if ( outputLVL == 3 && Serial ) | |
{ | |
Serial.print("scaledWeightedSummedObsPM25: "); Serial.println(scaledWeightedSummedObsPM25); | |
Serial.print("scaledWeightedSummedObsPM10: "); Serial.println(scaledWeightedSummedObsPM10); | |
} | |
#endif | |
// AQI Calculation, step 5: | |
float WeightPowerSummedPM25{0}; | |
float WeightPowerSummedPM10{0}; | |
for ( int i = 0; i < hoursCount; i++ ) | |
{ | |
WeightPowerSummedPM25 += pow(weightFactorPM25,i); | |
WeightPowerSummedPM10 += pow(weightFactorPM10,i); | |
} | |
#ifdef DEBUG | |
if ( outputLVL == 3 && Serial ) | |
{ | |
Serial.print("WeightPowerSummedPM25: "); Serial.println(WeightPowerSummedPM25); | |
Serial.print("WeightPowerSummedPM10: "); Serial.println(WeightPowerSummedPM10); | |
} | |
#endif | |
nowCastPM25 = scaledWeightedSummedObsPM25 / WeightPowerSummedPM25; | |
nowCastPM10 = scaledWeightedSummedObsPM10 / WeightPowerSummedPM10; | |
#ifdef DEBUG | |
if ( outputLVL == 3 && Serial ) | |
{ | |
Serial.print("nowCastPM25: "); Serial.println(nowCastPM25); | |
Serial.print("nowCastPM25: "); Serial.println(nowCastPM25); | |
Serial.println(" "); | |
} | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment