RubySunrise 0.3.1 → 0.3.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 +5 -5
- data/lib/solareventcalculator.rb +31 -34
- data/rubysunrise.gemspec +2 -2
- metadata +8 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2925333b6dad5cdec7f8b89883b3e0e94e2511aa928924ab7221dcf330ee44d6
|
4
|
+
data.tar.gz: 8c7eb64768f429d7e61561e8edf6f900329b87eb622a5d467370dcbee0c325ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6389404d2377c5dd2bbff2bc05deb5344d777d0d1b09edae4afcd8545f7f8eca640a09e40e00ffe55a83084d5d8b161c74348d35f7a54cd8dd887f0894bf7c57
|
7
|
+
data.tar.gz: a3a3fd2991867b29b49babec552b261fe63dffa1a9ef3773b823392dcf32189ca64c2a23ff68b00cce2a6b48d90770e7fd4ab8a325cc8a0649117a0bdc11ee1c
|
data/lib/solareventcalculator.rb
CHANGED
@@ -4,10 +4,6 @@ require 'tzinfo'
|
|
4
4
|
|
5
5
|
class SolarEventCalculator
|
6
6
|
|
7
|
-
@date
|
8
|
-
@latitude
|
9
|
-
@longitude
|
10
|
-
|
11
7
|
def initialize(date, latitude, longitude)
|
12
8
|
@date = date
|
13
9
|
@latitude = latitude
|
@@ -15,64 +11,64 @@ class SolarEventCalculator
|
|
15
11
|
end
|
16
12
|
|
17
13
|
def compute_lnghour
|
18
|
-
lngHour = @longitude / BigDecimal
|
14
|
+
lngHour = @longitude / BigDecimal("15")
|
19
15
|
lngHour.round(4)
|
20
16
|
end
|
21
17
|
|
22
18
|
def compute_longitude_hour(isSunrise)
|
23
|
-
minuend = (isSunrise) ? BigDecimal
|
24
|
-
longHour = @date.yday + ((minuend - compute_lnghour) / BigDecimal
|
19
|
+
minuend = (isSunrise) ? BigDecimal("6") : BigDecimal("18")
|
20
|
+
longHour = @date.yday + ((minuend - compute_lnghour) / BigDecimal("24"))
|
25
21
|
longHour.round(4)
|
26
22
|
end
|
27
23
|
|
28
24
|
def compute_sun_mean_anomaly(longHour)
|
29
|
-
constant = BigDecimal
|
30
|
-
((longHour * constant) - BigDecimal
|
25
|
+
constant = BigDecimal("0.9856")
|
26
|
+
((longHour * constant) - BigDecimal("3.289")).round(4)
|
31
27
|
end
|
32
28
|
|
33
29
|
def compute_sun_true_longitude(meanAnomaly)
|
34
30
|
mAsRads = degrees_as_rads(meanAnomaly)
|
35
|
-
sinM = BigDecimal
|
36
|
-
sinTwoM = BigDecimal
|
37
|
-
firstParens = BigDecimal
|
38
|
-
secondParens = BigDecimal
|
39
|
-
trueLong = meanAnomaly + firstParens + secondParens + BigDecimal
|
31
|
+
sinM = BigDecimal(Math.sin(mAsRads.to_f).to_s)
|
32
|
+
sinTwoM = BigDecimal(Math.sin((2 * mAsRads).to_f).to_s)
|
33
|
+
firstParens = BigDecimal("1.916") * sinM
|
34
|
+
secondParens = BigDecimal("0.020") * sinTwoM
|
35
|
+
trueLong = meanAnomaly + firstParens + secondParens + BigDecimal("282.634")
|
40
36
|
trueLong = put_in_range(trueLong, 0, 360, 360)
|
41
37
|
trueLong.round(4)
|
42
38
|
end
|
43
39
|
|
44
40
|
def compute_right_ascension(sunTrueLong)
|
45
|
-
tanL = BigDecimal
|
46
|
-
ra = rads_as_degrees(BigDecimal
|
41
|
+
tanL = BigDecimal(Math.tan(degrees_as_rads(sunTrueLong).to_f).to_s)
|
42
|
+
ra = rads_as_degrees(BigDecimal(Math.atan(BigDecimal("0.91764") * tanL).to_s))
|
47
43
|
|
48
44
|
ra = put_in_range(ra, 0, 360, 360)
|
49
45
|
ra.round(4)
|
50
46
|
end
|
51
47
|
|
52
48
|
def put_ra_in_correct_quadrant(sunTrueLong)
|
53
|
-
lQuadrant = BigDecimal
|
54
|
-
raQuadrant = BigDecimal
|
49
|
+
lQuadrant = BigDecimal("90") * (sunTrueLong / BigDecimal("90")).floor
|
50
|
+
raQuadrant = BigDecimal("90") * (compute_right_ascension(sunTrueLong) / BigDecimal("90")).floor
|
55
51
|
|
56
52
|
ra = compute_right_ascension(sunTrueLong) + (lQuadrant - raQuadrant)
|
57
|
-
ra = ra / BigDecimal
|
53
|
+
ra = ra / BigDecimal("15")
|
58
54
|
ra.round(4)
|
59
55
|
end
|
60
56
|
|
61
57
|
def compute_sin_sun_declination(sunTrueLong)
|
62
|
-
sinL = BigDecimal
|
63
|
-
sinDec = sinL * BigDecimal
|
58
|
+
sinL = BigDecimal(Math.sin(degrees_as_rads(sunTrueLong).to_f).to_s)
|
59
|
+
sinDec = sinL * BigDecimal("0.39782")
|
64
60
|
sinDec.round(4)
|
65
61
|
end
|
66
62
|
|
67
63
|
def compute_cosine_sun_declination(sinSunDeclination)
|
68
|
-
cosDec = BigDecimal
|
64
|
+
cosDec = BigDecimal(Math.cos(Math.asin(sinSunDeclination)).to_s)
|
69
65
|
cosDec.round(4)
|
70
66
|
end
|
71
67
|
|
72
68
|
def compute_cosine_sun_local_hour(sunTrueLong, zenith)
|
73
|
-
cosZenith = BigDecimal
|
74
|
-
sinLatitude = BigDecimal
|
75
|
-
cosLatitude = BigDecimal
|
69
|
+
cosZenith = BigDecimal(Math.cos(degrees_as_rads(BigDecimal(zenith.to_s))).to_s)
|
70
|
+
sinLatitude = BigDecimal(Math.sin(degrees_as_rads(@latitude)).to_s)
|
71
|
+
cosLatitude = BigDecimal(Math.cos(degrees_as_rads(@latitude)).to_s)
|
76
72
|
|
77
73
|
sinSunDeclination = compute_sin_sun_declination(sunTrueLong)
|
78
74
|
top = cosZenith - (sinSunDeclination * sinLatitude)
|
@@ -83,11 +79,11 @@ class SolarEventCalculator
|
|
83
79
|
end
|
84
80
|
|
85
81
|
def compute_local_hour_angle(cosSunLocalHour, isSunrise)
|
86
|
-
acosH = BigDecimal
|
82
|
+
acosH = BigDecimal(Math.acos(cosSunLocalHour).to_s)
|
87
83
|
acosHDegrees = rads_as_degrees(acosH)
|
88
84
|
|
89
|
-
localHourAngle = (isSunrise) ? BigDecimal
|
90
|
-
localHourAngle = localHourAngle / BigDecimal
|
85
|
+
localHourAngle = (isSunrise) ? BigDecimal("360") - acosHDegrees : acosHDegrees
|
86
|
+
localHourAngle = localHourAngle / BigDecimal("15")
|
91
87
|
localHourAngle.round(4)
|
92
88
|
end
|
93
89
|
|
@@ -95,8 +91,8 @@ class SolarEventCalculator
|
|
95
91
|
h = sunLocalHour
|
96
92
|
ra = put_ra_in_correct_quadrant(sunTrueLong)
|
97
93
|
|
98
|
-
parens = BigDecimal
|
99
|
-
time = h + ra - parens - BigDecimal
|
94
|
+
parens = BigDecimal("0.06571") * t
|
95
|
+
time = h + ra - parens - BigDecimal("6.622")
|
100
96
|
|
101
97
|
utcTime = time - longHour
|
102
98
|
utcTime = put_in_range(utcTime, 0, 24, 24)
|
@@ -111,7 +107,7 @@ class SolarEventCalculator
|
|
111
107
|
sunTrueLong = compute_sun_true_longitude(meanAnomaly)
|
112
108
|
cosineSunLocalHour = compute_cosine_sun_local_hour(sunTrueLong, zenith)
|
113
109
|
|
114
|
-
if(cosineSunLocalHour > BigDecimal
|
110
|
+
if(cosineSunLocalHour > BigDecimal("1") || cosineSunLocalHour < BigDecimal("-1"))
|
115
111
|
return nil
|
116
112
|
end
|
117
113
|
|
@@ -119,7 +115,7 @@ class SolarEventCalculator
|
|
119
115
|
localMeanTime = compute_local_mean_time(sunTrueLong, longHour, eventLongHour, sunLocalHour)
|
120
116
|
|
121
117
|
timeParts = localMeanTime.to_f.to_s.split('.')
|
122
|
-
mins = BigDecimal
|
118
|
+
mins = BigDecimal("." + timeParts[1]) * BigDecimal("60")
|
123
119
|
mins = mins.truncate()
|
124
120
|
mins = pad_minutes(mins.to_i)
|
125
121
|
hours = timeParts[0]
|
@@ -235,13 +231,14 @@ class SolarEventCalculator
|
|
235
231
|
|
236
232
|
def degrees_as_rads(degrees)
|
237
233
|
pi = BigDecimal(Math::PI.to_s)
|
238
|
-
radian = pi / BigDecimal
|
234
|
+
radian = pi / BigDecimal("180")
|
239
235
|
degrees * radian
|
240
236
|
end
|
241
237
|
|
242
238
|
def rads_as_degrees(radians)
|
243
239
|
pi = BigDecimal(Math::PI.to_s)
|
244
|
-
degree = BigDecimal
|
240
|
+
degree = BigDecimal("180") / pi
|
245
241
|
radians * degree
|
246
242
|
end
|
243
|
+
|
247
244
|
end
|
data/rubysunrise.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
spec = Gem::Specification.new do | s |
|
2
2
|
s.name = "RubySunrise"
|
3
|
-
s.version = "0.3.
|
3
|
+
s.version = "0.3.2"
|
4
4
|
s.author = "Mike Reedell / LuckyCatLabs"
|
5
5
|
s.email = "mike@reedell.com"
|
6
6
|
s.homepage = "http://www.mikereedell.com"
|
@@ -10,4 +10,4 @@ spec = Gem::Specification.new do | s |
|
|
10
10
|
s.test_files = Dir.glob("{test}/**/*test.rb")
|
11
11
|
s.has_rdoc = false
|
12
12
|
s.add_runtime_dependency "tzinfo"
|
13
|
-
end
|
13
|
+
end
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: RubySunrise
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Reedell / LuckyCatLabs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tzinfo
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
description:
|
@@ -30,8 +30,8 @@ executables: []
|
|
30
30
|
extensions: []
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
|
-
- rubysunrise.gemspec
|
34
33
|
- lib/solareventcalculator.rb
|
34
|
+
- rubysunrise.gemspec
|
35
35
|
- test/bulkdatatest.rb
|
36
36
|
- test/sunrisetest.rb
|
37
37
|
- test/sunsettest.rb
|
@@ -44,17 +44,16 @@ require_paths:
|
|
44
44
|
- lib
|
45
45
|
required_ruby_version: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
|
-
- -
|
47
|
+
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
49
|
version: '0'
|
50
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
requirements: []
|
56
|
-
|
57
|
-
rubygems_version: 2.0.14
|
56
|
+
rubygems_version: 3.0.3
|
58
57
|
signing_key:
|
59
58
|
specification_version: 4
|
60
59
|
summary: Calculate the sunrise/sunset given lat/long coordinates and the date. Computes
|