sunriseset 0.9.1 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/History.txt +4 -0
- data/Rakefile +1 -1
- data/lib/sunriseset.rb +96 -96
- data/test/manualtest.rb +4 -1
- metadata +23 -27
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9597a8b542e4134d16392af16920648220d15e3c
|
4
|
+
data.tar.gz: 903a23bf047e5d528755ce0f06809908e907d22a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 977cefe3583093a8169c204efd8342582b240442aa435df4c4ee02660616f57d5e1b9f817c6ac537f43c01387f830d8b74e6d336e8700e2c9650a00c19df41e1
|
7
|
+
data.tar.gz: 77f5ea9fd4da96f16eb870ce54469293184a812d179052b9d837f1cf82893bceb7c69ee6d9a22897dc5ea0238436f663f2fcae70e23ba53444fae6299c853a40
|
data/History.txt
CHANGED
@@ -1,2 +1,6 @@
|
|
1
|
+
robertburrowes Mon Jan 14 15:02:14 2013 +1300
|
2
|
+
Added sample code for html generation Fixed warning message about ( after the raise call line 172
|
3
|
+
robertburrowes Mon Jan 14 14:26:20 2013 +1300
|
4
|
+
Minor format and comment changes
|
1
5
|
robertburrowes Mon Jan 14 13:52:40 2013 +1300
|
2
6
|
Initital commit. Code refactored from my sunriseset html generating utility leaving just he SunRiseSet class, to create the gem.
|
data/Rakefile
CHANGED
data/lib/sunriseset.rb
CHANGED
@@ -7,7 +7,7 @@ require 'date'
|
|
7
7
|
#and .vb versions too.
|
8
8
|
#All had the same comments, so are of a common origin.
|
9
9
|
class SunRiseSet
|
10
|
-
VERSION = '0.9.
|
10
|
+
VERSION = '0.9.2'
|
11
11
|
|
12
12
|
#because I live here
|
13
13
|
LATITUDE_DEFAULT= -(36.0 + 59.0/60.0 + 27.60/3600)
|
@@ -70,17 +70,25 @@ class SunRiseSet
|
|
70
70
|
self.new(DateTime.now, latitude, longitude)
|
71
71
|
end
|
72
72
|
|
73
|
+
def time_format(t)
|
74
|
+
if t == nil
|
75
|
+
"Not Found"
|
76
|
+
else
|
77
|
+
t.strftime('%H:%M:%S %d-%m')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
73
81
|
# @return [String] dumps key attributes as a multiline string
|
74
82
|
def to_s
|
75
|
-
"Astro Twilight #{@astroTwilightStart
|
76
|
-
"Naval Twilight #{@navalTwilightStart
|
77
|
-
"Civil Twilight #{@civilTwilightStart
|
78
|
-
"Sun Rises #{@sunrise
|
79
|
-
"Solar noon #{@solNoon
|
80
|
-
"Sun Sets #{@sunset
|
81
|
-
"End of Civil Twilight #{@civilTwilightEnd
|
82
|
-
"Naval Twilight #{@navalTwilightEnd
|
83
|
-
"Astro Twilight #{@astroTwilightEnd
|
83
|
+
"Astro Twilight #{time_format(@astroTwilightStart)}\n" +
|
84
|
+
"Naval Twilight #{time_format(@navalTwilightStart)}\n" +
|
85
|
+
"Civil Twilight #{time_format(@civilTwilightStart)}\n" +
|
86
|
+
"Sun Rises #{time_format(@sunrise)}\n" +
|
87
|
+
"Solar noon #{time_format(@solNoon)}\n" +
|
88
|
+
"Sun Sets #{time_format(@sunset)}\n" +
|
89
|
+
"End of Civil Twilight #{time_format(@civilTwilightEnd)}\n" +
|
90
|
+
"Naval Twilight #{time_format(@navalTwilightEnd)}\n" +
|
91
|
+
"Astro Twilight #{time_format(@astroTwilightEnd)}\n"
|
84
92
|
end
|
85
93
|
|
86
94
|
# @return [String] the constant VERSION
|
@@ -102,28 +110,17 @@ class SunRiseSet
|
|
102
110
|
# Calculate sunrise for this date
|
103
111
|
# if no sunrise is found, set flag nosunrise
|
104
112
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
@navalTwilightStart = calcSunriseUTC( @julian_day, NAVAL_TWILIGHT)
|
110
|
-
@astroTwilightStart = calcSunriseUTC( @julian_day, ASTRO_TWILIGHT)
|
111
|
-
rescue Exception
|
112
|
-
@sunrise = @civilTwilightStart = @navalTwilightStart = @astroTwilightStart = nil
|
113
|
-
nosunrise = true
|
114
|
-
end
|
113
|
+
@sunrise = calcSunriseUTC(@julian_day)
|
114
|
+
@civilTwilightStart = calcSunriseUTC( @julian_day, CIVIL_TWILIGHT)
|
115
|
+
@navalTwilightStart = calcSunriseUTC( @julian_day, NAVAL_TWILIGHT)
|
116
|
+
@astroTwilightStart = calcSunriseUTC( @julian_day, ASTRO_TWILIGHT)
|
115
117
|
|
116
118
|
# Calculate sunset for this date
|
117
119
|
# if no sunrise is found, set flag nosunset
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
@astroTwilightEnd = calcSunsetUTC( @julian_day, ASTRO_TWILIGHT)
|
123
|
-
rescue Exception
|
124
|
-
@sunset = @civilTwilightEnd = @navalTwilightEnd = @astroTwilightEnd = nil
|
125
|
-
nosunset = true
|
126
|
-
end
|
120
|
+
@sunset = calcSunsetUTC(@julian_day)
|
121
|
+
@civilTwilightEnd = calcSunsetUTC( @julian_day, CIVIL_TWILIGHT)
|
122
|
+
@navalTwilightEnd = calcSunsetUTC( @julian_day, NAVAL_TWILIGHT)
|
123
|
+
@astroTwilightEnd = calcSunsetUTC( @julian_day, ASTRO_TWILIGHT)
|
127
124
|
|
128
125
|
# Calculate solar noon for this date
|
129
126
|
t = calcTimeJulianCent( @julian_day )
|
@@ -132,7 +129,7 @@ class SunRiseSet
|
|
132
129
|
|
133
130
|
# No sunrise or sunset found for today
|
134
131
|
doy = @julian_date.yday
|
135
|
-
if(
|
132
|
+
if(@sunrise == nil)
|
136
133
|
if ( ((@latitude > 66.4) && (doy > 79) && (doy < 267)) ||
|
137
134
|
((@latitude < -66.4) && ((doy < 83) || (doy > 263))) )
|
138
135
|
# if Northern hemisphere and spring or summer, OR
|
@@ -153,7 +150,7 @@ class SunRiseSet
|
|
153
150
|
|
154
151
|
end
|
155
152
|
|
156
|
-
if(
|
153
|
+
if(@sunset == nil)
|
157
154
|
if ( ((@latitude > 66.4) && (doy > 79) && (doy < 267)) ||
|
158
155
|
((@latitude < -66.4) && ((doy < 83) || (doy > 263))) )
|
159
156
|
# if Northern hemisphere and spring or summer, OR
|
@@ -263,8 +260,7 @@ class SunRiseSet
|
|
263
260
|
def calcSunRadVector(t)
|
264
261
|
v = calcSunTrueAnomaly(t)
|
265
262
|
e = calcEccentricityEarthOrbit(t)
|
266
|
-
|
267
|
-
(1.000001018 * (1 - e * e)) / (1 + e * Math.cos(degToRad(v))) # in AUs
|
263
|
+
(1.000001018 * (1.0 - e * e)) / (1.0 + e * Math.cos(degToRad(v))) # in AUs
|
268
264
|
end
|
269
265
|
|
270
266
|
# calculate the apparent longitude of the sun
|
@@ -272,7 +268,6 @@ class SunRiseSet
|
|
272
268
|
# @return [Float] sun's apparent longitude in degrees
|
273
269
|
def calcSunApparentLong(t)
|
274
270
|
o = calcSunTrueLong(t)
|
275
|
-
|
276
271
|
omega = 125.04 - 1934.136 * t
|
277
272
|
o - 0.00569 - 0.00478 * Math.sin(degToRad(omega)) # in degrees
|
278
273
|
end
|
@@ -290,7 +285,6 @@ class SunRiseSet
|
|
290
285
|
# @return [Float] corrected obliquity in degrees
|
291
286
|
def calcObliquityCorrection(t)
|
292
287
|
e0 = calcMeanObliquityOfEcliptic(t)
|
293
|
-
|
294
288
|
omega = 125.04 - 1934.136 * t
|
295
289
|
e0 + 0.00256 * Math.cos(degToRad(omega)) # in degrees
|
296
290
|
end
|
@@ -301,7 +295,6 @@ class SunRiseSet
|
|
301
295
|
def calcSunRtAscension(t)
|
302
296
|
e = calcObliquityCorrection(t)
|
303
297
|
lambda = calcSunApparentLong(t)
|
304
|
-
|
305
298
|
tananum = (Math.cos(degToRad(e)) * Math.sin(degToRad(lambda)))
|
306
299
|
tanadenom = (Math.cos(degToRad(lambda)))
|
307
300
|
radToDeg(Math.atan2(tananum, tanadenom)) # in degrees
|
@@ -313,7 +306,6 @@ class SunRiseSet
|
|
313
306
|
def calcSunDeclination(t)
|
314
307
|
e = calcObliquityCorrection(t)
|
315
308
|
lambda = calcSunApparentLong(t)
|
316
|
-
|
317
309
|
sint = Math.sin(degToRad(e)) * Math.sin(degToRad(lambda))
|
318
310
|
radToDeg(Math.asin(sint)) # in degrees
|
319
311
|
end
|
@@ -322,7 +314,6 @@ class SunRiseSet
|
|
322
314
|
# @param [Float] t number of Julian centuries since J2000.0
|
323
315
|
# @return [Float] equation of time in minutes of time
|
324
316
|
def calcEquationOfTime(t)
|
325
|
-
|
326
317
|
epsilon = calcObliquityCorrection(t)
|
327
318
|
l0 = calcGeomMeanLongSun(t)
|
328
319
|
e = calcEccentricityEarthOrbit(t)
|
@@ -337,7 +328,8 @@ class SunRiseSet
|
|
337
328
|
sin4l0 = Math.sin(4.0 * degToRad(l0))
|
338
329
|
sin2m = Math.sin(2.0 * degToRad(m))
|
339
330
|
|
340
|
-
radToDeg(y * sin2l0 - 2.0 * e * sinm + 4.0 * e * y * sinm * cos2l0
|
331
|
+
radToDeg(y * sin2l0 - 2.0 * e * sinm + 4.0 * e * y * sinm * cos2l0 -
|
332
|
+
0.5 * y * y * sin4l0 - 1.25 * e * e * sin2m)*4.0 # in minutes of time
|
341
333
|
end
|
342
334
|
|
343
335
|
# calculate the hour angle of the sun at sunrise for the latitude
|
@@ -346,11 +338,14 @@ class SunRiseSet
|
|
346
338
|
# @return [Float] hour angle of sunrise in radians
|
347
339
|
# 0.833 is an approximation of the reflaction caused by the atmosphere
|
348
340
|
def calcHourAngleSunrise(solarDec, angle=SUN_RISE_SET)
|
349
|
-
latRad = degToRad(@latitude)
|
341
|
+
latRad = degToRad(@latitude)
|
350
342
|
sdRad = degToRad(solarDec)
|
343
|
+
#puts "latRad = #{radToDeg(latRad)}, sdRad = #{radToDeg(sdRad)}, angle = #{angle}"
|
351
344
|
|
352
|
-
#
|
353
|
-
|
345
|
+
#ha_arg = Math.cos(degToRad(angle + 0.833))/(Math.cos(latRad)*Math.cos(sdRad))-Math.tan(latRad) * Math.tan(sdRad)
|
346
|
+
ha_arg = Math.cos(degToRad(angle))/
|
347
|
+
(Math.cos(latRad)*Math.cos(sdRad)) - Math.tan(latRad) * Math.tan(sdRad)
|
348
|
+
Math.acos(ha_arg) # in radians
|
354
349
|
end
|
355
350
|
|
356
351
|
# calculate the hour angle of the sun at sunset for the
|
@@ -367,36 +362,39 @@ class SunRiseSet
|
|
367
362
|
# @param [SUN_RISE_SET,CIVIL_TWILIGHT,NAVAL_TWILIGHT,ASTRO_TWILIGHT] angle
|
368
363
|
# @return [DateTime] Date and Time of event
|
369
364
|
def calcSunriseUTC( julian_day, angle=SUN_RISE_SET)
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
365
|
+
begin
|
366
|
+
t = calcTimeJulianCent( julian_day )
|
367
|
+
|
368
|
+
# *** Find the time of solar noon at the location, and use
|
369
|
+
# that declination. This is better than start of the
|
370
|
+
# Julian day
|
371
|
+
|
372
|
+
noonmin = calcSolNoonUTC(t)
|
373
|
+
tnoon = calcTimeJulianCent( julian_day+noonmin/1440.0)
|
374
|
+
|
375
|
+
# *** First pass to approximate sunrise (using solar noon)
|
376
|
+
|
377
|
+
eqTime = calcEquationOfTime(tnoon)
|
378
|
+
solarDec = calcSunDeclination(tnoon)
|
379
|
+
hourAngle = calcHourAngleSunrise(solarDec,angle)
|
380
|
+
delta = -@longitude - radToDeg(hourAngle)
|
381
|
+
timeDiff = 4 * delta; # in minutes of time
|
382
|
+
timeUTC = 720 + timeDiff - eqTime; # in minutes
|
383
|
+
|
384
|
+
# *** Second pass includes fractional jday in gamma calc
|
385
|
+
|
386
|
+
newt = calcTimeJulianCent(calcJDFromJulianCent(t) + timeUTC/1440.0)
|
387
|
+
eqTime = calcEquationOfTime(newt)
|
388
|
+
solarDec = calcSunDeclination(newt)
|
389
|
+
hourAngle = calcHourAngleSunrise(solarDec,angle)
|
390
|
+
delta = -@longitude - radToDeg(hourAngle)
|
391
|
+
timeDiff = 4 * delta
|
392
|
+
timeUTC = 720 + timeDiff - eqTime; # in minutes
|
393
|
+
|
394
|
+
to_datetime(julian_day,timeUTC)
|
395
|
+
rescue Math::DomainError => error
|
396
|
+
return nil #didn't find a Sunrise today. Will be raised by
|
397
|
+
end
|
400
398
|
end
|
401
399
|
|
402
400
|
# calculate the Universal Coordinated Time (UTC) of solar
|
@@ -404,7 +402,6 @@ class SunRiseSet
|
|
404
402
|
# @param [Float] t number of Julian centuries since J2000.0
|
405
403
|
# @return [Float] time in minutes from zero Z
|
406
404
|
def calcSolNoonUTC(t)
|
407
|
-
|
408
405
|
# First pass uses approximate solar noon to calculate eqtime
|
409
406
|
tnoon = calcTimeJulianCent(calcJDFromJulianCent(t) - @longitude/360.0)
|
410
407
|
eqTime = calcEquationOfTime(tnoon)
|
@@ -424,38 +421,41 @@ class SunRiseSet
|
|
424
421
|
# @param [SUN_RISE_SET,CIVIL_TWILIGHT,NAVAL_TWILIGHT,ASTRO_TWILIGHT] angle
|
425
422
|
# @return [DateTime] Date and Time of event
|
426
423
|
def calcSunsetUTC(julian_day, angle=SUN_RISE_SET)
|
424
|
+
begin
|
425
|
+
t = calcTimeJulianCent(julian_day)
|
427
426
|
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
# that declination. This is better than start of the
|
432
|
-
# Julian day
|
427
|
+
# *** Find the time of solar noon at the location, and use
|
428
|
+
# that declination. This is better than start of the
|
429
|
+
# Julian day
|
433
430
|
|
434
|
-
|
435
|
-
|
431
|
+
noonmin = calcSolNoonUTC(t)
|
432
|
+
tnoon = calcTimeJulianCent(julian_day+noonmin/1440.0)
|
436
433
|
|
437
|
-
|
434
|
+
# First calculates sunrise and approx length of day
|
438
435
|
|
439
|
-
|
440
|
-
|
441
|
-
|
436
|
+
eqTime = calcEquationOfTime(tnoon)
|
437
|
+
solarDec = calcSunDeclination(tnoon)
|
438
|
+
hourAngle = calcHourAngleSunset(solarDec, angle)
|
442
439
|
|
443
|
-
|
444
|
-
|
445
|
-
|
440
|
+
delta = -@longitude - radToDeg(hourAngle)
|
441
|
+
timeDiff = 4 * delta
|
442
|
+
timeUTC = 720 + timeDiff - eqTime
|
446
443
|
|
447
|
-
|
444
|
+
# first pass used to include fractional day in gamma calc
|
448
445
|
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
446
|
+
newt = calcTimeJulianCent(calcJDFromJulianCent(t) + timeUTC/1440.0)
|
447
|
+
eqTime = calcEquationOfTime(newt)
|
448
|
+
solarDec = calcSunDeclination(newt)
|
449
|
+
hourAngle = calcHourAngleSunset(solarDec, angle)
|
453
450
|
|
454
|
-
|
455
|
-
|
456
|
-
|
451
|
+
delta = -@longitude - radToDeg(hourAngle)
|
452
|
+
timeDiff = 4 * delta
|
453
|
+
timeUTC = 720 + timeDiff - eqTime; # in minutes
|
457
454
|
|
458
|
-
|
455
|
+
to_datetime(julian_day,timeUTC)
|
456
|
+
rescue Math::DomainError => error
|
457
|
+
return nil # no Sunset
|
458
|
+
end
|
459
459
|
end
|
460
460
|
|
461
461
|
# calculate the julian day of the most recent sunrise
|
data/test/manualtest.rb
CHANGED
metadata
CHANGED
@@ -1,49 +1,44 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sunriseset
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
5
|
-
prerelease:
|
4
|
+
version: 0.9.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Rob Burrowes
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-05-22 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: hoe-yard
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 0.1.2
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 0.1.2
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: hoe
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- - ~>
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version: '3.
|
33
|
+
version: '3.13'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- - ~>
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
version: '3.
|
46
|
-
description:
|
40
|
+
version: '3.13'
|
41
|
+
description: "SunRiseSet is a ruby class calculates the times of the sunrise, solar
|
47
42
|
noon and sunset.\nIt also calculates astronomical, naval and civil twilight times.\n\nNot
|
48
43
|
sure of the origin of the algorithm.\nI have seen a fortran version http://www.srrb.noaa.gov/highlights/sunrise/program.txt\na
|
49
44
|
.pl www.mso.anu.edu.au/~brian/grbs/astrosubs.pl and .vb versions for spreadsheets
|
@@ -55,43 +50,44 @@ extensions: []
|
|
55
50
|
extra_rdoc_files:
|
56
51
|
- History.txt
|
57
52
|
- Manifest.txt
|
53
|
+
- README.md
|
58
54
|
files:
|
55
|
+
- ".gemtest"
|
59
56
|
- History.txt
|
60
57
|
- Manifest.txt
|
61
58
|
- README.md
|
62
59
|
- Rakefile
|
63
60
|
- lib/sunriseset.rb
|
64
61
|
- test/manualtest.rb
|
65
|
-
- .gemtest
|
66
62
|
homepage: http://rbur004.github.com/sunriseset/
|
67
|
-
licenses:
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata: {}
|
68
66
|
post_install_message:
|
69
67
|
rdoc_options:
|
70
|
-
- --markup
|
68
|
+
- "--markup"
|
71
69
|
- markdown
|
72
|
-
- --protected
|
73
|
-
- --title
|
70
|
+
- "--protected"
|
71
|
+
- "--title"
|
74
72
|
- SunRiseSet
|
75
|
-
- --quiet
|
73
|
+
- "--quiet"
|
76
74
|
require_paths:
|
77
75
|
- lib
|
78
76
|
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
-
none: false
|
80
77
|
requirements:
|
81
|
-
- -
|
78
|
+
- - ">="
|
82
79
|
- !ruby/object:Gem::Version
|
83
80
|
version: '0'
|
84
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
-
none: false
|
86
82
|
requirements:
|
87
|
-
- -
|
83
|
+
- - ">="
|
88
84
|
- !ruby/object:Gem::Version
|
89
85
|
version: '0'
|
90
86
|
requirements: []
|
91
|
-
rubyforge_project:
|
92
|
-
rubygems_version:
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 2.2.2
|
93
89
|
signing_key:
|
94
|
-
specification_version:
|
90
|
+
specification_version: 4
|
95
91
|
summary: SunRiseSet is a ruby class calculates the times of the sunrise, solar noon
|
96
92
|
and sunset
|
97
93
|
test_files: []
|