Skip to content

Commit f9efef0

Browse files
[Rubin] Add the /blocks endpoint (#133)
* Update app * Add /blocks endpoint * Bump requirements * Bump requirements
1 parent 7b2da27 commit f9efef0

5 files changed

Lines changed: 79 additions & 2 deletions

File tree

app_lsst.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from apps.routes.v1.lsst.skymap.api import ns as ns_skymap
3535
from apps.routes.v1.lsst.statistics.api import ns as ns_stats
3636
from apps.routes.v1.lsst.tags.api import ns as ns_tags
37+
from apps.routes.v1.lsst.blocks.api import ns as ns_blocks
3738

3839
config = extract_configuration("config.yml")
3940

@@ -89,6 +90,7 @@ def after_request(response):
8990
api.add_namespace(ns_skymap)
9091
api.add_namespace(ns_stats)
9192
api.add_namespace(ns_tags)
93+
api.add_namespace(ns_blocks)
9294

9395
# Register blueprint
9496
app.register_blueprint(blueprint)

apps/routes/v1/lsst/blocks/__init__.py

Whitespace-only changes.

apps/routes/v1/lsst/blocks/api.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2026 AstroLab Software
2+
# Author: Julien Peloton
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
from flask import jsonify
16+
from flask_restx import Namespace, Resource
17+
18+
from apps.routes.v1.lsst.blocks.utils import extract_blocks
19+
20+
ns = Namespace("api/v1/blocks", "Get blocks definition")
21+
22+
23+
@ns.route("")
24+
class Blocks(Resource):
25+
def get(self):
26+
"""Retrieve block definition"""
27+
tags, descriptions = extract_blocks(True)
28+
out = {k: v for k, v in zip(tags, descriptions)}
29+
return jsonify(out)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright 2026 AstroLab Software
2+
# Author: Julien Peloton
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
import fink_filters.rubin.blocks as fblocks
16+
import importlib
17+
18+
19+
def extract_blocks(with_description=False):
20+
"""Extract user-defined blocks
21+
22+
Parameters
23+
----------
24+
with_description: bool
25+
If True, returns block names and descriptions.
26+
Otherwise, returns only block names.
27+
28+
Returns
29+
-------
30+
block_names: list of str
31+
List of block names
32+
descriptions: list of str, optional
33+
Long descriptions for blocks
34+
"""
35+
# User-defined blocks
36+
block_names = [prop for prop in dir(fblocks) if prop.startswith("b_")]
37+
38+
if with_description:
39+
module_name = importlib.import_module(fblocks.__name__)
40+
descriptions = [
41+
getattr(module_name, block).__doc__.split("\n")[0] for block in block_names
42+
]
43+
return block_names, descriptions
44+
45+
return block_names

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ flask
44
flask-restx
55
pandas
66
numpy
7-
fink-filters==7.12
8-
fink-utils==0.51.0
7+
#fink-filters==7.15-rc0
8+
git+https://github.com/astrolabsoftware/fink-filters@7.15-rc0
9+
fink-utils==0.52.0
910
line_profiler
1011
requests
1112
pyarrow

0 commit comments

Comments
 (0)