-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
78 lines (67 loc) · 2.28 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Copyright 2024 AstroLab Software
# Author: Julien Peloton
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import flask
from flask import request, jsonify
from apps.utils import format_and_send_cutout
app = flask.Flask(__name__)
args_cutouts = [
{
"name": "hdfsPath",
"required": True,
"description": "Data path on HDFS",
},
{
"name": "objectId",
"required": True,
"description": "ZTF Object ID",
},
{
"name": "kind",
"required": True,
"description": "Science, Template, Difference, or All",
},
{
"name": "candid",
"required": False,
"description": "Candidate ID of the alert. If not provided, the cutouts of the latest alert is returned",
},
{
"name": "return_type",
"required": False,
"description": "Returned type among `array` or `FITS`. If not provided, `array` is chosen.",
},
]
@app.route("/api/v1/cutouts", methods=["GET"])
def cutouts_arguments():
"""Obtain information about the cutouts service"""
if len(request.args) > 0:
# POST from query URL
return return_cutouts(payload=request.args)
else:
return jsonify({"args": args_cutouts})
@app.route("/api/v1/cutouts", methods=["POST"])
def return_cutouts(payload=None):
"""Retrieve cutout data from the Fink data lake"""
# get payload from the JSON
if payload is None:
payload = request.json
# Make some checks
assert payload["kind"] in ["Science", "Template", "Difference", "All"]
assert payload["objectId"].startswith("ZTF")
return format_and_send_cutout(payload)
if __name__ == "__main__":
import yaml
input_args = yaml.load(open("config.yml"), yaml.Loader)
app.run(input_args["APIURL"], port=int(input_args["PORT"]))