DaqLib: Merge helical/screening/standard scans
This commit is contained in:
@@ -5,7 +5,6 @@ from pydantic import Field, AfterValidator, BaseModel
|
||||
|
||||
from aaredaqlib.coordinate import Coordinate, positive_coords, SmargonCoordinate
|
||||
from aaredaqlib.sample_geometry import SampleGeometryModel
|
||||
from aaredaqlib.scan_request import ScanRequest
|
||||
|
||||
|
||||
def normalize_angle(angle_deg: float) -> float:
|
||||
@@ -14,6 +13,11 @@ def normalize_angle(angle_deg: float) -> float:
|
||||
|
||||
|
||||
class RasterGridRequest(BaseModel):
|
||||
dtz: float | None = None
|
||||
transmission: float | None = None
|
||||
file_prefix: str | None = None
|
||||
exp_time_s: float
|
||||
|
||||
# Number of grid elements
|
||||
n_x: Annotated[int, Field(ge=1)]
|
||||
n_y: Annotated[int, Field(ge=1)]
|
||||
|
||||
@@ -4,12 +4,17 @@ from aaredaqlib.coordinate import SmargonCoordinate
|
||||
|
||||
|
||||
class RotationScanRequest(BaseModel):
|
||||
dtz: float | None = None
|
||||
transmission: float | None = None
|
||||
file_prefix: str | None = None
|
||||
exp_time_s: float
|
||||
|
||||
start: SmargonCoordinate | None = None # None = start where you are
|
||||
end: SmargonCoordinate | None = None
|
||||
|
||||
start_omega_deg: float = 0
|
||||
omega_incr_deg: float
|
||||
incr_omega_deg: float
|
||||
steps: int
|
||||
|
||||
def get_image_number(self) -> int:
|
||||
return self.steps
|
||||
screening: bool = False
|
||||
wedge_omega_deg: float | None = None
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
from abc import abstractmethod, ABC
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from aaredaqlib.raster_grid import RasterGridRequest
|
||||
from aaredaqlib.rotation_scan import RotationScanRequest
|
||||
from aaredaqlib.screening_scan import ScreeningScanRequest
|
||||
|
||||
|
||||
class ScanRequest(BaseModel):
|
||||
dtz: float
|
||||
transmission: float
|
||||
file_prefix: str
|
||||
exp_time_s: float
|
||||
image_number: int
|
||||
|
||||
measurement: RasterGridRequest | ScreeningScanRequest | RotationScanRequest
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class ScreeningScanRequest(BaseModel):
|
||||
omega_start_deg: float
|
||||
omega_step_deg: float
|
||||
steps: int
|
||||
oscrange_deg: float
|
||||
|
||||
def get_image_number(self) -> int:
|
||||
return self.steps
|
||||
+14
-28
@@ -14,7 +14,6 @@ from aaredaqlib.models import (
|
||||
from aaredaqlib.raster_grid import RasterGridRequest
|
||||
from aaredaqlib.rotation_scan import RotationScanRequest
|
||||
from aaredaqlib.sample_geometry import SampleGeometryModel
|
||||
from aaredaqlib.screening_scan import ScreeningScanRequest
|
||||
|
||||
from aaredaq import workflows
|
||||
from aaredaqlib.beamline import MXBeamline
|
||||
@@ -233,12 +232,25 @@ class AareDAQ:
|
||||
|
||||
def __rotation(self, request: RotationScanRequest):
|
||||
self.__set_state(BeamlineStateEnum.DataCollection)
|
||||
|
||||
if request.start is not None:
|
||||
self.__devs.smargon.target = request.start
|
||||
self.__devs.smargon.wait()
|
||||
|
||||
if request.screening:
|
||||
self.__devs.aerotech.measure_screening(request.start_omega_deg,
|
||||
request.wedge_omega_deg,
|
||||
request.exp_time_s,
|
||||
request.incr_omega_deg,
|
||||
request.steps)
|
||||
self.__devs.aerotech.wait_scan_done(request.exp_time_s * request.steps + 60)
|
||||
return
|
||||
|
||||
total_omega = request.incr_omega_deg * request.steps
|
||||
total_time = request.exp_time_s * request.steps
|
||||
|
||||
self.__devs.aerotech.measure_standard(
|
||||
request.start_omega_deg, request.total_omega_deg, request.total_time_sec
|
||||
request.start_omega_deg, total_omega, total_time
|
||||
)
|
||||
|
||||
if request.start is not None and request.end is not None:
|
||||
@@ -265,32 +277,6 @@ class AareDAQ:
|
||||
self.__cfg.state_busy = False
|
||||
raise e
|
||||
|
||||
def __screening(self, request: ScreeningScanRequest):
|
||||
print(request)
|
||||
self.__devs.aerotech.measure_screening(request.omega_start_deg,
|
||||
request.oscrange_deg,
|
||||
request.exp_time_s,
|
||||
request.omega_step_deg,
|
||||
request.steps)
|
||||
self.__devs.aerotech.wait_scan_done(request.exp_time_s * request.steps + 60)
|
||||
self.__devs.aerotech.reset()
|
||||
|
||||
def measure_screening(self, request: ScreeningScanRequest) -> float:
|
||||
start = time.perf_counter()
|
||||
|
||||
self.__cfg.try_set_busy(timeout=ceil(360))
|
||||
self.__set_state(BeamlineStateEnum.DataCollection)
|
||||
|
||||
try:
|
||||
self.__screening(request)
|
||||
self.__set_state(BeamlineStateEnum.SampleAlignment)
|
||||
self.__cfg.state_busy = False
|
||||
except Exception as e:
|
||||
self.__cfg.state_busy = False
|
||||
raise e
|
||||
end = time.perf_counter()
|
||||
return end - start
|
||||
|
||||
def get_background(self):
|
||||
#if self.sample is not None:
|
||||
# raise Exception("Background cannot be measured when sample is mounted")
|
||||
|
||||
@@ -10,7 +10,6 @@ from aaredaqlib.models import SampleShortInfo, DAQStatusModel, BeamlineStateEnum
|
||||
from aaredaqlib.raster_grid import RasterGridRequest
|
||||
from aaredaqlib.rotation_scan import RotationScanRequest
|
||||
from aaredaqlib.sample_geometry import SampleGeometryModel
|
||||
from aaredaqlib.screening_scan import ScreeningScanRequest
|
||||
from fastapi import FastAPI, Depends
|
||||
from fastapi import HTTPException
|
||||
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
|
||||
@@ -228,14 +227,6 @@ async def rotation(val: RotationScanRequest, token: str = Depends(oauth2_scheme)
|
||||
daq.measure_rotation(val)
|
||||
return "OK"
|
||||
|
||||
|
||||
@app.post("/scan/screening")
|
||||
async def screening(val: ScreeningScanRequest, token: str = Depends(oauth2_scheme)):
|
||||
auth.check_jwt_rw(cfg, auth.parse_token(token))
|
||||
daq.measure_screening(val)
|
||||
return "OK"
|
||||
|
||||
|
||||
@app.post("/scan/auto")
|
||||
async def auto(s: SampleShortInfo, token: str = Depends(oauth2_scheme)):
|
||||
auth.check_jwt_rw(cfg, auth.parse_token(token))
|
||||
|
||||
@@ -149,7 +149,6 @@ class MainWindow(QMainWindow):
|
||||
|
||||
self.camera_image.run_raster.connect(self.daq.raster_scan)
|
||||
self.data_collection.standard_data_collection.connect(self.daq.standard_scan)
|
||||
self.data_collection.screening_data_collection.connect(self.daq.screening_scan)
|
||||
|
||||
self.data_collection.helical.show_helical_start.connect(self.camera_image.show_helical_start)
|
||||
self.data_collection.helical.show_helical_end.connect(self.camera_image.show_helical_end)
|
||||
|
||||
@@ -9,7 +9,6 @@ from PySide6.QtWidgets import (
|
||||
)
|
||||
from aaredaqlib.rotation_scan import RotationScanRequest
|
||||
from aaredaqlib.sample_geometry import SampleGeometryModel
|
||||
from aaredaqlib.screening_scan import ScreeningScanRequest
|
||||
|
||||
from aaregui.panels.file_path_panel import FilePathPanel
|
||||
from aaregui.panels.helical_scan_panel import HelicalDataCollectionPanel
|
||||
@@ -21,8 +20,6 @@ from aaregui.widgets.title_label import TitleLabel
|
||||
|
||||
class DataCollectionSettings(QFrame):
|
||||
standard_data_collection = Signal(RotationScanRequest)
|
||||
helical_data_collection = Signal(HelicalScanRequest)
|
||||
screening_data_collection = Signal(ScreeningScanRequest)
|
||||
|
||||
def __init__(self, s: SampleGeometryModel, parent=None):
|
||||
super().__init__(parent)
|
||||
@@ -82,14 +79,15 @@ class DataCollectionSettings(QFrame):
|
||||
print("No screening type selected.")
|
||||
return
|
||||
|
||||
s = ScreeningScanRequest(
|
||||
omega_start_deg=self.screening.start_angle.value,
|
||||
r = RotationScanRequest(
|
||||
start_omega_deg=self.screening.start_angle.value,
|
||||
exp_time_s=self.screening.image_time_enter.value,
|
||||
omega_step_deg=data["omega_step_deg"],
|
||||
incr_omega_deg=data["omega_step_deg"],
|
||||
wedge_omega_deg=0.1,
|
||||
steps=data["steps"],
|
||||
oscrange_deg=0.1
|
||||
screening=True
|
||||
)
|
||||
self.screening_data_collection.emit(s)
|
||||
self.standard_data_collection.emit(r)
|
||||
elif current_tab == self.standard:
|
||||
total_angle = self.standard.total_angle.value
|
||||
image_angle = self.standard.image_angle.value
|
||||
@@ -98,17 +96,17 @@ class DataCollectionSettings(QFrame):
|
||||
return
|
||||
|
||||
image_number = round(total_angle / image_angle)
|
||||
total_time = image_number * self.standard.image_time_enter.value
|
||||
|
||||
r = RotationScanRequest(
|
||||
start_omega_deg=self.standard.start_angle.value,
|
||||
total_omega_deg=total_angle,
|
||||
total_time_sec=total_time
|
||||
incr_omega_deg=self.standard.image_angle.value,
|
||||
steps=image_number,
|
||||
exp_time_s=self.standard.image_time_enter.value,
|
||||
)
|
||||
self.standard_data_collection.emit(r)
|
||||
elif current_tab == self.helical:
|
||||
r = self.helical.get_request()
|
||||
if r is not None:
|
||||
self.helical_data_collection.emit(r)
|
||||
self.standard_data_collection.emit(r)
|
||||
else:
|
||||
print("No matching tab found.")
|
||||
|
||||
@@ -8,7 +8,7 @@ from PySide6.QtWidgets import (
|
||||
QPushButton,
|
||||
)
|
||||
from aaredaqlib.coordinate import SmargonCoordinate
|
||||
from aaredaqlib.helical_geometry import HelicalScanRequest
|
||||
from aaredaqlib.rotation_scan import RotationScanRequest
|
||||
from aaredaqlib.models import DAQStatusModel
|
||||
from aaredaqlib.sample_geometry import SampleGeometryModel
|
||||
|
||||
@@ -16,7 +16,7 @@ from aaregui.widgets.number_line_edit import NumberLineEdit
|
||||
|
||||
|
||||
class HelicalDataCollectionPanel(QWidget):
|
||||
helical_scan = Signal(HelicalScanRequest)
|
||||
helical_scan = Signal(RotationScanRequest)
|
||||
show_helical_start = Signal(SmargonCoordinate)
|
||||
show_helical_end = Signal(SmargonCoordinate)
|
||||
|
||||
@@ -116,18 +116,18 @@ class HelicalDataCollectionPanel(QWidget):
|
||||
self.show_helical_end.emit(self.__end)
|
||||
|
||||
|
||||
def get_request(self) -> HelicalScanRequest | None:
|
||||
def get_request(self) -> RotationScanRequest | None:
|
||||
if self.__start.sh_mm is None or self.__end.sh_mm is None:
|
||||
return
|
||||
|
||||
omega_step = self.total_angle.value / self.__steps
|
||||
h = HelicalScanRequest(
|
||||
image_number = round(self.total_angle.value / self.image_angle.value)
|
||||
|
||||
h = RotationScanRequest(
|
||||
start=self.__start,
|
||||
end=self.__end,
|
||||
omega_start=self.start_angle.value,
|
||||
total_omega=self.total_angle.value,
|
||||
time_sec=self.image_time_enter.value
|
||||
* (self.total_angle.value / self.image_angle.value),
|
||||
steps=self.__steps,
|
||||
start_omega_deg=self.start_angle.value,
|
||||
incr_omega_deg=self.image_angle.value,
|
||||
exp_time_s=self.image_time_enter.value,
|
||||
steps=image_number,
|
||||
)
|
||||
return h
|
||||
|
||||
@@ -3,10 +3,8 @@ from PySide6.QtNetwork import QNetworkAccessManager, QNetworkRequest, QNetworkRe
|
||||
|
||||
from aaredaqlib.models import DAQStatusModel, SampleShortInfoList, SampleShortInfo
|
||||
from aaredaqlib.coordinate import SmargonCoordinate, Coordinate
|
||||
from aaredaqlib.helical_geometry import HelicalScanRequest
|
||||
from aaredaqlib.raster_grid import RasterGridRequest
|
||||
from aaredaqlib.rotation_scan import RotationScanRequest
|
||||
from aaredaqlib.screening_scan import ScreeningScanRequest
|
||||
|
||||
SPREADHSEET_FREQUENCY = 25 # Every 5 seconds
|
||||
|
||||
@@ -163,14 +161,6 @@ class DAQWorker(QObject):
|
||||
def standard_scan(self, r: RotationScanRequest):
|
||||
self.generic_post("scan/rotation", r.model_dump_json())
|
||||
|
||||
@Slot(ScreeningScanRequest)
|
||||
def screening_scan(self, r: ScreeningScanRequest):
|
||||
self.generic_post("scan/screening", r.model_dump_json())
|
||||
|
||||
@Slot(HelicalScanRequest)
|
||||
def helical_scan(self, h: HelicalScanRequest):
|
||||
self.generic_post("scan/helical", h.model_dump_json())
|
||||
|
||||
@Slot(RasterGridRequest)
|
||||
def raster_scan(self, r: RasterGridRequest):
|
||||
self.generic_post("scan/raster", r.model_dump_json())
|
||||
|
||||
Reference in New Issue
Block a user