opentideconstants 0.0.0 → 0.1.0
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 +4 -4
- data/README.md +132 -3
- data/lib/opentideconstants/bgzf.rb +436 -0
- data/lib/opentideconstants/cache.rb +559 -0
- data/lib/opentideconstants/cache_json.rb +67 -0
- data/lib/opentideconstants/canonical.rb +756 -0
- data/lib/opentideconstants/canonical_types.rb +2537 -0
- data/lib/opentideconstants/client.rb +1135 -0
- data/lib/opentideconstants/downloader.rb +400 -0
- data/lib/opentideconstants/errors.rb +210 -0
- data/lib/opentideconstants/fold.rb +24 -0
- data/lib/opentideconstants/historical_fingerprint.rb +58 -0
- data/lib/opentideconstants/http.rb +483 -0
- data/lib/opentideconstants/models.rb +635 -0
- data/lib/opentideconstants/name_fold.json +949 -0
- data/lib/opentideconstants/predict/astro.rb +85 -0
- data/lib/opentideconstants/predict/daily-facts.json +1 -0
- data/lib/opentideconstants/predict/daily.rb +62 -0
- data/lib/opentideconstants/predict/engine.rb +506 -0
- data/lib/opentideconstants/predict/harmonic.rb +228 -0
- data/lib/opentideconstants/predict/local.rb +49 -0
- data/lib/opentideconstants/predict/results.rb +357 -0
- data/lib/opentideconstants/predict/retained.rb +487 -0
- data/lib/opentideconstants/predict.rb +192 -0
- data/lib/opentideconstants/reader.rb +493 -0
- data/lib/opentideconstants/release.rb +1531 -0
- data/lib/opentideconstants/version.rb +15 -0
- data/lib/opentideconstants.rb +24 -3
- data/supported-formats.json +5 -0
- metadata +37 -5
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
class OpenTideConstants
|
|
2
|
+
module Predict
|
|
3
|
+
RAD = Math::PI / 180.0
|
|
4
|
+
module_function
|
|
5
|
+
def instant(value)
|
|
6
|
+
raise InvalidArgumentError, "an instant must be a Time" unless value.is_a?(Time)
|
|
7
|
+
value.to_r.floor
|
|
8
|
+
end
|
|
9
|
+
def utc(seconds)
|
|
10
|
+
Time.at(seconds).utc.freeze
|
|
11
|
+
end
|
|
12
|
+
def year_start(year)
|
|
13
|
+
Time.utc(year, 1, 1).to_i
|
|
14
|
+
end
|
|
15
|
+
def angle(value)
|
|
16
|
+
reduced = value - 360.0 * (value / 360.0).floor
|
|
17
|
+
reduced == 360.0 ? 0.0 : reduced
|
|
18
|
+
end
|
|
19
|
+
def number?(value)
|
|
20
|
+
value.is_a?(Numeric) && value.real? && value.to_f.finite?
|
|
21
|
+
end
|
|
22
|
+
def integer?(value)
|
|
23
|
+
number?(value) && value == value.floor
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
class AstroTable
|
|
27
|
+
def initialize(raw)
|
|
28
|
+
@raw = Util.deep_freeze(raw)
|
|
29
|
+
ident = raw.fetch("astro_table_id", "")
|
|
30
|
+
first, last = raw.values_at("first_year", "last_year")
|
|
31
|
+
unless Predict.integer?(first) && Predict.integer?(last) && first <= last
|
|
32
|
+
raise InvalidArgumentError, "astro table #{ident} first_year and last_year must be ordered integers"
|
|
33
|
+
end
|
|
34
|
+
@first, @last = first.to_i, last.to_i
|
|
35
|
+
rows = raw["constituents"]
|
|
36
|
+
raise InvalidArgumentError, "astro table #{ident} constituents must be an object" unless rows.is_a?(Hash)
|
|
37
|
+
rows.each do |name, row|
|
|
38
|
+
raise InvalidArgumentError, "astro table #{ident} row #{name} must be an object" unless row.is_a?(Hash)
|
|
39
|
+
%w[v0u_deg f].each do |key|
|
|
40
|
+
values = row[key]
|
|
41
|
+
unless values.is_a?(Array) && values.size == @last - @first + 1 && values.all? { |v| Predict.number?(v) }
|
|
42
|
+
raise InvalidArgumentError, "astro table #{ident} row #{name} #{key} must contain #{@last - @first + 1} numbers"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
speed = row["speed_deg_per_hour"]
|
|
46
|
+
raise InvalidArgumentError, "astro table #{ident} row #{name} speed must be nonnegative" unless speed.nil? || Predict.number?(speed) && speed >= 0
|
|
47
|
+
end
|
|
48
|
+
freeze
|
|
49
|
+
end
|
|
50
|
+
def valid_range
|
|
51
|
+
[@first, @last].freeze
|
|
52
|
+
end
|
|
53
|
+
def equilibrium_argument(name, at)
|
|
54
|
+
seconds = Predict.instant(at)
|
|
55
|
+
row = row_for(name)
|
|
56
|
+
year = Predict.utc(seconds).year
|
|
57
|
+
Predict.angle(row["v0u_deg"][index_for(year)] + row["speed_deg_per_hour"] * ((seconds - Predict.year_start(year)) / 3600.0))
|
|
58
|
+
end
|
|
59
|
+
def node_factor(name, at)
|
|
60
|
+
row_for(name)["f"][index_for(Predict.utc(Predict.instant(at)).year)]
|
|
61
|
+
end
|
|
62
|
+
def equilibrium_for_year(name, year)
|
|
63
|
+
row_for(name)["v0u_deg"][index_for(year)]
|
|
64
|
+
end
|
|
65
|
+
def node_factor_for_year(name, year)
|
|
66
|
+
row_for(name)["f"][index_for(year)]
|
|
67
|
+
end
|
|
68
|
+
private
|
|
69
|
+
def validate_year_argument(year)
|
|
70
|
+
raise InvalidArgumentError, "year must be an integer" unless Predict.integer?(year)
|
|
71
|
+
end
|
|
72
|
+
def index_for(year)
|
|
73
|
+
validate_year_argument(year)
|
|
74
|
+
unless year.between?(@first, @last)
|
|
75
|
+
raise TimeOutOfRangeError.new("year #{year} outside astro table", first_year: @first, last_year: @last)
|
|
76
|
+
end
|
|
77
|
+
year.to_i - @first
|
|
78
|
+
end
|
|
79
|
+
def row_for(name)
|
|
80
|
+
row = name.is_a?(String) && @raw["constituents"][name]
|
|
81
|
+
raise UnsupportedConstituentError.new("unsupported constituent #{name}", constituent: name) unless row && row["speed_deg_per_hour"]
|
|
82
|
+
row
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"basis":"CONGEN-compatible source correction","facts":{"2MK5":{"angular_weights":{"nu":-4.0,"nu_prime":-1.0,"xi":4.0},"factor_powers":{"227":1.0,"78":2.0}},"2MK6":{"angular_weights":{"nu":-4.0,"twice_nu_double_prime":-1.0,"xi":4.0},"factor_powers":{"235":1.0,"78":2.0}},"2MN6":{"angular_weights":{"nu":-6.0,"xi":6.0},"factor_powers":{"78":3.0}},"2MS6":{"angular_weights":{"nu":-4.0,"xi":4.0},"factor_powers":{"78":2.0}},"2N2":{"angular_weights":{"nu":-2.0,"xi":2.0},"factor_powers":{"78":1.0}},"2Q1":{"angular_weights":{"nu":-1.0,"xi":2.0},"factor_powers":{"75":1.0}},"2SK5":{"angular_weights":{"nu_prime":-1.0},"factor_powers":{"227":1.0}},"2SM6":{"angular_weights":{"nu":-2.0,"xi":2.0},"factor_powers":{"78":1.0}},"3MK7":{"angular_weights":{"nu":-6.0,"nu_prime":-1.0,"xi":6.0},"factor_powers":{"227":1.0,"78":3.0}},"ALP1":{"harmonic_satellites":[{"node":1.0,"perigee":0.0,"phase_degrees":0.0,"solar_perigee":0.0,"weight":0.1906}]},"BET1":{"harmonic_satellites":[{"node":1.0,"perigee":0.0,"phase_degrees":0.0,"solar_perigee":0.0,"weight":0.2266}]},"EPS2":{"harmonic_satellites":[{"node":1.0,"perigee":0.0,"phase_degrees":180.0,"solar_perigee":0.0,"weight":0.0373}]},"ETA2":{"harmonic_satellites":[{"node":-2.0,"perigee":0.0,"phase_degrees":0.0,"solar_perigee":0.0,"weight":0.0467},{"node":-1.0,"perigee":0.0,"phase_degrees":0.0,"solar_perigee":0.0,"weight":0.4355},{"node":1.0,"perigee":0.0,"phase_degrees":180.0,"solar_perigee":0.0,"weight":0.0187},{"node":-0.0,"perigee":2.0,"phase_degrees":180.0,"solar_perigee":0.0,"weight":0.0078}]},"H1":{"harmonic_satellites":[{"node":1.0,"perigee":0.0,"phase_degrees":180.0,"solar_perigee":0.0,"weight":0.0224},{"node":-0.0,"perigee":1.0,"phase_degrees":180.0,"solar_perigee":-1.0,"weight":0.0447}]},"H2":{"harmonic_satellites":[{"node":1.0,"perigee":0.0,"phase_degrees":180.0,"solar_perigee":0.0,"weight":0.0217}]},"J1":{"angular_weights":{"nu":-1.0},"factor_powers":{"76":1.0}},"K1":{"angular_weights":{"nu_prime":-1.0},"factor_powers":{"227":1.0}},"K2":{"angular_weights":{"twice_nu_double_prime":-1.0},"factor_powers":{"235":1.0}},"L2":{"angular_weights":{"nu":-2.0,"r":-1.0,"xi":2.0},"factor_powers":{"215":1.0}},"LDA2":{"angular_weights":{"nu":-2.0,"xi":2.0},"factor_powers":{"78":1.0}},"M2":{"angular_weights":{"nu":-2.0,"xi":2.0},"factor_powers":{"78":1.0}},"M3":{"angular_weights":{"nu":-3.0,"xi":3.0},"factor_powers":{"149":1.0}},"M4":{"angular_weights":{"nu":-4.0,"xi":4.0},"factor_powers":{"78":2.0}},"M6":{"angular_weights":{"nu":-6.0,"xi":6.0},"factor_powers":{"78":3.0}},"M8":{"angular_weights":{"nu":-8.0,"xi":8.0},"factor_powers":{"78":4.0}},"MF":{"angular_weights":{"xi":-2.0},"factor_powers":{"74":1.0}},"MK3":{"angular_weights":{"nu":-2.0,"nu_prime":-1.0,"xi":2.0},"factor_powers":{"227":1.0,"78":1.0}},"MK4":{"angular_weights":{"nu":-2.0,"twice_nu_double_prime":-1.0,"xi":2.0},"factor_powers":{"235":1.0,"78":1.0}},"MKS2":{"angular_weights":{"nu":-2.0,"twice_nu_double_prime":-1.0,"xi":2.0},"factor_powers":{"235":1.0,"78":1.0}},"MM":{"angular_weights":{},"factor_powers":{"73":1.0}},"MN4":{"angular_weights":{"nu":-4.0,"xi":4.0},"factor_powers":{"78":2.0}},"MO3":{"angular_weights":{"nu":-3.0,"xi":4.0},"factor_powers":{"75":1.0,"78":1.0}},"MS4":{"angular_weights":{"nu":-2.0,"xi":2.0},"factor_powers":{"78":1.0}},"MSK6":{"angular_weights":{"nu":-2.0,"twice_nu_double_prime":-1.0,"xi":2.0},"factor_powers":{"235":1.0,"78":1.0}},"MSN2":{"angular_weights":{},"factor_powers":{"78":2.0}},"MU2":{"angular_weights":{"nu":-2.0,"xi":2.0},"factor_powers":{"78":1.0}},"N2":{"angular_weights":{"nu":-2.0,"xi":2.0},"factor_powers":{"78":1.0}},"NO1":{"angular_weights":{"nu":-1.0},"factor_powers":{"75":1.0,"78":1.0}},"NU2":{"angular_weights":{"nu":-2.0,"xi":2.0},"factor_powers":{"78":1.0}},"O1":{"angular_weights":{"nu":-1.0,"xi":2.0},"factor_powers":{"75":1.0}},"OO1":{"angular_weights":{"nu":-1.0,"xi":-2.0},"factor_powers":{"77":1.0}},"OQ2":{"harmonic_satellites":[{"node":1.0,"perigee":0.0,"phase_degrees":180.0,"solar_perigee":0.0,"weight":0.0386}]},"P1":{"angular_weights":{},"factor_powers":{}},"PHI1":{"angular_weights":{},"factor_powers":{}},"PI1":{"angular_weights":{},"factor_powers":{}},"PSI1":{"angular_weights":{},"factor_powers":{}},"Q1":{"angular_weights":{"nu":-1.0,"xi":2.0},"factor_powers":{"75":1.0}},"R2":{"angular_weights":{},"factor_powers":{}},"RHO1":{"angular_weights":{"nu":-1.0,"xi":2.0},"factor_powers":{"75":1.0}},"S1":{"angular_weights":{},"factor_powers":{}},"S2":{"angular_weights":{},"factor_powers":{}},"S4":{"angular_weights":{},"factor_powers":{}},"SA":{"angular_weights":{},"factor_powers":{}},"SIG1":{"angular_weights":{"nu":-1.0,"xi":2.0},"factor_powers":{"75":1.0}},"SK3":{"angular_weights":{"nu_prime":-1.0},"factor_powers":{"227":1.0}},"SK4":{"angular_weights":{"twice_nu_double_prime":-1.0},"factor_powers":{"235":1.0}},"SN4":{"angular_weights":{"nu":-2.0,"xi":2.0},"factor_powers":{"78":1.0}},"SO1":{"angular_weights":{"nu":-1.0},"factor_powers":{"76":1.0}},"SO3":{"angular_weights":{"nu":-1.0,"xi":2.0},"factor_powers":{"75":1.0}},"SSA":{"angular_weights":{},"factor_powers":{}},"T2":{"angular_weights":{},"factor_powers":{}},"TAU1":{"harmonic_satellites":[{"node":-0.0,"perigee":-2.0,"phase_degrees":0.0,"solar_perigee":0.0,"weight":0.0446},{"node":-2.0,"perigee":0.0,"phase_degrees":180.0,"solar_perigee":0.0,"weight":0.0142},{"node":-1.0,"perigee":0.0,"phase_degrees":180.0,"solar_perigee":0.0,"weight":0.217},{"node":1.0,"perigee":0.0,"phase_degrees":180.0,"solar_perigee":0.0,"weight":0.0284}]},"THE1":{"angular_weights":{"nu":-1.0},"factor_powers":{"76":1.0}}},"method":"source_daily_utc_noon"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
class OpenTideConstants
|
|
4
|
+
module Predict
|
|
5
|
+
class DailyCorrection
|
|
6
|
+
FACTS = JSON.parse(File.binread(File.join(__dir__, "daily-facts.json"))).fetch("facts").freeze
|
|
7
|
+
RAD = Math::PI / 180.0
|
|
8
|
+
|
|
9
|
+
def initialize(names)
|
|
10
|
+
@facts = names.map do |name|
|
|
11
|
+
FACTS.fetch(name) { raise UnsupportedError, "daily correction unavailable for #{name}" }
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def at(seconds)
|
|
16
|
+
t = (seconds + 2209032000.0) / 3155760000.0
|
|
17
|
+
p = 334 + 19.0 / 60 + 40.87 / 3600 + (3960 + 392515.94 / 3600) * t - 37.24 / 3600 * t**2 - 0.045 / 3600 * t**3
|
|
18
|
+
p1 = 281 + 13.0 / 60 + 15.0 / 3600 + 6189.03 / 3600 * t + 1.63 / 3600 * t**2 + 0.012 / 3600 * t**3
|
|
19
|
+
n = 259 + 10.0 / 60 + 57.12 / 3600 - (1800 + 482912.63 / 3600) * t + 7.58 / 3600 * t**2 + 0.008 / 3600 * t**3
|
|
20
|
+
w = (23 + 27.0 / 60 + 8.26 / 3600) * RAD
|
|
21
|
+
j = (5 + 8.0 / 60 + 43.3546 / 3600) * RAD
|
|
22
|
+
nr = n * RAD
|
|
23
|
+
i = Math.acos(Math.cos(w) * Math.cos(j) - Math.sin(w) * Math.sin(j) * Math.cos(nr))
|
|
24
|
+
nu = Math.asin(Math.sin(j) * Math.sin(nr) / Math.sin(i))
|
|
25
|
+
xi = n - Math.atan2(Math.sin(w) * Math.sin(nr) / Math.sin(i), Math.cos(nr) * Math.cos(nu) + Math.sin(nr) * Math.sin(nu) * Math.cos(w)) / RAD
|
|
26
|
+
pp = (p - xi) * RAD
|
|
27
|
+
q = Math.atan2(0.483 * Math.sin(pp), Math.cos(pp)) / RAD
|
|
28
|
+
r = Math.atan2(Math.sin(2 * pp), 1 / (6 * Math.tan(i / 2)**2) - Math.cos(2 * pp)) / RAD
|
|
29
|
+
angles = {"nu" => nu / RAD, "xi" => xi, "q" => q, "r" => r,
|
|
30
|
+
"nu_prime" => Math.atan2(Math.sin(2 * i) * Math.sin(nu), Math.sin(2 * i) * Math.cos(nu) + 0.3347) / RAD,
|
|
31
|
+
"twice_nu_double_prime" => Math.atan2(Math.sin(i)**2 * Math.sin(2 * nu), Math.sin(i)**2 * Math.cos(2 * nu) + 0.0727) / RAD,
|
|
32
|
+
"perigee_minus_xi_minus_q" => p - xi - q}
|
|
33
|
+
s, c, h = Math.sin(i), Math.cos(i / 2), Math.sin(i / 2)
|
|
34
|
+
factors = {"73" => (2.0 / 3 - s**2) / 0.5021, "74" => s**2 / 0.1578,
|
|
35
|
+
"75" => s * c**2 / 0.38, "76" => Math.sin(2 * i) / 0.7214,
|
|
36
|
+
"77" => s * h**2 / 0.0164, "78" => c**4 / 0.9154,
|
|
37
|
+
"79" => s**2 / 0.1565, "144" => (1 - 10 * h**2 + 15 * h**4) * c**2 / 0.5873,
|
|
38
|
+
"149" => c**6 / 0.8758,
|
|
39
|
+
"227" => Math.sqrt(0.8965 * Math.sin(2 * i)**2 + 0.6001 * Math.sin(2 * i) * Math.cos(nu) + 0.1006),
|
|
40
|
+
"235" => Math.sqrt(19.0444 * s**4 + 2.7702 * s**2 * Math.cos(2 * nu) + 0.0981)}
|
|
41
|
+
factors["206"] = factors["75"] * Math.sqrt(2.31 + 1.435 * Math.cos(2 * pp))
|
|
42
|
+
factors["215"] = factors["78"] * Math.sqrt(1 - 12 * Math.tan(i / 2)**2 * Math.cos(2 * pp) + 36 * Math.tan(i / 2)**4)
|
|
43
|
+
values = @facts.map do |fact|
|
|
44
|
+
if fact.key?("harmonic_satellites")
|
|
45
|
+
x, y = 1.0, 0.0
|
|
46
|
+
fact["harmonic_satellites"].each do |sat|
|
|
47
|
+
theta = (sat["phase_degrees"] + sat["perigee"] * p + sat["node"] * n + sat["solar_perigee"] * p1) * RAD
|
|
48
|
+
x += sat["weight"] * Math.cos(theta)
|
|
49
|
+
y += sat["weight"] * Math.sin(theta)
|
|
50
|
+
end
|
|
51
|
+
[Math.hypot(x, y), Math.atan2(y, x) / RAD, 0.0]
|
|
52
|
+
else
|
|
53
|
+
weights = fact.fetch("angular_weights")
|
|
54
|
+
[fact.fetch("factor_powers").reduce(1.0) { |v, (k, power)| v * factors.fetch(k)**power },
|
|
55
|
+
weights.sum { |k, value| angles.fetch(k) * value }, weights.fetch("q", 0.0)]
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
[p, values]
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|