-
Notifications
You must be signed in to change notification settings - Fork 0
fix from_json, extract routes to files #42
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,4 +52,3 @@ async def read_data( | |
:param shape: in scale voxels | ||
:returns: numpy array of shape shape | ||
""" | ||
pass |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
|
||
@dataclass(frozen=True) | ||
class Scale: | ||
chunk_sizes: Tuple[Vec3D] | ||
chunk_sizes: Tuple[Vec3D, ...] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we want tuples of unknown length instead of plain lists? Does that help with hashability/typechecking etc? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exactly, tuples can be cached, lists not. |
||
encoding: str | ||
key: str | ||
resolution: Vec3D | ||
|
@@ -38,7 +38,7 @@ class Layer: | |
source: str | ||
data_type: str | ||
num_channels: int | ||
scales: Tuple[Scale] | ||
scales: Tuple[Scale, ...] | ||
type: str | ||
# InitVar allows to consume mesh argument in init without storing it | ||
mesh: InitVar[Any] = None | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from sanic import Blueprint | ||
|
||
from .datasets import datasets | ||
from .triggers import triggers | ||
from .trace import trace | ||
|
||
data = Blueprint.group(datasets, triggers, url_prefix="/data") | ||
routes = Blueprint.group(data, trace) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from sanic import Blueprint | ||
|
||
from .read_data import read_data | ||
from .thumbnail import thumbnail | ||
|
||
datasets = Blueprint.group(read_data, thumbnail, url_prefix="/datasets") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import asyncio | ||
import json | ||
from typing import List | ||
|
||
import numpy as np | ||
from sanic import Blueprint, response | ||
from sanic.request import Request | ||
|
||
from ...utils.json import from_json | ||
from ...utils.types import Vec3D | ||
from ...webknossos.access import AccessRequest, authorized | ||
from ...webknossos.models import DataRequest as WKDataRequest | ||
|
||
read_data = Blueprint(__name__) | ||
|
||
|
||
@read_data.route( | ||
"/<organization_name>/<dataset_name>/layers/<layer_name>/data", | ||
methods=["POST", "OPTIONS"], | ||
) | ||
@authorized(AccessRequest.read_dataset) | ||
async def get_data_post( | ||
request: Request, organization_name: str, dataset_name: str, layer_name: str | ||
) -> response.HTTPResponse: | ||
(backend_name, dataset) = request.app.repository.get_dataset( | ||
organization_name, dataset_name | ||
) | ||
backend = request.app.backends[backend_name] | ||
|
||
bucket_requests = from_json(request.json, List[WKDataRequest]) | ||
assert all(not request.fourBit for request in bucket_requests) | ||
|
||
buckets = await asyncio.gather( | ||
*( | ||
backend.read_data( | ||
dataset, | ||
layer_name, | ||
r.zoomStep, | ||
Vec3D(*r.position), | ||
Vec3D(r.cubeSize, r.cubeSize, r.cubeSize), | ||
) | ||
for r in bucket_requests | ||
) | ||
) | ||
missing_buckets = [index for index, data in enumerate(buckets) if data is None] | ||
existing_buckets = [data.flatten(order="F") for data in buckets if data is not None] | ||
data = ( | ||
np.concatenate(existing_buckets).tobytes() if len(existing_buckets) > 0 else b"" | ||
) | ||
|
||
headers = { | ||
"Access-Control-Expose-Headers": "MISSING-BUCKETS", | ||
"MISSING-BUCKETS": json.dumps(missing_buckets), | ||
} | ||
return response.raw(data, headers=headers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a bug in mypy version
0.670
, which was just released:python/mypy#6364
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch!