Skip to content

Commit

Permalink
Merge pull request #13 from TOMToolkit/issue/12/classanddate
Browse files Browse the repository at this point in the history
[API] Add possibility to search by class in the last <n> days
  • Loading branch information
JulienPeloton committed May 3, 2021
2 parents fb661ad + a8d54b4 commit e66b3bc
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions tom_fink/fink.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import requests
import markdown as md
import numpy as np
from astropy.time import Time

FINK_URL = "http://134.158.75.151:24000"
COLUMNS = 'i:candid,d:rfscore,i:ra,i:dec,i:jd,i:magpsf,i:objectId,d:cdsxmatch'
Expand Down Expand Up @@ -106,7 +107,7 @@ class FinkQueryForm(GenericQueryForm):
""".format(FINK_URL)
classsearch = forms.CharField(
required=False,
label='Class Search',
label='Class Search by number',
help_text=md.markdown(
help_classsearch
),
Expand All @@ -117,6 +118,26 @@ class FinkQueryForm(GenericQueryForm):
)
)

help_classsearchdate = """
Choose a class of interest from {}/api/v1/classes
to see the alerts processed by Fink in the last `n_days_in_past` days. Example
- Early SN Ia the last day: Early SN candidate, 1
- Early SN Ia the last 10 days: Early SN candidate, 10
Note that n_days_in_past_max = 15.
""".format(FINK_URL)
classsearchdate = forms.CharField(
required=False,
label='Class Search by date',
help_text=md.markdown(
help_classsearchdate
),
widget=forms.TextInput(
attrs={
'placeholder': 'class, n_days_in_past'
}
)
)

help_ssosearch = """
The list of arguments for retrieving SSO data can be found at {}/api/v1/sso.
The numbers or designations are taken from the MPC archive.
Expand Down Expand Up @@ -188,7 +209,8 @@ def fetch_alerts(self, parameters: dict) -> iter:
"""
# Check the user fills only one query form
allowed_search = [
'objectId', 'conesearch', 'datesearch', 'classsearch', 'ssosearch'
'objectId', 'conesearch', 'datesearch',
'classsearch', 'classsearchdate', 'ssosearch'
]
nquery = np.sum([len(parameters[i].strip()) > 0 for i in allowed_search])
if nquery > 1:
Expand Down Expand Up @@ -249,6 +271,23 @@ def fetch_alerts(self, parameters: dict) -> iter:
'n': n_alert
}
)
elif len(parameters['classsearchdate'].strip()) > 0:
try:
class_name, n_days_in_past = parameters['classsearchdate'].split(',')
except ValueError:
raise
now = Time.now()
start = Time(now.jd - float(n_days_in_past), format='jd').iso
end = now.iso
r = requests.post(
FINK_URL + '/api/v1/latests',
json={
'class': class_name,
'n': 1000,
'startdate': start,
'stopdate': end
}
)
elif len(parameters['ssosearch'].strip()) > 0:
r = requests.post(
FINK_URL + '/api/v1/sso',
Expand Down

0 comments on commit e66b3bc

Please sign in to comment.