Class: SunRiseSet

Inherits:
Object
  • Object
show all
Defined in:
lib/sunriseset.rb

Overview

Calculates the sun rise and sunset times, with civil, naval and astronomical twilight values. Not sure of the origin of the code. I have seen a fortran version www.srrb.noaa.gov/highlights/sunrise/program.txt a .pl www.mso.anu.edu.au/~brian/grbs/astrosubs.pl and .vb versions too. All had the same comments, so are of a common origin.

Constant Summary collapse

VERSION =
'0.9.1'
LATITUDE_DEFAULT =

because I live here

-(36.0 + 59.0/60.0 + 27.60/3600)
LONGITUDE_DEFAULT =
(174.0 + 29/60.0 + 13.20/3600)
CIVIL_TWILIGHT =

In degrees from the Zenith. Represents the Time when we turn car lights on and off

96
102
ASTRO_TWILIGHT =

In degrees from the Zenith. Represents the Time when the sun is not interfering with viewing distant stars.

108
SUN_RISE_SET =

0.833 is allowing for the bending in the atmosphere.

90.833

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(datetime, latitude = LATITUDE_DEFAULT, longitude = LONGITUDE_DEFAULT) ⇒ SunRiseSet

Returns Constructor for any datetime and location.

Parameters:

  • datetime (DateTime, #jd, #offset)
  • latitude (Float) (defaults to: LATITUDE_DEFAULT)
  • longitude (Float) (defaults to: LONGITUDE_DEFAULT)


51
52
53
54
55
56
57
# File 'lib/sunriseset.rb', line 51

def initialize(datetime, latitude=LATITUDE_DEFAULT, longitude=LONGITUDE_DEFAULT)
  @latitude, @longitude = latitude, longitude
  @julian_date = DateTime.jd(datetime.jd.to_f)
  @julian_day = @julian_date.jd.to_f #Shorthand for later use, where we want this value as a float.
  @zone = datetime.offset #datetime.utc_offset/86400 #time zone offset + daylight savings as a fraction of a day
  calcSun
end

Instance Attribute Details

#astroTwilightEndDateTime (readonly)

Returns end of astronomical twilight (sky is now fully dark).

Returns:

  • (DateTime)

    end of astronomical twilight (sky is now fully dark)



41
42
43
# File 'lib/sunriseset.rb', line 41

def astroTwilightEnd
  @astroTwilightEnd
end

#astroTwilightStartDateTime (readonly)

Returns Naval Twilight begins (Sun is begining to lighten the sky ).

Returns:

  • (DateTime)

    Naval Twilight begins (Sun is begining to lighten the sky )



26
27
28
# File 'lib/sunriseset.rb', line 26

def astroTwilightStart
  @astroTwilightStart
end

#civilTwilightEndDateTime (readonly)

Returns End of Civil Twilight.

Returns:

  • (DateTime)

    End of Civil Twilight



37
38
39
# File 'lib/sunriseset.rb', line 37

def civilTwilightEnd
  @civilTwilightEnd
end

#civilTwilightStartDateTime (readonly)

Returns Civil Twilight begins.

Returns:

  • (DateTime)

    Civil Twilight begins



30
31
32
# File 'lib/sunriseset.rb', line 30

def civilTwilightStart
  @civilTwilightStart
end

Returns end of naval twilight.

Returns:

  • (DateTime)

    end of naval twilight



39
40
41
# File 'lib/sunriseset.rb', line 39

def navalTwilightEnd
  @navalTwilightEnd
end

Returns Naval Twilight begins.

Returns:

  • (DateTime)

    Naval Twilight begins



28
29
30
# File 'lib/sunriseset.rb', line 28

def navalTwilightStart
  @navalTwilightStart
end

#solNoonDateTime (readonly)

Returns Sun is at the midpoint for today (varies throughout the year).

Returns:

  • (DateTime)

    Sun is at the midpoint for today (varies throughout the year)



44
45
46
# File 'lib/sunriseset.rb', line 44

def solNoon
  @solNoon
end

#sunriseDateTime (readonly)

Returns Sun rise.

Returns:

  • (DateTime)

    Sun rise



32
33
34
# File 'lib/sunriseset.rb', line 32

def sunrise
  @sunrise
end

#sunsetDateTime (readonly)

Returns Sun set.

Returns:

  • (DateTime)

    Sun set



35
36
37
# File 'lib/sunriseset.rb', line 35

def sunset
  @sunset
end

Class Method Details

.now(latitude = LATITUDE_DEFAULT, longitude = LONGITUDE_DEFAULT) ⇒ SunRiseSet

Returns Constructor for date == today, at location specified.

Parameters:

  • latitude (Float) (defaults to: LATITUDE_DEFAULT)
  • longitude (Float) (defaults to: LONGITUDE_DEFAULT)

Returns:

  • (SunRiseSet)

    Constructor for date == today, at location specified



69
70
71
# File 'lib/sunriseset.rb', line 69

def self.now(latitude=LATITUDE_DEFAULT, longitude=LONGITUDE_DEFAULT)
  self.new(DateTime.now, latitude, longitude)
end

.today(latitude = LATITUDE_DEFAULT, longitude = LONGITUDE_DEFAULT) ⇒ SunRiseSet

Returns Constructor for date == today, at location specified.

Parameters:

  • latitude (Float) (defaults to: LATITUDE_DEFAULT)
  • longitude (Float) (defaults to: LONGITUDE_DEFAULT)

Returns:

  • (SunRiseSet)

    Constructor for date == today, at location specified



62
63
64
# File 'lib/sunriseset.rb', line 62

def self.today(latitude=LATITUDE_DEFAULT, longitude=LONGITUDE_DEFAULT)
  self.new(DateTime.now, latitude, longitude)
end

Instance Method Details

#to_sString

Returns dumps key attributes as a multiline string.

Returns:

  • (String)

    dumps key attributes as a multiline string



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/sunriseset.rb', line 74

def to_s
  "Astro Twilight #{@astroTwilightStart.strftime('%H:%M:%S %d-%m')}\n" +
  "Naval Twilight #{@navalTwilightStart.strftime('%H:%M:%S %d-%m')}\n" +
  "Civil Twilight #{@civilTwilightStart.strftime('%H:%M:%S %d-%m')}\n" +
  "Sun Rises #{@sunrise.strftime('%H:%M:%S %d-%m')}\n" +
  "Solar noon  #{@solNoon.strftime('%H:%M:%S %Z %d-%m')}\n" +
  "Sun Sets #{@sunset.strftime('%H:%M:%S %d-%m')}\n" +
  "End of Civil Twilight  #{@civilTwilightEnd.strftime('%H:%M:%S %d-%m')}\n" +
  "Naval Twilight #{@navalTwilightEnd.strftime('%H:%M:%S %d-%m')}\n" +
  "Astro Twilight #{@astroTwilightEnd.strftime('%H:%M:%S %d-%m')}\n" 
end

#versionString

Returns the constant VERSION.

Returns:

  • (String)

    the constant VERSION



87
88
89
# File 'lib/sunriseset.rb', line 87

def version
  VERSION
end