Skip to content

Commit

Permalink
Add to_target method
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienPeloton committed Apr 30, 2021
1 parent fb661ad commit 803de3f
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions tom_fink/fink.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from tom_alerts.alerts import GenericAlert, GenericBroker, GenericQueryForm
from tom_targets.models import Target, TargetName

from django import forms
import requests
Expand Down Expand Up @@ -275,13 +276,7 @@ def fetch_alert(self, id: str):
Parameters
----------
parameters: dict
Dictionary that contains query parameters defined in the Form
Example: {
'query_name': 'toto',
'broker': 'Fink',
'objectId': 'ZTF19acnjwgm'
}
parameters: str
Returns
----------
Expand All @@ -303,6 +298,25 @@ def fetch_alert(self, id: str):
def process_reduced_data(self, target, alert=None):
pass

def to_target(self, alert: dict) -> Target:
""" Redirect query result to a Target
Parameters
----------
alert: dict
Dictionary containing alert data: {column name: value}. See
`self.fetch_alerts` for more information.
"""
target = Target.objects.create(
name=alert['i:objectId'],
type='SIDEREAL',
ra=alert['i:ra'],
dec=alert['i:dec'],
)
aliases = [TargetName(target=target, name=alert['i:objectId'])]
return target, [], aliases

def to_generic_alert(self, alert):
""" Extract relevant parameters from the Fink alert to the TOM interface
Expand Down

0 comments on commit 803de3f

Please sign in to comment.