Skip to content
Snippets Groups Projects
Commit 2b8f9208 authored by Nico Vermaas's avatar Nico Vermaas
Browse files

adding dataproduct_type, dataproduct_subtype, level, collection filters

parent b85f52a0
No related branches found
No related tags found
1 merge request!5adding dataproduct_type, dataproduct_subtype, level, collection filters
Pipeline #35489 passed
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
* http://localhost:8000/adex-fastapi/skyviews/ * http://localhost:8000/adex-fastapi/skyviews/
* http://localhost:8000/adex-fastapi/skyviews_rectangle/?ra_min=40&ra_max=50&dec_min=25&dec_max=35&limit=1000 * http://localhost:8000/adex-fastapi/skyviews_rectangle/?ra_min=40&ra_max=50&dec_min=25&dec_max=35&limit=1000
* http://localhost:8000/adex-fastapi/docs
* http://localhost:8000/adex-fastapi/redoc
### sdc-dev (test environment) ### sdc-dev (test environment)
* https://sdc-dev.astron.nl/adex-fastapi/skyviews/ * https://sdc-dev.astron.nl/adex-fastapi/skyviews/
* https://sdc-dev.astron.nl/adex-fastapi/skyviews_rectangle/?ra_min=40&ra_max=50&dec_min=25&dec_max=35&limit=1000 * https://sdc-dev.astron.nl/adex-fastapi/skyviews_rectangle/?ra_min=40&ra_max=50&dec_min=25&dec_max=35&limit=1000
......
...@@ -17,3 +17,31 @@ def get_skyviews_rectangle(db: Session, ra_min: float = 0.0, ra_max: float = 1.0 ...@@ -17,3 +17,31 @@ def get_skyviews_rectangle(db: Session, ra_min: float = 0.0, ra_max: float = 1.0
).limit(limit).all() ).limit(limit).all()
print("retrieved "+str(len(list)) + ' dataproducts') print("retrieved "+str(len(list)) + ' dataproducts')
return list return list
@timeit
def get_skyviews_dataproducts(
db: Session,
ra_min: float = 0.0, ra_max: float = 1.0,
dec_min: float = 0.0, dec_max: float = 1.0,
limit: int = 1000,
collections: list = None,
beams : list = None,
levels : list = None,
dp_types : list = None,
dp_subtypes: list = None):
# https://www.tutorialspoint.com/sqlalchemy/sqlalchemy_orm_using_query.htm
# https://docs.sqlalchemy.org/en/14/orm/query.html
list = db.query(SkyView).filter(
SkyView.ra > ra_min,
SkyView.ra < ra_max,
SkyView.dec > dec_min,
SkyView.dec < dec_max,
SkyView.collection.in_(collections),
#SkyView.beam.in_(beams),
SkyView.level.in_(levels),
SkyView.dataproduct_type.in_(dp_types),
SkyView.dataproduct_subtype.in_(dp_subtypes),
).limit(limit).all()
print("retrieved "+str(len(list)) + ' dataproducts')
return list
\ No newline at end of file
...@@ -10,6 +10,9 @@ app = FastAPI( ...@@ -10,6 +10,9 @@ app = FastAPI(
title="ADEX backend", title="ADEX backend",
description="ADEX backend FastAPI", description="ADEX backend FastAPI",
version="0.0.1", version="0.0.1",
docs_url='/adex-fastapi/docs',
redoc_url='/adex-fastapi/redoc',
openapi_url='/adex-fastapi/openapi.json',
contact={ contact={
"name": "Nico Vermaas", "name": "Nico Vermaas",
"email": "vermaas@astron.nl", "email": "vermaas@astron.nl",
......
from typing import List from typing import List, Union
from fastapi import APIRouter, Query, Depends from fastapi import APIRouter, Query, Depends
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
...@@ -15,6 +15,13 @@ def get_db(): ...@@ -15,6 +15,13 @@ def get_db():
finally: finally:
db.close() db.close()
def get_all_dp_types():
return ['image','cube','timeSeries','visibility']
def get_all_dp_subtypes():
return ['uncalibratedVisibility','lineCube','continuumCube','beamCube','continuumChunk','polarizationCube',
'pulsarTimingTimeSeries','compressedUncalibratedVisibility','splitttedUncalibratedVisibility',
'calibratedImage','calibratedVisibility','continuumMF','polarisationImage']
# http://127.0.0.1:8000/skyviews/ # http://127.0.0.1:8000/skyviews/
# http://127.0.0.1:8000/skyviews/?skip=100&limit=100 # http://127.0.0.1:8000/skyviews/?skip=100&limit=100
...@@ -25,9 +32,60 @@ async def get_skyviews(skip: int = 0, limit: int = 1000, db: Session = Depends(g ...@@ -25,9 +32,60 @@ async def get_skyviews(skip: int = 0, limit: int = 1000, db: Session = Depends(g
# http://localhost:8000/adex-fastapi/skyviews_rectangle/?ra_min=40&ra_max=50&dec_min=25&dec_max=35&limit=1000 # http://localhost:8000/adex-fastapi/skyviews_rectangle/?ra_min=40&ra_max=50&dec_min=25&dec_max=35&limit=1000
@router.get("/skyviews_rectangle/", tags=["skyviews"], response_model=List[schemas.SkyView]) @router.get("/skyviews_rectangle/", tags=["skyviews"], response_model=List[schemas.SkyView])
async def get_skyviews_rectangle(ra_min: float = 0.0, ra_max: float = 1.0, async def get_skyviews_rectangle(db: Session = Depends(get_db),
dec_min: float = 0.0, dec_max: float = 1.0, ra_min: float = 0.0, ra_max: float = 1.0, dec_min: float = 0.0, dec_max: float = 1.0,
limit: int = 1000, db: Session = Depends(get_db)): limit: int = 1000):
items = crud.get_skyviews_rectangle(db, ra_min=ra_min, ra_max=ra_max, dec_min=dec_min, dec_max=dec_max, limit=limit) items = crud.get_skyviews_rectangle(db, ra_min=ra_min, ra_max=ra_max, dec_min=dec_min, dec_max=dec_max, limit=limit)
return items return items
# http://localhost:8000/adex-fastapi/skyviews_dataproducts/?ra_min=40&ra_max=50&dec_min=25&dec_max=35&limit=1000&dp_types=image,ube
@router.get("/skyviews_dataproducts/", tags=["skyviews"], response_model=List[schemas.SkyView])
async def get_skyviews_dataproducts(db: Session = Depends(get_db),
ra_min: float = 0.0, ra_max: float = 1.0, dec_min: float = 0.0, dec_max: float = 1.0,
collections: str = None,
beams: str = None,
levels : str = None,
dp_types: str = None,
dp_subtypes: str = None,
limit: int = 1000):
# TODO: get rid of these hardcoded values
# no values should result in something like 'all',
# but I don't know how to do that in SQLAlchemy query filters
try:
collections_list = collections.split(',')
except:
collections_list = ['apertif-imaging','apertif-timeseries']
try:
beams_list = beams.split(',')
except:
beams_list = [0]
try:
levels_list = levels.split(',')
except:
levels_list = [0,1,2]
try:
dp_types_list = dp_types.split(',')
except:
# if no dp_types are given, assume 'image' (better than nothing)
dp_types_list = get_all_dp_types()
try:
dp_subtypes_list = dp_subtypes.split(',')
except:
# if no dp_types are given, assume 'image' (better than nothing)
dp_subtypes_list = get_all_dp_subtypes()
items = crud.get_skyviews_dataproducts(
db, ra_min=ra_min, ra_max=ra_max, dec_min=dec_min, dec_max=dec_max,
collections=collections_list,
beams=beams_list,
levels=levels_list,
dp_types=dp_types_list,
dp_subtypes=dp_subtypes_list, limit=limit)
return items
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment