Skip to content

Commit

Permalink
Adds more endpoints (#14)
Browse files Browse the repository at this point in the history
* adds more endpoints

* update readme

* bump version

* allow Path in LoadHDF5File pydantic model
  • Loading branch information
fhernandezvivanco authored Nov 1, 2024
1 parent c6f6b2f commit 4e986e4
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 19 deletions.
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,6 @@ Follow these steps to run the app locally:
3. **Run the FAST-API application**
```bash
uvicorn ansto_simplon_api.main:app
```
> **Note:** The FastAPI Swagger / ReDoc endpoint documentation is disabled by default, to enable the documentation, please set the following environment variables.
> ```bash
> export AS_API_DOCS_URL=/swagger
> export AS_API_REDOC_URL=/docs
> export AS_API_OPENAPI_URL=/openapi.json
>```
## Example usage
Once the simulated SIMPLON API is up and running, you can verify its functionality by:
Expand Down
6 changes: 3 additions & 3 deletions ansto_simplon_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ class APISettings(BaseSettings):
)
API_DOCS_URL: str | None = Field(
title="OpenAPI Docs Path",
default=None,
default="/swagger",
)
API_REDOC_URL: str | None = Field(
title="ReDocs Path",
default=None,
default="/docs",
)
API_OPENAPI_URL: str | None = Field(
title="OpenAPI Path",
default=None,
default="/openapi.json",
)
API_FAVICON: FilePath = Field(
title="Favicon Image",
Expand Down
2 changes: 2 additions & 0 deletions ansto_simplon_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .routes.ansto_endpoints.load_hdf5_files import router as ansto_endpoints
from .routes.detector.command import router as command
from .routes.detector.config import router as detector_config
from .routes.status.status import router as status
from .routes.stream.config import router as stream_config

config = get_settings()
Expand Down Expand Up @@ -44,6 +45,7 @@ async def favicon():
app.include_router(command)
app.include_router(stream_config)
app.include_router(detector_config)
app.include_router(status)
app.include_router(ansto_endpoints)


Expand Down
24 changes: 22 additions & 2 deletions ansto_simplon_api/routes/detector/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,28 @@ async def put_photon_energy(input: SimplonRequestFloat):


# pixel_mask
# pixel_mask_applied
# roi_mode
@router.get("/pixel_mask_applied")
async def get_pixel_mask():
zmq_stream.detector_config.pixel_mask_applied
return {"value": zmq_stream.detector_config.pixel_mask_applied}


@router.put("/pixel_mask_applied")
async def set_pixel_mask(input: SimplonRequestBool):
zmq_stream.detector_config.pixel_mask_applied = input.value
return {"value": zmq_stream.detector_config.pixel_mask_applied}


@router.get("/roi_mode")
async def get_roi_mode():
zmq_stream.detector_config.roi_mode
return {"value": zmq_stream.detector_config.roi_mode}


@router.put("/roi_mode")
async def put_roi_mode(input: SimplonRequestStr):
zmq_stream.detector_config.roi_mode = input.value
return {"value": zmq_stream.detector_config.roi_mode}


@router.put("/sensor_material")
Expand Down
8 changes: 8 additions & 0 deletions ansto_simplon_api/routes/status/status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from fastapi import APIRouter

router = APIRouter(prefix="/detector/api/1.8.0/status", tags=["Detector Status"])


@router.get("/state")
def get_detector_state():
return {"value": "idle"}
30 changes: 29 additions & 1 deletion ansto_simplon_api/routes/stream/config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
from fastapi import APIRouter

from ...schemas.configuration import SimplonRequestAny
from ...schemas.configuration import (
SimplonRequestAny,
SimplonRequestStr,
StreamConfiguration,
)
from ...simulate_zmq_stream import zmq_stream

router = APIRouter(prefix="/stream/api/1.8.0/config", tags=["Stream Configuration"])

stream_config = StreamConfiguration()


@router.put("/header_appendix")
async def set_user_data(user_data: SimplonRequestAny):
Expand All @@ -17,6 +23,28 @@ async def get_user_data():
return {"value": zmq_stream.user_data}


@router.get("/format")
async def get_format():
return {"value": stream_config.format}


@router.put("/format")
async def set_format(input: SimplonRequestStr):
stream_config.format = input.value
return {"value": stream_config.format}


@router.get("/mode")
async def get_mode():
return {"value": stream_config.format}


@router.put("/mode")
async def set_mode(input: SimplonRequestStr):
stream_config.mode = input.value
return {"value": stream_config.mode}


### Stream subsystem config
# header_detail
# image_appendix
Expand Down
3 changes: 2 additions & 1 deletion ansto_simplon_api/schemas/ansto_endpoints.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from pathlib import Path
from typing import Literal

from pydantic import BaseModel, Field


class LoadHDF5File(BaseModel):
hdf5_file_path: str = Field(examples=["/path/to/master_file"])
hdf5_file_path: str | Path = Field(examples=["/path/to/master_file"])
number_of_datafiles: int | None = Field(default=None, examples=[1])
compression: Literal["bslz4", "none"] = Field(default="bslz4", examples=["bslz4"])
9 changes: 8 additions & 1 deletion ansto_simplon_api/schemas/configuration.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime, timezone
from typing import Any
from typing import Any, Literal

from pydantic import BaseModel

Expand Down Expand Up @@ -85,3 +85,10 @@ class DetectorConfiguration(BaseModel):
detector_trigger_mode: str = "exts"
software_version: str = "E-32-0130"
eiger_fw_version: str = "release-2022.1.2rc2"
roi_mode: Literal["disabled", "4M"] = "disabled"
pixel_mask_applied: bool = True


class StreamConfiguration(BaseModel):
format: Literal["cbor", "legacy"] = "cbor"
mode: Literal["enabled", "disabled"] = "enabled"
3 changes: 0 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ services:
dockerfile: Dockerfile
container_name: mx-simplon-api
environment:
- "AS_API_DOCS_URL=/swagger"
- "AS_API_REDOC_URL=/docs"
- "AS_API_OPENAPI_URL=/openapi.json"
- "AS_ZMQ_ADDRESS=tcp://*:5555"
#To access the masterfile, you can either copy it to the container by modifying
# the dockerfile, or you can mount a volume containing the masterfile.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ansto-simplon-api"
version = "0.3.2"
version = "0.3.3"
description = "Simulated simplon api"
authors = [
"Francisco Hernandez Vivanco <hernandf@ansto.gov.au>",
Expand Down

0 comments on commit 4e986e4

Please sign in to comment.