astropy / astroplan

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

[BUG] Observer.sun_set_time returns "--" #511

Closed martindevora closed 3 years ago

martindevora commented 3 years ago

Hi, I've experienced the error where sun_set_time method does not return a valid time. Hence, all my further calculations fail. By slightly modifying the time or the observer site, it seems to not be happening, but it is not something I can predict automatically.

Python version: 3.8 Astroplan version: 0.8 Astropy version: 4.3.1

Reproducible with this code:

from astroplan import Observer
import astropy.units as u
from astropy.time import Time

observer_site = Observer(latitude=-24.6272, longitude=-70.4042,
                         elevation=u.Quantity(2518, unit="m"))
time = Time(2459537.461248769, format="jd")
sunset = observer_site.sun_set_time(time, which="next")

This problem makes the plot_air_mass method fail with an exception because it cannot find the datetime of the sunset, as it is NaN. That is the root cause that triggered my issue.

Regards, Martín.

bmorris3 commented 3 years ago

Hi Martín,

This occurs when the Sun does not rise above the horizon within the twenty-four hours following the specified reference time. The code you've placed above raises the warning:

WARNING: TargetNeverUpWarning: Target with index 0 does not cross horizon=0.0 deg within 24 hours [astroplan.observer]

which indicates this exception as the source of the problem. This problem occurs for the time that you've supplied because the nearest sun set time is 2459537.4612224135, which is nearly the same exact time that you're querying. You shouldn't run into this problem if you query nearly any other time that is >a few minutes a way from the precise time of a sunset. For example, if you center your near local noon, this error won't arise.

Does that help?

martindevora commented 3 years ago

Hello,

I guessed so. The problem is that all of this is part of an automated code calling plot_air_mass and I'm interested in precise timings. That is, I think that such an exception from sun_set_time should probably be handled within the plot_air_mass method somehow, because it can receive a list of times from which I don't know which one caused the exception that broke the method. I could handle it though. To me you can close the issue.

Regards.