Skip to content

Commit

Permalink
Merge pull request #46 from mbirth/feature_add_cloud_base
Browse files Browse the repository at this point in the history
Added cloud base as suggested in Google group
  • Loading branch information
jim-easterbrook committed Oct 18, 2016
2 parents 632790c + d2a1be9 commit 7b86a51
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/pywws/conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,23 @@ def apparent_temp(temp, rh, wind):
17.27 * temp / (237.7 + temp))
return temp + (0.33 * vap_press) - (0.70 * wind) - 4.00

def cloud_base(temp, hum):
"""Calculate cumulus cloud base in metres, using formula from
https://en.wikipedia.org/wiki/Cloud_base or
https://de.wikipedia.org/wiki/Kondensationsniveau#Konvektionskondensationsniveau
"""
if temp is None or hum is None:
return None
dew_pt = dew_point(temp, hum)
spread = float(temp) - dew_pt
return spread * 125.0

def cloud_ft(m):
"Convert cloud base from metres to feet."
if m is None:
return None
return float(m) * 3.28084

def _main(argv=None):
global _winddir_text_array
# run some simple tests
Expand All @@ -287,6 +304,10 @@ def _main(argv=None):
for pts in range(16):
print winddir_text(pts),
print
print 'Cloud base in m and ft:'
for hum in range(25, 75, 5):
print "%8.3f m / %8.3f ft" % (cloud_base(15.0, hum), cloud_ft(cloud_base(15.0, hum)))
print

if __name__ == "__main__":
_main()
3 changes: 3 additions & 0 deletions src/pywws/examples/templates/6hrs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<col align="char" char="m" />
<col align="char" char="." />
<col align="char" char="," />
<col align="char" char="m" />
<tr>
<th colspan="2" rowspan="2">Date &amp; time</th>
<th rowspan="2">Temp</th>
Expand All @@ -35,6 +36,7 @@
<th colspan="3">Wind</th>
<th rowspan="2">Rain</th>
<th rowspan="2">Pressure</th>
<th rowspan="2">Cloud base</th>
</tr>
<tr>
<th>dir</th>
Expand All @@ -57,6 +59,7 @@
<td>#wind_gust "%.0f mph" "" "wind_mph(x)"#</td>
<td>#rain "%0.1f mm"#</td>
<td>#rel_pressure "%.1f hPa"#, #pressure_trend "%s" "" "pressure_trend_text(x)"#</td>
<td>#calc "cloud_base(data['temp_out'], data['hum_out'])" "%.1f m"#</td>
</tr>
#jump 1#
#endloop#
Expand Down

0 comments on commit 7b86a51

Please sign in to comment.