Class: WrfForecast::ForecastRepository
- Inherits:
-
Object
- Object
- WrfForecast::ForecastRepository
- Defined in:
- lib/wrf_forecast/data/forecast_repository.rb
Overview
This class contains all relevant forecast data that is required for generating a forecast text
Instance Attribute Summary collapse
-
#direction_distribution ⇒ Hash
readonly
The wind direction distribution.
-
#extreme_values ⇒ Hash
readonly
The extreme values for the interval data.
-
#forecast_data ⇒ Hash
readonly
The forecast data identified by a symbol.
-
#hourly_rain ⇒ Array
readonly
The hourly rain sums.
-
#prevalent_direction ⇒ Symbol
readonly
The prevalent wind direction.
-
#time_data ⇒ Array
readonly
private
The time stamp data.
Instance Method Summary collapse
-
#add_pressure_data(wrf_handler) ⇒ Object
private
method to add the pressure data und determine extreme values.
-
#add_rain_data(wrf_handler) ⇒ Object
private
method to add the rain data from the two different sources.
-
#add_temperature_data(wrf_handler) ⇒ Object
private
method to add the temperature data und determine extreme values.
-
#add_windspeed_data(wrf_handler) ⇒ Object
private
method to add the wind data und determine extreme values for wind speed.
-
#calculate_apparent_temperature(wrf_handler) ⇒ Object
private
method to calculate the apparant temperature from the given forecast data set.
-
#calculate_hourly_rainsum ⇒ Object
private
method to sum up the rain data into hourly rain sums for that calculate the difference from the rain value at the start and end of the currently checked hour.
-
#generate_wind_direction_statistic ⇒ Object
private
method to determine the wind direction distribution for the given data.
-
#initialize(wrf_handler) ⇒ ForecastRepository
constructor
initialization.
Constructor Details
#initialize(wrf_handler) ⇒ ForecastRepository
initialization
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/wrf_forecast/data/forecast_repository.rb', line 25 def initialize(wrf_handler) @extreme_values = Hash.new() @forecast_data = Hash.new() @time_data = wrf_handler.retrieve_data_set(:forecast_time) add_pressure_data(wrf_handler) add_temperature_data(wrf_handler) add_windspeed_data(wrf_handler) add_rain_data(wrf_handler) calculate_apparent_temperature(wrf_handler) end |
Instance Attribute Details
#direction_distribution ⇒ Hash (readonly)
Returns the wind direction distribution.
17 18 19 |
# File 'lib/wrf_forecast/data/forecast_repository.rb', line 17 def direction_distribution @direction_distribution end |
#extreme_values ⇒ Hash (readonly)
Returns the extreme values for the interval data.
13 14 15 |
# File 'lib/wrf_forecast/data/forecast_repository.rb', line 13 def extreme_values @extreme_values end |
#forecast_data ⇒ Hash (readonly)
Returns the forecast data identified by a symbol.
15 16 17 |
# File 'lib/wrf_forecast/data/forecast_repository.rb', line 15 def forecast_data @forecast_data end |
#hourly_rain ⇒ Array (readonly)
Returns the hourly rain sums.
21 22 23 |
# File 'lib/wrf_forecast/data/forecast_repository.rb', line 21 def hourly_rain @hourly_rain end |
#prevalent_direction ⇒ Symbol (readonly)
Returns the prevalent wind direction.
19 20 21 |
# File 'lib/wrf_forecast/data/forecast_repository.rb', line 19 def prevalent_direction @prevalent_direction end |
#time_data ⇒ Array (readonly, private)
Returns the time stamp data.
40 41 42 |
# File 'lib/wrf_forecast/data/forecast_repository.rb', line 40 def time_data @time_data end |
Instance Method Details
#add_pressure_data(wrf_handler) ⇒ Object (private)
method to add the pressure data und determine extreme values
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/wrf_forecast/data/forecast_repository.rb', line 44 def add_pressure_data(wrf_handler) pressure = wrf_handler.retrieve_data_set(:pressure) temperature = wrf_handler.retrieve_data_set(:air_temperature) elevation = wrf_handler.data_repository..station.elevation reduced_pressure = WrfLibrary::Measurand::Pressure.reduce_pressure_to_sealevel(pressure, temperature, elevation) @forecast_data[:pressure] = reduced_pressure @extreme_values[:pressure] = RubyUtils::Statistic.extreme_values(reduced_pressure) nil end |
#add_rain_data(wrf_handler) ⇒ Object (private)
method to add the rain data from the two different sources
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/wrf_forecast/data/forecast_repository.rb', line 94 def add_rain_data(wrf_handler) cumulus_rain = wrf_handler.retrieve_data_set(:cumulus_rainfall) explicit_rain = wrf_handler.retrieve_data_set(:explicit_rainfall) rain_data = Array.new() cumulus_rain.zip(explicit_rain).each { |c, e| rain_data << c + e } @forecast_data[:rain] = rain_data calculate_hourly_rainsum nil end |
#add_temperature_data(wrf_handler) ⇒ Object (private)
method to add the temperature data und determine extreme values
57 58 59 60 61 62 |
# File 'lib/wrf_forecast/data/forecast_repository.rb', line 57 def add_temperature_data(wrf_handler) temperature = wrf_handler.retrieve_data_set(:air_temperature) @forecast_data[:air_temperature] = temperature @extreme_values[:air_temperature] = RubyUtils::Statistic.extreme_values(temperature) nil end |
#add_windspeed_data(wrf_handler) ⇒ Object (private)
method to add the wind data und determine extreme values for wind speed
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/wrf_forecast/data/forecast_repository.rb', line 66 def add_windspeed_data(wrf_handler) r2d = 180.0 / (Math.atan(1) * 4.0) u_component = wrf_handler.retrieve_data_set(:u_wind) v_component = wrf_handler.retrieve_data_set(:v_wind) wind_speed = Array.new() wind_direction = Array.new() u_component.zip(v_component).each { |u, v| wind_speed << Math.sqrt(u**2+v**2) wind_direction << Math.atan2(u, v) * r2d + 180 } @forecast_data[:wind_speed] = wind_speed @forecast_data[:wind_direction] = wind_direction @extreme_values[:wind_speed] = RubyUtils::Statistic.extreme_values(wind_speed) generate_wind_direction_statistic nil end |
#calculate_apparent_temperature(wrf_handler) ⇒ Object (private)
method to calculate the apparant temperature from the given forecast data set
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/wrf_forecast/data/forecast_repository.rb', line 131 def calculate_apparent_temperature(wrf_handler) pressure = @forecast_data[:pressure] temperature = @forecast_data[:air_temperature] wind_speed = @forecast_data[:wind_speed] humidity = wrf_handler.retrieve_data_set(:mixing_ratio) apparent_temperature = Array.new() humidity.each_with_index { |value, i| temperature_value = temperature[i] - 273.15 pressure_value = pressure[i] / 100 apparent_temperature << WrfLibrary::ApparentTemperature.calculate_apparent_temperature( temperature_value, wind_speed[i], value, pressure_value) } @extreme_values[:apparent_temperature] = RubyUtils::Statistic.extreme_values(apparent_temperature) @forecast_data[:apparent_temperature] = apparent_temperature nil end |
#calculate_hourly_rainsum ⇒ Object (private)
method to sum up the rain data into hourly rain sums for that calculate the difference from the rain value at the start and end of the currently checked hour
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/wrf_forecast/data/forecast_repository.rb', line 109 def calculate_hourly_rainsum rain_data = @forecast_data[:rain] @hourly_rain = Array.new() # when using an offset, start with the current value as delta previous_hour = rain_data[0] = @time_data[0].hour rain_data.zip(@time_data).each { |rain, | # detect new hour, when the leading number increases by one if (.hour != ) @hourly_rain << rain - previous_hour previous_hour = rain end = .hour } @hourly_rain << rain_data[rain_data.size-1] - previous_hour @extreme_values[:rain] = RubyUtils::Statistic.extreme_values(@hourly_rain) nil end |
#generate_wind_direction_statistic ⇒ Object (private)
method to determine the wind direction distribution for the given data
84 85 86 87 88 89 90 |
# File 'lib/wrf_forecast/data/forecast_repository.rb', line 84 def generate_wind_direction_statistic direction_repository = WrfLibrary::WindDirectionRepository.new() direction_repository.generate_direction_distribution(@forecast_data[:wind_direction]) @direction_distribution = direction_repository.direction_distribution @prevalent_direction = direction_repository.determine_prevalent_direction nil end |