Format/comment improvements

This commit is contained in:
Richard Bowman 2023-12-13 16:31:18 +00:00
parent 3b2fd29fb0
commit d0eb9fa2c1
6 changed files with 9 additions and 20 deletions

View file

@ -1,5 +1,4 @@
import os
import requests
from argparse import ArgumentParser, Namespace
from zenodo import Zenodo
import yaml

View file

@ -1,10 +1,6 @@
from __future__ import annotations
import logging
import importlib.resources
import os.path
from fastapi import Response
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse, RedirectResponse
from labthings_fastapi.thing_server import ThingServer
from labthings_sangaboard import SangaboardThing
from labthings_picamera2.thing import StreamingPiCamera2
@ -42,6 +38,7 @@ app = thing_server.app
# This is necessary until Connect is rebuilt.
@app.get("/routes")
def routes_stub() -> dict[str, dict]:
"""A stub list of routes, used by OF Connect to identify the microscope"""
fake_routes = [
"/api/v2/",
"/api/v2/streams/snapshot",
@ -54,5 +51,6 @@ class JPEGResponse(Response):
@app.get("/api/v2/streams/snapshot")
@app.head("/api/v2/streams/snapshot")
async def thumbnail() -> JPEGResponse:
"""A low-resolution snapshot, for compatibility with OF connect"""
blob = await thing_server.things["/camera/"].lores_mjpeg_stream.grab_frame()
return JPEGResponse(blob)
return JPEGResponse(blob)

View file

@ -10,24 +10,18 @@ and return the calibration data.
This module is only intended to be called from the OpenFlexure Microscope
server, and depends on that server and its underlying LabThings library.
"""
import io
import json
import logging
import os
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
import numpy as np
from pydantic import BaseModel
import PIL
from camera_stage_mapping.camera_stage_calibration_1d import (
calibrate_backlash_1d,
image_to_stage_displacement_from_1d,
)
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_sangaboard import SangaboardThing
@ -53,8 +47,10 @@ class HardwareInterfaceModel(BaseModel):
def make_hardware_interface(stage: Stage, camera: Camera) -> HardwareInterfaceModel:
"""Construct the functions we need to interface with the hardware"""
axes = stage.axis_names
pos2dict = lambda pos: {k: p for k, p in zip(axes, pos)}
dict2pos = lambda posd: tuple(posd[k] for k in axes if k in posd)
def pos2dict(pos: Sequence[float]) -> Mapping[str, float]:
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:
current_pos = stage.position
new_pos = pos2dict(pos)

View file

@ -6,12 +6,11 @@ for code that currently lives in clients but needs to persist settings on
the server.
"""
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 labthings_fastapi.dependencies.metadata import GetThingStates
from labthings_fastapi.thing import Thing
from labthings_fastapi.decorators import thing_action, thing_property
from pydantic import BaseModel
def recursive_update(old_dict: MutableMapping, update: Mapping):

View file

@ -1,5 +1,4 @@
import os
from typing import Type
import pytest
from freezegun import freeze_time

View file

@ -1,8 +1,6 @@
import json
import re
import uuid
from fractions import Fraction
from uuid import uuid3
import numpy as np
import pytest