From 58dcaf892f9f2250c83a8f800c13d3dabad317e7 Mon Sep 17 00:00:00 2001 From: GotthardG <51994228+GotthardG@users.noreply.github.com> Date: Tue, 29 Apr 2025 23:17:53 +0200 Subject: [PATCH] Add 'type' field to ExperimentParametersModel This commit introduces a new 'type' field in the ExperimentParametersModel schema and updates the associated code in `sample.py` to include this field during object creation. Additionally, unnecessary lines and redundant code in `testfunctions.ipynb` have been removed for better readability and maintainability. --- backend/app/models.py | 1 + backend/app/routers/sample.py | 1 + backend/app/schemas.py | 1 + backend/propipe_sim.ipynb | 9 +--- testfunctions.ipynb | 84 ++++++++++++++++++----------------- 5 files changed, 48 insertions(+), 48 deletions(-) diff --git a/backend/app/models.py b/backend/app/models.py index 536d26b..e97ff49 100644 --- a/backend/app/models.py +++ b/backend/app/models.py @@ -272,6 +272,7 @@ class ExperimentParameters(Base): __tablename__ = "experiment_parameters" id = Column(Integer, primary_key=True, index=True, autoincrement=True) run_number = Column(Integer, nullable=False) + type = Column(String(255), nullable=False) beamline_parameters = Column(JSON, nullable=True) dataset = Column(JSON, nullable=True) sample_id = Column(Integer, ForeignKey("samples.id"), nullable=False) diff --git a/backend/app/routers/sample.py b/backend/app/routers/sample.py index 1b7927c..5be00f3 100644 --- a/backend/app/routers/sample.py +++ b/backend/app/routers/sample.py @@ -334,6 +334,7 @@ def create_experiment_parameters_for_sample( # stored as JSON. new_exp = ExperimentParametersModel( run_number=new_run_number, + type=exp_params.type, beamline_parameters=exp_params.beamline_parameters.dict() if exp_params.beamline_parameters else None, diff --git a/backend/app/schemas.py b/backend/app/schemas.py index 7dc0aaa..0342217 100644 --- a/backend/app/schemas.py +++ b/backend/app/schemas.py @@ -906,6 +906,7 @@ class Datasets(BaseModel): class ExperimentParametersBase(BaseModel): run_number: int + type: str beamline_parameters: Optional[BeamlineParameters] = None dataset: Optional[Datasets] = None sample_id: int diff --git a/backend/propipe_sim.ipynb b/backend/propipe_sim.ipynb index 339a7dd..45c430b 100644 --- a/backend/propipe_sim.ipynb +++ b/backend/propipe_sim.ipynb @@ -9,7 +9,7 @@ "is_executing": true }, "ExecuteTime": { - "start_time": "2025-04-29T20:30:28.354331Z" + "start_time": "2025-04-29T21:16:51.426746Z" } }, "source": [ @@ -67,18 +67,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "Starting job status updater...\n", - "Jobs received: [{'job_id': 1, 'sample_id': 230, 'run_id': 1, 'sample_name': 'Sample230', 'status': 'todo', 'type': 'default_type', 'created_at': '2025-04-29T20:25:20.888394', 'updated_at': None, 'data_collection_parameters': None, 'experiment_parameters': {'synchrotron': 'Swiss Light Source', 'beamline': 'PXIII', 'detector': {'manufacturer': 'DECTRIS', 'model': 'PILATUS4 2M', 'type': 'photon-counting', 'serialNumber': '16684dscsd668468', 'detectorDistance_mm': 95.0, 'beamCenterX_px': 512.0, 'beamCenterY_px': 512.0, 'pixelSizeX_um': 150.0, 'pixelSizeY_um': 150.0}, 'wavelength': 1.0, 'ringCurrent_A': 0.0, 'ringMode': 'Machine Down', 'undulator': None, 'undulatorgap_mm': None, 'monochromator': 'Si111', 'transmission': 1.0, 'focusingOptic': 'Kirkpatrick-Baez', 'beamlineFluxAtSample_ph_s': 0.0, 'beamSizeWidth': 30.0, 'beamSizeHeight': 30.0, 'characterization': None, 'rotation': {'omegaStart_deg': 0.0, 'omegaStep': 0.1, 'chi': 0.0, 'phi': 10.0, 'numberOfImages': 3600, 'exposureTime_s': 0.02}, 'gridScan': None, 'jet': None, 'cryojetTemperature_K': None, 'humidifierTemperature_K': None, 'humidifierHumidity': None}, 'slurm_id': None}]\n", - "Job ID: 1, Current status: todo\n", - "✅ Job 1 status updated to 'submitted'. Response: {'job_id': 1, 'status': 'submitted', 'slurm_id': 76545678}\n" + "Starting job status updater...\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "/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 '127.0.0.1'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings\n", - " warnings.warn(\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 '127.0.0.1'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings\n", " warnings.warn(\n" ] diff --git a/testfunctions.ipynb b/testfunctions.ipynb index 335667d..8cba734 100644 --- a/testfunctions.ipynb +++ b/testfunctions.ipynb @@ -3,8 +3,8 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-04-29T20:17:17.478562Z", - "start_time": "2025-04-29T20:17:16.842590Z" + "end_time": "2025-04-29T21:16:17.176129Z", + "start_time": "2025-04-29T21:16:17.104720Z" } }, "cell_type": "code", @@ -48,7 +48,7 @@ ] } ], - "execution_count": 1 + "execution_count": 3 }, { "metadata": {}, @@ -427,21 +427,21 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-04-29T20:17:43.335654Z", - "start_time": "2025-04-29T20:17:43.333828Z" + "end_time": "2025-04-29T21:15:51.203912Z", + "start_time": "2025-04-29T21:15:51.200888Z" } }, "cell_type": "code", - "source": "sample_id = 230", + "source": "sample_id = 204", "id": "54d4d46ca558e7b9", "outputs": [], - "execution_count": 2 + "execution_count": 1 }, { "metadata": { "ExecuteTime": { - "end_time": "2025-04-29T20:17:46.414835Z", - "start_time": "2025-04-29T20:17:46.379138Z" + "end_time": "2025-04-29T20:57:41.460728Z", + "start_time": "2025-04-29T20:57:41.399620Z" } }, "cell_type": "code", @@ -493,7 +493,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/230/events HTTP/1.1\" 200 413\n" + "DEBUG:urllib3.connectionpool:https://localhost:8000 \"POST /samples/samples/204/events HTTP/1.1\" 200 413\n" ] }, { @@ -503,8 +503,8 @@ "Payload being sent to API:\n", "{\"event_type\":\"Collecting\"}\n", "API response:\n", - "('id', 230)\n", - "('sample_name', 'Sample230')\n", + "('id', 204)\n", + "('sample_name', 'Sample204')\n", "('position', 16)\n", "('puck_id', 30)\n", "('crystalname', None)\n", @@ -513,13 +513,13 @@ "('priority', None)\n", "('comments', None)\n", "('data_collection_parameters', None)\n", - "('events', [SampleEventResponse(event_type='Mounting', id=453, sample_id=230, timestamp=datetime.datetime(2025, 4, 28, 13, 22)), SampleEventResponse(event_type='Collecting', id=454, sample_id=230, timestamp=datetime.datetime(2025, 4, 29, 20, 17, 46, 405264))])\n", + "('events', [SampleEventResponse(event_type='Mounting', id=396, sample_id=204, timestamp=datetime.datetime(2025, 4, 28, 12, 56)), SampleEventResponse(event_type='Collecting', id=397, sample_id=204, timestamp=datetime.datetime(2025, 4, 29, 20, 57, 41, 453326))])\n", "('mount_count', 0)\n", "('unmount_count', 0)\n" ] } ], - "execution_count": 3 + "execution_count": 15 }, { "metadata": { @@ -563,8 +563,8 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-04-29T20:17:52.059793Z", - "start_time": "2025-04-29T20:17:51.939047Z" + "end_time": "2025-04-29T20:57:47.969390Z", + "start_time": "2025-04-29T20:57:47.936166Z" } }, "cell_type": "code", @@ -635,7 +635,7 @@ "DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): 127.0.0.1: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 '127.0.0.1'. 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://127.0.0.1:8000 \"POST /samples/230/upload-images HTTP/1.1\" 200 205\n" + "DEBUG:urllib3.connectionpool:https://127.0.0.1:8000 \"POST /samples/204/upload-images HTTP/1.1\" 200 205\n" ] }, { @@ -645,11 +645,11 @@ "Uploading after_dc.jpeg.jpg...\n", "API Response for after_dc.jpeg.jpg:\n", "200\n", - "{'pgroup': 'p20003', 'sample_id': 230, 'sample_event_id': 454, 'filepath': 'images/p20003/2025-04-29/Dewar Five/PKK007/16/Collecting_2025-04-29_20-17-46/after_dc.jpeg.jpg', 'status': 'active', 'comment': None, 'id': 1}\n" + "{'pgroup': 'p20003', 'sample_id': 204, 'sample_event_id': 397, 'filepath': 'images/p20003/2025-04-29/Dewar Five/PKK007/16/Collecting_2025-04-29_20-57-41/after_dc.jpeg.jpg', 'status': 'active', 'comment': None, 'id': 1}\n" ] } ], - "execution_count": 4 + "execution_count": 16 }, { "metadata": {}, @@ -662,8 +662,8 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-04-29T20:17:56.494919Z", - "start_time": "2025-04-29T20:17:56.469538Z" + "end_time": "2025-04-29T21:16:26.759058Z", + "start_time": "2025-04-29T21:16:26.727172Z" } }, "cell_type": "code", @@ -674,7 +674,8 @@ " ExperimentParametersCreate,\n", " RotationParameters,\n", " BeamlineParameters,\n", - " GridScanParamers\n", + " GridScanParamers,\n", + " Detector\n", ")\n", "\n", "\n", @@ -712,17 +713,17 @@ "# If your client code requires you to build a detector model,\n", "# you can either use a Detector model or pass a dictionary.\n", "# Here we pass a dictionary.\n", - "detector_data = {\n", - " \"manufacturer\": \"DECTRIS\",\n", - " \"model\": \"PILATUS4 2M\",\n", - " \"type\": \"photon-counting\",\n", - " \"serialNumber\": \"16684dscsd668468\",\n", - " \"detectorDistance_mm\": 95.0,\n", - " \"beamCenterX_px\": 512.0,\n", - " \"beamCenterY_px\": 512.0,\n", - " \"pixelSizeX_um\": 150.0,\n", - " \"pixelSizeY_um\": 150.0,\n", - "}\n", + "detector_data = Detector(\n", + " manufacturer=\"DECTRIS\",\n", + " model=\"PILATUS4 2M\",\n", + " type=\"photon-counting\",\n", + " serialNumber=\"16684dscsd668468\",\n", + " detectorDistance_mm=95.0,\n", + " beamCenterX_px=512.0,\n", + " beamCenterY_px=512.0,\n", + " pixelSizeX_um=150.0,\n", + " pixelSizeY_um=150.0,\n", + ")\n", "\n", "beamline_params = BeamlineParameters(\n", " synchrotron=\"Swiss Light Source\",\n", @@ -748,6 +749,7 @@ "# it out or set it to a dummy value if your client model requires it.\n", "experiment_params_payload = ExperimentParametersCreate(\n", " # run_number can be omitted/ignored if computed on the server\n", + " type=\"standard\",\n", " beamline_parameters=beamline_params,\n", " sample_id=sample_id # change sample_id to an existing sample in your database\n", ")\n", @@ -778,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/230/experiment_parameters HTTP/1.1\" 200 875\n" + "DEBUG:urllib3.connectionpool:https://localhost:8000 \"POST /samples/samples/204/experiment_parameters HTTP/1.1\" 200 893\n" ] }, { @@ -786,17 +788,17 @@ "output_type": "stream", "text": [ "API Response:\n", - "run_number=1 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=95.0, beam_center_x_px=512.0, beam_center_y_px=512.0, pixel_size_x_um=150.0, pixel_size_y_um=150.0), wavelength=1.0, ring_current_a=0.0, ring_mode='Machine Down', undulator=None, undulatorgap_mm=None, monochromator='Si111', transmission=1.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.1, chi=0.0, phi=10.0, number_of_images=3600, exposure_time_s=0.02), grid_scan=None, jet=None, cryojet_temperature_k=None, humidifier_temperature_k=None, humidifier_humidity=None) dataset=None sample_id=230 id=1\n" + "run_number=1 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=95.0, beam_center_x_px=512.0, beam_center_y_px=512.0, pixel_size_x_um=150.0, pixel_size_y_um=150.0), wavelength=1.0, ring_current_a=0.0, ring_mode='Machine Down', undulator=None, undulatorgap_mm=None, monochromator='Si111', transmission=1.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.1, chi=0.0, phi=10.0, number_of_images=3600, exposure_time_s=0.02), grid_scan=None, jet=None, cryojet_temperature_k=None, humidifier_temperature_k=None, humidifier_humidity=None) dataset=None sample_id=204 id=1\n" ] } ], - "execution_count": 5 + "execution_count": 4 }, { "metadata": { "ExecuteTime": { - "end_time": "2025-04-29T20:29:27.657874Z", - "start_time": "2025-04-29T20:29:27.623737Z" + "end_time": "2025-04-29T21:17:02.855772Z", + "start_time": "2025-04-29T21:17:02.821634Z" } }, "cell_type": "code", @@ -838,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/230/1 HTTP/1.1\" 200 1056\n" + "DEBUG:urllib3.connectionpool:https://localhost:8000 \"PATCH /samples/update-dataset/204/1 HTTP/1.1\" 200 1074\n" ] }, { @@ -846,11 +848,11 @@ "output_type": "stream", "text": [ "Dataset updated successfully:\n", - "run_number=1 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=95.0, beam_center_x_px=512.0, beam_center_y_px=512.0, pixel_size_x_um=150.0, pixel_size_y_um=150.0), wavelength=1.0, ring_current_a=0.0, ring_mode='Machine Down', undulator=None, undulatorgap_mm=None, monochromator='Si111', transmission=1.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.1, chi=0.0, phi=10.0, number_of_images=3600, exposure_time_s=0.02), 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, 29, 22, 29, 27, 626524)) sample_id=230 id=1\n" + "run_number=1 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=95.0, beam_center_x_px=512.0, beam_center_y_px=512.0, pixel_size_x_um=150.0, pixel_size_y_um=150.0), wavelength=1.0, ring_current_a=0.0, ring_mode='Machine Down', undulator=None, undulatorgap_mm=None, monochromator='Si111', transmission=1.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.1, chi=0.0, phi=10.0, number_of_images=3600, exposure_time_s=0.02), 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, 29, 23, 17, 2, 823503)) sample_id=204 id=1\n" ] } ], - "execution_count": 13 + "execution_count": 5 }, { "metadata": {