Class: WrfForecast::Threshold::BaseThreshold

Inherits:
Object
  • Object
show all
Defined in:
lib/wrf_forecast/threshold/base_threshold.rb

Overview

This abstract class determines the significant thresholds for a forecast day. That means that this class can only work correctly if the data represents a time span of up to 24 hours. Will raise an NotImplementedError if the abstract methods are called without an implementation in a child class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_values) ⇒ BaseThreshold

initialization

Parameters:

  • data_values (Array)

    the input values



23
24
25
26
27
28
# File 'lib/wrf_forecast/threshold/base_threshold.rb', line 23

def initialize(data_values)
  @indicators = Hash.new()
  initialize_indicators
  check_data_values(data_values)
  determine_indicators(data_values)
end

Instance Attribute Details

#indicatorsHash (readonly)

Returns the indicator by mapping symbol => boolean.

Returns:

  • (Hash)

    the indicator by mapping symbol => boolean



19
20
21
# File 'lib/wrf_forecast/threshold/base_threshold.rb', line 19

def indicators
  @indicators
end

Instance Method Details

#add_indicator(identifier, is_active, warning_text) ⇒ Object (private)

method to add a threshold value to the indicator hash

Parameters:

  • identifier (Symbol)

    the symbol that identifies the threshold

  • is_active (boolean)

    a bool flag that indicated if the threshold was activated

  • warning_text (String)

    the corresponding warning text to the threshold



36
37
38
39
# File 'lib/wrf_forecast/threshold/base_threshold.rb', line 36

def add_indicator(identifier, is_active, warning_text)
  @indicators[identifier] = 
    WrfForecast::Threshold::ThresholdValue.new(identifier, is_active, warning_text)
end

#change_indicator(identifier, flag, condition) ⇒ Object (private)

method to change a given indicator to the given flag if the condition if met

Parameters:

  • identifier (Symbol)

    the symbol that identifies the threshold

  • flag (boolean)

    the bool flag that should be set

  • condition (boolean)

    the condition bool for which the flag should be set



45
46
47
# File 'lib/wrf_forecast/threshold/base_threshold.rb', line 45

def change_indicator(identifier, flag, condition)
  @indicators[identifier].is_active = flag if (condition)
end

#check_data_values(data_values) ⇒ Object (private)

method to check if the data sample offers enough data for the indicators less than 720 data points means, less than 1 data point every 2 minutes less then 48 data points means, less than 2 data points per hours

Raises:

  • (ArgumentError)

    if the data values are not sufficient



53
54
55
56
57
58
59
60
# File 'lib/wrf_forecast/threshold/base_threshold.rb', line 53

def check_data_values(data_values)
  if (data_values.size < 720)
    puts "Warning: Data values for #{self.class} are lesser than 720."
  end
  if (data_values.size < 48)
    raise ArgumentError, "Error: Lesser than 48 data values available for threshold."
  end
end

#determine_indicators(data_values) ⇒ Object (private)

abstract method to determine the indicators based on the input data

Parameters:

  • data_values (Array)

    the input values

Raises:

  • (NotImplementedError)

    if the child class does not implement this



72
73
74
75
# File 'lib/wrf_forecast/threshold/base_threshold.rb', line 72

def determine_indicators(data_values)
  fail NotImplementedError, " Error: the subclass #{self.class} needs " \
   "to implement the method: determine_indicators from its base class".red      
end

#initialize_indicatorsObject (private)

abstract method to initialize of the required indicators

Raises:

  • (NotImplementedError)

    if the child class does not implement this



64
65
66
67
# File 'lib/wrf_forecast/threshold/base_threshold.rb', line 64

def initialize_indicators
  fail NotImplementedError, " Error: the subclass #{self.class} needs " \
   "to implement the method: initialize_indicators from its base class".red
end