BHTOM-Team / bhtom2

7 stars 2 forks source link

Photometric classifier (Heroku) add in create target #57

Closed wyrzykow closed 1 year ago

wyrzykow commented 1 year ago

Output of the photometric classifier https://photometric-classifier.herokuapp.com/ should be displayed also generated during create (based on Ra,Dec) and displayed. The problem is that the output is a long json. Maybe display only the best class? Or store the entire output and display on request (but do not run the classifier again)

wyrzykow commented 1 year ago
import requests
import json

# api-endpoint
url = "https://photometric-classifier.herokuapp.com/classify"
# defining a params dict for the parameters to be sent to the API
#payload = { "coordinates": [[116.0932, 28.44343], [274.25440,  -31.38352]] }
payload = { "coordinates": [[274.25440, -31.38352]] }

r = requests.post(url, data=json.dumps(payload))
data = r.json()
pred = data['payload']['results'][0]['predictions']
if len(pred)==0: 
  print("NO RESULT")

best=data['payload']['results'][0]['best_class']
arr=data['payload']['results'][0]['predictions']

for element in arr:
    if element[0] == best:
        best_value = element[1]
        break

print(best, '{:.1%}'.format(best_value))

data = {'message': 'Success', 'payload': {'results': [{'best_class': 'Ulens Candidate', 'best_class_confidence': 0.556, 'classifier': 2, 'dec': '-31.38352', 'predictions': [['Be Star', 0.358], ['Evolved', 0.0], ['Ulens Candidate', 0.556], ['YSO', 0.086]], 'ra': '274.2544'}]}}

wyrzykow commented 1 year ago

Added as an TargetExtra field phot_class.

image

It is displayed at the very end of the extra fields list as currently the list of extra fields is displayed in the order it is in the DB.