antares-devkit 0.11.1__tar.gz → 0.12.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/PKG-INFO +1 -1
- antares_devkit-0.12.1/antares_devkit/filters/gw_em_candidates/__init__.py +73 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/nuclear_transient/__init__.py +1 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/refitt_newsources_snrcut/__init__.py +1 -0
- antares_devkit-0.12.1/antares_devkit/filters/simple_slsn_filter/__init__.py +356 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/models.py +10 -3
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/utils.py +68 -1
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/pyproject.toml +1 -1
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/test/unit/antares_devkit/test_models.py +78 -0
- antares_devkit-0.12.1/test/unit/antares_devkit/test_utils.py +95 -0
- antares_devkit-0.12.1/test/unit/test_filters.py +39 -0
- antares_devkit-0.11.1/antares_devkit/filters/simple_slsn_filter/__init__.py +0 -135
- antares_devkit-0.11.1/test/unit/test_filters.py +0 -17
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/LICENSE.txt +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/README.md +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/bad_detection/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/bad_seeing/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/crash_filter/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/decam_shadow/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/desi_target/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/dwarf_nova_outburst/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/ecl_transient_1/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/ecl_transient_2/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/extragalactic/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/highamp/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/highfluxchange/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/highsnr/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/if_anomaly_detection/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/if_anomaly_detection/data/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/if_anomaly_detection/data/paleo2_106IFmodel_472727objs_nest=1000_cont=0.001_transf.pkl +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/imbh/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/inm31/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/laiss_rfc_ad_filter/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/laiss_rfc_ad_filter/data/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/laiss_rfc_ad_filter/data/cls=binary_n_estimators=100_max_depth=35_rs=11_max_feats=35_cw=balanced.pkl +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/lantern/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/lantern/data/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/lantern/data/lantern_xgboost_t2.0.7.pkl +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/lsst_ddf/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/lsst_transient_quality_scimma/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/malanchev_anomaly_transient_dmdt/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/malanchev_anomaly_transient_dmdt/data/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/malanchev_anomaly_transient_dmdt/data/malanchev_ssiforest_v1.pickle +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/malanchev_features_v1/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/microlensing/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/novtest/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/nuttela_tao/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/passta_nearby_transients/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/persistent_dimmers/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/random_tagger_filter/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/recent_reddening/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/rubin_NovTest_soraisam/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/sample_filter/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/shadow_virgo/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/siena_mag_coord_cut/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/sso/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/sub_lum/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/superphot_plus_v1/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/superphot_plus_ztf_v3/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/test_dev_all/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/test_dev_lsst/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/test_dev_ztf/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/uniform_random_sample/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/vpdf/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/vpdf/data/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/vpdf/data/matheson_percent_grid_v1 +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/young_extragalactic_candidate/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/young_rubin_transients_soraisam/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/test/Dockerfile +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/test/__init__.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/test/conftest.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/test/data/large_locus.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/test/data/small_locus.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/test/unit/antares_devkit/filters/test_test_dev_all.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/test/unit/antares_devkit/filters/test_test_dev_lsst.py +0 -0
- {antares_devkit-0.11.1 → antares_devkit-0.12.1}/test/unit/antares_devkit/filters/test_test_dev_ztf.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: antares-devkit
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.12.1
|
|
4
4
|
Summary: Provides tools and utility methods to write and debug ANTARES filters with Python.
|
|
5
5
|
Keywords: antares,devkit,filter development
|
|
6
6
|
Author-Email: NSF NOIRLab ANTARES Team <antares@noirlab.edu>
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
from antares_devkit.models import BaseFilter
|
|
2
|
+
|
|
3
|
+
class GW_EM_Candidates(BaseFilter):
|
|
4
|
+
SLACK_CHANNEL = "#filter-gw-em-candidates"
|
|
5
|
+
|
|
6
|
+
TRIGGERING_SURVEY = "all"
|
|
7
|
+
|
|
8
|
+
REQUIRED_ALERT_PROPERTIES = [
|
|
9
|
+
"ant_survey",
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
# setting this class variable gives us all the alerts associated with *any*
|
|
13
|
+
# (including both retracted and non-retracted events) GW event within this
|
|
14
|
+
# localization contour
|
|
15
|
+
REQUIRED_GRAV_WAVE_PROB_REGION = 95.0 # set to 100 to get *all* alerts
|
|
16
|
+
|
|
17
|
+
OUTPUT_LOCUS_TAGS = [
|
|
18
|
+
{
|
|
19
|
+
"name": "gw_em_candidates",
|
|
20
|
+
"description": (
|
|
21
|
+
"Detection inside an active (10-day window), non-retracted "
|
|
22
|
+
"GW localization, and not a known SSO"
|
|
23
|
+
),
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
def _run(self, locus):
|
|
28
|
+
alert = locus.alert
|
|
29
|
+
props = alert.properties
|
|
30
|
+
survey = props.get("ant_survey")
|
|
31
|
+
|
|
32
|
+
# Detections only (skip ZTF upper limits)
|
|
33
|
+
if survey == 2:
|
|
34
|
+
return
|
|
35
|
+
|
|
36
|
+
# Not a known solar system object
|
|
37
|
+
if (
|
|
38
|
+
survey == 1 and
|
|
39
|
+
'ztf_ssnamenr' in locus.properties and
|
|
40
|
+
locus.properties['ztf_ssnamenr'] != 'null'
|
|
41
|
+
):
|
|
42
|
+
return
|
|
43
|
+
|
|
44
|
+
if (
|
|
45
|
+
survey == 4 and
|
|
46
|
+
'survey' in locus.properties and
|
|
47
|
+
"lsst" in locus.properties["survey"] and
|
|
48
|
+
"ss_object_id" in locus.properties["survey"]["lsst"] and
|
|
49
|
+
len(locus.properties["survey"]["lsst"]["ss_object_id"])
|
|
50
|
+
):
|
|
51
|
+
return
|
|
52
|
+
|
|
53
|
+
# Must match an active, non-retracted GW event.
|
|
54
|
+
# ANTARES drops notice metadata after 10 days, so a missing
|
|
55
|
+
# notice means the event is no longer active.
|
|
56
|
+
# But also, retracted events seem to remain associated even after
|
|
57
|
+
# they are no longer "active", so we still need to filter out retracted
|
|
58
|
+
# GW events
|
|
59
|
+
for event in alert.grav_wave_events:
|
|
60
|
+
|
|
61
|
+
# Only consider candidates where the transient is inside the credible region
|
|
62
|
+
if event["contour_level"] > self.REQUIRED_GRAV_WAVE_PROB_REGION:
|
|
63
|
+
continue
|
|
64
|
+
|
|
65
|
+
# ensure that the GW notice is not retracted
|
|
66
|
+
notice = locus.grav_wave_events_metadata.get(event["gracedb_id"])
|
|
67
|
+
if notice is None or notice.notice_type == "RETRACTION":
|
|
68
|
+
continue
|
|
69
|
+
|
|
70
|
+
# if it passes these filters for at least one GW event then we can tag it
|
|
71
|
+
# and move on to the next alert!
|
|
72
|
+
locus.tag("gw_em_candidates")
|
|
73
|
+
break
|
{antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/nuclear_transient/__init__.py
RENAMED
|
@@ -9,6 +9,7 @@ class NuclearTransient(BaseFilter):
|
|
|
9
9
|
# NAME = "Nuclear Transient"
|
|
10
10
|
# [ANTARES] Original owner does not belong to the organization anymore
|
|
11
11
|
SLACK_CHANNEL = "#filter-nuclear-transient"
|
|
12
|
+
TRIGGERING_SURVEY = "ztf"
|
|
12
13
|
REQUIRED_LOCUS_PROPERTIES = [
|
|
13
14
|
"ztf_object_id",
|
|
14
15
|
]
|
|
@@ -8,6 +8,7 @@ from antares_devkit.models import BaseFilter
|
|
|
8
8
|
class refitt_newsources_snrcut(BaseFilter):
|
|
9
9
|
# NAME = "refitt_newsources_snrcut"
|
|
10
10
|
SLACK_CHANNEL = "#filter-refitt-newsources-snrcut"
|
|
11
|
+
TRIGGERING_SURVEY = "ztf"
|
|
11
12
|
# REQUIRED_LOCUS_PROPERTIES = []
|
|
12
13
|
REQUIRED_ALERT_PROPERTIES = [
|
|
13
14
|
"ztf_sigmapsf",
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
from antares_devkit.models import BaseFilter
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class SimpleSLSNPreFilter(BaseFilter):
|
|
6
|
+
"""ZTF SLSN filter: new transients (<= 300 d before peak) reaching M <= -20."""
|
|
7
|
+
|
|
8
|
+
SLACK_CHANNEL = "#filter-simple-slsn-prefilter"
|
|
9
|
+
TRIGGERING_SURVEY = "ztf"
|
|
10
|
+
|
|
11
|
+
REQUIRED_LOCUS_PROPERTIES = []
|
|
12
|
+
REQUIRED_ALERT_PROPERTIES = ["ant_mjd", "ztf_magpsf", "ztf_sigmapsf", "ztf_fid"]
|
|
13
|
+
REQUIRED_TAGS = []
|
|
14
|
+
|
|
15
|
+
OUTPUT_LOCUS_PROPERTIES = [
|
|
16
|
+
{
|
|
17
|
+
"name": "eyoue_slsn_peak_apparent_mag",
|
|
18
|
+
"type": "float",
|
|
19
|
+
"description": "Brightest valid ZTF PSF magnitude.",
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"name": "eyoue_slsn_peak_mag_error",
|
|
23
|
+
"type": "float",
|
|
24
|
+
"description": "Error of brightest ZTF measurement.",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"name": "eyoue_slsn_peak_mjd",
|
|
28
|
+
"type": "float",
|
|
29
|
+
"description": "MJD of brightest ZTF measurement.",
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"name": "eyoue_slsn_peak_band",
|
|
33
|
+
"type": "str",
|
|
34
|
+
"description": "Band of brightest ZTF measurement.",
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"name": "eyoue_slsn_duration_days",
|
|
38
|
+
"type": "float",
|
|
39
|
+
"description": "Days from first detection to peak.",
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"name": "eyoue_slsn_late_detections",
|
|
43
|
+
"type": "int",
|
|
44
|
+
"description": "Positive detections > 500 d after peak.",
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"name": "eyoue_slsn_galactic_latitude",
|
|
48
|
+
"type": "float",
|
|
49
|
+
"description": "Galactic latitude (deg).",
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"name": "eyoue_slsn_nuclear_offset",
|
|
53
|
+
"type": "float",
|
|
54
|
+
"description": "Distance to nearest reference-image source (arcsec).",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"name": "eyoue_slsn_host_mag",
|
|
58
|
+
"type": "float",
|
|
59
|
+
"description": "PS1 r mag of nearest PS1 source (likely host).",
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"name": "eyoue_slsn_host_redshift",
|
|
63
|
+
"type": "float",
|
|
64
|
+
"description": "Redshift from an ANTARES catalog match.",
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"name": "eyoue_slsn_redshift_source",
|
|
68
|
+
"type": "str",
|
|
69
|
+
"description": "Catalog and column of the redshift.",
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"name": "eyoue_slsn_peak_abs_mag",
|
|
73
|
+
"type": "float",
|
|
74
|
+
"description": "Peak absolute magnitude from the catalog redshift.",
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"name": "eyoue_slsn_min_redshift_for_slsn",
|
|
78
|
+
"type": "float",
|
|
79
|
+
"description": "Redshift needed for the peak to reach M = -20.",
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"name": "eyoue_slsn_prefilter_status",
|
|
83
|
+
"type": "str",
|
|
84
|
+
"description": "SLSN filter result.",
|
|
85
|
+
},
|
|
86
|
+
]
|
|
87
|
+
|
|
88
|
+
OUTPUT_LOCUS_TAGS = [
|
|
89
|
+
{
|
|
90
|
+
"name": "eyoue_slsn_prefilter",
|
|
91
|
+
"description": "Candidate for downstream SLSN enrichment.",
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"name": "eyoue_slsn_luminous",
|
|
95
|
+
"description": "Catalog redshift shows peak M <= -20 (SLSN).",
|
|
96
|
+
},
|
|
97
|
+
]
|
|
98
|
+
|
|
99
|
+
REQUIRES_FILES = []
|
|
100
|
+
|
|
101
|
+
def setup(self):
|
|
102
|
+
# Light-curve cuts
|
|
103
|
+
self.minimum_valid_detections = 3
|
|
104
|
+
self.minimum_amplitude = 0.5 # mag, within one band
|
|
105
|
+
self.maximum_peak_mag_error = 0.30
|
|
106
|
+
self.min_drb, self.min_rb = 0.5, 0.55
|
|
107
|
+
# AGN / variable cuts
|
|
108
|
+
self.maximum_duration_days = 300.0 # activity before peak
|
|
109
|
+
self.max_post_peak_days = 500.0
|
|
110
|
+
self.max_late_detections = 5
|
|
111
|
+
self.max_negative_detections, self.max_negative_fraction = 3, 0.15
|
|
112
|
+
self.min_abs_galactic_latitude = 5.0
|
|
113
|
+
# Position cuts (arcsec / mag)
|
|
114
|
+
self.star_sgscore, self.star_max_distance = 0.8, 1.0
|
|
115
|
+
self.nuclear_max_distance, self.nuclear_max_magnitude = 0.5, 18.5
|
|
116
|
+
self.nuclear_host_max_distance, self.nuclear_host_max_mag = 0.6, 20.0
|
|
117
|
+
self.host_max_distance, self.max_host_abs_mag = 3.0, -22.0
|
|
118
|
+
# SLSN cutoff
|
|
119
|
+
self.slsn_abs_mag_cutoff = -20.0
|
|
120
|
+
self.abs_mag_tolerance = 0.2 # accepts M <= -19.8 (no K-corr / dust)
|
|
121
|
+
|
|
122
|
+
self.agn_catalogs = (
|
|
123
|
+
"milliquas",
|
|
124
|
+
"veron_agn",
|
|
125
|
+
"xmm",
|
|
126
|
+
"vii_274_bzcat",
|
|
127
|
+
"chandra",
|
|
128
|
+
)
|
|
129
|
+
self.star_catalogs = (
|
|
130
|
+
"asassn_variable",
|
|
131
|
+
"csdr2",
|
|
132
|
+
"vsx",
|
|
133
|
+
"gaia_dr3_variab",
|
|
134
|
+
"ztf_variables",
|
|
135
|
+
"gaia_edr3_distances",
|
|
136
|
+
"sdss_stars",
|
|
137
|
+
)
|
|
138
|
+
# Only catalogs whose ANTARES copies carry a redshift column
|
|
139
|
+
self.redshift_catalogs = ("tns", "ned", "sdss")
|
|
140
|
+
self.redshift_columns = (
|
|
141
|
+
"redshift",
|
|
142
|
+
"redshift_1", # NED (Redshift_1, lower-cased below)
|
|
143
|
+
"z",
|
|
144
|
+
"z_spec",
|
|
145
|
+
"zspec",
|
|
146
|
+
"specz",
|
|
147
|
+
"photo_z",
|
|
148
|
+
"photoz",
|
|
149
|
+
"z_phot",
|
|
150
|
+
"zphot",
|
|
151
|
+
)
|
|
152
|
+
self.ztf_band_names = {1: "g", 2: "r", 3: "i"}
|
|
153
|
+
|
|
154
|
+
# Distance modulus table, flat LCDM (H0=70, Om=0.3), simple K-correction
|
|
155
|
+
z = np.linspace(0.0, 3.0, 3001)
|
|
156
|
+
inv_e = 1.0 / np.sqrt(0.3 * (1 + z) ** 3 + 0.7)
|
|
157
|
+
steps = 0.5 * (inv_e[1:] + inv_e[:-1]) * np.diff(z)
|
|
158
|
+
dc = np.concatenate([[0.0], np.cumsum(steps)])
|
|
159
|
+
dl = (1 + z[1:]) * dc[1:] * (299792.458 / 70.0)
|
|
160
|
+
self.z_grid = z[1:]
|
|
161
|
+
self.dist_mod = 5 * np.log10(dl * 1e5) - 2.5 * np.log10(1 + z[1:])
|
|
162
|
+
|
|
163
|
+
def _run(self, locus):
|
|
164
|
+
def stop(reason):
|
|
165
|
+
locus.set_property("eyoue_slsn_prefilter_status", reason)
|
|
166
|
+
|
|
167
|
+
def col(name): # column as float array (NaN for masked); None if missing
|
|
168
|
+
if name not in ts.colnames:
|
|
169
|
+
return None
|
|
170
|
+
return np.ma.filled(np.ma.asarray(ts[name], dtype=float), np.nan)
|
|
171
|
+
|
|
172
|
+
def med(name, mask): # median of a ZTF column (ignores -999 "no value")
|
|
173
|
+
v = col(name)
|
|
174
|
+
v = v[mask] if v is not None else np.array([])
|
|
175
|
+
v = v[np.isfinite(v) & (v > -998)]
|
|
176
|
+
return float(np.median(v)) if v.size else np.nan
|
|
177
|
+
|
|
178
|
+
def dmod(z):
|
|
179
|
+
return float(np.interp(z, self.z_grid, self.dist_mod))
|
|
180
|
+
|
|
181
|
+
# Load ZTF light curve
|
|
182
|
+
ts = locus.timeseries("ztf")
|
|
183
|
+
mjd, mag = col("ant_mjd"), col("ztf_magpsf")
|
|
184
|
+
err, band = col("ztf_sigmapsf"), col("ztf_fid")
|
|
185
|
+
if any(x is None for x in (mjd, mag, err, band)):
|
|
186
|
+
return stop("Unable to evaluate ZTF data")
|
|
187
|
+
|
|
188
|
+
# Valid g/r/i photometry that passes real/bogus
|
|
189
|
+
valid = (
|
|
190
|
+
np.isfinite(mjd)
|
|
191
|
+
& np.isfinite(mag)
|
|
192
|
+
& np.isfinite(err)
|
|
193
|
+
& (err > 0)
|
|
194
|
+
& np.isin(band, [1, 2, 3])
|
|
195
|
+
)
|
|
196
|
+
drb, rb = col("ztf_drb"), col("ztf_rb")
|
|
197
|
+
has_drb = np.isfinite(drb) if drb is not None else np.zeros(len(mjd), bool)
|
|
198
|
+
if drb is not None:
|
|
199
|
+
valid &= ~(has_drb & (drb < self.min_drb))
|
|
200
|
+
if rb is not None:
|
|
201
|
+
valid &= ~(~has_drb & (rb < self.min_rb))
|
|
202
|
+
|
|
203
|
+
# Positive vs negative subtractions
|
|
204
|
+
if "ztf_isdiffpos" in ts.colnames:
|
|
205
|
+
raw = np.ma.filled(np.ma.asarray(ts["ztf_isdiffpos"]).astype(str), "")
|
|
206
|
+
sign = np.char.lower(raw.astype(str))
|
|
207
|
+
else:
|
|
208
|
+
sign = np.full(len(mjd), "t")
|
|
209
|
+
negative = np.isin(sign, ["f", "0", "false", "0.0"])
|
|
210
|
+
positive = valid & ~negative
|
|
211
|
+
|
|
212
|
+
# Require >= 3 detections and >= 0.5 mag variation within one band
|
|
213
|
+
if positive.sum() < self.minimum_valid_detections:
|
|
214
|
+
return stop("Rejected: too few valid measurements")
|
|
215
|
+
p_mag, p_band = mag[positive], band[positive].astype(int)
|
|
216
|
+
amps = [
|
|
217
|
+
np.ptp(p_mag[p_band == b])
|
|
218
|
+
for b in np.unique(p_band)
|
|
219
|
+
if (p_band == b).sum() >= 2
|
|
220
|
+
]
|
|
221
|
+
if not amps or max(amps) < self.minimum_amplitude:
|
|
222
|
+
return stop("Rejected: insufficient brightness variation")
|
|
223
|
+
|
|
224
|
+
# Peak (brightest positive detection)
|
|
225
|
+
i = np.flatnonzero(positive)[np.argmin(p_mag)]
|
|
226
|
+
peak_mag, peak_err, peak_mjd = float(mag[i]), float(err[i]), float(mjd[i])
|
|
227
|
+
if peak_err > self.maximum_peak_mag_error:
|
|
228
|
+
return stop("Rejected: excessive peak uncertainty")
|
|
229
|
+
peak_band = self.ztf_band_names.get(int(band[i]), "unknown")
|
|
230
|
+
locus.set_property("eyoue_slsn_peak_apparent_mag", peak_mag)
|
|
231
|
+
locus.set_property("eyoue_slsn_peak_mag_error", peak_err)
|
|
232
|
+
locus.set_property("eyoue_slsn_peak_mjd", peak_mjd)
|
|
233
|
+
locus.set_property("eyoue_slsn_peak_band", peak_band)
|
|
234
|
+
|
|
235
|
+
# AGN / long-term variables: activity long before peak, or long after it
|
|
236
|
+
duration = float(peak_mjd - mjd[valid].min())
|
|
237
|
+
late = positive & (mjd > peak_mjd + self.max_post_peak_days)
|
|
238
|
+
n_late = int(late.sum())
|
|
239
|
+
locus.set_property("eyoue_slsn_duration_days", duration)
|
|
240
|
+
locus.set_property("eyoue_slsn_late_detections", n_late)
|
|
241
|
+
if duration > self.maximum_duration_days:
|
|
242
|
+
return stop("Rejected: activity spans too long (> 300 d before peak)")
|
|
243
|
+
if n_late > self.max_late_detections:
|
|
244
|
+
return stop("Rejected: still active long after peak (persistent variable)")
|
|
245
|
+
|
|
246
|
+
# Negative subtractions before/around peak => variable source
|
|
247
|
+
early = valid & (mjd <= peak_mjd + 30)
|
|
248
|
+
n_neg = int((early & negative).sum())
|
|
249
|
+
neg_fraction = n_neg / max(early.sum(), 1)
|
|
250
|
+
if (
|
|
251
|
+
n_neg >= self.max_negative_detections
|
|
252
|
+
and neg_fraction > self.max_negative_fraction
|
|
253
|
+
):
|
|
254
|
+
return stop("Rejected: repeated negative subtractions (variable source)")
|
|
255
|
+
|
|
256
|
+
# Galactic plane
|
|
257
|
+
b = float(locus.location.galactic.b.deg)
|
|
258
|
+
locus.set_property("eyoue_slsn_galactic_latitude", b)
|
|
259
|
+
if abs(b) < self.min_abs_galactic_latitude:
|
|
260
|
+
return stop("Rejected: Galactic plane")
|
|
261
|
+
|
|
262
|
+
# Catalog matches: AGN and stars
|
|
263
|
+
catalogs = {str(k): (v or []) for k, v in dict(locus.catalog_objects).items()}
|
|
264
|
+
for name, objs in catalogs.items():
|
|
265
|
+
if objs and name.lower().startswith(self.agn_catalogs):
|
|
266
|
+
return stop(f"Rejected: AGN/QSO catalog match ({name})")
|
|
267
|
+
if objs and name.lower().startswith(self.star_catalogs):
|
|
268
|
+
return stop(f"Rejected: star / variable-star catalog match ({name})")
|
|
269
|
+
|
|
270
|
+
# Position checks: PS1 star, bright nucleus, nuclear in bright galaxy
|
|
271
|
+
pre_peak = positive & (mjd <= peak_mjd) # later refs can contain the SN
|
|
272
|
+
sgscore = med("ztf_sgscore1", positive)
|
|
273
|
+
dist_ps1 = med("ztf_distpsnr1", positive)
|
|
274
|
+
dist_nr = med("ztf_distnr", pre_peak)
|
|
275
|
+
mag_nr = med("ztf_magnr", pre_peak)
|
|
276
|
+
host_mag = med("ztf_srmag1", positive)
|
|
277
|
+
if np.isfinite(dist_nr):
|
|
278
|
+
locus.set_property("eyoue_slsn_nuclear_offset", dist_nr)
|
|
279
|
+
if host_mag > 0:
|
|
280
|
+
locus.set_property("eyoue_slsn_host_mag", host_mag)
|
|
281
|
+
if sgscore >= self.star_sgscore and dist_ps1 <= self.star_max_distance:
|
|
282
|
+
return stop("Rejected: coincident with PS1 star")
|
|
283
|
+
if (
|
|
284
|
+
dist_nr <= self.nuclear_max_distance
|
|
285
|
+
and mag_nr <= self.nuclear_max_magnitude
|
|
286
|
+
):
|
|
287
|
+
return stop("Rejected: nuclear in bright point-like source (likely AGN)")
|
|
288
|
+
if (
|
|
289
|
+
dist_ps1 <= self.nuclear_host_max_distance
|
|
290
|
+
and 0 < host_mag <= self.nuclear_host_max_mag
|
|
291
|
+
and sgscore < 0.5
|
|
292
|
+
):
|
|
293
|
+
return stop(
|
|
294
|
+
f"Rejected: nuclear in bright galaxy (host r={host_mag:.1f}, "
|
|
295
|
+
"likely AGN/TDE)"
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
# Redshift needed to reach the SLSN cutoff
|
|
299
|
+
z_needed = float(
|
|
300
|
+
np.interp(
|
|
301
|
+
peak_mag - self.slsn_abs_mag_cutoff,
|
|
302
|
+
self.dist_mod,
|
|
303
|
+
self.z_grid,
|
|
304
|
+
left=np.nan,
|
|
305
|
+
right=np.nan,
|
|
306
|
+
)
|
|
307
|
+
)
|
|
308
|
+
if np.isfinite(z_needed):
|
|
309
|
+
locus.set_property("eyoue_slsn_min_redshift_for_slsn", z_needed)
|
|
310
|
+
|
|
311
|
+
# Catalog redshift (first match, in catalog priority order)
|
|
312
|
+
redshift = source = None
|
|
313
|
+
for prefix in self.redshift_catalogs:
|
|
314
|
+
for name, objs in catalogs.items():
|
|
315
|
+
if not name.lower().startswith(prefix):
|
|
316
|
+
continue
|
|
317
|
+
for obj in objs:
|
|
318
|
+
lower = {str(k).lower(): v for k, v in obj.items()}
|
|
319
|
+
for key in self.redshift_columns:
|
|
320
|
+
try:
|
|
321
|
+
z = float(lower.get(key))
|
|
322
|
+
except (TypeError, ValueError):
|
|
323
|
+
continue
|
|
324
|
+
if redshift is None and 0.001 < z < 3.0:
|
|
325
|
+
redshift, source = z, f"{name}:{key}"
|
|
326
|
+
|
|
327
|
+
# With redshift: tag once the peak reaches the cutoff
|
|
328
|
+
if redshift is not None:
|
|
329
|
+
abs_mag = peak_mag - dmod(redshift)
|
|
330
|
+
locus.set_property("eyoue_slsn_host_redshift", redshift)
|
|
331
|
+
locus.set_property("eyoue_slsn_redshift_source", source)
|
|
332
|
+
locus.set_property("eyoue_slsn_peak_abs_mag", abs_mag)
|
|
333
|
+
if abs_mag > self.slsn_abs_mag_cutoff + self.abs_mag_tolerance:
|
|
334
|
+
return stop(f"Not yet SLSN: peak M={abs_mag:.2f} at z={redshift:.3f}")
|
|
335
|
+
stop(f"SLSN: peak M={abs_mag:.2f} at z={redshift:.3f}")
|
|
336
|
+
return locus.tag("eyoue_slsn_luminous")
|
|
337
|
+
|
|
338
|
+
# Without redshift: reject if the host would be too bright at SLSN distance
|
|
339
|
+
if (
|
|
340
|
+
np.isfinite(z_needed)
|
|
341
|
+
and host_mag > 0
|
|
342
|
+
and dist_ps1 <= self.host_max_distance
|
|
343
|
+
and not sgscore >= self.star_sgscore
|
|
344
|
+
):
|
|
345
|
+
host_abs = host_mag - dmod(z_needed)
|
|
346
|
+
if host_abs < self.max_host_abs_mag:
|
|
347
|
+
return stop(
|
|
348
|
+
"Rejected: host too bright for an SLSN distance "
|
|
349
|
+
f"(host M={host_abs:.1f})"
|
|
350
|
+
)
|
|
351
|
+
|
|
352
|
+
stop(
|
|
353
|
+
"Passed pre-filter; requires downstream NED enrichment "
|
|
354
|
+
f"(SLSN if z >= {z_needed:.3f})"
|
|
355
|
+
)
|
|
356
|
+
locus.tag("eyoue_slsn_prefilter")
|
|
@@ -720,17 +720,24 @@ class BaseFilter(abc.ABC):
|
|
|
720
720
|
is_ztf_alert = alert.properties["ant_survey"] in SURVEYS["ztf"]
|
|
721
721
|
is_lsst_alert = alert.properties["ant_survey"] in SURVEYS["lsst"]
|
|
722
722
|
is_decat_alert = alert.properties["ant_survey"] in SURVEYS["decat"]
|
|
723
|
+
found_any = False
|
|
723
724
|
for prop in self.REQUIRED_ALERT_PROPERTIES:
|
|
724
725
|
# if the required prop is survey specific and it doesn't match the survey
|
|
725
726
|
# for this alert then simply ignore that required prop.
|
|
726
727
|
if not is_lsst_alert and prop.startswith(PROPERTY_PREFIX["lsst"]):
|
|
727
728
|
continue
|
|
728
|
-
|
|
729
|
+
if not is_ztf_alert and prop.startswith(PROPERTY_PREFIX["ztf"]):
|
|
729
730
|
continue
|
|
730
|
-
|
|
731
|
+
if not is_decat_alert and prop.startswith(PROPERTY_PREFIX["decat"]):
|
|
731
732
|
continue
|
|
732
|
-
|
|
733
|
+
if prop not in alert.properties:
|
|
733
734
|
return False
|
|
735
|
+
found_any = True
|
|
736
|
+
|
|
737
|
+
# Properies were required, but none were present on this alert.
|
|
738
|
+
if self.REQUIRED_ALERT_PROPERTIES and not found_any:
|
|
739
|
+
return False
|
|
740
|
+
|
|
734
741
|
if max_level := self.REQUIRED_GRAV_WAVE_PROB_REGION:
|
|
735
742
|
matches = [
|
|
736
743
|
gw["contour_level"] <= max_level for gw in alert.grav_wave_events
|
|
@@ -4,7 +4,10 @@ import inspect
|
|
|
4
4
|
import time
|
|
5
5
|
from typing import Optional
|
|
6
6
|
|
|
7
|
-
from antares_devkit.models import BaseFilter, DevKitLocus
|
|
7
|
+
from antares_devkit.models import BaseFilter, DevKitLocus, FilterProperty
|
|
8
|
+
|
|
9
|
+
REQUIRED_PROPERTY_FIELDS = {"name", "description", "type"}
|
|
10
|
+
VALID_PROPERTY_TYPES = {"int", "float", "str"}
|
|
8
11
|
|
|
9
12
|
|
|
10
13
|
def get_filters_path():
|
|
@@ -56,6 +59,7 @@ def get_filters_path():
|
|
|
56
59
|
"UniformRandomSample": "antares_devkit.filters.uniform_random_sample",
|
|
57
60
|
"Lantern": "antares_devkit.filters.lantern",
|
|
58
61
|
"SimpleSLSNPreFilter": "antares_devkit.filters.simple_slsn_filter",
|
|
62
|
+
"GW_EM_Candidates": "antares_devkit.filters.gw_em_candidates",
|
|
59
63
|
}
|
|
60
64
|
|
|
61
65
|
|
|
@@ -196,3 +200,66 @@ def filter_report(filter_instance: BaseFilter, locus: DevKitLocus) -> dict:
|
|
|
196
200
|
"new_locus_properties": new_locus_properties,
|
|
197
201
|
"new_tags": new_tags,
|
|
198
202
|
}
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
class FilterValidationError(ValueError):
|
|
206
|
+
"""Exception class for filter validation errors."""
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def validate_property_definition(property_definition: FilterProperty) -> None:
|
|
210
|
+
"""Validate the fields of a single OUTPUT_LOCUS_PROPERTIES entry."""
|
|
211
|
+
if any(field not in property_definition for field in REQUIRED_PROPERTY_FIELDS):
|
|
212
|
+
missing_fields = {
|
|
213
|
+
field
|
|
214
|
+
for field in REQUIRED_PROPERTY_FIELDS
|
|
215
|
+
if field not in property_definition
|
|
216
|
+
}
|
|
217
|
+
raise FilterValidationError(f"Missing properties: {', '.join(missing_fields)}")
|
|
218
|
+
|
|
219
|
+
property_type = property_definition["type"]
|
|
220
|
+
|
|
221
|
+
if not isinstance(property_type, str):
|
|
222
|
+
raise FilterValidationError(
|
|
223
|
+
f"Expected str for filter type property, not {type(property_type)}"
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
if property_type not in VALID_PROPERTY_TYPES:
|
|
227
|
+
raise FilterValidationError(
|
|
228
|
+
f"{property_type} is not a valid filter type property. "
|
|
229
|
+
f"Expected one of {', '.join(VALID_PROPERTY_TYPES)}"
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
if not isinstance(property_definition["name"], str):
|
|
233
|
+
raise FilterValidationError(
|
|
234
|
+
(
|
|
235
|
+
f"Expected str for filter name property, not "
|
|
236
|
+
f"{type(property_definition['name'])}"
|
|
237
|
+
)
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
if not property_definition["name"].strip():
|
|
241
|
+
raise FilterValidationError(
|
|
242
|
+
"Must provide non-empty string for filter name property."
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
if not isinstance(property_definition["description"], str):
|
|
246
|
+
raise FilterValidationError(
|
|
247
|
+
(
|
|
248
|
+
f"Expected str for filter description property, not "
|
|
249
|
+
f"{type(property_definition['description'])}"
|
|
250
|
+
)
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
for field in REQUIRED_PROPERTY_FIELDS:
|
|
254
|
+
value = property_definition[field]
|
|
255
|
+
|
|
256
|
+
if value != value.strip():
|
|
257
|
+
raise FilterValidationError(
|
|
258
|
+
f"Leading and trailing whitespace forbidden in '{field!r}'. "
|
|
259
|
+
f"Got value: {value!r}"
|
|
260
|
+
)
|
|
261
|
+
|
|
262
|
+
if not property_definition["description"].strip():
|
|
263
|
+
raise FilterValidationError(
|
|
264
|
+
"Must provide non-empty filter description property."
|
|
265
|
+
)
|
|
@@ -6,7 +6,7 @@ build-backend = "pdm.backend"
|
|
|
6
6
|
|
|
7
7
|
[project]
|
|
8
8
|
name = "antares-devkit"
|
|
9
|
-
version = "0.
|
|
9
|
+
version = "0.12.1"
|
|
10
10
|
description = "Provides tools and utility methods to write and debug ANTARES filters with Python."
|
|
11
11
|
readme = "README.md"
|
|
12
12
|
requires-python = ">=3.9"
|
|
@@ -118,6 +118,32 @@ class TestBaseFilter:
|
|
|
118
118
|
def _run(self, locus):
|
|
119
119
|
locus.tag("some_tag")
|
|
120
120
|
|
|
121
|
+
class ZtfFilterWithTriggeringAll(BaseFilter):
|
|
122
|
+
TRIGGERING_SURVEY = "all"
|
|
123
|
+
|
|
124
|
+
REQUIRED_ALERT_PROPERTIES = [
|
|
125
|
+
"ztf_sgscore1",
|
|
126
|
+
"ztf_distpsnr1",
|
|
127
|
+
"ztf_magpsf",
|
|
128
|
+
"ztf_magnr",
|
|
129
|
+
"ztf_distnr",
|
|
130
|
+
]
|
|
131
|
+
|
|
132
|
+
def _run(self, locus):
|
|
133
|
+
locus.tag("some_tag")
|
|
134
|
+
|
|
135
|
+
class ZtfFilterWithDefaultTriggeringSurvey(BaseFilter):
|
|
136
|
+
REQUIRED_ALERT_PROPERTIES = [
|
|
137
|
+
"ztf_sgscore1",
|
|
138
|
+
"ztf_distpsnr1",
|
|
139
|
+
"ztf_magpsf",
|
|
140
|
+
"ztf_magnr",
|
|
141
|
+
"ztf_distnr",
|
|
142
|
+
]
|
|
143
|
+
|
|
144
|
+
def _run(self, locus):
|
|
145
|
+
locus.tag("some_tag")
|
|
146
|
+
|
|
121
147
|
def test_filter_skips_alert_from_different_survey(self):
|
|
122
148
|
locus = DevKitLocus(
|
|
123
149
|
id="locus-001",
|
|
@@ -195,3 +221,55 @@ class TestBaseFilter:
|
|
|
195
221
|
)
|
|
196
222
|
result = self.AllFilter().run(locus)
|
|
197
223
|
assert result.status == "Succeeded"
|
|
224
|
+
|
|
225
|
+
def test_filter_skips_alert_when_no_properties_are_present(self):
|
|
226
|
+
locus = DevKitLocus(
|
|
227
|
+
id="locus-001",
|
|
228
|
+
ra=1.0,
|
|
229
|
+
dec=1.0,
|
|
230
|
+
alerts=[
|
|
231
|
+
{
|
|
232
|
+
"id": "alert-001",
|
|
233
|
+
"mjd": 11111.1,
|
|
234
|
+
"properties": {
|
|
235
|
+
"ant_survey": 4,
|
|
236
|
+
"ant_mjd": 1.0,
|
|
237
|
+
"ant_ra": 1.0,
|
|
238
|
+
"ant_dec": 1.0,
|
|
239
|
+
"ant_passband": "g",
|
|
240
|
+
"ant_mag": 1,
|
|
241
|
+
"ant_magerr": 0,
|
|
242
|
+
"ant_maglim": 2,
|
|
243
|
+
},
|
|
244
|
+
"grav_wave_events": [],
|
|
245
|
+
}
|
|
246
|
+
],
|
|
247
|
+
)
|
|
248
|
+
result = self.ZtfFilterWithTriggeringAll().run(locus)
|
|
249
|
+
assert result.status == "Skipped"
|
|
250
|
+
|
|
251
|
+
def test_filter_with_default_survey_skips_alert_when_no_properties_are_present(self):
|
|
252
|
+
locus = DevKitLocus(
|
|
253
|
+
id="locus-001",
|
|
254
|
+
ra=1.0,
|
|
255
|
+
dec=1.0,
|
|
256
|
+
alerts=[
|
|
257
|
+
{
|
|
258
|
+
"id": "alert-001",
|
|
259
|
+
"mjd": 11111.1,
|
|
260
|
+
"properties": {
|
|
261
|
+
"ant_survey": 4,
|
|
262
|
+
"ant_mjd": 1.0,
|
|
263
|
+
"ant_ra": 1.0,
|
|
264
|
+
"ant_dec": 1.0,
|
|
265
|
+
"ant_passband": "g",
|
|
266
|
+
"ant_mag": 1,
|
|
267
|
+
"ant_magerr": 0,
|
|
268
|
+
"ant_maglim": 2,
|
|
269
|
+
},
|
|
270
|
+
"grav_wave_events": [],
|
|
271
|
+
}
|
|
272
|
+
],
|
|
273
|
+
)
|
|
274
|
+
result = self.ZtfFilterWithDefaultTriggeringSurvey().run(locus)
|
|
275
|
+
assert result.status == "Skipped"
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"""Tests for util functions in the devkit."""
|
|
2
|
+
|
|
3
|
+
import string
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
from antares_devkit.models import FilterProperty
|
|
8
|
+
from antares_devkit.utils import FilterValidationError, validate_property_definition
|
|
9
|
+
|
|
10
|
+
VALID_PROPERTY_DEFINITION: FilterProperty = {
|
|
11
|
+
"name": "test-author",
|
|
12
|
+
"type": "float",
|
|
13
|
+
"description": "A desription of the filter.",
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def without(key: str) -> dict[str, object]:
|
|
18
|
+
if key not in VALID_PROPERTY_DEFINITION:
|
|
19
|
+
raise KeyError(
|
|
20
|
+
f"Key {key} not in property definition: "
|
|
21
|
+
f"expected one of {tuple(VALID_PROPERTY_DEFINITION.keys())}"
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
return {k: v for k, v in VALID_PROPERTY_DEFINITION.items() if k != key}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def with_(**kwargs: object) -> dict[str, object]:
|
|
28
|
+
if any(key not in VALID_PROPERTY_DEFINITION for key in kwargs):
|
|
29
|
+
missing_keys = {key for key in kwargs if key not in VALID_PROPERTY_DEFINITION}
|
|
30
|
+
raise KeyError(
|
|
31
|
+
f"Keys {tuple(missing_keys)} not in property definition: "
|
|
32
|
+
f"expected one of {tuple(VALID_PROPERTY_DEFINITION.keys())}. "
|
|
33
|
+
f"If you want to add a valid key, add it to VALID_PROPERTY_DEFINITION."
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
return {**VALID_PROPERTY_DEFINITION, **kwargs}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@pytest.mark.parametrize(
|
|
40
|
+
"property_definition, bad_field",
|
|
41
|
+
[
|
|
42
|
+
(without("description"), "description"),
|
|
43
|
+
(without("type"), "type"),
|
|
44
|
+
(without("name"), "name"),
|
|
45
|
+
(with_(name=""), "name"),
|
|
46
|
+
(with_(name=" "), "name"),
|
|
47
|
+
(with_(type="bad-type"), "type"),
|
|
48
|
+
(with_(description=""), "description"),
|
|
49
|
+
(with_(description=" "), "description"),
|
|
50
|
+
(with_(name=None), "name"),
|
|
51
|
+
(with_(description=None), "description"),
|
|
52
|
+
(with_(type=None), "type"),
|
|
53
|
+
],
|
|
54
|
+
)
|
|
55
|
+
def test_invalid_property_definition_fails_validation(property_definition, bad_field):
|
|
56
|
+
"""Parametrized test of various values expected to fail validation."""
|
|
57
|
+
with pytest.raises(FilterValidationError, match=bad_field):
|
|
58
|
+
validate_property_definition(property_definition)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_valid_property_definition_passes_validation():
|
|
62
|
+
"""Test for the positive code path that a fully populated definition passes."""
|
|
63
|
+
validate_property_definition(VALID_PROPERTY_DEFINITION)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@pytest.mark.parametrize("field", list(VALID_PROPERTY_DEFINITION.keys()))
|
|
67
|
+
@pytest.mark.parametrize(
|
|
68
|
+
"template",
|
|
69
|
+
[
|
|
70
|
+
lambda whitespace, value: f"{whitespace}{value}",
|
|
71
|
+
lambda whitespace, value: f"{value}{whitespace}",
|
|
72
|
+
],
|
|
73
|
+
ids=["leading", "trailing"],
|
|
74
|
+
)
|
|
75
|
+
@pytest.mark.parametrize("whitespace", string.whitespace + "\u00a0\u2003")
|
|
76
|
+
def test_surrounding_whitespace_is_invalid(field, template, whitespace):
|
|
77
|
+
new_field: str = template(whitespace, VALID_PROPERTY_DEFINITION[field])
|
|
78
|
+
new_property_definition = with_(**{field: new_field})
|
|
79
|
+
|
|
80
|
+
with pytest.raises(FilterValidationError):
|
|
81
|
+
validate_property_definition(new_property_definition)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
@pytest.mark.parametrize(
|
|
85
|
+
"property_definition",
|
|
86
|
+
[
|
|
87
|
+
with_(name="author name"),
|
|
88
|
+
with_(name="a uthor name"),
|
|
89
|
+
with_(name="author nam e"),
|
|
90
|
+
],
|
|
91
|
+
ids=lambda definition: repr(definition["name"]),
|
|
92
|
+
)
|
|
93
|
+
def test_whitespace_allowed_in_author_name(property_definition):
|
|
94
|
+
"""Test that spaces are allowed in the author name."""
|
|
95
|
+
validate_property_definition(property_definition)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import itertools
|
|
2
|
+
from test.conftest import test_sample
|
|
3
|
+
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
from antares_devkit.utils import (
|
|
7
|
+
FilterValidationError,
|
|
8
|
+
get_filter_instances,
|
|
9
|
+
get_filters,
|
|
10
|
+
validate_property_definition,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@pytest.mark.parametrize(
|
|
15
|
+
"data, c_filter",
|
|
16
|
+
itertools.product(
|
|
17
|
+
test_sample,
|
|
18
|
+
get_filter_instances(),
|
|
19
|
+
),
|
|
20
|
+
)
|
|
21
|
+
def test_filter(memory_and_time_tracker, request, data, c_filter):
|
|
22
|
+
memory_and_time_tracker(c_filter, data)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@pytest.mark.parametrize(
|
|
26
|
+
"filter_class",
|
|
27
|
+
get_filters(select_all=True),
|
|
28
|
+
ids=lambda filter: filter.__name__,
|
|
29
|
+
)
|
|
30
|
+
def test_filter_class_output_locus_properties_are_valid(filter_class):
|
|
31
|
+
for property_definition in filter_class.OUTPUT_LOCUS_PROPERTIES:
|
|
32
|
+
try:
|
|
33
|
+
validate_property_definition(property_definition)
|
|
34
|
+
|
|
35
|
+
except FilterValidationError as err:
|
|
36
|
+
pytest.fail(
|
|
37
|
+
f"{filter_class.__name__}: property "
|
|
38
|
+
f"{property_definition.get('name')!r}: {err}"
|
|
39
|
+
)
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
from antares_devkit.models import BaseFilter
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class SimpleSLSNPreFilter(BaseFilter):
|
|
5
|
-
"""ZTF pre-filter for downstream SLSN host/redshift enrichment."""
|
|
6
|
-
|
|
7
|
-
SLACK_CHANNEL = "#filter-simple-slsn-prefilter"
|
|
8
|
-
TRIGGERING_SURVEY = "ztf"
|
|
9
|
-
|
|
10
|
-
REQUIRED_LOCUS_PROPERTIES = []
|
|
11
|
-
REQUIRED_ALERT_PROPERTIES = [
|
|
12
|
-
"ant_mjd",
|
|
13
|
-
"ztf_magpsf",
|
|
14
|
-
"ztf_sigmapsf",
|
|
15
|
-
"ztf_fid",
|
|
16
|
-
]
|
|
17
|
-
REQUIRED_TAGS = []
|
|
18
|
-
|
|
19
|
-
OUTPUT_LOCUS_PROPERTIES = [
|
|
20
|
-
{
|
|
21
|
-
"name": "eyoue_slsn_peak_apparent_mag",
|
|
22
|
-
"type": "float",
|
|
23
|
-
"description": "Brightest valid ZTF PSF magnitude.",
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
"name": "eyoue_slsn_peak_mag_error",
|
|
27
|
-
"type": "float",
|
|
28
|
-
"description": "Error of brightest ZTF measurement.",
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
"name": "eyoue_slsn_peak_mjd",
|
|
32
|
-
"type": "float",
|
|
33
|
-
"description": "MJD of brightest ZTF measurement.",
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
"name": "eyoue_slsn_peak_band",
|
|
37
|
-
"type": "str",
|
|
38
|
-
"description": "Band of brightest ZTF measurement.",
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
"name": "eyoue_slsn_prefilter_status",
|
|
42
|
-
"type": "str",
|
|
43
|
-
"description": "SLSN pre-filter result.",
|
|
44
|
-
},
|
|
45
|
-
]
|
|
46
|
-
|
|
47
|
-
OUTPUT_LOCUS_TAGS = [
|
|
48
|
-
{
|
|
49
|
-
"name": "eyoue_slsn_prefilter",
|
|
50
|
-
"description": "Candidate for downstream SLSN enrichment.",
|
|
51
|
-
}
|
|
52
|
-
]
|
|
53
|
-
|
|
54
|
-
REQUIRES_FILES = []
|
|
55
|
-
|
|
56
|
-
def setup(self):
|
|
57
|
-
# False-positive rejection thresholds
|
|
58
|
-
self.minimum_valid_detections = 5
|
|
59
|
-
self.minimum_bands = 2
|
|
60
|
-
self.minimum_amplitude = 0.5 # mag
|
|
61
|
-
self.maximum_duration_days = 300.0
|
|
62
|
-
self.maximum_peak_mag_error = 0.30
|
|
63
|
-
self.ztf_band_names = {1: "g", 2: "r", 3: "i"}
|
|
64
|
-
|
|
65
|
-
def _run(self, locus):
|
|
66
|
-
import numpy as np
|
|
67
|
-
|
|
68
|
-
def stop(reason):
|
|
69
|
-
locus.set_property("eyoue_slsn_prefilter_status", reason)
|
|
70
|
-
return None
|
|
71
|
-
|
|
72
|
-
# Load ZTF light curve
|
|
73
|
-
try:
|
|
74
|
-
ts = locus.timeseries("ztf")
|
|
75
|
-
mjd = np.asarray(ts["ant_mjd"].data, dtype=float)
|
|
76
|
-
mag = np.asarray(ts["ztf_magpsf"].data, dtype=float)
|
|
77
|
-
err = np.asarray(ts["ztf_sigmapsf"].data, dtype=float)
|
|
78
|
-
band = np.asarray(ts["ztf_fid"].data, dtype=float)
|
|
79
|
-
except Exception:
|
|
80
|
-
return stop("Unable to evaluate ZTF data")
|
|
81
|
-
|
|
82
|
-
# Keep valid g/r/i photometry
|
|
83
|
-
valid = (
|
|
84
|
-
np.isfinite(mjd)
|
|
85
|
-
& np.isfinite(mag)
|
|
86
|
-
& np.isfinite(err)
|
|
87
|
-
& (err > 0)
|
|
88
|
-
& np.isfinite(band)
|
|
89
|
-
& np.isin(band, [1.0, 2.0, 3.0])
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
if np.sum(valid) < self.minimum_valid_detections:
|
|
93
|
-
return stop("Rejected: too few valid measurements")
|
|
94
|
-
|
|
95
|
-
mjd, mag, err, band = (
|
|
96
|
-
mjd[valid],
|
|
97
|
-
mag[valid],
|
|
98
|
-
err[valid],
|
|
99
|
-
band[valid].astype(int),
|
|
100
|
-
)
|
|
101
|
-
|
|
102
|
-
# Require >=2 bands
|
|
103
|
-
if len(np.unique(band)) < self.minimum_bands:
|
|
104
|
-
return stop("Rejected: fewer than two bands")
|
|
105
|
-
|
|
106
|
-
# Require >=0.5 mag variability
|
|
107
|
-
if np.ptp(mag) < self.minimum_amplitude:
|
|
108
|
-
return stop("Rejected: insufficient brightness variation")
|
|
109
|
-
|
|
110
|
-
# Reject long-term variables
|
|
111
|
-
if np.ptp(mjd) > self.maximum_duration_days:
|
|
112
|
-
return stop("Rejected: activity spans too long")
|
|
113
|
-
|
|
114
|
-
# Find brightest observation (lowest magnitude)
|
|
115
|
-
i = int(np.argmin(mag))
|
|
116
|
-
peak_mag = float(mag[i])
|
|
117
|
-
peak_err = float(err[i])
|
|
118
|
-
peak_mjd = float(mjd[i])
|
|
119
|
-
peak_band = self.ztf_band_names.get(int(band[i]), "unknown")
|
|
120
|
-
|
|
121
|
-
# Require reliable peak photometry
|
|
122
|
-
if peak_err > self.maximum_peak_mag_error:
|
|
123
|
-
return stop("Rejected: excessive peak uncertainty")
|
|
124
|
-
|
|
125
|
-
# Store values for downstream NED analysis
|
|
126
|
-
locus.set_property("eyoue_slsn_peak_apparent_mag", peak_mag)
|
|
127
|
-
locus.set_property("eyoue_slsn_peak_mag_error", peak_err)
|
|
128
|
-
locus.set_property("eyoue_slsn_peak_mjd", peak_mjd)
|
|
129
|
-
locus.set_property("eyoue_slsn_peak_band", peak_band)
|
|
130
|
-
locus.set_property(
|
|
131
|
-
"eyoue_slsn_prefilter_status",
|
|
132
|
-
"Passed pre-filter; requires downstream NED enrichment",
|
|
133
|
-
)
|
|
134
|
-
|
|
135
|
-
locus.tag("eyoue_slsn_prefilter")
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import itertools
|
|
2
|
-
from test.conftest import test_sample
|
|
3
|
-
|
|
4
|
-
import pytest
|
|
5
|
-
|
|
6
|
-
from antares_devkit.utils import get_filter_instances
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
@pytest.mark.parametrize(
|
|
10
|
-
"data, c_filter",
|
|
11
|
-
itertools.product(
|
|
12
|
-
test_sample,
|
|
13
|
-
get_filter_instances(),
|
|
14
|
-
),
|
|
15
|
-
)
|
|
16
|
-
def test_filter(memory_and_time_tracker, request, data, c_filter):
|
|
17
|
-
memory_and_time_tracker(c_filter, data)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/bad_detection/__init__.py
RENAMED
|
File without changes
|
{antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/bad_seeing/__init__.py
RENAMED
|
File without changes
|
{antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/crash_filter/__init__.py
RENAMED
|
File without changes
|
{antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/decam_shadow/__init__.py
RENAMED
|
File without changes
|
{antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/desi_target/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/ecl_transient_1/__init__.py
RENAMED
|
File without changes
|
{antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/ecl_transient_2/__init__.py
RENAMED
|
File without changes
|
{antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/extragalactic/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/highfluxchange/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/lantern/data/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/microlensing/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/nuttela_tao/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/recent_reddening/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/sample_filter/__init__.py
RENAMED
|
File without changes
|
{antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/shadow_virgo/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/superphot_plus_v1/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/test_dev_all/__init__.py
RENAMED
|
File without changes
|
{antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/test_dev_lsst/__init__.py
RENAMED
|
File without changes
|
{antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/test_dev_ztf/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{antares_devkit-0.11.1 → antares_devkit-0.12.1}/antares_devkit/filters/vpdf/data/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|