Skip to content

Commit 3d26a3b

Browse files
Miriade interface improvements (#173)
* Add test * Add new fields to ephems * PEP8 * Safe insertion of values * PEP8 * Fix offending statement * Doc
1 parent 0cc900c commit 3d26a3b

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

fink_utils/sso/ephem.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,32 @@
2727

2828
from fink_utils.tester import spark_unit_tests
2929

30-
31-
COLUMNS = ["Dobs", "Dhelio", "Phase", "Elong.", "RA", "DEC"]
30+
import logging
31+
32+
_LOG = logging.getLogger(__name__)
33+
34+
COLUMNS = [
35+
"Dobs",
36+
"Dhelio",
37+
"Phase",
38+
"Elong.",
39+
"RA",
40+
"DEC",
41+
"px",
42+
"py",
43+
"pz",
44+
"vx",
45+
"vy",
46+
"vz",
47+
]
48+
49+
50+
def safe_insert(dic, k):
51+
"""Safely return value if the key exists"""
52+
if k in dic:
53+
return dic[k]
54+
else:
55+
return None
3256

3357

3458
def sanitize_name(col):
@@ -69,7 +93,7 @@ def expand_columns(df, col_to_expand="ephem"):
6993
>>> assert "a" not in df.columns, df.columns
7094
"""
7195
if col_to_expand not in df.columns:
72-
print(
96+
_LOG.warning(
7397
"{} not found in the DataFrame columns. Have you computed ephemerides?".format(
7498
col_to_expand
7599
)
@@ -194,7 +218,8 @@ def extract_ztf_ephemerides_from_miriade(ssnamenr, cjd, uid, method):
194218
if ephems.get("data", None) is not None:
195219
# Remove any "." in name
196220
ephems_corr = {
197-
sanitize_name(k): [dic[k] for dic in ephems["data"]] for k in COLUMNS
221+
sanitize_name(k): [safe_insert(dic, k) for dic in ephems["data"]]
222+
for k in COLUMNS
198223
}
199224

200225
# In-place transformation of RA/DEC coordinates

fink_utils/sso/miriade.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import subprocess
1919
import json
2020
import os
21+
import io
2122

2223
from astropy.coordinates import SkyCoord
2324
import astropy.units as u
@@ -31,6 +32,25 @@
3132
from fink_utils.tester import regular_unit_tests
3233

3334

35+
def get_sso_data(ssnamenr):
36+
"""Wrapper for tests
37+
38+
Parameters
39+
----------
40+
ssnamenr: str
41+
SSO name
42+
"""
43+
r = requests.post(
44+
"https://api.fink-portal.org/api/v1/sso",
45+
json={"n_or_d": ssnamenr, "withEphem": True, "output-format": "json"},
46+
)
47+
48+
if r.status_code != 200:
49+
raise AssertionError((r.content, ssnamenr))
50+
pdf = pd.read_json(io.BytesIO(r.content))
51+
return pdf
52+
53+
3454
@profile
3555
def query_miriade(
3656
ident,
@@ -289,6 +309,14 @@ def get_miriade_data(
289309
-------
290310
out: pd.DataFrame
291311
DataFrame of the same length, but with new columns from the ephemerides service.
312+
313+
Examples
314+
--------
315+
>>> ssnamenrs = ["33803"]
316+
>>> for ssnamenr in ssnamenrs:
317+
... pdf = get_sso_data(ssnamenr)
318+
... pdfEphem = get_miriade_data(pdf, withecl=False)
319+
... assert "Phase" in pdfEphem.columns, (ssnamenr)
292320
"""
293321
if parameters is None:
294322
parameters = {}

0 commit comments

Comments
 (0)