astropy / astroplan

Observation planning package for astronomers – maintainer @bmorris3
https://astroplan.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
198 stars 109 forks source link

Error in set time calculation #547

Closed sarrvesh closed 1 year ago

sarrvesh commented 1 year ago

While calculating set times, I notice that sometimes Observer.target_set_time() misbehaves for certain combinations of targets, time, and horizon.

For pointing and location defined as

start_time = Time('2023-01-01T00:00:00', format="isot", scale="utc")
mid_array_centre = EarthLocation.from_geodetic(
    21.443803, -30.712925, 1053.0, ellipsoid="WGS84"
)
mid_observatory = Observer(mid_array_centre, timezone="utc")
pointing = SkyCoord(ra=1*units.deg, dec=-56*units.deg, frame="icrs")

I compute the source elevations for two times:

print(mid_observatory.altaz(start_time, target=pointing).alt.deg) # result = 10.237
print(mid_observatory.altaz(start_time + TimeDelta(120, format="sec"), target=pointing).alt.deg) # result = 10.026

Based on these outcomes, I expect the next set time (with horizon=10 degrees) to be close to 2023-01-01T00:02:00. However, when I do

mid_observatory.target_set_time(time=start_time, target=pointing, which="next", horizon=10.*units.deg)

I get 2023-01-01 23:58:20.315970.

I tested this using pyephem and there, I get 2023/1/1 00:03:04 as the next setting time.

bmorris3 commented 1 year ago

Hi @sarrvesh!

This issue is covered here in the FAQ. The problem here is that start_time is very close to the set time (within 4 minutes). As a result, the numerical horizon-crossing time calculation can "miss" the true set time near start_time.

You can avoid this behavior by starting your rise/set search at a different time. Here's a very small tweak that produces the result you expected.

start_time = Time('2023-01-01T00:00:00', format="isot", scale="utc") - 12*u.hour

Hope this helps!