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

SSHG1G2 in the API #682

Merged
merged 7 commits into from
Oct 25, 2024
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
9 changes: 6 additions & 3 deletions apps/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
COLUMNS_HG,
COLUMNS_HG1G2,
COLUMNS_SHG1G2,
COLUMNS_SSHG1G2,
)
from fink_utils.xmatch.simbad import get_simbad_labels
from flask import Blueprint, Response, jsonify, request
Expand Down Expand Up @@ -588,7 +589,7 @@ def layout():
{
"name": "flavor",
"required": False,
"description": "Data model among SHG1G2 (default), HG1G2, HG.",
"description": "Data model among SSHG1G2, SHG1G2 (default), HG1G2, HG.",
},
{
"name": "version",
Expand Down Expand Up @@ -1529,12 +1530,14 @@ def ssoft_table(payload=None):
if "schema" in payload:
if "flavor" in payload:
flavor = payload["flavor"]
if flavor not in ["SHG1G2", "HG1G2", "HG"]:
if flavor not in ["SSHG1G2", "SHG1G2", "HG1G2", "HG"]:
rep = {
"status": "error",
"text": "flavor needs to be in ['SHG1G2', 'HG1G2', 'HG']\n",
"text": "flavor needs to be in ['SSHG1G2', 'SHG1G2', 'HG1G2', 'HG']\n",
}
return Response(str(rep), 400)
elif flavor == "SSHG1G2":
ssoft_columns = {**COLUMNS, **COLUMNS_SSHG1G2}
elif flavor == "SHG1G2":
ssoft_columns = {**COLUMNS, **COLUMNS_SHG1G2}
elif flavor == "HG1G2":
Expand Down
4 changes: 2 additions & 2 deletions apps/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1689,10 +1689,10 @@ def return_ssoft_pdf(payload: dict) -> pd.DataFrame:

if "flavor" in payload:
flavor = payload["flavor"]
if flavor not in ["SHG1G2", "HG1G2", "HG"]:
if flavor not in ["SSHG1G2", "SHG1G2", "HG1G2", "HG"]:
rep = {
"status": "error",
"text": "flavor needs to be in ['SHG1G2', 'HG1G2', 'HG']\n",
"text": "flavor needs to be in ['SSHG1G2', 'SHG1G2', 'HG1G2', 'HG']\n",
}
return Response(str(rep), 400)
else:
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ emcee==3.1.4
faust-cchardet==2.1.19
fink-filters==3.35
fink-spins==0.3.7
fink-utils==0.28.0
fink-utils==0.29.5
Flask==3.0.1
fonttools==4.47.2
frozenlist==1.4.1
Expand Down Expand Up @@ -159,4 +159,4 @@ Werkzeug==3.0.1
wrapt==1.16.0
yarl==1.9.4
zipp==3.17.0
git+https://github.com/astrolabsoftware/fink-science@5.21.1
git+https://github.com/astrolabsoftware/fink-science@5.21.3
28 changes: 23 additions & 5 deletions tests/api_ssoft_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,18 @@ def test_schema() -> None:
--------
>>> test_schema()
"""
pdf = ssoftsearch()
pdf = ssoftsearch(flavor="SSHG1G2")

schema = ssoftsearch(schema=True, output_format="json")
schema = ssoftsearch(schema=True, flavor="SSHG1G2", output_format="json")

# check columns
msg = "Found {} entries in the DataFrame and {} entries in the schema".format(
not_in_pdf = [i for i in set(schema["args"].keys()) if i not in set(pdf.columns)]
not_in_schema = [i for i in set(pdf.columns) if i not in set(schema["args"].keys())]

assert not_in_pdf == [], not_in_pdf
assert not_in_schema == [], not_in_schema

msg = "Found {} entries in the DataFrame and {} entries in the schema.".format(
len(pdf.columns), len(schema)
)
assert set(schema["args"].keys()) == set(pdf.columns), msg
Expand All @@ -151,17 +157,29 @@ def compare_schema() -> None:
--------
>>> compare_schema()
"""
schema1 = ssoftsearch(schema=True, output_format="json")
schema1 = ssoftsearch(schema=True, flavor="SSHG1G2", output_format="json")

# get the schema
r = requests.get("{}/api/v1/ssoft?schema".format(APIURL))
r = requests.get("{}/api/v1/ssoft?schema&flavor=SSHG1G2".format(APIURL))
schema2 = r.json()

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


def check_sshg1g2() -> None:
"""
Examples
--------
>>> check_sshg1g2()
"""
pdf = ssoftsearch(flavor="SSHG1G2")

assert "period" in pdf.columns
assert "a_b" in pdf.columns


if __name__ == "__main__":
""" Execute the test suite """
import sys
Expand Down
Loading