Format/comment improvements
This commit is contained in:
parent
3b2fd29fb0
commit
d0eb9fa2c1
6 changed files with 9 additions and 20 deletions
|
|
@ -1,5 +1,4 @@
|
||||||
import os
|
import os
|
||||||
import requests
|
|
||||||
from argparse import ArgumentParser, Namespace
|
from argparse import ArgumentParser, Namespace
|
||||||
from zenodo import Zenodo
|
from zenodo import Zenodo
|
||||||
import yaml
|
import yaml
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,6 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
import logging
|
import logging
|
||||||
import importlib.resources
|
|
||||||
import os.path
|
|
||||||
from fastapi import Response
|
from fastapi import Response
|
||||||
from fastapi.staticfiles import StaticFiles
|
|
||||||
from fastapi.responses import FileResponse, RedirectResponse
|
|
||||||
from labthings_fastapi.thing_server import ThingServer
|
from labthings_fastapi.thing_server import ThingServer
|
||||||
from labthings_sangaboard import SangaboardThing
|
from labthings_sangaboard import SangaboardThing
|
||||||
from labthings_picamera2.thing import StreamingPiCamera2
|
from labthings_picamera2.thing import StreamingPiCamera2
|
||||||
|
|
@ -42,6 +38,7 @@ app = thing_server.app
|
||||||
# This is necessary until Connect is rebuilt.
|
# This is necessary until Connect is rebuilt.
|
||||||
@app.get("/routes")
|
@app.get("/routes")
|
||||||
def routes_stub() -> dict[str, dict]:
|
def routes_stub() -> dict[str, dict]:
|
||||||
|
"""A stub list of routes, used by OF Connect to identify the microscope"""
|
||||||
fake_routes = [
|
fake_routes = [
|
||||||
"/api/v2/",
|
"/api/v2/",
|
||||||
"/api/v2/streams/snapshot",
|
"/api/v2/streams/snapshot",
|
||||||
|
|
@ -54,5 +51,6 @@ class JPEGResponse(Response):
|
||||||
@app.get("/api/v2/streams/snapshot")
|
@app.get("/api/v2/streams/snapshot")
|
||||||
@app.head("/api/v2/streams/snapshot")
|
@app.head("/api/v2/streams/snapshot")
|
||||||
async def thumbnail() -> JPEGResponse:
|
async def thumbnail() -> JPEGResponse:
|
||||||
|
"""A low-resolution snapshot, for compatibility with OF connect"""
|
||||||
blob = await thing_server.things["/camera/"].lores_mjpeg_stream.grab_frame()
|
blob = await thing_server.things["/camera/"].lores_mjpeg_stream.grab_frame()
|
||||||
return JPEGResponse(blob)
|
return JPEGResponse(blob)
|
||||||
|
|
@ -10,24 +10,18 @@ and return the calibration data.
|
||||||
This module is only intended to be called from the OpenFlexure Microscope
|
This module is only intended to be called from the OpenFlexure Microscope
|
||||||
server, and depends on that server and its underlying LabThings library.
|
server, and depends on that server and its underlying LabThings library.
|
||||||
"""
|
"""
|
||||||
import io
|
|
||||||
import json
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
import time
|
import time
|
||||||
from typing import Annotated, Any, Callable, Dict, List, NamedTuple, Optional, Tuple
|
from typing import Annotated, Any, Callable, Dict, List, Mapping, NamedTuple, Optional, Sequence, Tuple
|
||||||
from fastapi import Depends, HTTPException
|
from fastapi import Depends, HTTPException
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
import PIL
|
|
||||||
from camera_stage_mapping.camera_stage_calibration_1d import (
|
from camera_stage_mapping.camera_stage_calibration_1d import (
|
||||||
calibrate_backlash_1d,
|
calibrate_backlash_1d,
|
||||||
image_to_stage_displacement_from_1d,
|
image_to_stage_displacement_from_1d,
|
||||||
)
|
)
|
||||||
from camera_stage_mapping.camera_stage_tracker import Tracker
|
from camera_stage_mapping.camera_stage_tracker import Tracker
|
||||||
from camera_stage_mapping.closed_loop_move import closed_loop_move, closed_loop_scan
|
|
||||||
from camera_stage_mapping.scan_coords_times import ordered_spiral
|
|
||||||
|
|
||||||
from labthings_picamera2.thing import StreamingPiCamera2
|
from labthings_picamera2.thing import StreamingPiCamera2
|
||||||
from labthings_sangaboard import SangaboardThing
|
from labthings_sangaboard import SangaboardThing
|
||||||
|
|
@ -53,8 +47,10 @@ class HardwareInterfaceModel(BaseModel):
|
||||||
def make_hardware_interface(stage: Stage, camera: Camera) -> HardwareInterfaceModel:
|
def make_hardware_interface(stage: Stage, camera: Camera) -> HardwareInterfaceModel:
|
||||||
"""Construct the functions we need to interface with the hardware"""
|
"""Construct the functions we need to interface with the hardware"""
|
||||||
axes = stage.axis_names
|
axes = stage.axis_names
|
||||||
pos2dict = lambda pos: {k: p for k, p in zip(axes, pos)}
|
def pos2dict(pos: Sequence[float]) -> Mapping[str, float]:
|
||||||
dict2pos = lambda posd: tuple(posd[k] for k in axes if k in posd)
|
return {k: p for k, p in zip(axes, pos)}
|
||||||
|
def dict2pos(posd: Mapping[str, float]) -> Sequence[float]:
|
||||||
|
return tuple(posd[k] for k in axes if k in posd)
|
||||||
def move(pos: CoordinateType) -> None:
|
def move(pos: CoordinateType) -> None:
|
||||||
current_pos = stage.position
|
current_pos = stage.position
|
||||||
new_pos = pos2dict(pos)
|
new_pos = pos2dict(pos)
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,11 @@ for code that currently lives in clients but needs to persist settings on
|
||||||
the server.
|
the server.
|
||||||
"""
|
"""
|
||||||
from collections.abc import Mapping
|
from collections.abc import Mapping
|
||||||
from typing import Any, Mapping, MutableMapping, Optional, Sequence
|
from typing import Any, MutableMapping, Optional, Sequence
|
||||||
from fastapi import HTTPException
|
from fastapi import HTTPException
|
||||||
from labthings_fastapi.dependencies.metadata import GetThingStates
|
from labthings_fastapi.dependencies.metadata import GetThingStates
|
||||||
from labthings_fastapi.thing import Thing
|
from labthings_fastapi.thing import Thing
|
||||||
from labthings_fastapi.decorators import thing_action, thing_property
|
from labthings_fastapi.decorators import thing_action, thing_property
|
||||||
from pydantic import BaseModel
|
|
||||||
|
|
||||||
|
|
||||||
def recursive_update(old_dict: MutableMapping, update: Mapping):
|
def recursive_update(old_dict: MutableMapping, update: Mapping):
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import os
|
import os
|
||||||
from typing import Type
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from freezegun import freeze_time
|
from freezegun import freeze_time
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
import json
|
import json
|
||||||
import re
|
|
||||||
import uuid
|
import uuid
|
||||||
from fractions import Fraction
|
from fractions import Fraction
|
||||||
from uuid import uuid3
|
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pytest
|
import pytest
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue