When the Moon is higher in Naples Sky

47 Views Asked by At

I wanted to calculate the time for which the Moon is higher for a local observer, so I have put together the following code, using a rather brute force approach

import ephem as x
from ephem.cities import city
# the time unit is a day, here we define day, hour, etc
d, h, m, s = 1.0, 1.0/24, 1.0/24/60, 1.0/24/60/60

my_city = 'Naples'
me  = city(my_city)
me2 = city(my_city)
moon = x.Moon()

def velocity(date):
    me2.date=date-0.1*s
    moon.compute(me2) ; alt0 = moon.alt
    me2.date=date+0.1*s
    moon.compute(me2) ; alt1 = moon.alt
    return alt1/0.2/s - alt0/0.2/s

me.date = "2022/01/01 00:00:01"
moon.compute(me)

mtt = moon.transit_time
time = x.Date(x.newton(velocity,mtt-0.2*h,mtt+0.2*h))

My code works, like if I plot the times and the elevations I have a "sinusoidal", and if I place the full Moon on the curve I see that it's higher near the Winter solstice...

I'd like to know if there is a less brute force approach to the solution of my problem, using possibly PyEphem, that I superficially know, or another Python package.

0

There are 0 best solutions below