DAQ+GUI: Work in progress
This commit is contained in:
@@ -67,47 +67,19 @@ class AareWrapper:
|
||||
)
|
||||
print(ret)
|
||||
|
||||
def create_manual_sample(
|
||||
self,
|
||||
s: SampleShortInfo,
|
||||
p: SessionStatus,
|
||||
cellparameters: Optional[str] = None,
|
||||
spacegroupnumber: Optional[int] = None,
|
||||
) -> Optional[object]:
|
||||
"""
|
||||
Insert a new manual sample into the database using a SampleShortInfo object.
|
||||
|
||||
Args:
|
||||
s (SampleShortInfo): The sample info object to extract data from.
|
||||
p (SessionStatus): The session status object to extract data from.
|
||||
cellparameters (Optional[str]): Unit cell parameters as a string.
|
||||
spacegroupnumber (Optional[int]): Space group number.
|
||||
|
||||
Returns:
|
||||
API response object or None if there was an error.
|
||||
"""
|
||||
from aareDBclient.models import ManualSampleCreate, DataCollectionParameters
|
||||
|
||||
data_collection_parameters = None
|
||||
if cellparameters is not None and spacegroupnumber is not None:
|
||||
data_collection_parameters = DataCollectionParameters(
|
||||
cellparameters=cellparameters,
|
||||
spacegroupnumber=spacegroupnumber
|
||||
)
|
||||
def create_manual_sample(self, s: SampleShortInfo):
|
||||
from aareDBclient.models import ManualSampleCreate
|
||||
|
||||
manual_sample = ManualSampleCreate(
|
||||
pgroup=p.current_pgroup,
|
||||
pgroup=s.user,
|
||||
sample_name=s.sample_name,
|
||||
data_collection_parameters=data_collection_parameters
|
||||
data_collection_parameters=s.data_collection_parameters
|
||||
)
|
||||
|
||||
try:
|
||||
result = self.__sample_api.insert_sample(manual_sample)
|
||||
print(f"Sample created: {result}")
|
||||
return result
|
||||
s.db_id = self.__sample_api.insert_sample(manual_sample).id
|
||||
except Exception as e:
|
||||
print(f"Error inserting sample: {e}")
|
||||
return None
|
||||
|
||||
def sample_mounted(self, s: Optional[SampleShortInfo]):
|
||||
if s is not None:
|
||||
|
||||
+22
-7
@@ -23,7 +23,7 @@ from aaredaqlib.models import (
|
||||
SampleShortInfoList,
|
||||
DAQStatusModel, BeamlineStatus, SessionStatus, SampleCameraSettings, AutofocusSettings, )
|
||||
from aaredaqlib.raster_grid import RasterGridRequest, CompletedRasterGrid
|
||||
from aaredaqlib.rotation_scan import RotationScanRequest
|
||||
from aaredaqlib.rotation_scan import RotationScanRequest, CompletedRotationScan
|
||||
from aaredaqlib.sample_geometry import SampleGeometryModel
|
||||
from mxlibs3.jfjoch import JFJochWrapper
|
||||
|
||||
@@ -176,6 +176,16 @@ class AareDAQ:
|
||||
self.__cfg.state_busy = False
|
||||
raise
|
||||
|
||||
def create_sample(self, target: SampleShortInfo):
|
||||
self.__aare.create_manual_sample(target)
|
||||
self.__cfg.current_sample = target
|
||||
|
||||
def clear_current_sample(self):
|
||||
curr_sample = self.__cfg.current_sample
|
||||
if curr_sample is not None:
|
||||
self.__aare.sample_unmounted(curr_sample)
|
||||
self.__cfg.current_sample = None
|
||||
|
||||
def __mount(self, target: SampleShortInfo | None):
|
||||
self.__set_state(BeamlineStateEnum.RobotSampleExchange)
|
||||
self.__devs.smargon.move_home(wait=True)
|
||||
@@ -192,8 +202,11 @@ class AareDAQ:
|
||||
curr_sample = self.__cfg.current_sample
|
||||
|
||||
self.__devs.tell.wait_ready()
|
||||
|
||||
if target is None:
|
||||
if curr_sample is not None and curr_sample.location is None:
|
||||
# TODO: Smarter way to know manual sample has be removed from goniometer
|
||||
self.__aare.sample_unmounted(curr_sample)
|
||||
self.__cfg.current_sample = None
|
||||
elif target is None:
|
||||
self.__devs.tell.unmount(wait=True, timeout=360)
|
||||
self.__aare.sample_unmounted(curr_sample)
|
||||
self.__cfg.current_sample = None
|
||||
@@ -300,7 +313,7 @@ class AareDAQ:
|
||||
self.__cfg.state_busy = False
|
||||
raise e
|
||||
|
||||
def __rotation(self, request: RotationScanRequest):
|
||||
def __rotation(self, request: RotationScanRequest) -> CompletedRotationScan:
|
||||
self.__cfg.dtz = request.dtz
|
||||
self.__set_state(BeamlineStateEnum.DataCollection)
|
||||
|
||||
@@ -343,18 +356,20 @@ class AareDAQ:
|
||||
time.sleep(smargon_time_step)
|
||||
|
||||
self.__devs.aerotech.wait_scan_done(total_time + 60)
|
||||
self.__jfjoch.wait_till_done(60)
|
||||
self.__aare.sample_collected(self.sample)
|
||||
self.__devs.aerotech.reset()
|
||||
result = self.__jfjoch.wait_till_done(60)
|
||||
return CompletedRotationScan(request=copy.deepcopy(request), result=result)
|
||||
|
||||
def measure_rotation(self, request: RotationScanRequest):
|
||||
def measure_rotation(self, request: RotationScanRequest) -> CompletedRotationScan:
|
||||
total_time = request.exp_time_s * request.steps
|
||||
self.__cfg.try_set_busy(timeout=ceil(total_time + 360))
|
||||
|
||||
try:
|
||||
self.__rotation(request)
|
||||
result = self.__rotation(request)
|
||||
self.__set_state(BeamlineStateEnum.SampleAlignment)
|
||||
self.__cfg.state_busy = False
|
||||
return result
|
||||
except Exception as e:
|
||||
self.__set_state(BeamlineStateEnum.SampleAlignment)
|
||||
self.__cfg.state_busy = False
|
||||
|
||||
+22
-10
@@ -9,7 +9,7 @@ from aaredaqlib.coordinate import SmargonCoordinate, Coordinate
|
||||
from aaredaqlib.models import SampleShortInfo, DAQStatusModel, BeamlineStateEnum, BeamlineSettingsModel, \
|
||||
SampleShortInfoList, SessionStatus, SampleCameraSettings, AutofocusSettings, TokenData
|
||||
from aaredaqlib.raster_grid import RasterGridRequest, CompletedRasterGrid
|
||||
from aaredaqlib.rotation_scan import RotationScanRequest
|
||||
from aaredaqlib.rotation_scan import RotationScanRequest, CompletedRotationScan
|
||||
from aaredaqlib.sample_geometry import SampleGeometryModel
|
||||
from fastapi import FastAPI, Depends
|
||||
from fastapi import HTTPException
|
||||
@@ -162,7 +162,7 @@ async def get_image(token: str = Depends(oauth2_scheme)):
|
||||
|
||||
|
||||
# TELL procedures
|
||||
@app.get("/tell/sample")
|
||||
@app.get("/sample/curr_sample")
|
||||
async def sample(token: str = Depends(oauth2_scheme)) -> SampleShortInfo:
|
||||
token_data = auth.parse_token(token)
|
||||
auth.check_jwt_ro(cfg, auth.parse_token(token))
|
||||
@@ -175,12 +175,12 @@ async def sample(token: str = Depends(oauth2_scheme)) -> SampleShortInfo:
|
||||
puck_name="",
|
||||
dewar_name="",
|
||||
db_id=-1,
|
||||
pin=sample.pin,
|
||||
location=sample.location
|
||||
pin=s.pin,
|
||||
location=s.location
|
||||
)
|
||||
|
||||
|
||||
@app.post("/tell/mount")
|
||||
@app.post("/sample/mount")
|
||||
async def mount(dbid: int, token: str = Depends(oauth2_scheme)):
|
||||
token_data = auth.parse_token(token)
|
||||
auth.check_jwt_rw(cfg, auth.parse_token(token))
|
||||
@@ -204,12 +204,25 @@ async def mount(dbid: int, token: str = Depends(oauth2_scheme)):
|
||||
)
|
||||
|
||||
|
||||
@app.post("/tell/unmount")
|
||||
@app.post("/sample/unmount")
|
||||
async def unmount(token: str = Depends(oauth2_scheme)):
|
||||
auth.check_jwt_rw(cfg, auth.parse_token(token))
|
||||
daq.sample = None
|
||||
return "OK"
|
||||
|
||||
@app.post("/sample/clear")
|
||||
async def sample_clear(token: str = Depends(oauth2_scheme)):
|
||||
auth.check_jwt_rw(cfg, auth.parse_token(token))
|
||||
daq.clear_current_sample()
|
||||
return "OK"
|
||||
|
||||
@app.post("/sample/manual")
|
||||
async def manual(s: SampleShortInfo, token: str = Depends(oauth2_scheme)):
|
||||
auth.check_jwt_rw(cfg, auth.parse_token(token))
|
||||
print(f"DB ID prior creating {s.db_id}")
|
||||
daq.create_sample(s)
|
||||
print(f"DB ID after creating {s.db_id}")
|
||||
|
||||
|
||||
def get_spreadsheet(data: TokenData) -> SampleShortInfoList:
|
||||
if data.staff:
|
||||
@@ -242,7 +255,7 @@ async def spreadsheet_sse(token: str = Depends(oauth2_scheme)):
|
||||
)
|
||||
|
||||
|
||||
@app.get("/tell/spreadsheet")
|
||||
@app.get("/sample/spreadsheet")
|
||||
async def spreadsheet(token: str = Depends(oauth2_scheme)) -> SampleShortInfoList:
|
||||
return get_spreadsheet(auth.parse_token(token))
|
||||
|
||||
@@ -280,10 +293,9 @@ async def raster(val: RasterGridRequest, token: str = Depends(oauth2_scheme)) ->
|
||||
|
||||
|
||||
@app.post("/scan/rotation")
|
||||
async def rotation(val: RotationScanRequest, token: str = Depends(oauth2_scheme)):
|
||||
async def rotation(val: RotationScanRequest, token: str = Depends(oauth2_scheme)) -> CompletedRotationScan:
|
||||
auth.check_jwt_rw(cfg, auth.parse_token(token))
|
||||
daq.measure_rotation(val)
|
||||
return "OK"
|
||||
return daq.measure_rotation(val)
|
||||
|
||||
@app.post("/scan/auto")
|
||||
async def auto(s: SampleShortInfo, token: str = Depends(oauth2_scheme)):
|
||||
|
||||
Reference in New Issue
Block a user