Skip to content

Commit 9810b27

Browse files
Force i:ssnamenr to be in the payload (#58)
* Check mandatory fields for cutouts * Force ssnamenr to be in the payload by default * Left TODOs * Add missing fields in the schema (#61) * Expand test
1 parent 1d32b7e commit 9810b27

File tree

4 files changed

+34
-12
lines changed

4 files changed

+34
-12
lines changed

apps/routes/v1/schema/api.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,16 @@ def get(self):
293293
"type": "float",
294294
"doc": "Feature for characterising CTAO blazar state. Related to low state duration.",
295295
},
296+
{
297+
"name": "gaiaClass",
298+
"type": "str",
299+
"doc": "Name of best class from Gaia DR3 Part 4. Variability (I/358/vclassre).",
300+
},
301+
{
302+
"name": "gaiaVarFlag",
303+
"type": "int",
304+
"doc": "Photometric variability flag from Gaia DR3. 1 if the source is variable, 0 otherwise.",
305+
},
296306
],
297307
)
298308

apps/routes/v1/schema/test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ def check_old_columns(columns, objectId):
146146
"blazar_stats_m0",
147147
"blazar_stats_m1",
148148
"blazar_stats_m2",
149+
"gaiaVarFlag",
150+
"gaiaClass",
149151
]
150152

151153
outside_obtained = [i for i in definition if i not in obtained]

apps/routes/v1/sso/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2022 AstroLab Software
1+
# Copyright 2022-2025 AstroLab Software
22
# Author: Julien Peloton
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");

apps/routes/v1/sso/utils.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@ def extract_sso_data(payload: dict) -> pd.DataFrame:
7272
):
7373
with_cutouts = True
7474

75+
if with_cutouts and truncated:
76+
# Check mandatory fields
77+
if "i:objectId" not in cols or "i:candid" not in cols:
78+
rep = {
79+
"status": "error",
80+
"text": "You need to add 'i:objectId,i:candid' to the columns.\n",
81+
}
82+
return Response(str(rep), 400)
83+
84+
if truncated and "i:ssnamenr" not in cols:
85+
# For name resolving, i:ssnamenr must be here
86+
# In case the user forgot, let's add it silently
87+
cols += ",i:ssnamenr"
88+
7589
n_or_d = str(payload["n_or_d"])
7690

7791
if "," in n_or_d:
@@ -187,14 +201,12 @@ def extract_sso_data(payload: dict) -> pd.DataFrame:
187201
download_cutout(row["i:objectId"], row["i:candid"], cutout_kind)
188202
)
189203
pdf[colname] = cutouts
190-
# pdf[colname] = pdf[["i:objectId", "i:candid"]].apply(
191-
# lambda x: pd.Series([download_cutout(x.iloc[0], x.iloc[1], cutout_kind)]),
192-
# axis=1,
193-
# )
194204

195205
if with_ephem:
196-
# We should probably add a timeout
197-
# and try/except in case of miriade shutdown
206+
# TODO: In case truncated is True, check (before DB call)
207+
# the mandatory fields have been requested
208+
# TODO: We should probably add a timeout and try/except
209+
# in case of miriade shutdown
198210
pdf = get_miriade_data(pdf, sso_colname="sso_name")
199211
if "i:magpsf_red" not in pdf.columns:
200212
rep = {
@@ -204,13 +216,11 @@ def extract_sso_data(payload: dict) -> pd.DataFrame:
204216
return Response(str(rep), 400)
205217

206218
if with_residuals:
207-
# get phase curve parameters using
208-
# the sHG1G2 model
219+
# TODO: In case truncated is True, check (before DB call)
220+
# the mandatory fields have been requested
209221

210-
# Phase angle, in radians
222+
# Get phase curve parameters using the sHG1G2 model
211223
phase = np.deg2rad(pdf["Phase"].values)
212-
213-
# Required for sHG1G2
214224
ra = np.deg2rad(pdf["i:ra"].values)
215225
dec = np.deg2rad(pdf["i:dec"].values)
216226

0 commit comments

Comments
 (0)