Skip to content

Commit 20a4dcc

Browse files
SSHG1G2 in the API (#682)
* Enable SSHG1G2 to be downloaded * Update test * Test schema for SSHG1G2 * Fix test * Expand test * Update requirements
1 parent cec6f57 commit 20a4dcc

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

apps/api/api.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
COLUMNS_HG,
2222
COLUMNS_HG1G2,
2323
COLUMNS_SHG1G2,
24+
COLUMNS_SSHG1G2,
2425
)
2526
from fink_utils.xmatch.simbad import get_simbad_labels
2627
from flask import Blueprint, Response, jsonify, request
@@ -588,7 +589,7 @@ def layout():
588589
{
589590
"name": "flavor",
590591
"required": False,
591-
"description": "Data model among SHG1G2 (default), HG1G2, HG.",
592+
"description": "Data model among SSHG1G2, SHG1G2 (default), HG1G2, HG.",
592593
},
593594
{
594595
"name": "version",
@@ -1529,12 +1530,14 @@ def ssoft_table(payload=None):
15291530
if "schema" in payload:
15301531
if "flavor" in payload:
15311532
flavor = payload["flavor"]
1532-
if flavor not in ["SHG1G2", "HG1G2", "HG"]:
1533+
if flavor not in ["SSHG1G2", "SHG1G2", "HG1G2", "HG"]:
15331534
rep = {
15341535
"status": "error",
1535-
"text": "flavor needs to be in ['SHG1G2', 'HG1G2', 'HG']\n",
1536+
"text": "flavor needs to be in ['SSHG1G2', 'SHG1G2', 'HG1G2', 'HG']\n",
15361537
}
15371538
return Response(str(rep), 400)
1539+
elif flavor == "SSHG1G2":
1540+
ssoft_columns = {**COLUMNS, **COLUMNS_SSHG1G2}
15381541
elif flavor == "SHG1G2":
15391542
ssoft_columns = {**COLUMNS, **COLUMNS_SHG1G2}
15401543
elif flavor == "HG1G2":

apps/api/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,10 +1689,10 @@ def return_ssoft_pdf(payload: dict) -> pd.DataFrame:
16891689

16901690
if "flavor" in payload:
16911691
flavor = payload["flavor"]
1692-
if flavor not in ["SHG1G2", "HG1G2", "HG"]:
1692+
if flavor not in ["SSHG1G2", "SHG1G2", "HG1G2", "HG"]:
16931693
rep = {
16941694
"status": "error",
1695-
"text": "flavor needs to be in ['SHG1G2', 'HG1G2', 'HG']\n",
1695+
"text": "flavor needs to be in ['SSHG1G2', 'SHG1G2', 'HG1G2', 'HG']\n",
16961696
}
16971697
return Response(str(rep), 400)
16981698
else:

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ emcee==3.1.4
4646
faust-cchardet==2.1.19
4747
fink-filters==3.35
4848
fink-spins==0.3.7
49-
fink-utils==0.28.0
49+
fink-utils==0.29.5
5050
Flask==3.0.1
5151
fonttools==4.47.2
5252
frozenlist==1.4.1
@@ -159,4 +159,4 @@ Werkzeug==3.0.1
159159
wrapt==1.16.0
160160
yarl==1.9.4
161161
zipp==3.17.0
162-
git+https://github.com/astrolabsoftware/fink-science@5.21.1
162+
git+https://github.com/astrolabsoftware/fink-science@5.21.3

tests/api_ssoft_test.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,18 @@ def test_schema() -> None:
134134
--------
135135
>>> test_schema()
136136
"""
137-
pdf = ssoftsearch()
137+
pdf = ssoftsearch(flavor="SSHG1G2")
138138

139-
schema = ssoftsearch(schema=True, output_format="json")
139+
schema = ssoftsearch(schema=True, flavor="SSHG1G2", output_format="json")
140140

141141
# check columns
142-
msg = "Found {} entries in the DataFrame and {} entries in the schema".format(
142+
not_in_pdf = [i for i in set(schema["args"].keys()) if i not in set(pdf.columns)]
143+
not_in_schema = [i for i in set(pdf.columns) if i not in set(schema["args"].keys())]
144+
145+
assert not_in_pdf == [], not_in_pdf
146+
assert not_in_schema == [], not_in_schema
147+
148+
msg = "Found {} entries in the DataFrame and {} entries in the schema.".format(
143149
len(pdf.columns), len(schema)
144150
)
145151
assert set(schema["args"].keys()) == set(pdf.columns), msg
@@ -151,17 +157,29 @@ def compare_schema() -> None:
151157
--------
152158
>>> compare_schema()
153159
"""
154-
schema1 = ssoftsearch(schema=True, output_format="json")
160+
schema1 = ssoftsearch(schema=True, flavor="SSHG1G2", output_format="json")
155161

156162
# get the schema
157-
r = requests.get("{}/api/v1/ssoft?schema".format(APIURL))
163+
r = requests.get("{}/api/v1/ssoft?schema&flavor=SSHG1G2".format(APIURL))
158164
schema2 = r.json()
159165

160166
keys1 = set(schema1["args"].keys())
161167
keys2 = set(schema2["args"].keys())
162168
assert keys1 == keys2, [keys1, keys2]
163169

164170

171+
def check_sshg1g2() -> None:
172+
"""
173+
Examples
174+
--------
175+
>>> check_sshg1g2()
176+
"""
177+
pdf = ssoftsearch(flavor="SSHG1G2")
178+
179+
assert "period" in pdf.columns
180+
assert "a_b" in pdf.columns
181+
182+
165183
if __name__ == "__main__":
166184
""" Execute the test suite """
167185
import sys

0 commit comments

Comments
 (0)