Skip to content

Commit

Permalink
Merge 85ce3e3 into 10c3427
Browse files Browse the repository at this point in the history
  • Loading branch information
simeonreusch authored May 6, 2023
2 parents 10c3427 + 85ce3e3 commit f4b8d15
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
5 changes: 3 additions & 2 deletions nuztf/ampel_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
from ampel.ztf.util.ZTFIdMapper import ZTFIdMapper
from astropy.io import fits # type: ignore
from astropy.time import Time # type: ignore
from requests.auth import HTTPBasicAuth

from nuztf import utils
from nuztf.credentials import load_credentials
from requests.auth import HTTPBasicAuth

API_BASEURL = "https://ampel.zeuthen.desy.de"
API_ZTF_ARCHIVE_URL = API_BASEURL + "/api/ztf/archive/v3"
Expand Down Expand Up @@ -703,6 +702,8 @@ def get_preprocessed_results(file_basename: str, logger=None) -> None | list:
pp_reformatted = utils.reformat_downloaded_results(
photopoints=pp, ztf_id=ztf_id
)
kilonova_eval = t.get_latest_t2_body(unit="T2KilonovaEval")
pp_reformatted.update({"kilonova_eval": kilonova_eval})
res.append(pp_reformatted)

return res
18 changes: 14 additions & 4 deletions nuztf/base_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
from astropy.time import Time
from gwemopt.ztf_tiling import get_quadrant_ipix
from matplotlib.backends.backend_pdf import PdfPages
from tqdm import tqdm
from ztfquery import fields as ztfquery_fields

from nuztf.ampel_api import (
ampel_api_acknowledge_chunk,
ampel_api_cone,
Expand All @@ -41,6 +38,8 @@
from nuztf.observations import get_obs_summary
from nuztf.plot import lightcurve_from_alert
from nuztf.utils import cosmo
from tqdm import tqdm
from ztfquery import fields as ztfquery_fields

DEBUG = False
RATELIMIT_CALLS = 10
Expand Down Expand Up @@ -551,14 +550,25 @@ def create_overview_table(self, outfile=None):
mags = []
crossmatches = []

data = {"ztf_id": [], "RA": [], "Dec": [], "mag": [], "xmatch": []}
data = {
"ztf_id": [],
"RA": [],
"Dec": [],
"mag": [],
"xmatch": [],
"kilonova_score": [],
}

for ztf_id, alert in tqdm(sorted(self.cache.items())):
data["ztf_id"].append(ztf_id)
data["RA"].append(alert["candidate"]["ra"])
data["Dec"].append(alert["candidate"]["dec"])
data["mag"].append(alert["candidate"]["magpsf"])
data["xmatch"].append(get_cross_match_info(raw=alert, logger=self.logger))
if alert.get("kilonova_eval") is not None:
data["kilonova_score"].append(alert["kilonova_eval"]["kilonovaness"])
else:
data["kilonova_score"].append(None)

df = pandas.DataFrame.from_dict(data)

Expand Down
12 changes: 6 additions & 6 deletions nuztf/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
from astropy.time import Time
from matplotlib.colors import Normalize
from matplotlib.ticker import MultipleLocator
from ztfquery.utils.stamps import get_ps_stamp

from nuztf.ampel_api import create_empty_cutout, ensure_cutouts
from nuztf.cat_match import get_cross_match_info
from nuztf.utils import cosmo
from ztfquery.utils.stamps import get_ps_stamp


def alert_to_pandas(alert):
Expand Down Expand Up @@ -236,8 +235,11 @@ def absmag_to_mag(absmag):

for entry in ["sgscore1", "distpsnr1", "srmag1"]:
info.append(f"{entry[:-1]}: {candidate[entry]:.3f}")
# for k in [k for k in candidate.keys() if kk in k]:
# info.append(f"{k}: {candidate.get(k):.3f}")

if alert[0].get("kilonova_eval") is not None:
info.append(
f"------------------------\nKilonova score: {alert[0]['kilonova_eval']['kilonovaness']}"
)

fig.text(0.77, 0.55, "\n".join(info), va="top", fontsize="medium", alpha=0.5)

Expand Down Expand Up @@ -315,8 +317,6 @@ def create_stamp_plot(alert: dict, ax, cutout_type: str):
"Difference": "Cutoutdifference",
}

# print(alert.keys())

if alert.get(f"cutout{cutout_type}") is None:
v3_cutout_type = v3_cutout_names[cutout_type]
_data = alert.get(f"cutout{v3_cutout_type}", {}).get("stampData", {})
Expand Down

0 comments on commit f4b8d15

Please sign in to comment.