使用 Ruby Date 类处理天文数据

2024-04-08

~ 大约太阳正午

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

我们应该减少错误。自从我们的计算以来,我们只是使用哪个 从昨天中午开始?

该代码是从本页的两个方程推导出来的日出方程 http://en.wikipedia.org/wiki/Sunrise_equation.

我从这里的用户那里得到的第一个答案是我们不明白 0.0009 和 lw / 360。lw / 360 看起来是弧度的小数日 本初子午线。至于0.0009,它一定是一个很小的方差 自公元前 4713 年 1 月 1 日格林威治中午以来的秒数。请参阅 IAU 标准了解更多信息

我根据这个算出是0.007776秒page http://en.wikipedia.org/wiki/Julian_Day.

我有一些来自 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 有一种计算儒略日期的方法真是太好了。 我正在研究 Javascript 代码NOAA http://www.srrb.noaa.gov/highlights/sunrise/sunrise.html.

这是我受链接启发而写的一个课程。

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?


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 的儒略日很奇怪:

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

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

更严格的用法是在 UTC 中,并且 从第一天的中午开始计算。 这是在 Date 类中引用的 作为天文儒略日数, 并缩写为 ajd。在日期中 类,天文儒略日 数字包括小数天数。

(rubydoc http://stdlib.rubyonrails.org/libdoc/date/rdoc/index.html)

这就是您正在寻找的,并且。只需获取不带小数天数即可:

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

=> 2455622.5

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 Ruby Date 类处理天文数据 的相关文章

随机推荐

  • SQL增加重复值的计数?

    不知道如何问这个问题 我不是在寻找列中值的总数 而是想增量计算重复值 例如 如果我的表看起来像这样 1 ken 2 ken 3 adam 4 ken 5 adam 6 dan 我想在选择过程中添加一列 该列的标签与增量编号重复 如下所示 1
  • 如何获取 Jetty 线程转储?

    我有一个Ubuntu 服务器 10 10 64 位运行网络应用程序码头 6 1 24 6 on Sun 的 JVM 都从标准 Ubuntu 存储库安装 我正在尝试找出该服务器的问题 一段时间后 100 cpu 它可能与 NIO 选择器上的已
  • 使用 pgadmin 连接到远程服务器

    我正在使用 Linode 的本教程 https library linode com databases postgresql pgadmin macos x https library linode com databases postg
  • Sequelize js - 限制和排序错误

    在sequelize js中对查询进行排序的正确方法是什么 例子 db model findAll where conditions order postDate DESC limit 10 offset 0 include model1
  • 如何将对象作为数据类型传递给sequelize中的数据模型?

    我需要将一些不是原始数据类型的东西传递给数据类型 我正在构建类似的东西以发送到 create 方法 const p2 location model latitude lat longitude lng establishment id cr
  • Powershell PromptForChoice - 如何编辑描述?

    我需要创建脚本 该脚本将根据用户输入运行不同的代码块 为此 我在 PS 中使用 PromptForChoice 方法 我的代码目前如下所示 title Disk clear question What do you want to remo
  • 如何在 RecyclerView 中使用拖动手势进行多选?

    这是一个很短的问题 最近 谷歌更新了其材料设计指南 表明多选项目应该像谷歌照片应用程序一样 here https material io guidelines patterns selection html selection usage
  • 如何停止 Visual Studio 缓存导入的 MSBuild 脚本?

    我有一个 csproj 文件 它引用一个共享的 MSBuild 脚本
  • 添加一个复选框以在 Woocommerce 中显示/隐藏结帐字段

    让我们浏览一下这个场景 客户在结帐页面上 有一个复选框 其中包含文字 这是礼物吗 如果选中该复选框 下面的字段将淡入以记笔记 基于这个线程和其他一些线程 这里是我的代码 add filter woocommerce checkout fie
  • RxJava,改造错误:预期为 BEGIN_ARRAY,但在第 1 行第 2 列路径 $ 处为 BEGIN_OBJECT

    我正在使用改造和RxJava库并尝试解析此网址 https api myjson com bins tdze5 我的代码如下 API接口 java public interface APIService GET bins tdze5 Obs
  • 包装函数的函数名称? [复制]

    这个问题在这里已经有答案了 如何获取原始函数的名称 def wrap f def wrapped f args kwargs do something return wrapped f wrap def A params do someth
  • SQL - 如何只获取小数点后的数字?

    如何只获取小数点后的数字 例子 2 938 938 尝试这个 SELECT num 1
  • SQL 查询将一列数字变成字符串

    是否可以转换大字符串中的双精度列 就像是 att1 123 2 3 6 6 77 23 43 4 78 7 6 123 2 9 6 1 77 3 43 24 78 76 6 411 5 346 5 975 75 162 788 4 5 16
  • 如何为 GKE 服务创建 Google CDN

    我已经在 GKE kubernetes 上部署了一个 WordPress 网站 我可以像 mysite test com 这样从互联网访问我的网站 并且工作起来就像一个魅力 现在我想使用Google CDN来加速访问 我尝试过使用 Ingr
  • 如何更改 Visual Code Studio 提交作者

    我不知道为什么 但我的 Visual Studio Code 显示错误的提交作者姓名 我正在尝试更改提交的作者 我怎样才能做到这一点 我已经有很多东西了 但没有运气 这是我尝试过的 由于我有三个提交 所以我尝试了git rebase i H
  • 如何排除“git diff-index”中的文件

    我正在使用 git 预提交挂钩来检查提交 预提交脚本基本上做了一件事 exec git diff index check cached HEAD 它还做了一些其他事情 但它们与本次讨论无关 问题是 我的存储库中有各种各样的文件 但并非所有文
  • 通过单击按钮旋转/翻转两种布局

    我有两个布局 xml 文件 我想从一个页面翻转到另一个页面 这两个 xml 文件是 main xml 和 register xml 如果我单击 main xml 中的登录按钮 页面应该翻转并显示 register xml并且在 regist
  • 在 Anaconda 中安装 Kivy

    我正在尝试在 Windows 7 的 Anaconda 3 4 1 1 中安装 Kivy 但我找不到合适的用户指南来指导我如何安装 但到目前为止 我能够在链接上找到在 OS X 上安装它的说明https github com kivy ki
  • matplotlib 中的曲面图

    我有一个 3 元组列表 表示 3D 空间中的一组点 我想绘制一个覆盖所有这些点的曲面 The plot surface函数在mplot3d包要求参数 X Y 和 Z 为二维数组 是plot surface绘制曲面的正确函数以及如何将数据转换
  • 使用 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 l