Module: WrfLibrary::Statistic
- Defined in:
- lib/wrf_library/statistic/hourly.rb,
lib/wrf_library/statistic.rb
Overview
module to aggregate statistic based logic applied to wrf data
Defined Under Namespace
Modules: Hourly
Class Method Summary collapse
-
.add_rain_data(handler) ⇒ Array
private
method to add the rain data from the two different sources.
-
.calculate_direction_means(timestamps, timespan, data) ⇒ Array
private
method to determine the prevalent wind direction for the given data per timespan.
-
.calculate_means_for_timespan(timestamps, timespan, data) ⇒ Array
private
method to create mean values for the given data and timespan.
-
.calculate_timespan_means(measurand, handler, timespan) ⇒ Array
method to generate timespan mean values for the given measurand.
-
.calculate_timespan_rainsum(handler, timespan) ⇒ Array
method to sum up the rain data into the given timespan rain sums for that calculate the difference from the rain value at the start and end of the currently checked hour.
-
.calculate_timespan_winddirection_means(handler, timespan) ⇒ Array
method to calculate the wind direction means for the given timespan.
-
.calculate_timespan_windspeed_means(handler, timespan) ⇒ Array
method to calculate the windspeed means for the given timespan.
Class Method Details
.add_rain_data(handler) ⇒ Array (private)
method to add the rain data from the two different sources
77 78 79 80 81 82 83 84 85 |
# File 'lib/wrf_library/statistic.rb', line 77 private_class_method def self.add_rain_data(handler) cumulus_rain = handler.retrieve_data_set(:cumulus_rainfall) explicit_rain = handler.retrieve_data_set(:explicit_rainfall) rain_data = Array.new() cumulus_rain.zip(explicit_rain).each { |c, e| rain_data << c + e } rain_data end |
.calculate_direction_means(timestamps, timespan, data) ⇒ Array (private)
method to determine the prevalent wind direction for the given data per timespan
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/wrf_library/statistic.rb', line 120 private_class_method def self.calculate_direction_means(, timespan, data) results = Array.new() hourly_subset = Array.new() # use send to get the desired value to the time object, e.g. for hourly value get the current hour value = [0].send(timespan) data.zip().each { |value, | # detect new time interval value, when the leading number increases by one if (.send(timespan) != ) directions = WindDirectionRepository.new(hourly_subset) results << directions.determine_prevalent_direction = .send(timespan) hourly_subset.clear end hourly_subset << value } directions = WindDirectionRepository.new(hourly_subset) results << directions.determine_prevalent_direction end |
.calculate_means_for_timespan(timestamps, timespan, data) ⇒ Array (private)
method to create mean values for the given data and timespan
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/wrf_library/statistic.rb', line 92 private_class_method def self.calculate_means_for_timespan(, timespan, data) results = Array.new() value_count = 0 mean = 0.0 # use send to get the desired value to the time object, e.g. for hourly value get the current hour value = [0].send(timespan) data.zip().each { |value, | # detect new time interval value, when the leading number increases by one if (.send(timespan) != ) results << (mean / value_count).round(3) mean = 0.0 value_count = 0 end = .send(timespan) mean += value value_count += 1 } results << (mean / value_count).round(3) end |
.calculate_timespan_means(measurand, handler, timespan) ⇒ Array
method to generate timespan mean values for the given measurand
14 15 16 17 18 |
# File 'lib/wrf_library/statistic.rb', line 14 def self.calculate_timespan_means(measurand, handler, timespan) = handler.retrieve_data_set(:forecast_time) data = handler.retrieve_data_set(measurand) calculate_means_for_timespan(, timespan, data) end |
.calculate_timespan_rainsum(handler, timespan) ⇒ Array
method to sum up the rain data into the given timespan rain sums for that calculate the difference from the rain value at the start and end of the currently checked hour
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/wrf_library/statistic.rb', line 52 def self.calculate_timespan_rainsum(handler, timespan) = handler.retrieve_data_set(:forecast_time) rain_data = add_rain_data(handler) results = Array.new() # when using an offset, start with the current value as delta previous_timespan = rain_data[0] # use send to get the desired value to the time object, e.g. for hourly value get the current hour value = [0].send(timespan) rain_data.zip().each { |rain, | # detect new time interval value, when the leading number increases by one if (.send(timespan) != ) results << (rain - previous_timespan).round(3) previous_timespan = rain end = .send(timespan) } # workaround to satisfy the current requirement for daily values results << (rain_data[rain_data.size-1] - previous_timespan).round(3) end |
.calculate_timespan_winddirection_means(handler, timespan) ⇒ Array
method to calculate the wind direction means for the given timespan
37 38 39 40 41 42 43 44 |
# File 'lib/wrf_library/statistic.rb', line 37 def self.calculate_timespan_winddirection_means(handler, timespan) = handler.retrieve_data_set(:forecast_time) u_component = handler.retrieve_data_set(:u_wind) v_component = handler.retrieve_data_set(:v_wind) wind_direction = Measurand::Wind.calculate_winddirection(u_component, v_component) calculate_direction_means(, timespan, wind_direction) end |
.calculate_timespan_windspeed_means(handler, timespan) ⇒ Array
method to calculate the windspeed means for the given timespan
24 25 26 27 28 29 30 31 |
# File 'lib/wrf_library/statistic.rb', line 24 def self.calculate_timespan_windspeed_means(handler, timespan) = handler.retrieve_data_set(:forecast_time) u_component = handler.retrieve_data_set(:u_wind) v_component = handler.retrieve_data_set(:v_wind) wind_speed = Measurand::Wind.calculate_windspeed(u_component, v_component) calculate_means_for_timespan(, timespan, wind_speed) end |