44namespace SQM
55{
66
7- CloudMetrics CloudDetection::calculate (float skyTemp, float ambientTemp, float relativeHumidity)
7+ CloudMetrics CloudDetection::calculate (float skyTemp, float ambientTemp, float relativeHumidity,
8+ float clearSkyThreshold, float cloudyThreshold, float humidityCorrection)
89 {
910 CloudMetrics metrics;
1011
@@ -13,39 +14,39 @@ namespace SQM
1314
1415 // Apply humidity correction
1516 // High humidity makes the sky appear warmer, reducing the delta
16- metrics.correctedDelta = applyHumidityCorrection (metrics.temperatureDelta , relativeHumidity);
17+ metrics.correctedDelta = applyHumidityCorrection (metrics.temperatureDelta , relativeHumidity, humidityCorrection );
1718
1819 // Estimate cloud cover percentage
19- metrics.cloudCoverPercent = estimateCloudCover (metrics.correctedDelta );
20+ metrics.cloudCoverPercent = estimateCloudCover (metrics.correctedDelta , clearSkyThreshold, cloudyThreshold );
2021
2122 // Classify condition
22- metrics.condition = classifyCondition (metrics.correctedDelta );
23+ metrics.condition = classifyCondition (metrics.correctedDelta , clearSkyThreshold, cloudyThreshold );
2324 metrics.description = getConditionDescription (metrics.condition );
2425
2526 return metrics;
2627 }
2728
28- float CloudDetection::applyHumidityCorrection (float tempDelta, float humidity)
29+ float CloudDetection::applyHumidityCorrection (float tempDelta, float humidity, float correctionFactor )
2930 {
3031 // Clamp humidity to valid range
3132 humidity = std::max (0 .0f , std::min (100 .0f , humidity));
3233
3334 // AAG CloudWatcher correction formula
3435 // Humidity increases the apparent sky temperature, reducing the delta
35- float correction = (HUMIDITY_CORRECTION_FACTOR / 100 .0f ) * humidity;
36+ float correction = (correctionFactor / 100 .0f ) * humidity;
3637
3738 return tempDelta - correction;
3839 }
3940
40- CloudCondition CloudDetection::classifyCondition (float correctedDelta)
41+ CloudCondition CloudDetection::classifyCondition (float correctedDelta, float clearThreshold, float cloudyThreshold )
4142 {
4243 // Conservative thresholds for astronomical observations (zenith sensor)
4344 // Errs on the side of caution - better to overestimate cloud cover
44- if (correctedDelta < CLEAR_SKY_THRESHOLD )
45+ if (correctedDelta < clearThreshold )
4546 {
4647 return CloudCondition::CLEAR ;
4748 }
48- else if (correctedDelta < CLOUDY_THRESHOLD )
49+ else if (correctedDelta < cloudyThreshold )
4950 {
5051 return CloudCondition::CLOUDY ;
5152 }
@@ -55,27 +56,23 @@ namespace SQM
5556 }
5657 }
5758
58- float CloudDetection::estimateCloudCover (float correctedDelta)
59+ float CloudDetection::estimateCloudCover (float correctedDelta, float clearThreshold, float cloudyThreshold )
5960 {
60- // Linear interpolation between clear and overcast
61- // Conservative thresholds for zenith-pointing sensors:
62- // Clear sky (< -13°C) = 0%
63- // Overcast (≥ -3°C) = 100%
64- // 10°C range for fine-grained detection
61+ // Linear interpolation between clear and overcast thresholds
6562
66- if (correctedDelta < CLEAR_SKY_THRESHOLD )
63+ if (correctedDelta < clearThreshold )
6764 {
6865 return 0 .0f ; // Truly clear
6966 }
70- else if (correctedDelta >= CLOUDY_THRESHOLD )
67+ else if (correctedDelta >= cloudyThreshold )
7168 {
7269 return 100 .0f ; // Overcast
7370 }
7471 else
7572 {
7673 // Linear interpolation in the cloudy range
77- float range = CLOUDY_THRESHOLD - CLEAR_SKY_THRESHOLD ; // 10°C range
78- float position = correctedDelta - CLEAR_SKY_THRESHOLD ;
74+ float range = cloudyThreshold - clearThreshold;
75+ float position = correctedDelta - clearThreshold ;
7976 float percent = (position / range) * 100 .0f ;
8077
8178 return std::max (0 .0f , std::min (100 .0f , percent));
0 commit comments