Update sample handling and experiment linkage logic

Added `type` to experiment runs in `sample.py` and improved filtering in `processing.py` to match experiments by both `sample_id` and `run_id`. Removed extensive unnecessary code in `testfunctions.ipynb` for clarity and maintenance.
This commit is contained in:
GotthardG 2025-04-30 16:41:05 +02:00
parent b3847a0bf0
commit 9e875c5a04
4 changed files with 19 additions and 15 deletions

View File

@ -24,14 +24,17 @@ async def job_event_generator(db: Session):
sample = db.query(SampleModel).filter_by(id=job.sample_id).first()
experiment = (
db.query(ExperimentParametersModel)
.filter(ExperimentParametersModel.sample_id == sample.id)
.filter(
ExperimentParametersModel.sample_id == sample.id,
ExperimentParametersModel.id == job.run_id,
)
.first()
)
job_item = JobsResponse(
job_id=job.id,
sample_id=sample.id,
run_id=getattr(experiment, "run_number", None),
run_id=job.run_id,
sample_name=sample.sample_name,
status=job.status,
type=experiment.type,

View File

@ -297,6 +297,7 @@ async def get_sample_results(active_pgroup: str, db: Session = Depends(get_db)):
experiment_runs=[
ExperimentParametersRead(
id=ex.id,
type=ex.type,
run_number=ex.run_number,
beamline_parameters=ex.beamline_parameters,
sample_id=ex.sample_id,

View File

@ -19,8 +19,8 @@ services:
- postgres
healthcheck:
test: [ "CMD-SHELL", "curl -k -f https://localhost:${PORT}/openapi.json || exit 1" ]
interval: 5s
timeout: 5s
interval: 1m
timeout: 10s
retries: 5
environment: # ⬅️ Provide DB info to your backend
ENVIRONMENT: ${ENVIRONMENT}

View File

@ -662,8 +662,8 @@
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-04-30T09:31:19.697284Z",
"start_time": "2025-04-30T09:31:19.678837Z"
"end_time": "2025-04-30T14:32:12.061767Z",
"start_time": "2025-04-30T14:32:12.043500Z"
}
},
"cell_type": "code",
@ -780,7 +780,7 @@
"DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): localhost:8000\n",
"/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/connectionpool.py:1103: InsecureRequestWarning: Unverified HTTPS request is being made to host 'localhost'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings\n",
" warnings.warn(\n",
"DEBUG:urllib3.connectionpool:https://localhost:8000 \"POST /samples/samples/204/experiment_parameters HTTP/1.1\" 200 904\n"
"DEBUG:urllib3.connectionpool:https://localhost:8000 \"POST /samples/samples/204/experiment_parameters HTTP/1.1\" 200 905\n"
]
},
{
@ -788,17 +788,17 @@
"output_type": "stream",
"text": [
"API Response:\n",
"run_number=4 type='standard' beamline_parameters=BeamlineParameters(synchrotron='Swiss Light Source', beamline='PXIII', detector=Detector(manufacturer='DECTRIS', model='PILATUS4 2M', type='photon-counting', serial_number='16684dscsd668468', detector_distance_mm=232.0, beam_center_x_px=768.0, beam_center_y_px=857.0, pixel_size_x_um=150.0, pixel_size_y_um=150.0), wavelength=1.033, ring_current_a=0.4, ring_mode='Machine Development', undulator=None, undulatorgap_mm=None, monochromator='Si111', transmission=10.0, focusing_optic='Kirkpatrick-Baez', beamline_flux_at_sample_ph_s=0.0, beam_size_width=30.0, beam_size_height=30.0, characterization=None, rotation=RotationParameters(omega_start_deg=0.0, omega_step=0.2, chi=0.0, phi=10.0, number_of_images=1800, exposure_time_s=0.01), grid_scan=None, jet=None, cryojet_temperature_k=None, humidifier_temperature_k=None, humidifier_humidity=None) dataset=None sample_id=204 id=6\n"
"run_number=8 type='standard' beamline_parameters=BeamlineParameters(synchrotron='Swiss Light Source', beamline='PXIII', detector=Detector(manufacturer='DECTRIS', model='PILATUS4 2M', type='photon-counting', serial_number='16684dscsd668468', detector_distance_mm=232.0, beam_center_x_px=768.0, beam_center_y_px=857.0, pixel_size_x_um=150.0, pixel_size_y_um=150.0), wavelength=1.033, ring_current_a=0.4, ring_mode='Machine Development', undulator=None, undulatorgap_mm=None, monochromator='Si111', transmission=10.0, focusing_optic='Kirkpatrick-Baez', beamline_flux_at_sample_ph_s=0.0, beam_size_width=30.0, beam_size_height=30.0, characterization=None, rotation=RotationParameters(omega_start_deg=0.0, omega_step=0.2, chi=0.0, phi=10.0, number_of_images=1800, exposure_time_s=0.01), grid_scan=None, jet=None, cryojet_temperature_k=None, humidifier_temperature_k=None, humidifier_humidity=None) dataset=None sample_id=204 id=10\n"
]
}
],
"execution_count": 18
"execution_count": 26
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-04-30T09:31:29.122855Z",
"start_time": "2025-04-30T09:31:29.103718Z"
"end_time": "2025-04-30T14:32:24.370041Z",
"start_time": "2025-04-30T14:32:24.347435Z"
}
},
"cell_type": "code",
@ -806,7 +806,7 @@
"from datetime import datetime\n",
"\n",
"sample_id = sample_id\n",
"run_id = 6\n",
"run_id = 10\n",
"\n",
"def test_mark_run_written(sample_id, run_id, configuration):\n",
" # Prepare your dataset dict as required by your API (.dict() results if using Pydantic model)\n",
@ -840,7 +840,7 @@
"DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): localhost:8000\n",
"/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/connectionpool.py:1103: InsecureRequestWarning: Unverified HTTPS request is being made to host 'localhost'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings\n",
" warnings.warn(\n",
"DEBUG:urllib3.connectionpool:https://localhost:8000 \"PATCH /samples/update-dataset/204/6 HTTP/1.1\" 200 1085\n"
"DEBUG:urllib3.connectionpool:https://localhost:8000 \"PATCH /samples/update-dataset/204/10 HTTP/1.1\" 200 1086\n"
]
},
{
@ -848,11 +848,11 @@
"output_type": "stream",
"text": [
"Dataset updated successfully:\n",
"run_number=4 type='standard' beamline_parameters=BeamlineParameters(synchrotron='Swiss Light Source', beamline='PXIII', detector=Detector(manufacturer='DECTRIS', model='PILATUS4 2M', type='photon-counting', serial_number='16684dscsd668468', detector_distance_mm=232.0, beam_center_x_px=768.0, beam_center_y_px=857.0, pixel_size_x_um=150.0, pixel_size_y_um=150.0), wavelength=1.033, ring_current_a=0.4, ring_mode='Machine Development', undulator=None, undulatorgap_mm=None, monochromator='Si111', transmission=10.0, focusing_optic='Kirkpatrick-Baez', beamline_flux_at_sample_ph_s=0.0, beam_size_width=30.0, beam_size_height=30.0, characterization=None, rotation=RotationParameters(omega_start_deg=0.0, omega_step=0.2, chi=0.0, phi=10.0, number_of_images=1800, exposure_time_s=0.01), grid_scan=None, jet=None, cryojet_temperature_k=None, humidifier_temperature_k=None, humidifier_humidity=None) dataset=Datasets(filepath='/das/work/p11/p11206/raw_data/vincent/20250415_6D_SLS2_1st_data/20250415_fullbeam_dtz220_Lyso102_again_360deg', status='written', written_at=datetime.datetime(2025, 4, 30, 11, 31, 29, 105136)) sample_id=204 id=6\n"
"run_number=8 type='standard' beamline_parameters=BeamlineParameters(synchrotron='Swiss Light Source', beamline='PXIII', detector=Detector(manufacturer='DECTRIS', model='PILATUS4 2M', type='photon-counting', serial_number='16684dscsd668468', detector_distance_mm=232.0, beam_center_x_px=768.0, beam_center_y_px=857.0, pixel_size_x_um=150.0, pixel_size_y_um=150.0), wavelength=1.033, ring_current_a=0.4, ring_mode='Machine Development', undulator=None, undulatorgap_mm=None, monochromator='Si111', transmission=10.0, focusing_optic='Kirkpatrick-Baez', beamline_flux_at_sample_ph_s=0.0, beam_size_width=30.0, beam_size_height=30.0, characterization=None, rotation=RotationParameters(omega_start_deg=0.0, omega_step=0.2, chi=0.0, phi=10.0, number_of_images=1800, exposure_time_s=0.01), grid_scan=None, jet=None, cryojet_temperature_k=None, humidifier_temperature_k=None, humidifier_humidity=None) dataset=Datasets(filepath='/das/work/p11/p11206/raw_data/vincent/20250415_6D_SLS2_1st_data/20250415_fullbeam_dtz220_Lyso102_again_360deg', status='written', written_at=datetime.datetime(2025, 4, 30, 16, 32, 24, 348891)) sample_id=204 id=10\n"
]
}
],
"execution_count": 19
"execution_count": 27
},
{
"metadata": {