3

I tried to loop the sky field data to get Apogee and Perigee for a given date #range but could not succeed. Grateful for any help. Thanks in advance

import numpy as np
import matplotlib.pyplot as plt

from skyfield.api import Loader, Topos 

load = Loader('~/Documents/fishing/SkyData')
data = load('de421.bsp')
ts   = load.timescale()

planets = load('de421.bsp')
earth   = planets['earth']
moon    = planets['moon']
Chennai  = earth + Topos('13.0827 N', '80.2707 E', elevation_m = 6.7)


alt, az, dist  = Chennai.at(dt).observe(moon).apparent().altaz()

from datetime import timedelta, date

def daterange(date1, date2):
    for n in range(int ((date2 - date1).days)+1):
    yield date1 + timedelta(n)


start_dt = date(2018, 12, 20)
end_dt = date(2019, 1, 13)


for dt in daterange(start_dt, end_dt):
    print(dt.strftime("%Y-%m-%d"))
    print ("altitude: ", alt.degrees)
    print ("azimuth:  ", az.degrees)
    print ("distance (to center of Moon): ", dist.km)
    print ("distance to closest point on moon: ", round(dist.km, 0) - 1767.)
    print ("compare to: ", 364857)
Community
  • 1
  • 1
Chaks
  • 31
  • 3

1 Answers1

1

It looks like your code will print out the same values over and over again, because you only call .at().observe() once up at the top of your program. Instead, try calling it every time you go through the for loop by having it be the first statement inside of the for loop's block of code.

Brandon Rhodes
  • 83,755
  • 16
  • 106
  • 147
  • Thank You very much – Chaks Jan 21 '19 at 14:04
  • [How to find my IDLE's Python, then apply pip upgrade to a package it uses?](https://stackoverflow.com/q/54798448/3904031) I'm not sure if this is related to Skyfield or not. Please don't scold me for using IDLE and 2.7 ;-) – uhoh Feb 21 '19 at 16:53