Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed wrong values in isclose when forcediffimflux and/or forcediffimfluxunc is -99999 #326

Merged
merged 2 commits into from
Dec 9, 2023
Merged
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
4 changes: 2 additions & 2 deletions prv_candidates_step/prv_candidates_step/core/strategy/ztf.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ def __calculate_mag(cls, data):
mag = -2.5 * np.log10(np.abs(forcediffimflux)) + 23.9
e_mag = 1.0857 * forcediffimfluxunc / np.abs(forcediffimflux)

if np.isclose(data["forcediffimflux"], _ZERO_MAG):
if np.isclose(data["forcediffimflux"], -99999):
mag = _ZERO_MAG
e_mag = _ZERO_MAG

if np.isclose(data["forcediffimfluxunc"], _ZERO_MAG):
if np.isclose(data["forcediffimfluxunc"], -99999):
e_mag = _ZERO_MAG

return mag, e_mag
Expand Down
21 changes: 18 additions & 3 deletions prv_candidates_step/tests/unit/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def test_prv_detections_parser():
assert result["oid"] == "oid"
assert result["aid"] == "aid"
assert not result["has_stamp"]
assert result["extra_fields"]["ef1"] == 1
assert "ef1" not in result["extra_fields"]
assert "distnr" in result["extra_fields"]
# Other extra fields should be verified as well
assert result["parent_candid"] == "123"


Expand All @@ -52,12 +54,25 @@ def test_ztf_extract_detections_and_non_detections():
"oid": "oid",
"candid": "123",
"fid": 1,
"extra_fields": {"ef1": 1, "prv_candidates": pickle.dumps(data)},
"extra_fields": {
"ef1": 1,
"prv_candidates": pickle.dumps(data),
"distnr": -555,
},
}
result = ztf_extract(alert)
assert len(result["detections"]) == 2
for res in result["detections"]:
assert res["extra_fields"]["ef1"] == 1
assert (
"ef1" in res["extra_fields"]
if res["candid"] == "123"
else "ef1" not in res["extra_fields"]
)
assert (
res["extra_fields"]["distnr"] == -555
if res["candid"] == "123"
else res["extra_fields"]["distnr"] > 0
)


def test_elasticc_extract_detections_and_non_detections():
Expand Down