astropy / astroplan

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

Missing targets in plot_airmass and wrong values #576

Open jorgepiloto opened 1 year ago

jorgepiloto commented 1 year ago

🐞 Problem

I wanted to study the visibility of two comets. The coordinates for the comets are stored in a comets.dat file:

Name,RA(J2000),DE(J2000)

12P/Pons-Brooks,18h27m29.43s,38°37'1.25"
C/2023 H2 (Lemmon),22h17m4.56s,-37°36'10.31"

The main code looks like this:

import matplotlib.pyplot as plt
import pandas as pd
from astroplan import FixedTarget, Observer
from astroplan.plots import plot_airmass
from astropy import units as u
from astropy.coordinates import Angle, EarthLocation, SkyCoord
from astropy.time import Time

location = EarthLocation.from_geodetic(
    lon="3d23m05s",
    lat="37d03m51s",
    height=2896.0 * u.m,
)
telescope = Observer(
    location,
    name="Observatorio Sierra Nevada (OSN)",
    timezone="Europe/Madrid",
)
observation_data = pd.read_csv("comets.dat")
time = Time("2023-12-01 18:00:00")

def main():
    targets = []
    for _, body in observation_data.iterrows():
        name, ra, dec = (
            body["Name"],
            Angle(body["RA(J2000)"], unit=u.hour),
            Angle(body["DE(J2000)"], unit=u.deg),
        )
        target_coords = SkyCoord(ra=ra, dec=dec, frame="icrs")
        targets.append(FixedTarget(coord=target_coords, name=name))

    plot_airmass(
        targets,
        telescope,
        time,
        altitude_yaxis=True,
        brightness_shading=True,
        style_kwargs={"linestyle": "--"},
    )
    plt.show()

if __name__ == "__main__":
    main()

The output figure is this one:

output

Note that there is only one object instead of two. Furthermore, the values being displayed in the graph are not the ones I get with other software (KStars and Stellarium) for the same location and time.

I am missing something in my code? The documentation and tutorials are very clean and detailed on how to use the library.

bmorris3 commented 1 year ago

If you run this addition to your code:

import numpy as np

times = time + np.linspace(-12, 12, 20) * u.hour
for target in targets:
    max_altitude = max(telescope.altaz(times, target).alt)
    print(f"{target.name} reaches max(alt): {max_altitude:.1f}" )

You'll see that only one target would fall within the axis limits on this plot:

12P/Pons-Brooks reaches max(alt): 88.4 deg
C/2023 H2 (Lemmon) reaches max(alt): 15.4 deg

You're seeing the airmass curve for 12P/Pons-Brooks in the plot above.

How are you comparing to the results from other software?

jorgepiloto commented 1 year ago

Hi @bmorris3, you are right. The C/2023 H2 line was below the default air mass limit. I just changed and it is getting displayed as expected. All values look fine now compared to KStars.

One last issue I have noticed is the lack of a legend even after adding:

plt.legend(shadow=True)

I thought it would use the names of the Targets. I also tried to declare the labels using the style_kwargs but it didn't work neither.

jorgepiloto commented 1 year ago

This is very weird. It looks like everything is working now including the legend. I did not modified the code in any way. Closing this for the moment.

Thanks for your support, @bmorris3. I really appreciate it 🚀

jorgepiloto commented 1 year ago

Opening this again. Using a "dummy" loop displays the legend with all labels:

    # Displays the legend
    for _ in targets:
        plot_airmass(
            targets,
            telescope,
            time,
            altitude_yaxis=True,
            brightness_shading=True,
            style_kwargs={"linestyle": "--"},
            max_airmass=5,
        )
    plt.legend(shadow=True)
    plt.show()

But without the loop the legend shows empty.

jorgepiloto commented 1 year ago

Using a custom ax solves the issue.