2011-02-23 45 views
2

〜大約正午

lw = 88.743 # my longitude 

jdate = Date.ordinal_to_jd(Time.now.year, Time.now.yday) 
n = (jdate - 2451545 - 0.0009 - lw/360).round # lw is users longitude west of 0. 
j_noon = 2451545 + 0.0009 + lw/360 + n 
puts j_noon 

=> 2455616.24740833 

作爲更新,混亂的部分將是正午太陽是所有 計算,因爲1月1日,4713 BC格林威治中午開始。使用Ruby Date類的天文數據

Date.ordinal_to_jd的正確使用尚未彌補這一事實。因此,通過 加上或減去12小時這樣的:

jdn = Date.ordinal_to_jd(Time.now.year, Time.now.yday) - 0.5 

我們應該得到更少的錯誤。雖然我們使用了哪些,但由於我們的計算 從昨天中午開始?

該代碼是從這個頁面的兩個方程派生的Sunrise_equation

我從這裏用戶那裏得到的第一個回答是,我們不明白使用 0.0009和LW/360 LW/360似乎是弧從 本初子午線分數的日子。至於0.0009,它必須是自公元前4713年1月1日格林尼治中午公元前 秒以內的少量變化。請參閱IAU標準更多信息

根據此page我計算它爲0.007776秒。

我有一些來自Date類的信息,不包括方法的細節。

 =begin 
--------------------------------------------------------------------- Class: Date 
Class representing a date. 

See the documentation to the file date.rb for an overview. 

Internally, the date is represented as an Astronomical Julian Day Number, ajd. 
The Day of Calendar Reform, sg, is also stored, for conversions to other date formats. 
(There is also an of field for a time zone offset, 
but this is only for the use of the DateTime subclass.) 

A new Date object is created using one of the object creation class methods named 
after the corresponding date format, and the arguments appropriate to that date 
format; for instance, Date::civil() 
(aliased to Date::new()) with year, month, and day-of-month, or Date::ordinal() with 
year and day-of-year. 

All of these object creation class methods also take the Day of Calendar Reform as an 
optional argument. 

Date objects are immutable once created. 

Once a Date has been created, date values can be retrieved for the different date 
formats supported using instance methods. For instance, #mon() gives the Civil month, 
#cwday() gives the Commercial day of the week, and #yday() gives the Ordinal day of 
the year. Date values can be retrieved in any format, regardless of what format was 
used to create the Date instance. 

The Date class includes the Comparable module, allowing date objects to be compared 
and sorted, ranges of dates to be created, and so forth. 

--------------------------------------------------------------------------------- 

Includes: 
Comparable(<, <=, ==, >, >=, between?) 

Constants: 
MONTHNAMES:  [nil] + %w(January February March April May June July August 
          September October November December) 
DAYNAMES:  %w(Sunday Monday Tuesday Wednesday Thursday Friday Saturday) 
ABBR_MONTHNAMES: [nil] + %w(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) 
ABBR_DAYNAMES: %w(Sun Mon Tue Wed Thu Fri Sat) 
ITALY:   2299161 
ENGLAND:   2361222 
JULIAN:   Infinity.new 
GREGORIAN:  -Infinity.new 

Class methods: 
_load, _parse, _strptime, ajd_to_amjd, ajd_to_jd, amjd_to_ajd, civil, civil_to_jd, 
commercial, commercial_to_jd, day_fraction_to_time, gregorian?, gregorian_leap?, jd, 
jd_to_ajd, jd_to_civil, jd_to_commercial, jd_to_ld, jd_to_mjd, jd_to_ordinal, 
jd_to_wday, julian?, julian_leap?, ld_to_jd, mjd_to_jd, new, now, ordinal, 
ordinal_to_jd, parse, s3e, strptime, time_to_day_fraction, today, valid_civil?, 
valid_commercial?, valid_jd?, valid_ordinal?, valid_time? 

Instance methods: 
+, -, <<, <=>, ===, >>, _dump, ajd, amjd, asctime, civil, commercial, ctime, cwday, 
cweek, cwyear, day, day_fraction, downto, england, eql?, gregorian, gregorian?, hash, 
hour, inspect, italy, jd, julian, julian?, ld, leap?, mday, min, mjd, mon, month, 
new_offset, new_start, next, next_day, offset, ordinal, sec, sec_fraction, start, 
step, strftime, succ, time, to_s, to_yaml, upto, wday, weeknum0, weeknum1, wnum0, 
wnum1, yday, year, zone 

=end 

作爲一個方面說明,Ruby有一種方法可以計算出Julian日期。 我在尋找來自NOAA的Javascript代碼。

這是一個我受到啓發的鏈接寫的類。

class JulianDayNumber 

    def initialize(year = 2000, month = 1, day = 1) #defaults to Jan. 01, 2000 
    @year = year 
    @month = month 
    @day = day 
    end 

    def calcJDN 

    if (@month <= 2) then 
     @year -= 1 
     @month += 12 
    end 

    varA = (@year/100).floor 
    varB = 2 - varA + (varA/4).floor 

    jdn = (365.25*(@year + 4716)).floor \ 
      + (30.6001*(@month+1)).floor \ 
      + @day + varB - 1524.5 

    return jdn 
    end 

