Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/routes/v1/ztf/latests/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
required=True,
),
"trend": fields.String(
description="Desired trend among: rising, fading. For `class=(CTA) Blazar`, two specific trends are available: low_state, new_low_state.",
description="Desired trend among: rising, fading. For `class=(CTA) Blazar low state`, two specific trends are available: low_state, new_low_state.",
example="rising",
required=False,
),
Expand Down
4 changes: 2 additions & 2 deletions apps/routes/v1/ztf/latests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,13 @@ def test_blazar_trends() -> None:
start = "2025-02-02 12:30:00"
stop = "2025-03-02 12:30:00"
pdf_low_state = classsearch(
myclass="(CTA) Blazar",
myclass="(CTA) Blazar low state",
trend="low_state",
startdate=start,
stopdate=stop,
)
pdf_new_low_state = classsearch(
myclass="(CTA) Blazar",
myclass="(CTA) Blazar low state",
trend="new_low_state",
startdate=start,
stopdate=stop,
Expand Down
22 changes: 14 additions & 8 deletions apps/routes/v1/ztf/latests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ def extract_object_from_class(payload: dict, return_raw: bool = False) -> pd.Dat

if (
payload.get("trend", None) in ["low_state", "new_low_state"]
and payload.get("class", None) != "(CTA) Blazar"
and payload.get("class", None) != "(CTA) Blazar low state"
):
msg = """
{} trend is only implemented for the `(CTA) Blazar` class.
{} trend is only implemented for the `(CTA) Blazar low state` class.
{} class can accept trend among: rising, fading.
""".format(payload["trend"], payload["class"])
return Response(msg, 400)
Expand Down Expand Up @@ -96,7 +96,8 @@ def extract_object_from_class(payload: dict, return_raw: bool = False) -> pd.Dat
is_tns = payload["class"].startswith("(TNS)") and (
payload["class"].split("(TNS) ")[1] in tns_classes
)
is_cta_blazar = payload["class"] == "(CTA) Blazar"
is_cta_blazar_low = payload["class"] == "(CTA) Blazar low state"
is_cta_blazar_high = payload["class"] == "(CTA) Blazar high state"
is_slsn = payload["class"] == "SLSN candidate"
if is_tns:
client = connect_to_hbase_table("ztf.tns")
Expand All @@ -115,10 +116,12 @@ def extract_object_from_class(payload: dict, return_raw: bool = False) -> pd.Dat
)
schema_client = client.schema()
group_alerts = False
elif is_cta_blazar:
# CTAO Blazars with low states
# To be changed when more trend will appear, like flares
client = connect_to_hbase_table("ztf.low_state_blazars")
elif is_cta_blazar_low or is_cta_blazar_high:
# CTAO Blazars with low/high states
if is_cta_blazar_low:
client = connect_to_hbase_table("ztf.low_state_blazars")
elif is_cta_blazar_high:
client = connect_to_hbase_table("ztf.high_state_blazars")

client.setLimit(nalerts)
client.setRangeScan(True)
Expand Down Expand Up @@ -200,6 +203,9 @@ def extract_object_from_class(payload: dict, return_raw: bool = False) -> pd.Dat
pdf = pdf[pdf["d:mag_rate"] > 0]
elif payload.get("trend", None) == "new_low_state":
# TODO: use fink-filters directly
pdf = pdf[pdf["d:blazar_stats_m0"] >= 1]
if "d:blazar_stats_m0" in pdf.columns:
pdf = pdf[pdf["d:blazar_stats_m0"] >= 1]
elif "d:blazar_stats_instantness_low" in pdf.columns:
pdf = pdf[pdf["d:blazar_stats_instantness_low"] >= 1]

return pdf
17 changes: 11 additions & 6 deletions apps/routes/v1/ztf/schema/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,19 +278,24 @@ def get(self):
"doc": "TNS label, if it exists.",
},
{
"name": "blazar_stats_m0",
"name": "blazar_stats_instantness_low",
"type": "float",
"doc": "Feature for characterising CTAO blazar state. Related to low state robustness.",
"doc": "Feature for characterising CTAO blazar low state. From fink_science>=8.42.0",
},
{
"name": "blazar_stats_m1",
"name": "blazar_stats_robustness_low",
"type": "float",
"doc": "Feature for characterising CTAO blazar state. Related to low state robustness.",
"doc": "Feature for characterising CTAO blazar low state. From fink_science>=8.42.0",
},
{
"name": "blazar_stats_m2",
"name": "blazar_stats_instantness_high",
"type": "float",
"doc": "Feature for characterising CTAO blazar state. Related to low state duration.",
"doc": "Feature for characterising CTAO blazar high state. From fink_science>=8.42.0",
},
{
"name": "blazar_stats_robustness_high",
"type": "float",
"doc": "Feature for characterising CTAO blazar high state. From fink_science>=8.42.0",
},
{
"name": "gaiaClass",
Expand Down
3 changes: 2 additions & 1 deletion assets/fink_types.csv
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ Tracklet
Solar System MPC
Solar System candidate
Ambiguous
(CTA) Blazar
(CTA) Blazar low state
(CTA) Blazar high state
Loading