# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: ztf_paper_env
#     language: python
#     name: ztf_paper_env
# ---

# %matplotlib inline
import matplotlib
import matplotlib.pyplot as plt
import pandas as pd
import os
import numpy as np
from astropy.time import Time
from astropy.table import Table
from astropy import units as u
from astropy import constants as const
from astropy.coordinates.name_resolve import NameResolveError
from ztfquery.lightcurve import LCQuery
from astropy.coordinates import SkyCoord 
from astropy.cosmology import WMAP9 as cosmo
from astropy.io import fits
from astropy.table import Table
import logging
import sys
from nuztf.ampel_api import ampel_api_name
from nuztf.irsa import plot_irsa_lightcurve
from nuztfpaper.style import plot_dir, output_folder
from nuztfpaper.candidates import candidates

# Set up logging level
for logname in ["nuztf", "nuztfpaper"]:
    logger = logging.getLogger(logname)
    # handler = logging.StreamHandler(sys.stdout)
    # formatter = logging.Formatter('%(name)s - %(levelname)s - %(message)s')
    # handler.setFormatter(formatter)
    # logger.addHandler(handler)
    logger.setLevel(logging.INFO)

sources = candidates[candidates["sub_class"] == "AGN Flare"]

names = [
    ("MCG +00-02-020", "IC190922B"),
    ("WISEA J205314.58+125218.9", "IC191001A"),
    ("ZTF19abexshr", "IC191001A"),
    ("CGCG 67-27", "IC200109A"),
    ("SDSS J105752.69+105037.9", "IC200109A"),
    ("NPM 1G+12.0265", "IC200109A"),
    ("SDSS J104431.98+110105.6", "IC200109A"),
    ("ZTF18aamjqes", "IC200530A"),
    ("WISEA J170539.32+273641.2", "IC200530A"),
    ("WISEA J165707.06+234643.8", "IC200530A"),
    ("ZTF18adbbnry", "IC200916A"),
    ("ZTF20aamoxyt", "IC200929A"),
    ("ZTF18abxrpgu", "IC201130A"),
    ("SDSS J002553.11-091252.1", "IC201209A"),
    ("4C 05.57", "IC210210A"),
    ("SDSS J134034.75+045241.3", "IC210210A"),
    ("WISE J224645.73+122935.7", "IC210629A"),
]

# +
# text = "\\begin{figure*} \n"

# for i, (_, row) in enumerate(sources.iterrows()):
#     print(i, row["Name"], row["Catalogue Name"],row["neutrino"], names[i])
    
# #     try:
# #         plot_irsa_lightcurve(
# #             str(row["Catalogue Name"]),
# #             nu_name=row["neutrino"],
# #             plot_mag=False,
# #             plot_folder=output_folder
# #         )
        
# # #     except (TypeError, NameResolveError) as e:
# #     except (NameResolveError, RemoteServiceError) as e:

#     res = ampel_api_name(row["Name"], with_history=False)[0]
        
#     plot_irsa_lightcurve(
#         row["Name"],
#         source_coords=[res["candidate"]["ra"], res["candidate"]["dec"]],
#         nu_name=row["neutrino"],
#         plot_mag=False,
#         plot_folder=plot_dir,
#         extra_folder=output_folder
#     )
#     text += f"    \centering \includegraphics[width=0.45\\textwidth]{{figures/{row['Name']}_lightcurve_flux}}\n"
    
# text += f"""
#     \caption{{ZTF lightcurves of {len(sources)} AGN flares coincident with high-energy neutrinos.}}
#     \label{{fig:flares}}
# \end{{figure*}}
# """        
        
    
    

# +
# print(text)
# -

literature_candidates = [
    ("PKS 1502+106", "IC190730A"),
#     ("BZB J0955+3551", "IC200107A"),
#     ("PKS 0735+178", "IC211208A")
]

for name, nu in literature_candidates:
    plot_irsa_lightcurve(
        name,
        nu_name=nu,
        plot_mag=False,
        plot_folder=plot_dir,
        extra_folder=output_folder
    )



from astropy.coordinates import SkyCoord

c = SkyCoord(115.0271293, 29.2021507, unit=u.deg, frame='icrs')



StarcoderdataJupyterScriptsDedupFiltered