使用Ruby Date类获取天文数据 [英] Using the Ruby Date class for Astronomical data

查看:77
本文介绍了使用Ruby 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日格林威治标准时间开始.

As an update, part of the confusion would be that solar noon is where all calculations started since January 1, 4713 BC Greenwich noon.

正确使用Date.ordinal_to_jd不能弥补这一事实.所以 像这样增加或减去12小时:

The correct use of Date.ordinal_to_jd has not compensated for this fact. So by adding or subtracting 12 hours like this:

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

我们应该得到更少的错误.自从我们计算以来,我们只使用哪个 从昨天中午开始?

we should get less errors. Just which do we use though since our calculations start with yesterdays noon?

此代码是从此页面 Sunrise_equation 的两个方程式得出的.

The code is derived from the two equations from this page Sunrise_equation.

我从这里的用户那里得到的第一个答案是,我们不了解使用 0.0009和lw/360.lw/360从 本初子午线.至于0.0009,则必须是 自公元前4713年1月1日格林威治标准时间以来的秒数.有关更多信息,请参见IAU标准.

The first answer I got from a user here was that we don't understand the use of 0.0009 and lw / 360. lw / 360 would appear to be a fractional day of arc from the prime meridian. As for the 0.0009, it must be a small amount of variance in seconds since January 1, 4713 BC Greenwich noon. see IAU standards for more info

根据此页面,我将其计算为0.007776秒.

I calculate it to be 0.007776 seconds according to this page.

我从Date类中获得了一些信息,其中不包括方法的详细信息.

I have a little bit of info from Date class not including method details.

        =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代码.

As a side note, it's great that Ruby has a way to calculate the julian-date. I'm looking into the Javascript code from NOAA.

这是我受链接启发编写的一类.

Here is a class that I was inspired to write by the link.

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?

Now this gets me there but I'm still researching for the way back for a number such as the one calculated by the top most equation. Trying this we can see that we do get a 0.5 in the JDN. Who is right? Ruby or NOAA?

NOAA使用从jd中减去的2000年1月1日的值2451545.0来获取时间 在这样的分数世纪

NOAA uses the January 1st 2000 value of 2451545.0 that is subtracted from the jd to get time in fractional century like this

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

推荐答案

Ruby有许多计算儒略日的方法,您需要选择正确的方法.您知道,自从公元前4713年1月1日格林威治标准时间以来,NOAA就开始计算JD.它总是以.5结尾,因为他们忽略了小数天.

Ruby has a number of ways of calculating Julian Day and you need to pick the right one. NOAA is calculating the JD since January 1, 4713 BC Greenwich noon as you know. It always ends in .5 because they are leaving out the fractional days.

Ruby的儒略日很奇怪:

Ruby's Julian Day is weird:

出于科学目的,它是 方便简单地引用日期 作为一天的计数,从 任意的初始日.日期优先 为此选择的是4713年1月1日 公元前.从该日期算起的天数是 朱利安天数或朱利安日期, 在日期中缩写为jd 班级.这是当地时间 从最初的午夜开始算起 一天.

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.

这对于天文使用毫无意义.但是等等.

Which makes no sense for astronomical use. but wait..

更严格的用法是在UTC中,并且 从第一天的中午开始计数. 在Date类中引用 作为天文朱利安天数, 并缩写为ajd.在日期 课,朱利安天文学节 数字包括小数天.

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.

( ruby​​doc )

这就是您要寻找的ajd.不用花费很少的时间就可以得到它:

This is what you are looking for, ajd. Just get it without the fractional days:

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

=> 2455622.5

无需从NOAA移植9行JavaScript.露比支持你;)

No need to port 9 lines of JavaScript from NOAA. Ruby's got your back! ;)

这篇关于使用Ruby Date类获取天文数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