sun 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sun.rb +117 -1
- data/lib/sun/version.rb +1 -1
- data/sun.gemspec +5 -2
- metadata +53 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62b638fc2309bc08dff55796cee15932fd4d791d
|
4
|
+
data.tar.gz: c6c556fafabec3ea2d959d1c2c13c80299d15836
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b8411da7c981e71efb2584e05278c7f001bb3ca069feb5281dcb7af8782b58d5f7d2ff83f7156ed14a2eb29c0412f8e91e789fbe3d6aaa9283a3637f54539ae
|
7
|
+
data.tar.gz: 7747c1543b1769044b0430c7ed6257b88f4d903eb688e04aed82bc5521c3b016e2bdc3e6e942cf6ac77832b1d17473160273b5ce3fe187572d152883bf9a8b2c
|
data/lib/sun.rb
CHANGED
@@ -1,5 +1,121 @@
|
|
1
1
|
require 'sun/version'
|
2
2
|
|
3
3
|
module Sun
|
4
|
-
|
4
|
+
SOLAR_ZENITH = 90.833
|
5
|
+
|
6
|
+
# Noon on January 1st, 2000
|
7
|
+
JULIAN_CONSTANT = 2451545.to_r
|
8
|
+
|
9
|
+
# Sun times
|
10
|
+
def self.solar_noon(time, latitude, longitude)
|
11
|
+
minutes = solar_noon_minutes(time, latitude, longitude)
|
12
|
+
date_at_time(time.to_date, minutes)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.sunrise(time, latitude, longitude)
|
16
|
+
minutes = sunrise_minutes(time, latitude, longitude)
|
17
|
+
date_at_time(time.to_date, minutes)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.sunset(time, latitude, longitude)
|
21
|
+
minutes = sunset_minutes(time, latitude, longitude)
|
22
|
+
date_at_time(time.to_date, minutes)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Helpers
|
26
|
+
def self.degrees(radians)
|
27
|
+
180.0 * radians / Math::PI
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.radians(degrees)
|
31
|
+
Math::PI * degrees / 180.0
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.date_to_unix_time(date)
|
35
|
+
Time.utc(date.year, date.month, date.day).to_i
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.date_at_time(date, minutes)
|
39
|
+
date_to_unix_time(date) + minutes * 60
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.julian_days(time)
|
43
|
+
time.utc.to_datetime.ajd
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.julian_century(time)
|
47
|
+
(julian_days(time) - JULIAN_CONSTANT) / 36525
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.mean_obliquity_of_ecliptic(julian_century)
|
51
|
+
23 + (26 + ((21.448 - julian_century * (46.815 + julian_century * (0.00059 - julian_century * 0.001813)))) / 60) / 60
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.oblique_correction(julian_century)
|
55
|
+
mean_obliquity_of_ecliptic(julian_century) + 0.00256 * Math.cos(radians(125.04 - 1934.136 * julian_century))
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.geometric_mean_anomoly(julian_century)
|
59
|
+
357.52911 + julian_century * (35999.05029 - 0.0001537 * julian_century)
|
60
|
+
end
|
61
|
+
|
62
|
+
# MOD(280.46646+G2*(36000.76983 + G2*0.0003032),360)
|
63
|
+
def self.geometric_mean_longitude(julian_century)
|
64
|
+
280.46646 + julian_century * (36000.76983 + julian_century * 0.0003032) % 360
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.y(oblique_correction)
|
68
|
+
Math.tan(radians(Rational(oblique_correction, 2))) * Math.tan(radians(Rational(oblique_correction, 2)))
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.eccentricity_of_earth_orbit(julian_century)
|
72
|
+
0.016708634 - julian_century * (0.000042037 + 0.0000001267 * julian_century)
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.equation_of_center(julian_century)
|
76
|
+
geometric_mean_anomoly = geometric_mean_anomoly(julian_century)
|
77
|
+
Math.sin(radians(geometric_mean_anomoly)) * (1.914602 - julian_century * (0.004817 + 0.000014 * julian_century)) + Math.sin(radians(2 * geometric_mean_anomoly)) * (0.019993 - 0.000101 * julian_century) + Math.sin(radians(3 * geometric_mean_anomoly)) * 0.00028
|
78
|
+
# =SIN(RADIANS(J2))*(1.914602-G2*(0.004817+0.000014*G2))+SIN(RADIANS(2*J2))*(0.019993-0.000101*G2)+SIN(RADIANS(3*J2))*0.00028
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.true_longitude(julian_century)
|
82
|
+
geometric_mean_longitude(julian_century) + equation_of_center(julian_century)
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.apparent_longitude(julian_century)
|
86
|
+
true_longitude(julian_century) - 0.00569 - 0.00478 * Math.sin(radians(125.04 - 1934.136 * julian_century))
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.declination(oblique_correction, julian_century)
|
90
|
+
degrees(Math.asin(Math.sin(radians(oblique_correction)) * Math.sin(radians(apparent_longitude(julian_century)))))
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.equation_of_time(time, longitude)
|
94
|
+
julian_century = julian_century(time)
|
95
|
+
oblique_correction = oblique_correction(julian_century)
|
96
|
+
geometric_mean_anomoly = geometric_mean_anomoly(julian_century)
|
97
|
+
geometric_mean_longitude = geometric_mean_longitude(julian_century)
|
98
|
+
eccentricity_of_earth_orbit = eccentricity_of_earth_orbit(julian_century)
|
99
|
+
y = y(oblique_correction)
|
100
|
+
4 * degrees(y * Math.sin(2 * radians(geometric_mean_longitude)) - 2 * eccentricity_of_earth_orbit * Math.sin(radians(geometric_mean_anomoly)) + 4 * eccentricity_of_earth_orbit * y * Math.sin(radians(geometric_mean_anomoly)) * Math.cos(2 * radians(geometric_mean_longitude)) - 0.5 * y * y * Math.sin(4 * radians(geometric_mean_longitude)) - 1.25 * eccentricity_of_earth_orbit * eccentricity_of_earth_orbit * Math.sin(2 * radians(geometric_mean_anomoly)))
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.hour_angle(time, latitude)
|
104
|
+
julian_century = julian_century(time)
|
105
|
+
oblique_correction = oblique_correction(julian_century)
|
106
|
+
declination = declination(oblique_correction, julian_century)
|
107
|
+
degrees(Math.acos(Math.cos(radians(90.833)) / (Math.cos(radians(latitude)) * Math.cos(radians(declination))) - Math.tan(radians(latitude)) * Math.tan(radians(declination))))
|
108
|
+
end
|
109
|
+
|
110
|
+
def self.solar_noon_minutes(time, latitude, longitude)
|
111
|
+
720 - (4 * longitude) - equation_of_time(time, longitude)
|
112
|
+
end
|
113
|
+
|
114
|
+
def self.sunrise_minutes(time, latitude, longitude)
|
115
|
+
solar_noon_minutes(time, latitude, longitude) - 4 * hour_angle(time, latitude)
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.sunset_minutes(time, latitude, longitude)
|
119
|
+
solar_noon_minutes(time, latitude, longitude) + 4 * hour_angle(time, latitude)
|
120
|
+
end
|
5
121
|
end
|
data/lib/sun/version.rb
CHANGED
data/sun.gemspec
CHANGED
@@ -26,7 +26,10 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
27
|
spec.require_paths = ['lib']
|
28
28
|
|
29
|
-
spec.add_development_dependency 'bundler'
|
30
|
-
spec.add_development_dependency '
|
29
|
+
spec.add_development_dependency 'bundler'
|
30
|
+
spec.add_development_dependency 'byebug'
|
31
31
|
spec.add_development_dependency 'minitest'
|
32
|
+
spec.add_development_dependency 'minitest-reporters'
|
33
|
+
spec.add_development_dependency 'rake'
|
34
|
+
spec.add_development_dependency 'tzinfo'
|
32
35
|
end
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cory Kaufman-Schofield
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: byebug
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +52,48 @@ dependencies:
|
|
52
52
|
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest-reporters
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: tzinfo
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
55
97
|
description:
|
56
98
|
email:
|
57
99
|
- cory@corykaufman.com
|