Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import requests
- from astropy.coordinates import SkyCoord, Angle
- from astropy import units as u
- import matplotlib.pyplot as plt
- # Define the sector to analyze
- sector = "079"
- # Define URLs for 2-minute and 20-second cadence targets
- url_2m = f"https://tess.mit.edu/public/target_lists/2m/all_targets_S{sector}_v1.csv"
- url_20s = f"https://tess.mit.edu/public/target_lists/20s/all_targets_20s_S{sector}_v1.csv"
- def load_tess_targets(url):
- # Download the CSV file from the URL
- response = requests.get(url)
- file_name = url.split("/")[-1]
- with open(file_name, 'wb') as file:
- file.write(response.content)
- try:
- # Load the CSV into a DataFrame, skipping the first 5 rows
- df = pd.read_csv(file_name, skiprows=5)
- return df
- except Exception as e:
- print(f"Failed to load CSV file: {e}")
- return None
- def add_galactic_coords(df):
- # Convert RA and Dec to numeric values
- df['RA'] = pd.to_numeric(df['RA'])
- df['Dec'] = pd.to_numeric(df['Dec'])
- # Convert RA and Dec to Galactic coordinates
- coords = SkyCoord(ra=df['RA'].values*u.degree, dec=df['Dec'].values*u.degree, frame='icrs')
- galactic_coords = coords.galactic
- df['l'] = galactic_coords.l.value # Extract values as dimensionless
- df['b'] = galactic_coords.b.value # Extract values as dimensionless
- return df
- # Load and process the 2-minute cadence targets
- df_2m = load_tess_targets(url_2m)
- if df_2m is not None:
- df_2m = add_galactic_coords(df_2m)
- print("\n2-Minute Cadence Targets:")
- print(df_2m.head()) # This should now work without raising a UnitConversionError
- print(df_2m.shape[0])
- # Load and process the 20-second cadence targets
- df_20s = load_tess_targets(url_20s)
- if df_20s is not None:
- df_20s = add_galactic_coords(df_20s)
- print("\n20-Second Cadence Targets:")
- print(df_20s.head()) # This should now work without raising a UnitConversionError
- print(df_20s.shape[0])
- # Plotting function for both datasets
- def plot_targets(df, title):
- if df is not None:
- fig = plt.figure(figsize=(20, 10))
- ax = fig.add_subplot(111, projection='aitoff')
- # Correctly wrap longitudes using the astropy 'Angle' object
- l_wrap = Angle(df['l'], unit=u.degree).wrap_at(180 * u.degree).radian
- b_rad = Angle(df['b'], unit=u.degree).radian
- image = ax.scatter(l_wrap, b_rad, c=df['Tmag'], cmap='jet', marker='.')
- bar = fig.colorbar(image, orientation="vertical", pad=0.01)
- bar.set_label("Tmag", size=15)
- plt.title(f"{title} [{df.shape[0]} targets]", fontsize=16)
- plt.grid()
- plt.show()
- # Plot the data for both 2-minute and 20-second cadence targets
- plot_targets(df_2m, f"TESS Sector {sector} - 2-Minute Cadence")
- plot_targets(df_20s, f"TESS Sector {sector} - 20-Second Cadence")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement