Advertisement
UF6

TESS sector 79 TIC list

UF6
Sep 1st, 2024
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.88 KB | Source Code | 0 0
  1. import pandas as pd
  2. import requests
  3. from astropy.coordinates import SkyCoord, Angle
  4. from astropy import units as u
  5. import matplotlib.pyplot as plt
  6.  
  7. # Define the sector to analyze
  8. sector = "079"
  9.  
  10. # Define URLs for 2-minute and 20-second cadence targets
  11. url_2m = f"https://tess.mit.edu/public/target_lists/2m/all_targets_S{sector}_v1.csv"
  12. url_20s = f"https://tess.mit.edu/public/target_lists/20s/all_targets_20s_S{sector}_v1.csv"
  13.  
  14. def load_tess_targets(url):
  15.     # Download the CSV file from the URL
  16.     response = requests.get(url)
  17.     file_name = url.split("/")[-1]
  18.     with open(file_name, 'wb') as file:
  19.         file.write(response.content)
  20.  
  21.     try:
  22.         # Load the CSV into a DataFrame, skipping the first 5 rows
  23.         df = pd.read_csv(file_name, skiprows=5)
  24.         return df
  25.     except Exception as e:
  26.         print(f"Failed to load CSV file: {e}")
  27.         return None
  28.  
  29. def add_galactic_coords(df):
  30.     # Convert RA and Dec to numeric values
  31.     df['RA'] = pd.to_numeric(df['RA'])
  32.     df['Dec'] = pd.to_numeric(df['Dec'])
  33.  
  34.     # Convert RA and Dec to Galactic coordinates
  35.     coords = SkyCoord(ra=df['RA'].values*u.degree, dec=df['Dec'].values*u.degree, frame='icrs')
  36.     galactic_coords = coords.galactic
  37.     df['l'] = galactic_coords.l.value  # Extract values as dimensionless
  38.     df['b'] = galactic_coords.b.value  # Extract values as dimensionless
  39.  
  40.     return df
  41.  
  42. # Load and process the 2-minute cadence targets
  43. df_2m = load_tess_targets(url_2m)
  44. if df_2m is not None:
  45.     df_2m = add_galactic_coords(df_2m)
  46.     print("\n2-Minute Cadence Targets:")
  47.     print(df_2m.head())  # This should now work without raising a UnitConversionError
  48.     print(df_2m.shape[0])
  49.  
  50. # Load and process the 20-second cadence targets
  51. df_20s = load_tess_targets(url_20s)
  52. if df_20s is not None:
  53.     df_20s = add_galactic_coords(df_20s)
  54.     print("\n20-Second Cadence Targets:")
  55.     print(df_20s.head())  # This should now work without raising a UnitConversionError
  56.     print(df_20s.shape[0])
  57.  
  58. # Plotting function for both datasets
  59. def plot_targets(df, title):
  60.     if df is not None:
  61.         fig = plt.figure(figsize=(20, 10))
  62.         ax = fig.add_subplot(111, projection='aitoff')
  63.        
  64.         # Correctly wrap longitudes using the astropy 'Angle' object
  65.         l_wrap = Angle(df['l'], unit=u.degree).wrap_at(180 * u.degree).radian
  66.         b_rad = Angle(df['b'], unit=u.degree).radian
  67.  
  68.         image = ax.scatter(l_wrap, b_rad, c=df['Tmag'], cmap='jet', marker='.')
  69.         bar = fig.colorbar(image, orientation="vertical", pad=0.01)
  70.         bar.set_label("Tmag", size=15)
  71.        
  72.         plt.title(f"{title} [{df.shape[0]} targets]", fontsize=16)
  73.         plt.grid()
  74.         plt.show()
  75.  
  76. # Plot the data for both 2-minute and 20-second cadence targets
  77. plot_targets(df_2m, f"TESS Sector {sector} - 2-Minute Cadence")
  78. plot_targets(df_20s, f"TESS Sector {sector} - 20-Second Cadence")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement