ruby - 使用 Ruby Date 类处理天文数据

标签 ruby astronomy ordinal julian-date

~ 大约太阳正午

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

作为更新,部分困惑可能是太阳正午是所有 计算自公元前 4713 年 1 月 1 日格林威治中午开始。

正确使用 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 有一种计算儒略日期的方法真是太棒了。 我正在研究 NOAA 中的 Javascript 代码.

这是我受链接启发而写的一个类(class)。

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 使用 2000 年 1 月 1 日的值 2451545.0 从 jd 中减去该值来获取时间 在这样的分数世纪

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

最佳答案

Ruby 有多种计算儒略日的方法,您需要选择正确的一种。如您所知,NOAA 自公元前 4713 年 1 月 1 日格林威治中午开始计算 JD。它总是以 0.5 结尾,因为他们省略了小数天数。

Ruby 的儒略日很奇怪:

For scientific purposes, it is convenient to refer to a date simply as a day count, counting from an arbitrary initial day. The date first chosen for this was January 1, 4713 BCE. A count of days from this date is the Julian Day Number or Julian Date, which is abbreviated as jd in the Date class. This is in local time, and counts from midnight on the initial day.

这对于天文用途来说毫无意义。但等等..

The stricter usage is in UTC, and counts from midday on the initial day. This is referred to in the Date class as the Astronomical Julian Day Number, and abbreviated as ajd. In the Date class, the Astronomical Julian Day Number includes fractional days.

( rubydoc )

这就是你要找的东西,ajd。只需获取不带小数天数即可:

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

=> 2455622.5

无需从 NOAA 移植 9 行 JavaScript。 Ruby 为你提供支持! ;)

关于ruby - 使用 Ruby Date 类处理天文数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5095456/

相关文章:

ruby-on-rails - Rails simple_form_for 与 form_for 值/标题

Python 和一维谱 - 如何访问拟合文件中的数据

ruby-on-rails - 安装 json Ruby gem 时出错

Ruby新手: Writing a method to read mulitple arrays from a file?

ruby-on-rails - 如何在 Rails 3 项目中包含 SSL 证书

algorithm - 哪些算法可以让我模拟行星物理?

快速球体结合星数据

Java 等同于 Python 的 toordinal()?

python - 使用循环动态查找序数 : find th - st - nd - rd