Skip to content

Commit

Permalink
Support filename templates (#5)
Browse files Browse the repository at this point in the history
E.g. centroid_####.cbf

* GET -> POST in README
  • Loading branch information
rjgildea authored May 17, 2023
1 parent 2f0157f commit de27d83
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,22 @@ Start the app:
$ uvicorn dials_rest.main:app --reload
```

<!-- curl -X 'POST' 'http://127.0.0.1:8001/export_bitmap/' -H 'accept: application/json' -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2ODU1Nzc2MDB9.i6ipplAzjhfBDAZFRsw3UTXYWbQnzZ02YDUSnpvz4j0' -H 'Content-Type: application/json' -d '{ -->
In another terminal:
```
curl -X 'GET' 'http://127.0.0.1:8000/export_bitmap/' -H 'accept: application/json' -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NzI0NDQ4MDB9.8J_5yadgK3UrErs1AOXKxjlvkzc-GCNA6Eg-v9obpvU' -H 'Content-Type: application/json' -d '{
curl -X 'POST' 'http://127.0.0.1:8000/export_bitmap/' -H 'accept: application/json' -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NzI0NDQ4MDB9.8J_5yadgK3UrErs1AOXKxjlvkzc-GCNA6Eg-v9obpvU' -H 'Content-Type: application/json' -d '{
"filename": "/dls/i24/data/2022/cm31109-5/myoglobin_dithionite/myglobin_3_00001.cbf",
"image_index": 1,
"format": "png",
"binning": 4,
"display": "image",
"colour_scheme": "greyscale",
"brightness": 10
}' > image.png
"brightness": 10,
"resolution_rings": {
"show": true,
"number": 10
}
}' -o image.png
```

To build with docker/podman:
Expand Down
5 changes: 4 additions & 1 deletion src/dials_rest/routers/find_spots.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ class PerImageAnalysisResults(pydantic.BaseModel):

@router.post("/")
async def find_spots(params: PerImageAnalysisParameters) -> PerImageAnalysisResults:
experiments = ExperimentListFactory.from_filenames([params.filename])
if "#" in params.filename.stem:
experiments = ExperimentListFactory.from_templates([params.filename])
else:
experiments = ExperimentListFactory.from_filenames([params.filename])
if params.scan_range and len(experiments) > 1:
# This means we've imported a sequence of still image: select
# only the experiment, i.e. image, we're interested in
Expand Down
5 changes: 4 additions & 1 deletion src/dials_rest/routers/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ class ExportBitmapParams(pydantic.BaseModel):

@router.post("/")
async def image_as_bitmap(params: ExportBitmapParams):
expts = ExperimentListFactory.from_filenames([params.filename])
if "#" in params.filename.stem:
expts = ExperimentListFactory.from_templates([params.filename])
else:
expts = ExperimentListFactory.from_filenames([params.filename])
imageset = expts.imagesets()[0]

if params.filename.suffix in {".h5", ".nxs"}:
Expand Down
8 changes: 6 additions & 2 deletions tests/routers/test_find_spots.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import os
from unittest import mock

import pytest

def test_find_spots_cbf(client, authentication_headers, dials_data):

@pytest.mark.parametrize("filename", ["centroid_0001.cbf", "centroid_####.cbf"])
def test_find_spots_cbf(filename, client, authentication_headers, dials_data):
data = {
"filename": os.fspath(
dials_data("centroid_test_data", pathlib=True) / "centroid_0001.cbf"
dials_data("centroid_test_data", pathlib=True) / filename
),
"scan_range": (1, 1),
"d_min": 3.5,
}
response = client.post("find_spots", json=data, headers=authentication_headers)
Expand Down
6 changes: 4 additions & 2 deletions tests/routers/test_image.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from io import BytesIO

import pytest
from PIL import Image


Expand All @@ -9,10 +10,11 @@ def test_export_bitmap_without_jwt_responds_403(client):
assert response.status_code == 403


def test_export_bitmap_cbf(client, authentication_headers, dials_data):
@pytest.mark.parametrize("filename", ["centroid_0001.cbf", "centroid_####.cbf"])
def test_export_bitmap_cbf(filename, client, authentication_headers, dials_data):
data = {
"filename": os.fspath(
dials_data("centroid_test_data", pathlib=True) / "centroid_0001.cbf"
dials_data("centroid_test_data", pathlib=True) / filename
),
"image_index": 1,
"format": "png",
Expand Down

0 comments on commit de27d83

Please sign in to comment.