-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load arbitrary number of datafiles from a master file (#6)
* add option to specify number of datafiles loaded * bump version * raise HTTPException when datafiles cannot be loaded * update get_master_file return schema
- Loading branch information
1 parent
c6a80f3
commit 789d6e2
Showing
6 changed files
with
234 additions
and
359 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 30 additions & 4 deletions
34
ansto_simplon_api/routes/ansto_endpoints/load_hdf5_files.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,40 @@ | ||
from fastapi import APIRouter | ||
from fastapi.exceptions import HTTPException | ||
from starlette import status | ||
|
||
from ...schemas.configuration import SimplonRequestStr | ||
from ...schemas.ansto_endpoints import LoadHDF5File | ||
from ...simulate_zmq_stream import zmq_stream | ||
|
||
router = APIRouter(prefix="/ansto_endpoints", tags=["ANSTO Endpoints"]) | ||
|
||
|
||
@router.put("/load_hdf5_master_file") | ||
async def set_user_data(hdf5_file_path: SimplonRequestStr): | ||
zmq_stream.hdf5_file_path = hdf5_file_path.value | ||
@router.put("/hdf5_master_file") | ||
async def set_master_file(hdf5_model: LoadHDF5File): | ||
try: | ||
zmq_stream.create_list_of_compressed_frames( | ||
hdf5_file_path=hdf5_model.hdf5_file_path, | ||
compression=hdf5_model.compression, | ||
number_of_datafiles=hdf5_model.number_of_datafiles, | ||
) | ||
except IndexError: | ||
raise HTTPException( | ||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, | ||
detail="The number of datafiles specified exceed the number of datafiles available " | ||
"in the master file. Reduce number_of_datafiles", | ||
) | ||
except Exception as e: | ||
raise HTTPException( | ||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e) | ||
) | ||
zmq_stream.frame_id = 0 | ||
zmq_stream.image_number = 0 | ||
return {"value": zmq_stream.hdf5_file_path} | ||
|
||
|
||
@router.get("/hdf5_master_file") | ||
async def get_master_file() -> LoadHDF5File: | ||
return LoadHDF5File( | ||
hdf5_file_path=zmq_stream.hdf5_file_path, | ||
number_of_datafiles=zmq_stream.number_of_data_files, | ||
compression=zmq_stream.compression, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from typing import Literal | ||
|
||
from pydantic import BaseModel, Field | ||
|
||
|
||
class LoadHDF5File(BaseModel): | ||
hdf5_file_path: str = 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"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.