#!/usr/bin/env python3
#Running this script produces a CSV file containing information about the
#positions of Jupiter and Saturn
import ephem
from datetime import datetime, timedelta
my_lat = 40.0150 # Boulder, Colorado is a space-y place
my_lng = -105.2705
ephem_tdfmt = '%Y-%m-%d %H:%M:%S' # Used for formatting PyEphem strings
p1 = ephem.Jupiter() # Planet of interest
p2 = ephem.Saturn() # Second planet of interest
observer = ephem.Observer()
observer.lat = str(my_lat) # PyEphem takes lat/lng in strings
observer.lon = str(my_lng)
observer.elev = 1624 # Elevation in metres
# We'll generate a large amount of data, one point for each day,
# starting at the time below. We choose the hour/minute to be a
# time when we're interested in looking at the sky
base_time = datetime(year=2018, month=12, day=21, hour=23, minute=0, second=0, microsecond=0)
# Let's print a CSV to stdout with info about the planets
print("date time Planet az alt sep mag")
for x in range(2000*365): # 365 days a year for 2000 years
calc_time = base_time + timedelta(days=x)
observer.date = ephem.date(calc_time.strftime(ephem_tdfmt))
p1.compute(observer)
p2.compute(observer)
sep = ephem.separation(p1, p2)
print(calc_time, "Jupiter", float(p1.az), float(p1.alt), float(sep), float(p1.mag))
print(calc_time, "Saturn", float(p2.az), float(p2.alt), float(sep), float(p2.mag))
分析和绘制数据(代码)
接下来,让我们用R来计算数字并绘制一些图
library(directlabels)
library(dplyr)
library(ggplot2)
library(ggrepel)
library(lubridate)
library(reshape2)
library(tidyr)
# Used for numbering the conjunctions
get.groups = function(x) with(rle(x),rep(1:length(lengths),lengths))
# Read the data
dat = read.table("output", header=TRUE)
dat = dat %>% mutate(date=lubridate:::date(date), sep=sep*180/2/pi)
# Plot angular separation for the next 2,000 years
# Since `sep` is common to both planets, we arbitrarily choose one
sep_over_time = dat %>% filter(Planet=="Jupiter")
ggplot(sep_over_time, aes(x=date, y=sep*180/2/pi)) +
geom_line() +
xlab("Date") +
ylab("Separation (degrees)") +
scale_y_log10() +
ggtitle("Angular Separation over time of Jupiter and Saturn (2018-4017)")
ggsave("/z/sep_over_time.png", width=10, height=6)
# Data used to plot the "shape" of a number of future conjunctions
conjunctions_time_normalized = dat %>%
group_by(Planet) %>%
mutate(cnum=get.groups(sep<1.5)) %>%
ungroup() %>%
filter(sep<1.5) %>%
group_by(cnum) %>%
mutate(days=date-first(date))
# Get information about the 2020 conjunction
this_year = conjunctions_time_normalized %>%
filter(year(date)==2020 | year(date)==2021) %>%
ungroup()
# Minimal angular separation of the 2020 conjunction
this_year_sep = min(this_year$sep)
# Plot the "shape" of future conjunctions by angular separation
ggplot(conjunctions_time_normalized %>% filter(Planet=="Jupiter"), aes(x=days, y=sep, group=as.factor(cnum))) +
geom_line(color="blue", alpha=0.3) +
geom_line(data=this_year, aes(x=days, y=sep), color="green") +
geom_hline(yintercept=this_year_sep) +
xlab("Days from first <1.5deg separation") +
ylab("Separation (deg)") +
ggtitle("Angular Separation and Timing of Jupiter-Saturn Conjunctions (2018-4017)")
ggsave("/z/all_conjunctions.png", width=10, height=6)
# Get positions of the planets for the current (2020) conjunction
temp = this_year %>% mutate(az=az*180/2/pi,alt=alt*180/2/pi) %>% mutate(date=ifelse(wday(date)==1,as.character(date),NA))
ggplot(temp, aes(x=az, y=alt, color=Planet, label=date)) +
geom_point() +
geom_text_repel(nudge_y=2) +
xlab("Azimuth") +
ylab("Zenith") +
theme(legend.position="bottom") +
ggtitle("2020 Conjunction of Jupiter and Saturn (16:00 local time)")
ggsave("/z/conjunction_timing.png")
# Get times of next conjunction
print("Times of next conjunctions")
print(dat %>% filter(sep<this_year_sep))
生成行星数据(代码)
首先,我用pyephem生成了很多关于行星相对位置的数据:
分析和绘制数据(代码)
接下来,让我们用R来计算数字并绘制一些图
当前连词
这是木星和土星穿过天空的路径。请注意,如果你错过了21日最接近的分居点,今晚(22日)和23日也会很好。在那之后,你可以尽情地看着他们彼此拉开距离
什么时候会再次发生
虽然木星和土星经常彼此靠近(周期约为20年),但下面的图表显示,它们很少如此接近
事实上,在接下来的2000年中,它们只有几次如此接近:
连词总是这样吗
不!如下图所示,木星和土星非常接近的合相持续时间很短。然而,它们有点接近的连接可以持续近一年。在这里,我用亮绿色突出显示了当前连接,并用黑线突出显示了最小角度间隔
快乐的星星/行星凝视
相关问题 更多 >
编程相关推荐