Class: SimpleMetarParser::Temperature
- Defined in:
- lib/simple_metar_parser/metar/temperature.rb
Instance Attribute Summary collapse
-
#dew ⇒ Object
readonly
Dew temperature.
-
#humidity ⇒ Object
readonly
Relative humidity.
-
#temperature ⇒ Object
(also: #degrees)
readonly
Temperature in C.
-
#wind_chill ⇒ Object
readonly
Wind chill index.
-
#wind_chill_us ⇒ Object
readonly
US Wind chill index.
Attributes inherited from Base
Instance Method Summary collapse
- #calculate_humidity ⇒ Object
- #calculate_wind_chill ⇒ Object
- #decode_split(s) ⇒ Object
- #post_process ⇒ Object
- #reset ⇒ Object
Methods inherited from Base
Constructor Details
This class inherits a constructor from SimpleMetarParser::Base
Instance Attribute Details
#dew ⇒ Object (readonly)
Dew temperature
16 17 18 |
# File 'lib/simple_metar_parser/metar/temperature.rb', line 16 def dew @dew end |
#humidity ⇒ Object (readonly)
Relative humidity
19 20 21 |
# File 'lib/simple_metar_parser/metar/temperature.rb', line 19 def humidity @humidity end |
#temperature ⇒ Object (readonly) Also known as: degrees
Temperature in C
12 13 14 |
# File 'lib/simple_metar_parser/metar/temperature.rb', line 12 def temperature @temperature end |
#wind_chill ⇒ Object (readonly)
Wind chill index
22 23 24 |
# File 'lib/simple_metar_parser/metar/temperature.rb', line 22 def wind_chill @wind_chill end |
#wind_chill_us ⇒ Object (readonly)
US Wind chill index
25 26 27 |
# File 'lib/simple_metar_parser/metar/temperature.rb', line 25 def wind_chill_us @wind_chill_us end |
Instance Method Details
#calculate_humidity ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/simple_metar_parser/metar/temperature.rb', line 62 def calculate_humidity # Calculate relative humidity return if self.temperature.nil? or self.dew.nil? # http://github.com/brandonh/ruby-metar/blob/master/lib/metar.rb # http://www.faqs.org/faqs/meteorology/temp-dewpoint/ es0 = 6.11 # hPa t0 = 273.15 # kelvin td = self.dew + t0 # kelvin t = self.temperature + t0 # kelvin lv = 2500000 # joules/kg rv = 461.5 # joules*kelvin/kg e = es0 * Math::exp(lv/rv * (1.0/t0 - 1.0/td)) es = es0 * Math::exp(lv/rv * (1.0/t0 - 1.0/t)) rh = 100 * e/es @humidity = rh.round end |
#calculate_wind_chill ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/simple_metar_parser/metar/temperature.rb', line 82 def calculate_wind_chill return if self.temperature.nil? or self.parent.wind.wind_speed.nil? return if self.temperature > 10 or self.parent.wind.wind_speed_kmh < 4.8 # http://en.wikipedia.org/wiki/Wind_chill v = self.parent.wind.wind_speed ta = self.temperature @wind_chill_us = 13.12 + 0.6215 * ta - 11.37 * v + 0.3965 * ta * v @wind_chill = (10.0 * Math.sqrt(v) - v + 10.5)*(33.0 - ta) end |
#decode_split(s) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/simple_metar_parser/metar/temperature.rb', line 27 def decode_split(s) # Temperature in Celsius degrees if s =~ /^(M?)(\d{2})\/(M?)(\d{2})$/ if $1 == "M" @temperature = -1.0 * $2.to_f else @temperature = $2.to_f end if $3 == "M" @dew = -1.0 * $4.to_f else @dew = $4.to_f end return end # shorter version if s =~ /^(M?)(\d{2})\/$/ if $1 == "M" @temperature = -1.0 * $2.to_f else @temperature = $2.to_f end return end end |
#post_process ⇒ Object
57 58 59 60 |
# File 'lib/simple_metar_parser/metar/temperature.rb', line 57 def post_process calculate_humidity calculate_wind_chill end |
#reset ⇒ Object
6 7 8 9 |
# File 'lib/simple_metar_parser/metar/temperature.rb', line 6 def reset @temperature = nil @dew = nil end |