solar_noon 1.0.0.pre
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/.gitignore +4 -0
- data/.ruby-version +1 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +21 -0
- data/README.md +4 -0
- data/Rakefile +7 -0
- data/lib/solar_noon.rb +21 -0
- data/lib/solar_noon/calculator.rb +116 -0
- data/solar_noon.gemspec +27 -0
- data/test/minitest_helper.rb +8 -0
- data/test/solar_noon_test.rb +34 -0
- metadata +100 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 3260bd1d603d32f6ec25343d8f31795927477ea5
|
|
4
|
+
data.tar.gz: bbe6dd0b6c42ad966086e72306e6ec3fde22ca37
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 22704c71e0126483011ef41172aa47de5d84df7cf12f2252b53ef16a327e988fc478eba046bdb506981a88ffe1d75f19281444d85dfe3af3dbbbe596bc008aba
|
|
7
|
+
data.tar.gz: 55576a3bca8a30caa861e7064c94d533d309de4f3ba814783b53bad9681ee661bcae1e5a365bbc94221eb669dc7ca0788e466c9bcf1f9a9d9fe04deef8eca8d6
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2.0.0
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2013 Jason Roth
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
data/lib/solar_noon.rb
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require File.expand_path('../solar_noon/calculator', __FILE__)
|
|
2
|
+
|
|
3
|
+
module SolarNoon
|
|
4
|
+
module Extensions
|
|
5
|
+
def solar_noon(longitude)
|
|
6
|
+
SolarNoon::Calculator.new(self).calculate(longitude)
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class Date
|
|
12
|
+
include SolarNoon::Extensions
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
class DateTime
|
|
16
|
+
include SolarNoon::Extensions
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class Time
|
|
20
|
+
include SolarNoon::Extensions
|
|
21
|
+
end
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
require 'date'
|
|
2
|
+
|
|
3
|
+
module SolarNoon
|
|
4
|
+
|
|
5
|
+
class Calculator
|
|
6
|
+
|
|
7
|
+
attr_reader :date
|
|
8
|
+
|
|
9
|
+
def initialize(date)
|
|
10
|
+
@date = date.to_datetime
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Calculate noon for a given date at a given longitude
|
|
14
|
+
# Takes a Date, DateTime or Time and returns a Time instance at solar noon
|
|
15
|
+
# for that day. Time returned is UTC; to get local time call `getlocal on the
|
|
16
|
+
# result.
|
|
17
|
+
def calculate(longitude)
|
|
18
|
+
raise ArgumentError.new "Invalid longitude" unless -180.0 <= longitude && longitude <= 180.0
|
|
19
|
+
|
|
20
|
+
eq_time = true_solar_time_diff_mean_solar_time
|
|
21
|
+
|
|
22
|
+
minutes = 720 - (longitude * 4) - eq_time # in minutes
|
|
23
|
+
|
|
24
|
+
# Returned time is UTC
|
|
25
|
+
noon = Time.utc(date.year, date.month, date.day) + (minutes * 60)
|
|
26
|
+
|
|
27
|
+
noon.to_datetime
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
# convert Julian Day to centuries since J2000.0.
|
|
33
|
+
# return the T value corresponding to the Julian Day
|
|
34
|
+
def jd_centuries
|
|
35
|
+
(date.jd - 2451545.0) / 36525.0
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# calculate the difference between true solar time and mean solar time
|
|
39
|
+
# Takes a Date or DateTime and returns the equation of time in minutes of time
|
|
40
|
+
def true_solar_time_diff_mean_solar_time
|
|
41
|
+
epsilon = obliquity_correction
|
|
42
|
+
l0 = geometric_mean_longitude_of_sun
|
|
43
|
+
e = earth_orbit_eccentricity
|
|
44
|
+
m = geometric_mean_anomaly_sun
|
|
45
|
+
y = Math.tan(degree_to_radians(epsilon) / 2.0) ** 2
|
|
46
|
+
|
|
47
|
+
sin2l0 = Math.sin(2.0 * degree_to_radians(l0))
|
|
48
|
+
sinm = Math.sin(degree_to_radians(m))
|
|
49
|
+
cos2l0 = Math.cos(2.0 * degree_to_radians(l0))
|
|
50
|
+
sin4l0 = Math.sin(4.0 * degree_to_radians(l0))
|
|
51
|
+
sin2m = Math.sin(2.0 * degree_to_radians(m))
|
|
52
|
+
|
|
53
|
+
etime = y * sin2l0 - 2.0 * e * sinm + 4.0 * e * y * sinm * cos2l0 - 0.5 * y * y * sin4l0 - 1.25 * e * e * sin2m
|
|
54
|
+
|
|
55
|
+
radian_to_degrees(etime) * 4.0
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# calculate the corrected obliquity of the ecliptic
|
|
59
|
+
# Takes a Date or DateTime and returns the corrected obliquity in degrees
|
|
60
|
+
def obliquity_correction
|
|
61
|
+
t = jd_centuries
|
|
62
|
+
e0 = mean_obliquity_of_ecliptic
|
|
63
|
+
omega = 125.04 - 1934.136 * t
|
|
64
|
+
e0 + 0.00256 * Math.cos(degree_to_radians(omega))
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# calculate the Geometric Mean Longitude of the Sun
|
|
68
|
+
# Takes a Date or DateTime and returns the Geometric Mean Longitude of the
|
|
69
|
+
# Sun in degrees.
|
|
70
|
+
def geometric_mean_longitude_of_sun
|
|
71
|
+
t = jd_centuries
|
|
72
|
+
|
|
73
|
+
l0 = 280.46646 + t * (36000.76983 + 0.0003032 * t)
|
|
74
|
+
|
|
75
|
+
l0 -= 360.0 while l0 > 360.0
|
|
76
|
+
l0 += 360.0 while l0 < 0.0
|
|
77
|
+
|
|
78
|
+
l0
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# calculate the eccentricity of earth's orbit
|
|
82
|
+
# Takes a Date or DateTime and returns the unitless eccentricity
|
|
83
|
+
def earth_orbit_eccentricity
|
|
84
|
+
t = jd_centuries
|
|
85
|
+
0.016708634 - t * (0.000042037 + 0.0000001267 * t)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# calculate the Geometric Mean Anomaly of the Sun
|
|
89
|
+
# Takes a Date or DateTime and returns the Geometric Mean Anomaly of the Sun
|
|
90
|
+
# in degrees
|
|
91
|
+
def geometric_mean_anomaly_sun
|
|
92
|
+
t = jd_centuries
|
|
93
|
+
357.52911 + t * (35999.05029 - 0.0001537 * t)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# calculate the mean obliquity of the ecliptic
|
|
97
|
+
# Takes a Date or DateTime and returns the mean obliquity in degrees
|
|
98
|
+
def mean_obliquity_of_ecliptic
|
|
99
|
+
t = jd_centuries
|
|
100
|
+
seconds = 21.448 - t * (46.8150 + t * (0.00059 - t * (0.001813)))
|
|
101
|
+
23.0 + (26.0 + (seconds / 60.0)) / 60.0
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Convert degree angle to radians
|
|
105
|
+
def degree_to_radians(angle)
|
|
106
|
+
Math::PI * angle / 180.0
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Convert radian angle to degrees
|
|
110
|
+
def radian_to_degrees(angle)
|
|
111
|
+
180.0 * angle / Math::PI
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
end
|
data/solar_noon.gemspec
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |s|
|
|
5
|
+
s.name = "solar_noon"
|
|
6
|
+
s.version = "1.0.0.pre"
|
|
7
|
+
s.authors = ["Jason Roth"]
|
|
8
|
+
s.email = ["jasonmichaelroth@gmail.com"]
|
|
9
|
+
s.homepage = "https://github.com/jasonmichaelroth/solar_noon"
|
|
10
|
+
s.summary = "A solar noon calculator."
|
|
11
|
+
s.description = %q{
|
|
12
|
+
This gem extends Date, Time and DateTime with solar noon calculation
|
|
13
|
+
functions. It is based on the NOAA solar noon calculator:
|
|
14
|
+
http://www.esrl.noaa.gov/gmd/grad/solcalc
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
s.rubyforge_project = "solar_noon"
|
|
18
|
+
|
|
19
|
+
s.files = `git ls-files`.split("\n")
|
|
20
|
+
s.test_files = `git ls-files -- test/*`.split("\n")
|
|
21
|
+
s.require_paths = ["lib"]
|
|
22
|
+
|
|
23
|
+
s.add_development_dependency 'rake', '~> 10.0'
|
|
24
|
+
s.add_development_dependency 'bundler', '~> 1.3'
|
|
25
|
+
s.add_development_dependency 'minitest', '~> 5'
|
|
26
|
+
|
|
27
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require 'minitest_helper'
|
|
2
|
+
require 'solar_noon'
|
|
3
|
+
|
|
4
|
+
class SolarNoonTest < Minitest::Spec
|
|
5
|
+
|
|
6
|
+
def assert_within_one_minute(expected, actual)
|
|
7
|
+
flunk "#{actual.inspect} is not a Time or DateTime instance" unless [DateTime, Time].include? actual.class
|
|
8
|
+
flunk "#{expected.inspect} is not a Time or DateTime instance" unless [DateTime, Time].include? expected.class
|
|
9
|
+
flunk "#{actual.inspect} is not the same class as #{expected.inspect}" unless expected.is_a? actual.class
|
|
10
|
+
assert_in_delta expected, actual, 60
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
test "DST time - 2011-03-26 11:42:36 MDT at -105.0" do
|
|
14
|
+
expected = DateTime.civil(2011, 3, 26, 19, 5, 00, 'UTC')
|
|
15
|
+
assert_within_one_minute expected, Date.civil(2011, 3, 26).solar_noon(-105.0)
|
|
16
|
+
assert_within_one_minute expected, DateTime.civil(2011, 3, 26, 11, 42, 36).solar_noon(-105.0)
|
|
17
|
+
assert_within_one_minute expected, Time.local(2011, 3, 26, 11, 42, 36).solar_noon(-105.0)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
test "UTC time - 2001-06-12 19:18:15 UTC at 82.5" do
|
|
21
|
+
expected = DateTime.civil(2001, 6, 12, 6, 29, 00, 'UTC')
|
|
22
|
+
assert_within_one_minute expected, Date.civil(2001, 6, 12).solar_noon(82.5)
|
|
23
|
+
assert_within_one_minute expected, DateTime.civil(2001, 6, 12, 19, 18, 15, "UTC").solar_noon(82.5)
|
|
24
|
+
assert_within_one_minute expected, Time.utc(2001, 6, 12, 19, 18, 15).solar_noon(82.5)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
test "future time - 2031-11-28 05:07:26 MDT at 132.2" do
|
|
28
|
+
expected = DateTime.civil(2031, 11, 28, 2, 59, 00, 'UTC')
|
|
29
|
+
assert_within_one_minute expected, Date.civil(2031, 11, 28).solar_noon(132.2)
|
|
30
|
+
assert_within_one_minute expected, DateTime.civil(2031, 11, 28, 5, 7, 26, "MDT").solar_noon(132.2)
|
|
31
|
+
assert_within_one_minute expected, Time.utc(2031, 11, 28, 5, 7, 26).solar_noon(132.2)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: solar_noon
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0.pre
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Jason Roth
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2013-10-27 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rake
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ~>
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '10.0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ~>
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '10.0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: bundler
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ~>
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.3'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ~>
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.3'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: minitest
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ~>
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '5'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ~>
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '5'
|
|
55
|
+
description: "\n This gem extends Date, Time and DateTime with solar noon calculation\n
|
|
56
|
+
\ functions. It is based on the NOAA solar noon calculator:\n http://www.esrl.noaa.gov/gmd/grad/solcalc\n
|
|
57
|
+
\ "
|
|
58
|
+
email:
|
|
59
|
+
- jasonmichaelroth@gmail.com
|
|
60
|
+
executables: []
|
|
61
|
+
extensions: []
|
|
62
|
+
extra_rdoc_files: []
|
|
63
|
+
files:
|
|
64
|
+
- .gitignore
|
|
65
|
+
- .ruby-version
|
|
66
|
+
- Gemfile
|
|
67
|
+
- LICENSE.txt
|
|
68
|
+
- README.md
|
|
69
|
+
- Rakefile
|
|
70
|
+
- lib/solar_noon.rb
|
|
71
|
+
- lib/solar_noon/calculator.rb
|
|
72
|
+
- solar_noon.gemspec
|
|
73
|
+
- test/minitest_helper.rb
|
|
74
|
+
- test/solar_noon_test.rb
|
|
75
|
+
homepage: https://github.com/jasonmichaelroth/solar_noon
|
|
76
|
+
licenses: []
|
|
77
|
+
metadata: {}
|
|
78
|
+
post_install_message:
|
|
79
|
+
rdoc_options: []
|
|
80
|
+
require_paths:
|
|
81
|
+
- lib
|
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
|
+
requirements:
|
|
84
|
+
- - '>='
|
|
85
|
+
- !ruby/object:Gem::Version
|
|
86
|
+
version: '0'
|
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
|
+
requirements:
|
|
89
|
+
- - '>'
|
|
90
|
+
- !ruby/object:Gem::Version
|
|
91
|
+
version: 1.3.1
|
|
92
|
+
requirements: []
|
|
93
|
+
rubyforge_project: solar_noon
|
|
94
|
+
rubygems_version: 2.0.3
|
|
95
|
+
signing_key:
|
|
96
|
+
specification_version: 4
|
|
97
|
+
summary: A solar noon calculator.
|
|
98
|
+
test_files:
|
|
99
|
+
- test/minitest_helper.rb
|
|
100
|
+
- test/solar_noon_test.rb
|