Module: WrfLibrary::SunEquation
- Defined in:
- lib/wrf_library/sun_equation.rb
Overview
module to calculate the time of the sunrise and sunset for a given location with geo coordinates and the given day as a date source: babel.hathitrust.org/cgi/pt?id=uc1.31822006852784&view=1up&seq=26
Constant Summary collapse
- @@rotation_time =
Returns the rotation distance per hour.
360.0 / 24.0
- @@cos_z =
Returns the zenith distance at rise and set.
-0.01454
Class Method Summary collapse
-
.calculate_center_equation(date = Time.now, longitude, event) ⇒ Float
method to calculate the center equation.
-
.calculate_current_day_of_year(date = Time.now, longitude, event) ⇒ Float
method to get the day of the year for the given date.
-
.calculate_event_time(date = Time.now, longitude, latitude, event) ⇒ Float
method to calculate the time of the given event.
-
.calculate_local_event_time(date = Time.now, longitude, latitude, event) ⇒ Float
method to calculate the local time of the given event.
-
.calculate_local_hour_angle(date = Time.now, longitude, latitude, event) ⇒ Float
method to calculate the local hour angle.
-
.calculate_solar_mean_anomaly(date = Time.now, longitude, event) ⇒ Float
method to calculate the solar mean.
-
.calculate_sun_ascension(center_equation) ⇒ Float
method to calculate the sun ascension value.
-
.calculate_sun_declination(center_equation) ⇒ Float
method to calculate the sun declination value.
-
.calculate_sunrise_time(date = Time.now, longitude, latitude) ⇒ Float
method to calculate the time of the sunrise fpr the given data.
-
.calculate_sunset_time(date = Time.now, longitude, latitude) ⇒ Float
method to calculate the time of the sunset fpr the given data.
-
.convert_degree_to_radiant(angle) ⇒ Float
helper method to convert a degree value into radians.
-
.convert_radiant_to_degree(angle) ⇒ Float
helper method to convert a radiant value into degrees.
-
.normalize_angle(angle) ⇒ Float
helper method to transform the given angle into the interval [-360:360].
Class Method Details
.calculate_center_equation(date = Time.now, longitude, event) ⇒ Float
method to calculate the center equation
62 63 64 65 66 67 |
# File 'lib/wrf_library/sun_equation.rb', line 62 def self.calculate_center_equation(date=Time.now, longitude, event) m = calculate_solar_mean_anomaly(date, longitude, event) rad_m = convert_degree_to_radiant(m) l = m + 1.9148 * Math.sin(rad_m) + 0.02 * Math.sin(2*rad_m) + 282.634 normalize_angle(l) end |
.calculate_current_day_of_year(date = Time.now, longitude, event) ⇒ Float
method to get the day of the year for the given date
43 44 45 46 |
# File 'lib/wrf_library/sun_equation.rb', line 43 def self.calculate_current_day_of_year(date=Time.now, longitude, event) offset = if (event == :rise) then 6.0 else 18.0 end date.yday().to_f + (offset - longitude / @@rotation_time) / 24 end |
.calculate_event_time(date = Time.now, longitude, latitude, event) ⇒ Float
method to calculate the time of the given event
121 122 123 124 |
# File 'lib/wrf_library/sun_equation.rb', line 121 def self.calculate_event_time(date=Time.now, longitude, latitude, event) t_l = calculate_local_event_time(date, longitude, latitude, event) t_l - longitude / @@rotation_time end |
.calculate_local_event_time(date = Time.now, longitude, latitude, event) ⇒ Float
method to calculate the local time of the given event
108 109 110 111 112 113 |
# File 'lib/wrf_library/sun_equation.rb', line 108 def self.calculate_local_event_time(date=Time.now, longitude, latitude, event) h = calculate_local_hour_angle(date, longitude, latitude, event) / 15 ascension = calculate_sun_ascension(calculate_center_equation(date, longitude, event)) t = calculate_current_day_of_year(date, longitude, event) h + ascension / @@rotation_time - 0.06571* t - 6.622 end |
.calculate_local_hour_angle(date = Time.now, longitude, latitude, event) ⇒ Float
method to calculate the local hour angle
93 94 95 96 97 98 99 100 |
# File 'lib/wrf_library/sun_equation.rb', line 93 def self.calculate_local_hour_angle(date=Time.now, longitude, latitude, event) center_equation = calculate_center_equation(date, longitude, event) declination = calculate_sun_declination(center_equation) cos_h = (@@cos_z - Math.sin(declination) * Math.sin(convert_degree_to_radiant(latitude))) / (Math.cos(declination) * Math.cos(convert_degree_to_radiant(latitude))) return 360.0 - convert_radiant_to_degree(Math.acos(cos_h)) if (event == :rise) convert_radiant_to_degree(Math.acos(cos_h)) end |
.calculate_solar_mean_anomaly(date = Time.now, longitude, event) ⇒ Float
method to calculate the solar mean
53 54 55 |
# File 'lib/wrf_library/sun_equation.rb', line 53 def self.calculate_solar_mean_anomaly(date=Time.now, longitude, event) 0.98560028 * calculate_current_day_of_year(date, longitude, event) - 3.289 end |
.calculate_sun_ascension(center_equation) ⇒ Float
method to calculate the sun ascension value
72 73 74 75 76 77 78 |
# File 'lib/wrf_library/sun_equation.rb', line 72 def self.calculate_sun_ascension(center_equation) ra = Math.atan(0.91746 * Math.tan(convert_degree_to_radiant(center_equation))) ran = normalize_angle(convert_radiant_to_degree(ra)) sun_quadrant = (center_equation / 90.0).floor * 90 ascension_quadrant = (ran / 90.0).floor * 90 ran + (sun_quadrant - ascension_quadrant) end |
.calculate_sun_declination(center_equation) ⇒ Float
method to calculate the sun declination value
83 84 85 |
# File 'lib/wrf_library/sun_equation.rb', line 83 def self.calculate_sun_declination(center_equation) Math.asin(0.39782 * Math.sin(convert_degree_to_radiant(center_equation))) end |
.calculate_sunrise_time(date = Time.now, longitude, latitude) ⇒ Float
method to calculate the time of the sunrise fpr the given data
131 132 133 134 135 136 |
# File 'lib/wrf_library/sun_equation.rb', line 131 def self.calculate_sunrise_time(date=Time.now, longitude, latitude) event_utc = calculate_event_time(date, longitude, latitude, :rise) event_utc += 24.0 if (event_utc < 0) event_utc -= 24.0 if (event_utc > 24.0) event_utc + date.gmt_offset / 3600 end |
.calculate_sunset_time(date = Time.now, longitude, latitude) ⇒ Float
method to calculate the time of the sunset fpr the given data
143 144 145 146 147 148 |
# File 'lib/wrf_library/sun_equation.rb', line 143 def self.calculate_sunset_time(date=Time.now, longitude, latitude) event_utc = calculate_event_time(date, longitude, latitude, :sunset) event_utc += 24.0 if (event_utc < 0) event_utc -= 24.0 if (event_utc > 24.0) event_utc + date.gmt_offset / 3600 end |
.convert_degree_to_radiant(angle) ⇒ Float
helper method to convert a degree value into radians
25 26 27 |
# File 'lib/wrf_library/sun_equation.rb', line 25 def self.convert_degree_to_radiant(angle) angle * Math::PI / 180 end |
.convert_radiant_to_degree(angle) ⇒ Float
helper method to convert a radiant value into degrees
18 19 20 |
# File 'lib/wrf_library/sun_equation.rb', line 18 def self.convert_radiant_to_degree(angle) angle * 180 / Math::PI end |
.normalize_angle(angle) ⇒ Float
helper method to transform the given angle into the interval [-360:360]
32 33 34 35 36 |
# File 'lib/wrf_library/sun_equation.rb', line 32 def self.normalize_angle(angle) angle -= 360.0 while (angle > 360.0) angle += 360.0 while (angle < -360.0) angle end |