来自命令行的日出和其他天文数据

来自命令行的日出和其他天文数据

是否有一个简单的开源命令行程序可以显示给定日期和位置的日出和日落时间,也许还可以显示月球和行星数据?

浏览 Debian 软件包数据库和 Google 搜索,我找不到任何相关内容。这让我感到惊讶——考虑到天文学极客和 Unix 极客的人数,我本来期望有一个事实上的标准sunrise(1)(或者也许sunrise(6))。

我对顺便执行计算的更复杂的程序不感兴趣,例如天空地图(celestia、kstars、starplot、stellarium)、地球地图(sunclock、xplanet)、日历/议程(emacs、remember)、时钟(glunarclock、wmsun) )、潮汐年鉴 (xtide)。或许有aa天文年历),但我没有看到一个简单的方法来询问太阳在这个日期在这些经度和纬度的什么时间升起。

我错过了什么?

答案1

你试过了sunwait吗 ?

Sunwait 是一个小型 C 程序,用于计算日出和日落,以及民用、航海和天文黄昏。 [..]

该项目可用在 GitHub 上并可以按如下方式克隆:

$ git clone https://github.com/risacher/sunwait
Cloning into 'sunwait'...
remote: Enumerating objects: 107, done.
remote: Counting objects: 100% (62/62), done.
remote: Compressing objects: 100% (26/26), done.
remote: Total 107 (delta 45), reused 37 (delta 36), pack-reused 45
Receiving objects: 100% (107/107), 121.93 KiB | 2.65 MiB/s, done.
Resolving deltas: 100% (55/55), done.
$ cd sunwait/

修复后括号问题,可以构建程序

$ make
gcc -c -Wall  sunwait.cpp -o sunwait.o
gcc -c -Wall  sunriset.cpp -o sunriset.o
sunriset.cpp: In function ‘void sun_RA_dec(double, double*, double*, double*)’:
sunriset.cpp:151:18: warning: variable ‘zs’ set but not used [-Wunused-but-set-variable]
  151 |   double xs, ys, zs;
      |                  ^~
gcc -c -Wall  print.cpp -o print.o
gcc sunwait.o sunriset.o print.o -o sunwait -lm -lstdc++
$ ./sunwait help
Calculate sunrise and sunset times for the current or targetted day.
The times can be adjusted either for twilight or fixed durations.

The program can either: wait for sunrise or sunset   (function: wait),
  or return the time (GMT or local) the event occurs (function: list),
  or report the day length and twilight timings      (function: report),
  or simply report if it is DAY or NIGHT             (function: poll).

You should specify the latitude and longitude of your target location.


Usage: sunwait [major options] [minor options] [twilight type] [rise|set] [offset] [latitude] [longitude]

Major options, either:
    poll          Returns immediately indicating DAY or NIGHT. See 'program exit codes'. Default.
    wait          Sleep until specified event occurs. Else exit immediate.
    list [X]      Report twilight times for next 'X' days (inclusive). Default: 1.
    report        Generate a report about the days sunrise and sunset timings.

Minor options, any of:
    [no]debug     Print extra info and returns in one minute. Default: nodebug.
    [no]version   Print the version number. Default: noversion.
    [no]help      Print this help. Default: nohelp.
    [no]gmt       Print times in GMT or local-time.  Default: nogmt.

Twilight types, either:
    daylight      Top of sun just below the horizon. Default.
    civil         Civil Twilight.         -6 degrees below horizon.
    nautical      Nautical twilight.     -12 degrees below horizon.
    astronomical  Astronomical twilight. -18 degrees below horizon.
    angle [X.XX]  User-specified twilight-angle (degrees). Default: 0.

Sunrise/sunset. Only useful with major-options: 'wait' and 'list'. Any of: (default: both)
    rise          Wait for the sun to rise past specified twilight & offset.
    set           Wait for the sun to  set past specified twilight & offset.

Offset:
    offset [MM|HH:MM] Time interval (+ve towards noon) to adjust twilight calculation.

Target date. Only useful with major-options: 'report' or 'list'. Default: today
    d [DD]        Set the target Day-of-Month to calculate for. 1 to 31.
    m [MM]        Set the target Month to calculate for. 1 to 12.
    y [YYYY]      Set the target Year to calculate for. 2000 to 2099.

latitude/longitude coordinates: floating-point degrees, with [NESW] appended. Default: Bingham, England.

Exit (return) codes:
    0           OK: exit from 'wait' or 'list' only.
    1           Error.
    2           Exit from 'poll': it is DAY or twilight.
    3           Exit from 'poll': it is NIGHT (after twilight).

Example 1: sunwait wait rise offset -1:15:10 51.477932N 0.000000E
Wait until 1 hour 15 minutes 10 secs before the sun rises in Greenwich, London.

Example 2: sunwait list 7 civil 55.752163N 37.617524E
List civil sunrise and sunset times for today and next 6 days. Moscow.

Example 3: sunwait poll exit angle 10 54.897786N -1.517536E
Indicate by program exit-code if is Day or Night using a custom twilight angle of 10 degrees above horizon. Washington, UK.

Example 4: sunwait list 7 gmt sunrise angle 3
List next 7 days sunrise times, custom +3 degree twilight angle, default location.
Uses GMT; as any change in daylight saving over the specified period is not considered.

Note that program uses C library functions to determine time and localtime.
Error for timings are estimated at: +/- 4 minutes.

要全局安装它,请输入:

$ sudo install -vpm 755 sunwait /usr/local/bin/
'sunwait' -> '/usr/local/bin/sunwait'

答案2

我最终使用了 Perl 的DateTime::Event::Sunrise,因为对我来说从 CPAN 部署模块比编译 C 程序更容易。

使用示例:

use DateTime;
use DateTime::Astro::Sunrise;
$latitude = "+48.857"; $longitude = "+2.351"; 
$sr = DateTime::Astro::Sunrise->new($longitude, $latitude, 0, 3);
$date = DateTime->now; $date->set_time_zone("local");
($rise, $set) = $sr->sunrise($date);
$rise->set_time_zone("local"); $set->set_time_zone("local");
print $rise, " to ", $set, "\n";

我的sunrise剧本

答案3

对于像我这样的懒人来说,有一个非常简单的程序,叫做日期,在许多发行版中可用(apt-get install hdate在 Debian/Ubuntu/...):

hdate -s -l N50 -L E14 -z2

输出:

Wednesday, 26 June 2019, 23 Sivan 5779
sunrise: 04:55
sunset: 21:17

选项:

  • -s sunset sunrise
  • -l, -L: 布拉格的海拔和纬度 (50°05′N 14°25′E)
  • -z zone:SELC=+2

一切都已结束。 :-)

答案4

看看这个Linux 家庭自动化 Linux 家庭自动化网站并在页面中搜索“日出”。有一些来自 c 的命令行程序。 1985 年的风格非常简约。我有那个时代的许多相关程序的源代码,但我在网上找不到它们。

更新:我刚刚找到了其他一些内容的来源,包括 sdate事件记录器页。在页面中搜索“rise_set”。

2017-12-23 更新:Linux 家庭自动化项目已经移动,但看起来日出、日落等命令行程序仍然可用这里这里。我划掉了原始页面的链接,但保留了它以供参考,并添加了新页面的链接。

相关内容