Skip to content

Commit

Permalink
Add residuals when downloading SSO data (#670)
Browse files Browse the repository at this point in the history
* Add residuals when downloading SSO data

* Enable download even if the residuals is not available

* Enable download even if the residuals is not available

* Fix syntax

* Centralise computation of residuals and ephemerides

* Simplify ephemerides and residuals computation
  • Loading branch information
JulienPeloton authored Oct 14, 2024
1 parent 95c1c33 commit ce535e4
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 31 deletions.
34 changes: 20 additions & 14 deletions apps/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,20 +833,26 @@ def return_sso_pdf(payload: dict) -> pd.DataFrame:
normalise_to_V=False,
)

# per filter construction of the residual
pdf["residuals_shg1g2"] = 0.0
for filt in np.unique(pdf["i:fid"]):
cond = pdf["i:fid"] == filt
model = func_hg1g2_with_spin(
[phase[cond], ra[cond], dec[cond]],
outdic["H_{}".format(filt)],
outdic["G1_{}".format(filt)],
outdic["G2_{}".format(filt)],
outdic["R"],
np.deg2rad(outdic["alpha0"]),
np.deg2rad(outdic["delta0"]),
)
pdf.loc[cond, "residuals_shg1g2"] = pdf.loc[cond, "i:magpsf_red"] - model
# check if fit converged else return NaN
if outdic["fit"] != 0:
pdf["residuals_shg1g2"] = np.nan
else:
# per filter construction of the residual
pdf["residuals_shg1g2"] = 0.0
for filt in np.unique(pdf["i:fid"]):
cond = pdf["i:fid"] == filt
model = func_hg1g2_with_spin(
[phase[cond], ra[cond], dec[cond]],
outdic["H_{}".format(filt)],
outdic["G1_{}".format(filt)],
outdic["G2_{}".format(filt)],
outdic["R"],
np.deg2rad(outdic["alpha0"]),
np.deg2rad(outdic["delta0"]),
)
pdf.loc[cond, "residuals_shg1g2"] = (
pdf.loc[cond, "i:magpsf_red"] - model
)

return pdf

Expand Down
1 change: 1 addition & 0 deletions apps/sso/cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ def card_sso_left(ssnamenr):
body: JSON.stringify({
'n_or_d': name,
'withEphem': true,
'withResiduals': true,
'output-format': '$FORMAT'
}),
headers: {
Expand Down
17 changes: 1 addition & 16 deletions apps/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import dash_mantine_components as dmc
import numpy as np
import pandas as pd
import rocks
import visdcc
from dash import Input, Output, State, dcc, html, no_update
from dash.exceptions import PreventUpdate
Expand All @@ -34,7 +33,6 @@
)
from apps.sso.cards import card_sso_left
from apps.supernovae.cards import card_sn_scores
from fink_utils.sso.utils import get_miriade_data
from apps.utils import (
generate_qr,
loading,
Expand Down Expand Up @@ -602,22 +600,9 @@ def store_query(name):
if str(payload) != "null" and is_sso:
pdfsso = request_api(
"/api/v1/sso",
json={
"n_or_d": payload,
},
json={"n_or_d": payload, "withEphem": True, "withResiduals": True},
)

if pdfsso.empty:
# This can happen for SSO candidate with a ssnamenr
# e.g. ZTF21abatnkh
pdfsso = pd.DataFrame()
else:
# Extract miriade information as well
name = rocks.id(payload)[0]
if name:
pdfsso["sso_name"] = name

pdfsso = get_miriade_data(pdfsso, sso_colname="sso_name", withecl=False)
else:
pdfsso = pd.DataFrame()

Expand Down
17 changes: 16 additions & 1 deletion tests/api_sso_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,16 @@ def test_ephem() -> None:
--------
>>> test_ephem()
"""
names = ["8467", "BenoitCarry", "JulienPeloton", "Phaethon", 3200, "Lucretia", 269]
names = [
"8467",
"BenoitCarry",
"JulienPeloton",
"Phaethon",
3200,
"Lucretia",
269,
323137,
]
for name in names:
pdf = ssosearch(n_or_d=name, withEphem=True)

Expand All @@ -113,6 +122,12 @@ def test_residuals() -> None:

assert pdf.empty

pdf = ssosearch("323137", withResiduals=True)

assert not pdf.empty

assert np.isnan(pdf["residuals_shg1g2"].to_numpy()[0])


def test_comet() -> None:
"""
Expand Down

0 comments on commit ce535e4

Please sign in to comment.