首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >对天文数据使用Ruby Date类

对天文数据使用Ruby Date类
EN

Stack Overflow用户
提问于 2011-02-23 18:38:21
回答 3查看 994关注 0票数 2

~近似太阳正午

代码语言:javascript
代码运行次数:0
运行
复制
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年格林威治正午开始计算的地方。

正确使用Date.ordinal_to_jd并没有补偿这一事实。所以,通过加减12个小时,像这样:

代码语言:javascript
代码运行次数:0
运行
复制
jdn = Date.ordinal_to_jd(Time.now.year, Time.now.yday) - 0.5

我们应该少犯些错误。既然我们的计算是从昨天中午开始的,那么我们用哪种方法呢?

代码是从本页方程式中的两个方程导出的。

我从一个用户那里得到的第一个答案是,我们不理解0.0009和lw / 360的使用。lw / 360似乎是从主子午线开始的弧度的小数日。至于0.0009,一定是从公元前4713年格林威治正午开始的几秒钟内的变化。有关更多信息,请参见IAU标准

根据这个页面,我计算它是0.007776秒。

我有一些来自日期类的信息,不包括方法细节。

代码语言:javascript
代码运行次数:0
运行
复制
        =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有一种计算朱利安日期的方法是很好的。我正在查看诺阿的Javascript代码。

下面是我被这个链接启发编写的一个类。

代码语言:javascript
代码运行次数:0
运行
复制
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。谁是对的?红宝石还是诺阿?

NOAA使用从jd中减去的2002年1月1日的值2451545.0来获得分数世纪的时间,如下所示

代码语言:javascript
代码运行次数:0
运行
复制
    def calcTimeJulianCent(j)
      t = (j - 2451545.0)/36525.0
      return t
    end 
EN

回答 3

Stack Overflow用户

发布于 2011-03-08 10:56:42

Ruby有许多计算Julian的方法,您需要选择正确的方法。据你所知,NOAA从公元前4713年的格林威治正午开始计算JD。它总是以.5结尾,因为它们忽略了小数天。

鲁比的朱利安日很奇怪:

出于科学目的,将日期简单地称为一天计数,从任意的初始日期计数是很方便的。最初选择的日期是公元前4713年的1月1日。从这个日期算起的天数是朱利安日号或朱利安日期,在Date类中缩写为jd。这是当地时间,从最初一天的午夜算起。

这对天文学来说是没有意义的。但是等等..。

更严格的使用是在世界协调时,并计算从中午的第一天。这在日期类中被称为天文朱利安日号,缩写为ajd。在日期类中,天文朱利安日数包括小数日。

(鲁比多)

这就是你要找的东西,杰德。只要没有分数的日子就行了:

代码语言:javascript
代码运行次数:0
运行
复制
julianday = Date.civil(@year, @month, @day).ajd
puts julianday

=> 2455622.5

不需要从诺阿进口9行JavaScript。鲁比支持你!)

票数 3
EN

Stack Overflow用户

发布于 2011-02-23 18:49:03

方法ordinal_to_jd将2011年索引为0的一天(公历)转换为朱利安历法中相应的一天,然后使用神奇的值0.0009 (我不知道原因),然后添加经度的比率(东西?)整个360*圈,然后加上今天的一年(54,如果你今天评估)。朱利安日历和纵向比例的组合没有多大意义,但是嘿,这是一个不错的数字,因为你混合了0.0009英寸。

票数 0
EN

Stack Overflow用户

发布于 2011-03-12 04:23:47

谢谢大家,我想我现在可以回答我自己的问题了。我忽略了Date类中的一个简单方法。它是Date.day_fraction_to_time(日小数)。因为我现在有一个工作计划,所以我想和大家分享一下。

代码语言:javascript
代码运行次数:0
运行
复制
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}"
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5095456

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档