Skip to content
Open
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
19 changes: 8 additions & 11 deletions tools/scope_download_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@
import pandas as pd
from penquins import Kowalski
from time import sleep
from scope.fritz import save_newsource, api
from scope.fritz import api


def download_classification(file, gloria, group_ids):
"""
Upload labels to Fritz
:param file: file containing labels (csv)
:param file: file containing objects without labels (csv)
:param gloria: Gloria object
:param group_ids: group id on Fritz for upload target location (list)
"""
# create new empty classification column
file["classification"] = pd.NaT

for index, row in file.iterrows():
if index > 5:
break
# get information from objects
ra, dec, period = float(row.ra), float(row.dec), float(row.period)
ra, dec = float(row.ra), float(row.dec)

# get object id
response = api(
Expand All @@ -34,20 +32,19 @@ def download_classification(file, gloria, group_ids):
obj_id = data["sources"][0]["id"]
print(f"object {index} id:", obj_id)

# save new source
# no labels if new source
if obj_id is None:
obj_id = save_newsource(
gloria, group_ids, ra, dec, period=period, return_id=True
)
file.at[index, 'classification'] = None

# save existing source
else:
# save to group_id
json = {"objId": obj_id, "inviteGroupIds": group_ids}
response = api("POST", "/api/source_groups", args.token, json)

# get classificaiton
response = api("GET", f"/api/sources/{obj_id}/classifications", args.token)
# get classification
response = api(
"GET", f"/api/sources/{obj_id}/classifications", args.token)
data = response.json().get("data")

# store to new column
Expand Down