Class: SolarEphemeris

Inherits:
Object
  • Object
show all
Includes:
CalculationHelper
Defined in:
lib/PVLIB_Ruby/solar_ephemeris.rb

Instance Method Summary collapse

Methods included from CalculationHelper

#bigdecimal_acos, #bigdecimal_asin, #bigdecimal_atan2, #bigdecimal_cos, #bigdecimal_exp, #bigdecimal_sin, #bigdecimal_sqrt, #bigdecimal_tan, #degree_to_radian, #radian_to_degree

Constructor Details

#initialize(time, location, pressure: BigDecimal('101325'), temperature: BigDecimal('12')) ⇒ SolarEphemeris

Returns a new instance of SolarEphemeris.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/PVLIB_Ruby/solar_ephemeris.rb', line 6

def initialize(time, location, pressure: BigDecimal('101325'), temperature: BigDecimal('12'))
  @time = time
  @location = location
  @pressure = pressure
  @temperature = temperature

  utc_offset_in_hours = BigDecimal(@time.utc_offset.to_s) / BigDecimal('3600')
  dec_hours = BigDecimal(@time.hour.to_s) + BigDecimal(@time.min.to_s) / BigDecimal('60') + BigDecimal(@time.sec.to_s) / BigDecimal('3600')
  @universal_date = BigDecimal(@time.yday.to_s) + ((dec_hours - utc_offset_in_hours) / BigDecimal('24')).floor
  @universal_hour = (dec_hours - utc_offset_in_hours).modulo(BigDecimal('24')) 
end

Instance Method Details

#apparent_sun_elevationObject



31
32
33
# File 'lib/PVLIB_Ruby/solar_ephemeris.rb', line 31

def apparent_sun_elevation
  sun_elevation + reflaction
end

#solar_timeObject



35
36
37
38
39
40
41
42
43
# File 'lib/PVLIB_Ruby/solar_ephemeris.rb', line 35

def solar_time
  # BigDecimal#sign returns 2 for positive value, -2 for negative value, 1 for 0 and -1 for -0. 
  # Hence, decided to use the following statement: 
  hour_angle_sign = hour_angle < BigDecimal('0') ? BigDecimal('-1') : BigDecimal('1')

  adjusted_hour_angle = hour_angle.abs > BigDecimal('180') ? hour_angle - (BigDecimal('360') * hour_angle_sign) : hour_angle

  (BigDecimal('180') + adjusted_hour_angle) / BigDecimal('15')
end

#sun_azimuthObject



18
19
20
21
22
23
# File 'lib/PVLIB_Ruby/solar_ephemeris.rb', line 18

def sun_azimuth
  calculated_sun_azimuth = radian_to_degree(bigdecimal_atan2(BigDecimal('-1') * bigdecimal_sin(degree_to_radian(hour_angle)), 
                                            bigdecimal_cos(degree_to_radian(@location.latitude)) * bigdecimal_tan(degree_to_radian(declination)) - bigdecimal_sin(degree_to_radian(@location.latitude)) * bigdecimal_cos(degree_to_radian(hour_angle))))
  sun_azimuth = calculated_sun_azimuth < BigDecimal('0') ? calculated_sun_azimuth + BigDecimal('360') : calculated_sun_azimuth
  sun_azimuth
end

#sun_elevationObject



25
26
27
28
29
# File 'lib/PVLIB_Ruby/solar_ephemeris.rb', line 25

def sun_elevation
  # Caching because it's used several times for the calculation of apparent_sun_elevation
  @sun_elevation ||= radian_to_degree(bigdecimal_asin(bigdecimal_cos(degree_to_radian(@location.latitude)) * bigdecimal_cos(degree_to_radian(declination)) * bigdecimal_cos(degree_to_radian(hour_angle)) + 
                                                      bigdecimal_sin(degree_to_radian(@location.latitude)) * bigdecimal_sin(degree_to_radian(declination))))
end