end 

jd = JulianDayNumber.new(2011, 3, 2) 
julianday = jd.calcJDN 
puts julianday 

=> 2455622.5 

現在,這讓我有,但我仍然爲研究的方式回到了許多這樣的 由最上面的公式計算出的一個。嘗試這一點,我們可以看到我們在JDN中獲得了0.5。誰是對的? Ruby還是NOAA?


NOAA使用的2451545.0在2000年1月1日值從JD減去獲取時間 分數世紀這樣

def calcTimeJulianCent(j) 
     t = (j - 2451545.0)/36525.0 
     return t 
    end 
+0

有關Julian Day歷史的更多信息,請參閱http://en.wikipedia.org/wiki/Julian_day#History – Douglas 2011-05-18 16:26:25

回答

0

的方法ordinal_to_jd的一天,今年的指數0轉換2011(陽曆),以相應的一天的儒略曆,那麼你正在使用的0.0009對此我不魔法值知道任何理由,那麼你將你的經度的整個360的比例(東或西?) *圈子,然後添加今天的一天(今天54如果你今天評估它)。儒略曆和縱向比相結合,使沒有太大意義,但嘿它的一個不錯的號碼,因爲你在混合0.0009。

+0

我已經更正了現在的代碼。此外,我添加了一個用於我的目的的鏈接。 – Douglas 2011-02-23 22:44:46

3

Ruby有一些計算儒略日的方式,你需要選擇是正確的。如你所知,NOAA正在計算自BC 1月1日公元前4713年格林威治中午的JD。它總是以.5結尾,因爲他們正在離開分數日。

Ruby的儒略日是怪異:

爲了科學目的,是 方便指的日期只是 的天數,從 任意初始之日起計算。爲此選擇的日期第一個 是公元前4713年 年1月1日。此日期的天數爲 Julian日數或Julian日期, ,在Date 類中縮寫爲jd。這是在當地時間, 從午夜開始計算,最初的日期爲 。

這對天文學的使用沒有意義。但請稍等..

更嚴格的用法是UTC, 從第一天的中午開始計數。 這被稱爲日期類 作爲天文朱利安天數, 和縮寫爲ajd。在日期 班,天文朱利安日 數包括部分天數。

rubydoc

這是你在找什麼,AJD。只需得到它沒有小數天:

julianday = Date.civil(@year, @month, @day).ajd 
puts julianday 

=> 2455622.5 

無需端口來自NOAA的9行JavaScript。 Ruby回來了! ;)

0

謝謝大家,我猜我現在可以回答我自己的問題。我忽略了Date類中的一個簡單方法。它是Date.day_fraction_to_time(日期分數)。現在我有一個工作計劃,我想和eveyone分享。

include Math 
to_r = PI/180.0 
to_d = 180.0/PI 

latitude = 41.9478 # my latitude 
longitude = 88.74277 # my longitude 
lw = longitude/360 

jdate = Date.civil(Time.now.year, Time.now.month, Time.now.day).ajd 
jdate = (jdate * 2).to_i/2 + 1 

n = (jdate - 2451545 - 0.0009 - lw).round 
j_noon = 2451545 + 0.0009 + lw + n 
mean_anomaly = (357.52911 + 0.98560028 * (jdate - 2451545)) % 360 
center = 1.9148 * sin(mean_anomaly * to_r) + 0.0200 * sin(2 * mean_anomaly * to_r) + \ 
     0.0003 * sin(3 * mean_anomaly * to_r) 
lambda = (mean_anomaly + 102.9372 + center + 180) % 360 
j_transit = j_noon + (0.0053 * sin(mean_anomaly * to_r)) - (0.0069 * sin(2 * lambda * \ 
      to_r)) 
delta = asin(0.397753054 * sin(lambda * to_r)) * to_d 
omega = acos(sin(-0.83 * to_r)/cos(latitude * to_r) * cos(delta * to_r) \ 
     - tan(latitude * to_r) * tan(delta * to_r)) * to_d 
j_set = 2451545 + 0.0009 + ((omega + longitude)/360 + n + 0.0053 * sin(mean_anomaly * \ 
     to_r)) - 0.0069 * sin(2 * lambda * to_r) 

j_rise = j_transit - (j_set - j_transit) 

rise = Date.day_fraction_to_time(j_rise - jdate)# + 0.25 for + 6 hours 
risehour = rise[0].to_s 
risemin = rise[1].to_s 
risetime = "#{risehour}:#{risemin}" 
puts "Sun rise = #{risetime} UTC" 

transit = Date.day_fraction_to_time(j_transit - jdate)# + 0.25 
transithour = transit[0].to_s 
transitmin = transit[1].to_s 
transittime = "#{transithour}:#{transitmin}" 
puts "Solar noon = #{transittime} UTC" 

set = Date.day_fraction_to_time(j_set - jdate)# + 0.25 
sethour = set[0].to_s 
setmin = set[1].to_s 
settime = "#{sethour}:#{setmin} UTC" 
puts "Sun set = #{settime}" 
相關問題