Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
对天文数据使用Ruby Date类 约太阳正午_Ruby_Astronomy_Ordinal_Julian Date - Fatal编程技术网

对天文数据使用Ruby Date类 约太阳正午

对天文数据使用Ruby Date类 约太阳正午,ruby,astronomy,ordinal,julian-date,Ruby,Astronomy,Ordinal,Julian Date,作为一个更新,部分的混乱将是太阳正午是所有的地方 计算从公元前4713年1月1日格林威治中午开始 正确使用Date.ordinal_to_jd并不能弥补这一事实。所以 加上或减去12小时,如下所示: jdn = Date.ordinal_to_jd(Time.now.year, Time.now.yday) - 0.5 我们应该减少错误。既然我们已经计算过了,那我们用哪一个呢 从昨天中午开始 代码是从本页的两个方程式推导而来的 我从一位用户那里得到的第一个答案是,我们不理解 0.0009和lw

作为一个更新,部分的混乱将是太阳正午是所有的地方 计算从公元前4713年1月1日格林威治中午开始

正确使用Date.ordinal_to_jd并不能弥补这一事实。所以 加上或减去12小时,如下所示:

jdn = Date.ordinal_to_jd(Time.now.year, Time.now.yday) - 0.5
我们应该减少错误。既然我们已经计算过了,那我们用哪一个呢 从昨天中午开始

代码是从本页的两个方程式推导而来的

我从一位用户那里得到的第一个答案是,我们不理解 0.0009和lw/360。lw/360似乎是从地面到地面的弧度的小数天 本初子午线。对于0.0009,它必须是 从公元前4713年1月1日格林威治正午开始的第二秒。有关更多信息,请参见IAU标准

根据这个,我计算它是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

方法ordinal_to_jd将2011年(公历)索引为0的日期转换为儒略历中的相应日期,然后使用神奇的值0.0009,我不知道为什么,然后添加经度的比率(东或西?)然后再加上一年中的今天(如果今天进行评估,则为54天)。朱利安历法和纵向比率的结合没有多大意义,但这是一个不错的数字,因为你在其中混合了0.0009。Ruby有很多计算朱利安日的方法,你需要选择正确的方法。正如你所知,NOAA从公元前4713年1月1日格林威治中午开始计算JD。它总是以0.5结尾,因为他们忽略了分数天

鲁比的朱利安节很奇怪:

出于科学目的,它是 方便简单地引用日期 作为一天的计数,从一个 任意起始日。第一个日期 这次选举的日期是4713年1月1日 BCE。从该日期算起的天数为 朱利安日或朱利安日期, 在日期中缩写为jd 班级。这是当地时间,而且 首字母从午夜开始计数 一天

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

更严格的用法是UTC,以及 从第一天的正午开始计数。 这在Date类中引用 作为天文朱利安日的数字, 缩写为ajd。在日期中 同学们,天文朱利安日 数字包括小数天

()

这就是你要找的,ajd。只需在没有零碎天数的情况下获得:

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

=> 2455622.5

无需从NOAA移植9行JavaScript。鲁比支持你!;)

谢谢大家,我想我现在可以回答我自己的问题了。我忽略了Date类中的一个简单方法。它是Date.day\u分数到时间(day分数)。由于我现在有一个工作计划,我想与大家分享

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}"

我现在已经更正了代码。此外,我还添加了一个链接,以供参考。有关朱利安纪念日历史的更多信息,请参阅
    def calcTimeJulianCent(j)
      t = (j - 2451545.0)/36525.0
      return t
    end 
julianday = Date.civil(@year, @month, @day).ajd
puts julianday

=> 2455622.5
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}"