
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.
1209 lines
83 KiB
Plaintext
1209 lines
83 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-04-29T21:16:17.176129Z",
|
|
"start_time": "2025-04-29T21:16:17.104720Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"import json\n",
|
|
"\n",
|
|
"#from nbclient.client import timestamp\n",
|
|
"\n",
|
|
"import backend.aareDBclient as aareDBclient\n",
|
|
"from aareDBclient.rest import ApiException\n",
|
|
"from pprint import pprint\n",
|
|
"\n",
|
|
"from app.schemas import characterizationParameters, ResultCreate\n",
|
|
"\n",
|
|
"#from app.data.data import sample\n",
|
|
"\n",
|
|
"#from aareDBclient import SamplesApi, ShipmentsApi, PucksApi\n",
|
|
"#from aareDBclient.models import SampleEventCreate, SetTellPosition\n",
|
|
"#from examples.examples import api_response\n",
|
|
"\n",
|
|
"print(aareDBclient.__version__)\n",
|
|
"\n",
|
|
"configuration = aareDBclient.Configuration(\n",
|
|
" #host = \"https://mx-aare-test.psi.ch:1492\"\n",
|
|
" host = \"https://localhost:8000\"\n",
|
|
")\n",
|
|
"\n",
|
|
"print(configuration.host)\n",
|
|
"\n",
|
|
"configuration.verify_ssl = False # Disable SSL verification\n",
|
|
"#print(dir(SamplesApi))"
|
|
],
|
|
"id": "3b7c27697a4d5c83",
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"0.1.1a2\n",
|
|
"https://localhost:8000\n"
|
|
]
|
|
}
|
|
],
|
|
"execution_count": 3
|
|
},
|
|
{
|
|
"metadata": {},
|
|
"cell_type": "code",
|
|
"outputs": [],
|
|
"execution_count": null,
|
|
"source": [
|
|
"## Fetch all Shipments, list corresponding dewars and pucks\n",
|
|
"\n",
|
|
"from datetime import date, datetime\n",
|
|
"from aareDBclient import ShipmentsApi, SamplesApi, GridScanParamers\n",
|
|
"from aareDBclient.models import Shipment\n",
|
|
"\n",
|
|
"with aareDBclient.ApiClient(configuration) as api_client:\n",
|
|
" api_instance = aareDBclient.ShipmentsApi(api_client)\n",
|
|
"\n",
|
|
" try:\n",
|
|
" # Fetch all shipments\n",
|
|
" all_shipments_response = api_instance.fetch_shipments_shipments_get()\n",
|
|
"\n",
|
|
" # Print shipment names and their associated puck names\n",
|
|
" for shipment in all_shipments_response:\n",
|
|
" print(f\"Shipment ID: {shipment.id}, Shipment Name: {shipment.shipment_name}\")\n",
|
|
" if hasattr(shipment, 'dewars') and shipment.dewars: # Ensure 'dewars' exists\n",
|
|
" for dewar in shipment.dewars:\n",
|
|
" print(f\" Dewar ID: {dewar.id}, Dewar Name: {dewar.dewar_name}, Dewar Unique ID: {dewar.unique_id} \")\n",
|
|
"\n",
|
|
" if hasattr(dewar, 'pucks') and dewar.pucks: # Ensure 'pucks' exists\n",
|
|
" for puck in dewar.pucks:\n",
|
|
" print(f\" Puck ID: {puck.id}, Puck Name: {puck.puck_name}\")\n",
|
|
" else:\n",
|
|
" print(\" No pucks found in this dewar.\")\n",
|
|
" else:\n",
|
|
" print(\" No dewars found in this shipment.\")\n",
|
|
"\n",
|
|
" except ApiException as e:\n",
|
|
" print(f\"Exception when calling ShipmentsApi->fetch_shipments_shipments_get: {e}\")\n"
|
|
],
|
|
"id": "4955b858f2cef93e"
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-02-25T15:47:34.956061Z",
|
|
"start_time": "2025-02-25T15:47:34.941372Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"from datetime import date\n",
|
|
"from aareDBclient import LogisticsApi\n",
|
|
"from aareDBclient.models import LogisticsEventCreate # Import required model\n",
|
|
"\n",
|
|
"with aareDBclient.ApiClient(configuration) as api_client:\n",
|
|
" api_instance = aareDBclient.LogisticsApi(api_client)\n",
|
|
"\n",
|
|
" try:\n",
|
|
" # Create payload using the required model\n",
|
|
" logistics_event_create = LogisticsEventCreate(\n",
|
|
" dewar_qr_code='923db239427869be',\n",
|
|
" location_qr_code='A2-X06SA',\n",
|
|
" transaction_type='incoming',\n",
|
|
" timestamp=date.today() # Adjust if the API expects datetime\n",
|
|
" )\n",
|
|
"\n",
|
|
" # Pass the payload to the API function\n",
|
|
" api_response = api_instance.scan_dewar_logistics_dewar_scan_post(\n",
|
|
" logistics_event_create=logistics_event_create # Pass as an object\n",
|
|
" )\n",
|
|
" print(\"API Response:\", api_response)\n",
|
|
"\n",
|
|
" except ApiException as e:\n",
|
|
" print(f\"Exception when calling LogisticsApi->scan_dewar_logistics_dewar_scan_post: {e}\")\n",
|
|
"\n",
|
|
" try:\n",
|
|
" # Create payload using the required model\n",
|
|
" logistics_event_create = LogisticsEventCreate(\n",
|
|
" dewar_qr_code='923db239427869be',\n",
|
|
" location_qr_code='A2-X06SA',\n",
|
|
" transaction_type='refill',\n",
|
|
" timestamp=date.today() # Adjust if the API expects datetime\n",
|
|
" )\n",
|
|
"\n",
|
|
" # Pass the payload to the API function\n",
|
|
" api_response = api_instance.scan_dewar_logistics_dewar_scan_post(\n",
|
|
" logistics_event_create=logistics_event_create # Pass as an object\n",
|
|
" )\n",
|
|
" print(\"API Response:\", api_response)\n",
|
|
"\n",
|
|
" except ApiException as e:\n",
|
|
" print(f\"Exception when calling LogisticsApi->scan_dewar_logistics_dewar_scan_post: {e}\")\n",
|
|
"\n",
|
|
" try:\n",
|
|
" # Create payload using the required model\n",
|
|
" logistics_event_create = LogisticsEventCreate(\n",
|
|
" dewar_qr_code='923db239427869be',\n",
|
|
" location_qr_code='X06DA-Beamline',\n",
|
|
" transaction_type='beamline',\n",
|
|
" timestamp=date.today() # Adjust if the API expects datetime\n",
|
|
" )\n",
|
|
"\n",
|
|
" # Pass the payload to the API function\n",
|
|
" api_response = api_instance.scan_dewar_logistics_dewar_scan_post(\n",
|
|
" logistics_event_create=logistics_event_create # Pass as an object\n",
|
|
" )\n",
|
|
" print(\"API Response:\", api_response)\n",
|
|
"\n",
|
|
" except ApiException as e:\n",
|
|
" print(f\"Exception when calling LogisticsApi->scan_dewar_logistics_dewar_scan_post: {e}\")\n"
|
|
],
|
|
"id": "8fd3638bffaecd23",
|
|
"outputs": [
|
|
{
|
|
"ename": "TypeError",
|
|
"evalue": "ApiClient.call_api() got an unexpected keyword argument 'path_params'",
|
|
"output_type": "error",
|
|
"traceback": [
|
|
"\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
|
|
"\u001B[0;31mTypeError\u001B[0m Traceback (most recent call last)",
|
|
"Cell \u001B[0;32mIn[43], line 19\u001B[0m\n\u001B[1;32m 15\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[1;32m 16\u001B[0m \u001B[38;5;28;01mwith\u001B[39;00m \u001B[38;5;28mopen\u001B[39m(file_path, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mrb\u001B[39m\u001B[38;5;124m\"\u001B[39m) \u001B[38;5;28;01mas\u001B[39;00m file_data:\n\u001B[1;32m 17\u001B[0m \u001B[38;5;66;03m# Use the low-level call_api method; note that the files parameter here is\u001B[39;00m\n\u001B[1;32m 18\u001B[0m \u001B[38;5;66;03m# a dictionary with key matching the FastAPI parameter name.\u001B[39;00m\n\u001B[0;32m---> 19\u001B[0m response \u001B[38;5;241m=\u001B[39m \u001B[43mapi_client\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mcall_api\u001B[49m\u001B[43m(\u001B[49m\n\u001B[1;32m 20\u001B[0m \u001B[43m \u001B[49m\u001B[38;5;124;43mf\u001B[39;49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[38;5;124;43m/\u001B[39;49m\u001B[38;5;132;43;01m{\u001B[39;49;00m\u001B[43msample_id\u001B[49m\u001B[38;5;132;43;01m}\u001B[39;49;00m\u001B[38;5;124;43m/upload_images\u001B[39;49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[43m,\u001B[49m\n\u001B[1;32m 21\u001B[0m \u001B[43m \u001B[49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[38;5;124;43mPOST\u001B[39;49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[43m,\u001B[49m\n\u001B[1;32m 22\u001B[0m \u001B[43m \u001B[49m\u001B[43mpath_params\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43m{\u001B[49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[38;5;124;43msample_id\u001B[39;49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[43m:\u001B[49m\u001B[43m \u001B[49m\u001B[43msample_id\u001B[49m\u001B[43m}\u001B[49m\u001B[43m,\u001B[49m\n\u001B[1;32m 23\u001B[0m \u001B[43m \u001B[49m\u001B[43mfiles\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43m{\u001B[49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[38;5;124;43muploaded_file\u001B[39;49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[43m:\u001B[49m\u001B[43m \u001B[49m\u001B[43m(\u001B[49m\u001B[43mfilename\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mfile_data\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mmime_type\u001B[49m\u001B[43m)\u001B[49m\u001B[43m}\u001B[49m\n\u001B[1;32m 24\u001B[0m \u001B[43m \u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 25\u001B[0m \u001B[38;5;28mprint\u001B[39m(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mAPI Response:\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n\u001B[1;32m 26\u001B[0m \u001B[38;5;28mprint\u001B[39m(response)\n",
|
|
"\u001B[0;31mTypeError\u001B[0m: ApiClient.call_api() got an unexpected keyword argument 'path_params'"
|
|
]
|
|
}
|
|
],
|
|
"execution_count": 43
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-04-28T14:36:56.694422Z",
|
|
"start_time": "2025-04-28T14:36:56.656426Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"# Get a list of pucks that are \"at the beamline\"\n",
|
|
"\n",
|
|
"with aareDBclient.ApiClient(configuration) as api_client:\n",
|
|
" # Create an instance of the API class\n",
|
|
" api_instance = aareDBclient.PucksApi(api_client)\n",
|
|
" get_pucks_at_beamline = aareDBclient.PucksApi(api_client)\n",
|
|
"\n",
|
|
" try:\n",
|
|
" # Create Return Address\n",
|
|
" api_response = api_instance.get_pucks_by_slot_pucks_slot_slot_identifier_get(slot_identifier='X06DA')\n",
|
|
" print(\"The response of PucksApi->get_pucks_by_slot_pucks_slot_slot_identifier_get:\\n\")\n",
|
|
" pprint(api_response)\n",
|
|
"\n",
|
|
" except ApiException as e:\n",
|
|
" print(\"Exception when calling PucksApi->get_pucks_by_slot_pucks_slot_slot_identifier_get: %s\\n\" % e)"
|
|
],
|
|
"id": "9cf3457093751b61",
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"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:1097: 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 \"GET /pucks/slot/X06DA HTTP/1.1\" 200 693\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"The response of PucksApi->get_pucks_by_slot_pucks_slot_slot_identifier_get:\n",
|
|
"\n",
|
|
"[PuckWithTellPosition(id=27, puck_name='PKK004', puck_type='Unipuck', puck_location_in_dewar=4, dewar_id=5, dewar_name='Dewar Five', pgroup='p20003', samples=None, tell_position=None),\n",
|
|
" PuckWithTellPosition(id=28, puck_name='PKK005', puck_type='Unipuck', puck_location_in_dewar=5, dewar_id=5, dewar_name='Dewar Five', pgroup='p20003', samples=None, tell_position=None),\n",
|
|
" PuckWithTellPosition(id=29, puck_name='PKK006', puck_type='Unipuck', puck_location_in_dewar=6, dewar_id=5, dewar_name='Dewar Five', pgroup='p20003', samples=None, tell_position=None),\n",
|
|
" PuckWithTellPosition(id=30, puck_name='PKK007', puck_type='Unipuck', puck_location_in_dewar=7, dewar_id=5, dewar_name='Dewar Five', pgroup='p20003', samples=None, tell_position=None)]\n"
|
|
]
|
|
}
|
|
],
|
|
"execution_count": 3
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-04-28T14:37:09.989924Z",
|
|
"start_time": "2025-04-28T14:37:09.960196Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"from aareDBclient import SetTellPosition, SetTellPositionRequest\n",
|
|
"\n",
|
|
"with aareDBclient.ApiClient(configuration) as api_client:\n",
|
|
" # Create an instance of the API class\n",
|
|
" api_instance = aareDBclient.PucksApi(api_client)\n",
|
|
"\n",
|
|
" # Payload with SetTellPosition objects\n",
|
|
" payload = SetTellPositionRequest(\n",
|
|
" tell=\"X06DA\",\n",
|
|
" #pucks=[\n",
|
|
" # SetTellPosition(puck_name='PSIMX074', segment='B', puck_in_segment=1),\n",
|
|
" # SetTellPosition(puck_name='PSIMX080', segment='B', puck_in_segment=2),\n",
|
|
" # SetTellPosition(puck_name='PSIMX081', segment='C', puck_in_segment=3),\n",
|
|
" # SetTellPosition(puck_name='PSIMX084', segment='C', puck_in_segment=4),\n",
|
|
" # SetTellPosition(puck_name='PSIMX104', segment='E', puck_in_segment=5),\n",
|
|
" # SetTellPosition(puck_name='PSIMX107', segment='E', puck_in_segment=1),\n",
|
|
" # SetTellPosition(puck_name='PSIMX117', segment='F', puck_in_segment=2),\n",
|
|
" #]\n",
|
|
" #pucks=[\n",
|
|
" # SetTellPosition(puck_name='PSIMX074', segment='F', puck_in_segment=1),\n",
|
|
" # SetTellPosition(puck_name='PSIMX080', segment='F', puck_in_segment=2),\n",
|
|
" # SetTellPosition(puck_name='PSIMX107', segment='A', puck_in_segment=1),\n",
|
|
" # SetTellPosition(puck_name='PSIMX117', segment='A', puck_in_segment=2),\n",
|
|
" #]\n",
|
|
" pucks=[\n",
|
|
" SetTellPosition(puck_name='PKK006', segment='F', puck_in_segment=1),\n",
|
|
" SetTellPosition(puck_name='PKK005', segment='F', puck_in_segment=2),\n",
|
|
" SetTellPosition(puck_name='PKK007', segment='A', puck_in_segment=1),\n",
|
|
" SetTellPosition(puck_name='PKK004', segment='A', puck_in_segment=2),\n",
|
|
" ]\n",
|
|
" #pucks = []\n",
|
|
" )\n",
|
|
"\n",
|
|
" # Call the PUT method to update the tell_position\n",
|
|
" try:\n",
|
|
" api_response = api_instance.set_tell_positions_pucks_set_tell_positions_put(\n",
|
|
" set_tell_position_request=payload\n",
|
|
" ) # Pass the entire payload as a single parameter\n",
|
|
"\n",
|
|
" print(\"The response of PucksApi->pucks_puck_id_tell_position_put:\\n\")\n",
|
|
" pprint(api_response)\n",
|
|
"\n",
|
|
" except Exception as e:\n",
|
|
" print(f\"Exception when calling PucksApi: {e}\")\n"
|
|
],
|
|
"id": "37e3eac6760150ee",
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"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:1097: 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 \"PUT /pucks/set-tell-positions HTTP/1.1\" 200 601\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"The response of PucksApi->pucks_puck_id_tell_position_put:\n",
|
|
"\n",
|
|
"[{'message': 'Tell position updated successfully.',\n",
|
|
" 'new_position': 'F1',\n",
|
|
" 'previous_position': None,\n",
|
|
" 'puck_name': 'PKK006',\n",
|
|
" 'status': 'updated',\n",
|
|
" 'tell': 'X06DA'},\n",
|
|
" {'message': 'Tell position updated successfully.',\n",
|
|
" 'new_position': 'F2',\n",
|
|
" 'previous_position': None,\n",
|
|
" 'puck_name': 'PKK005',\n",
|
|
" 'status': 'updated',\n",
|
|
" 'tell': 'X06DA'},\n",
|
|
" {'message': 'Tell position updated successfully.',\n",
|
|
" 'new_position': 'A1',\n",
|
|
" 'previous_position': None,\n",
|
|
" 'puck_name': 'PKK007',\n",
|
|
" 'status': 'updated',\n",
|
|
" 'tell': 'X06DA'},\n",
|
|
" {'message': 'Tell position updated successfully.',\n",
|
|
" 'new_position': 'A2',\n",
|
|
" 'previous_position': None,\n",
|
|
" 'puck_name': 'PKK004',\n",
|
|
" 'status': 'updated',\n",
|
|
" 'tell': 'X06DA'}]\n"
|
|
]
|
|
}
|
|
],
|
|
"execution_count": 4
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-04-28T14:37:23.148869Z",
|
|
"start_time": "2025-04-28T14:37:23.115094Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"# Get puck_id puck_name sample_id sample_name of pucks in the tell\n",
|
|
"\n",
|
|
"with aareDBclient.ApiClient(configuration) as api_client:\n",
|
|
" # Create an instance of the API class\n",
|
|
" api_instance = aareDBclient.PucksApi(api_client)\n",
|
|
"\n",
|
|
" # GET request: Fetch all pucks in the tell\n",
|
|
" try:\n",
|
|
" # Call the API method to fetch pucks\n",
|
|
" all_pucks_response = api_instance.get_pucks_with_tell_position_pucks_with_tell_position_get(tell='X06DA')\n",
|
|
"\n",
|
|
" # Debug response structure by printing it in JSON format\n",
|
|
" formatted_response = json.dumps(\n",
|
|
" [p.to_dict() for p in all_pucks_response], # Assuming the API response can be converted to dicts\n",
|
|
" indent=4 # Use indentation for readability\n",
|
|
" )\n",
|
|
" #print(\"The response of PucksApi->get_all_pucks_in_tell (formatted):\\n\")\n",
|
|
" #print(formatted_response)\n",
|
|
"\n",
|
|
" # Iterate through each puck and print information\n",
|
|
" for p in all_pucks_response:\n",
|
|
" print(f\"Puck ID: {p.id}, Puck Name: {p.puck_name}\")\n",
|
|
"\n",
|
|
" ## Check if the puck has any samples\n",
|
|
" if hasattr(p, 'samples') and p.samples: # Ensure 'samples' attribute exists and is not empty\n",
|
|
" for sample in p.samples:\n",
|
|
" print(f\" Sample ID: {sample.id}, Sample Name: {sample.sample_name}, Position: {sample.position}, Mount count: {sample.mount_count}\")\n",
|
|
" else:\n",
|
|
" print(\" No samples found in this puck.\")\n",
|
|
"\n",
|
|
" except ApiException as e:\n",
|
|
" print(\"Exception when calling PucksApi->get_all_pucks_in_tell: %s\\n\" % e)"
|
|
],
|
|
"id": "51578d944878db6a",
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"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:1097: 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 \"GET /pucks/with-tell-position?tell=X06DA HTTP/1.1\" 200 7592\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Puck ID: 29, Puck Name: PKK006\n",
|
|
" Sample ID: 268, Sample Name: Sample268, Position: 13, Mount count: 0\n",
|
|
" Sample ID: 265, Sample Name: Sample265, Position: 3, Mount count: 0\n",
|
|
" Sample ID: 266, Sample Name: Sample266, Position: 4, Mount count: 0\n",
|
|
" Sample ID: 269, Sample Name: Sample269, Position: 16, Mount count: 0\n",
|
|
" Sample ID: 267, Sample Name: Sample267, Position: 6, Mount count: 0\n",
|
|
"Puck ID: 30, Puck Name: PKK007\n",
|
|
" Sample ID: 276, Sample Name: Sample276, Position: 15, Mount count: 0\n",
|
|
" Sample ID: 270, Sample Name: Sample270, Position: 1, Mount count: 0\n",
|
|
" Sample ID: 274, Sample Name: Sample274, Position: 6, Mount count: 0\n",
|
|
" Sample ID: 277, Sample Name: Sample277, Position: 16, Mount count: 0\n",
|
|
" Sample ID: 273, Sample Name: Sample273, Position: 5, Mount count: 0\n",
|
|
" Sample ID: 271, Sample Name: Sample271, Position: 2, Mount count: 0\n",
|
|
" Sample ID: 275, Sample Name: Sample275, Position: 7, Mount count: 0\n",
|
|
" Sample ID: 272, Sample Name: Sample272, Position: 4, Mount count: 0\n",
|
|
"Puck ID: 28, Puck Name: PKK005\n",
|
|
" Sample ID: 264, Sample Name: Sample264, Position: 11, Mount count: 0\n",
|
|
" Sample ID: 261, Sample Name: Sample261, Position: 6, Mount count: 0\n",
|
|
" Sample ID: 262, Sample Name: Sample262, Position: 7, Mount count: 0\n",
|
|
" Sample ID: 260, Sample Name: Sample260, Position: 5, Mount count: 0\n",
|
|
" Sample ID: 263, Sample Name: Sample263, Position: 9, Mount count: 0\n",
|
|
"Puck ID: 27, Puck Name: PKK004\n",
|
|
" Sample ID: 251, Sample Name: Sample251, Position: 3, Mount count: 0\n",
|
|
" Sample ID: 253, Sample Name: Sample253, Position: 7, Mount count: 0\n",
|
|
" Sample ID: 252, Sample Name: Sample252, Position: 4, Mount count: 0\n",
|
|
" Sample ID: 255, Sample Name: Sample255, Position: 9, Mount count: 0\n",
|
|
" Sample ID: 250, Sample Name: Sample250, Position: 2, Mount count: 0\n",
|
|
" Sample ID: 254, Sample Name: Sample254, Position: 8, Mount count: 0\n",
|
|
" Sample ID: 258, Sample Name: Sample258, Position: 14, Mount count: 0\n",
|
|
" Sample ID: 256, Sample Name: Sample256, Position: 12, Mount count: 0\n",
|
|
" Sample ID: 249, Sample Name: Sample249, Position: 1, Mount count: 0\n",
|
|
" Sample ID: 257, Sample Name: Sample257, Position: 13, Mount count: 0\n",
|
|
" Sample ID: 259, Sample Name: Sample259, Position: 16, Mount count: 0\n"
|
|
]
|
|
}
|
|
],
|
|
"execution_count": 5
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-04-29T21:15:51.203912Z",
|
|
"start_time": "2025-04-29T21:15:51.200888Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": "sample_id = 204",
|
|
"id": "54d4d46ca558e7b9",
|
|
"outputs": [],
|
|
"execution_count": 1
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-04-29T20:57:41.460728Z",
|
|
"start_time": "2025-04-29T20:57:41.399620Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"from aareDBclient import SampleEventCreate\n",
|
|
"\n",
|
|
"# Create an event for a sample\n",
|
|
"\n",
|
|
"with aareDBclient.ApiClient(configuration) as api_client:\n",
|
|
" # Instance of the API client\n",
|
|
" api_instance = aareDBclient.SamplesApi(api_client)\n",
|
|
" #sample_id=293\n",
|
|
" try:\n",
|
|
" # Define the payload with only `event_type`\n",
|
|
" sample_event_create = SampleEventCreate(\n",
|
|
" sample_id=sample_id,\n",
|
|
" #event_type=\"Centering\" # Valid event type\n",
|
|
" event_type=\"Collecting\" # Valid event type\n",
|
|
" )\n",
|
|
"\n",
|
|
" # Debug the payload before sending\n",
|
|
" print(\"Payload being sent to API:\")\n",
|
|
" print(sample_event_create.json()) # Ensure it matches `SampleEventCreate`\n",
|
|
"\n",
|
|
" # Call the API\n",
|
|
" api_response = api_instance.create_sample_event_samples_samples_sample_id_events_post(\n",
|
|
" sample_id=sample_id, # Ensure this matches a valid sample ID in the database\n",
|
|
" sample_event_create=sample_event_create\n",
|
|
" )\n",
|
|
"\n",
|
|
" print(\"API response:\")\n",
|
|
" #pprint(api_response)\n",
|
|
"\n",
|
|
" for p in api_response:\n",
|
|
" print(p)\n",
|
|
"\n",
|
|
" except ApiException as e:\n",
|
|
" print(\"Exception when calling post_sample_event:\")\n",
|
|
" print(f\"Status Code: {e.status}\")\n",
|
|
" if e.body:\n",
|
|
" print(f\"Error Details: {e.body}\")\n"
|
|
],
|
|
"id": "4a0665f92756b486",
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"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/events HTTP/1.1\" 200 413\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Payload being sent to API:\n",
|
|
"{\"event_type\":\"Collecting\"}\n",
|
|
"API response:\n",
|
|
"('id', 204)\n",
|
|
"('sample_name', 'Sample204')\n",
|
|
"('position', 16)\n",
|
|
"('puck_id', 30)\n",
|
|
"('crystalname', None)\n",
|
|
"('proteinname', None)\n",
|
|
"('positioninpuck', None)\n",
|
|
"('priority', None)\n",
|
|
"('comments', None)\n",
|
|
"('data_collection_parameters', None)\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": 15
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-04-29T14:27:46.730515Z",
|
|
"start_time": "2025-04-29T14:27:46.622922Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"### not working\n",
|
|
"with aareDBclient.ApiClient(configuration) as api_client:\n",
|
|
" # Create an instance of the Samples API class\n",
|
|
" api_instance = aareDBclient.SamplesApi(api_client)\n",
|
|
"\n",
|
|
" try:\n",
|
|
" # Get the last sample event\n",
|
|
" last_event_response = api_instance.get_last_sample_event_samples_samples_sample_id_events_last_get(27)\n",
|
|
" print(\"The response of get_last_sample_event:\\n\")\n",
|
|
" pprint(last_event_response)\n",
|
|
"\n",
|
|
" except ApiException as e:\n",
|
|
" print(\"Exception when calling get_last_sample_event: %s\\n\" % e)\n"
|
|
],
|
|
"id": "f1d171700d6cf7fe",
|
|
"outputs": [
|
|
{
|
|
"ename": "AttributeError",
|
|
"evalue": "'SamplesApi' object has no attribute 'get_last_sample_event_samples_samples_sample_id_events_last_get'",
|
|
"output_type": "error",
|
|
"traceback": [
|
|
"\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
|
|
"\u001B[0;31mAttributeError\u001B[0m Traceback (most recent call last)",
|
|
"Cell \u001B[0;32mIn[48], line 8\u001B[0m\n\u001B[1;32m 4\u001B[0m api_instance \u001B[38;5;241m=\u001B[39m aareDBclient\u001B[38;5;241m.\u001B[39mSamplesApi(api_client)\n\u001B[1;32m 6\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[1;32m 7\u001B[0m \u001B[38;5;66;03m# Get the last sample event\u001B[39;00m\n\u001B[0;32m----> 8\u001B[0m last_event_response \u001B[38;5;241m=\u001B[39m \u001B[43mapi_instance\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mget_last_sample_event_samples_samples_sample_id_events_last_get\u001B[49m(\u001B[38;5;241m27\u001B[39m)\n\u001B[1;32m 9\u001B[0m \u001B[38;5;28mprint\u001B[39m(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mThe response of get_last_sample_event:\u001B[39m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;124m\"\u001B[39m)\n\u001B[1;32m 10\u001B[0m pprint(last_event_response)\n",
|
|
"\u001B[0;31mAttributeError\u001B[0m: 'SamplesApi' object has no attribute 'get_last_sample_event_samples_samples_sample_id_events_last_get'"
|
|
]
|
|
}
|
|
],
|
|
"execution_count": 48
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-04-29T20:57:47.969390Z",
|
|
"start_time": "2025-04-29T20:57:47.936166Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"# Post multiple images to the sample database\n",
|
|
"\n",
|
|
"import os\n",
|
|
"import mimetypes\n",
|
|
"import requests\n",
|
|
"\n",
|
|
"# List of file paths to the images you want to upload\n",
|
|
"#file_paths = [\n",
|
|
"# \"backend/tests/sample_image/0_200.jpg\",\n",
|
|
"# \"backend/tests/sample_image/90_200.jpg\",\n",
|
|
"# \"backend/tests/sample_image/0_700.jpg\",\n",
|
|
"# \"backend/tests/sample_image/90_700.jpg\",\n",
|
|
"#]\n",
|
|
"\n",
|
|
"#file_paths = [\"backend/tests/sample_image/mount.jpeg.jpg\"]\n",
|
|
"\n",
|
|
"#file_paths = [\n",
|
|
"# \"backend/tests/sample_image/bb_raster_90.jpg\"\n",
|
|
"#]\n",
|
|
"\n",
|
|
"file_paths = [\"backend/tests/sample_image/after_dc.jpeg.jpg\"]\n",
|
|
"\n",
|
|
"\n",
|
|
"\n",
|
|
"# Base URL for the upload endpoint\n",
|
|
"url = f\"https://127.0.0.1:8000/samples/{sample_id}/upload-images\"\n",
|
|
"\n",
|
|
"# Iterate through each file and upload it\n",
|
|
"for file_path in file_paths:\n",
|
|
" # Determine file name and MIME type\n",
|
|
" filename = os.path.basename(file_path)\n",
|
|
" mime_type, _ = mimetypes.guess_type(file_path)\n",
|
|
" if mime_type is None:\n",
|
|
" mime_type = \"application/octet-stream\"\n",
|
|
"\n",
|
|
" # Open the file for uploading\n",
|
|
" with open(file_path, \"rb\") as file_data:\n",
|
|
" files = {\n",
|
|
" # Use key \"uploaded_file\" as required by your API\n",
|
|
" \"uploaded_file\": (filename, file_data, mime_type)\n",
|
|
" }\n",
|
|
" headers = {\n",
|
|
" \"accept\": \"application/json\"\n",
|
|
" }\n",
|
|
"\n",
|
|
" # Send the POST request\n",
|
|
" print(f\"Uploading {filename}...\")\n",
|
|
" response = requests.post(url, headers=headers, files=files, verify=False)\n",
|
|
"\n",
|
|
" # Check the API response\n",
|
|
" print(f\"API Response for {filename}:\")\n",
|
|
" print(response.status_code)\n",
|
|
" try:\n",
|
|
" print(response.json())\n",
|
|
" except Exception:\n",
|
|
" print(response.text)\n"
|
|
],
|
|
"id": "11f62976d2e7d9b1",
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"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/204/upload-images HTTP/1.1\" 200 205\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Uploading after_dc.jpeg.jpg...\n",
|
|
"API Response for after_dc.jpeg.jpg:\n",
|
|
"200\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": 16
|
|
},
|
|
{
|
|
"metadata": {},
|
|
"cell_type": "code",
|
|
"outputs": [],
|
|
"execution_count": null,
|
|
"source": "help(api_instance.upload_sample_images_samples_samples_sample_id_upload_images_post)",
|
|
"id": "cb1b99e6327fff84"
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-04-30T14:32:12.061767Z",
|
|
"start_time": "2025-04-30T14:32:12.043500Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"# post experiment results to sample database\n",
|
|
"\n",
|
|
"from aareDBclient.models import (\n",
|
|
" ExperimentParametersCreate,\n",
|
|
" RotationParameters,\n",
|
|
" BeamlineParameters,\n",
|
|
" GridScanParamers,\n",
|
|
" Detector\n",
|
|
")\n",
|
|
"\n",
|
|
"\n",
|
|
"# Build the nested parameters\n",
|
|
"rotation = RotationParameters(\n",
|
|
" omegaStart_deg=0.0,\n",
|
|
" omegaStep=0.2,\n",
|
|
" phi=10.0,\n",
|
|
" chi=0.0,\n",
|
|
" numberOfImages=1800,\n",
|
|
" exposureTime_s=0.01\n",
|
|
")\n",
|
|
"\n",
|
|
"#characterization = characterizationParameters(\n",
|
|
"# omegaStart_deg=0.0,\n",
|
|
"# omegaStep=90.0,\n",
|
|
"# oscillation_deg=1.0,\n",
|
|
"# phi=10.0,\n",
|
|
"# chi=0.0,\n",
|
|
"# numberOfImages=4,\n",
|
|
"# exposureTime_s=0.02\n",
|
|
"#)\n",
|
|
"\n",
|
|
"#gridscan = GridScanParamers(\n",
|
|
"# xStart=90.0,\n",
|
|
"# xStep=0.1,\n",
|
|
"# yStart=0.0,\n",
|
|
"# yStep= 0.1,\n",
|
|
"# zStart=0.0,\n",
|
|
"# zStep=0.0,\n",
|
|
"# numberOfImages=4600,\n",
|
|
"# exposureTime_s=0.001\n",
|
|
"#)\n",
|
|
"\n",
|
|
"# 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 = Detector(\n",
|
|
" manufacturer=\"DECTRIS\",\n",
|
|
" model=\"PILATUS4 2M\",\n",
|
|
" type=\"photon-counting\",\n",
|
|
" serialNumber=\"16684dscsd668468\",\n",
|
|
" detectorDistance_mm=232.0,\n",
|
|
" beamCenterX_px=768.0,\n",
|
|
" beamCenterY_px=857.0,\n",
|
|
" pixelSizeX_um=150.0,\n",
|
|
" pixelSizeY_um=150.0,\n",
|
|
")\n",
|
|
"\n",
|
|
"beamline_params = BeamlineParameters(\n",
|
|
" synchrotron=\"Swiss Light Source\",\n",
|
|
" beamline=\"PXIII\",\n",
|
|
" detector=detector_data,\n",
|
|
" wavelength=1.033,\n",
|
|
" ringCurrent_A=0.4,\n",
|
|
" ringMode=\"Machine Development\",\n",
|
|
" monochromator=\"Si111\",\n",
|
|
" transmission=10.00,\n",
|
|
" focusingOptic=\"Kirkpatrick-Baez\",\n",
|
|
" beamlineFluxAtSample_ph_s=0,\n",
|
|
" beamSizeWidth=30.0,\n",
|
|
" beamSizeHeight=30.0,\n",
|
|
" #characterization=characterization\n",
|
|
" rotation=rotation # Optional nested parameter\n",
|
|
" #gridScan=gridscan\n",
|
|
" # gridScan and jet are optional and can be added similarly\n",
|
|
")\n",
|
|
"\n",
|
|
"# Prepare the experiment parameters payload.\n",
|
|
"# Note that the run_number will be set on the server side, so you can leave\n",
|
|
"# 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",
|
|
"\n",
|
|
"# Now, use the API instance to send the POST request\n",
|
|
"with aareDBclient.ApiClient(configuration) as api_client:\n",
|
|
" api_instance = aareDBclient.SamplesApi(api_client)\n",
|
|
"\n",
|
|
" try:\n",
|
|
" # Call the endpoint. The endpoint path expects the sample_id.\n",
|
|
" api_response = api_instance.create_experiment_parameters_for_sample(\n",
|
|
" sample_id=experiment_params_payload.sample_id,\n",
|
|
" experiment_parameters_create=experiment_params_payload\n",
|
|
")\n",
|
|
"\n",
|
|
" print(\"API Response:\")\n",
|
|
" print(api_response)\n",
|
|
" except ApiException as e:\n",
|
|
" print(\"Exception when calling ExperimentParametersApi->create_experiment_parameters_for_sample:\")\n",
|
|
" print(e)\n"
|
|
],
|
|
"id": "421ba0710f29a5fa",
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"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 905\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"API Response:\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": 26
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-04-30T14:32:24.370041Z",
|
|
"start_time": "2025-04-30T14:32:24.347435Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"from datetime import datetime\n",
|
|
"\n",
|
|
"sample_id = sample_id\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",
|
|
" dataset_payload = {\n",
|
|
" \"filepath\": \"/das/work/p11/p11206/raw_data/vincent/20250415_6D_SLS2_1st_data/20250415_fullbeam_dtz220_Lyso102_again_360deg\",\n",
|
|
" \"status\": \"written\",\n",
|
|
" \"written_at\": datetime.now().isoformat()\n",
|
|
" }\n",
|
|
"\n",
|
|
" # The API method and argument names may differ if autogenerated — adjust accordingly\n",
|
|
" with aareDBclient.ApiClient(configuration) as api_client:\n",
|
|
" api_instance = aareDBclient.SamplesApi(api_client)\n",
|
|
" try:\n",
|
|
" api_response = api_instance.update_dataset_for_experiment_run(\n",
|
|
" sample_id=sample_id, run_id=run_id, datasets=dataset_payload\n",
|
|
" )\n",
|
|
" print(\"Dataset updated successfully:\")\n",
|
|
" print(api_response)\n",
|
|
" except ApiException as e:\n",
|
|
" print(f\"API call failed: {e}\")\n",
|
|
"\n",
|
|
"# Usage example (replace with your actual IDs and configuration):\n",
|
|
"test_mark_run_written(sample_id, run_id, configuration)"
|
|
],
|
|
"id": "77793ecd843c1ef3",
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"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/10 HTTP/1.1\" 200 1086\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Dataset updated successfully:\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": 27
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-04-29T08:37:38.265277Z",
|
|
"start_time": "2025-04-29T08:37:38.237143Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"from app.schemas import CurvePoint\n",
|
|
"# %%\n",
|
|
"from app.schemas import ResultCreate, Results\n",
|
|
"from pprint import pprint\n",
|
|
"import random\n",
|
|
"import math\n",
|
|
"import aareDBclient\n",
|
|
"from aareDBclient.rest import ApiException\n",
|
|
"\n",
|
|
"# Your actual sample and experiment IDs\n",
|
|
"sample_id = sample_id # Replace with valid IDs\n",
|
|
"run_id = 3 # Replace with valid run_id\n",
|
|
"\n",
|
|
"# Function to generate list of CurvePoint (resolution, value pairs)\n",
|
|
"def logarithmic_decay_curve(length, min_res=4.0, max_res=1.0, max_value=1.0, min_value=0.0, noise=0.005, decimals=3):\n",
|
|
" resolutions = sorted([round(random.uniform(min_res, max_res), decimals) for _ in range(length)], reverse=True) # Reverse order\n",
|
|
"\n",
|
|
" curve = []\n",
|
|
" for res in resolutions:\n",
|
|
" # Exponential-like decay: Higher resolution (small number) -> value ~1, Lower resolution (big number) -> value ~0\n",
|
|
" decay_factor = (res - max_res) / (min_res - max_res) # Normalize res to [0,1]\n",
|
|
" value = max_value - ( math.exp(- 20 * decay_factor ) ) # Exponential decay\n",
|
|
"\n",
|
|
" # Add small random noise for realism\n",
|
|
" noise_value = random.uniform(-noise, noise)\n",
|
|
" value = min(max(value + noise_value, min_value), max_value) # Clamp between min_value and max_value\n",
|
|
"\n",
|
|
" curve.append(CurvePoint(resolution=res, value=round(value, decimals)))\n",
|
|
"\n",
|
|
" return curve\n",
|
|
"\n",
|
|
"# Create random Results payload\n",
|
|
"results_data = Results(\n",
|
|
" pipeline=\"autoproc\",\n",
|
|
" resolution=round(random.uniform(1.0, 4.0), 2),\n",
|
|
" unit_cell=f\"{random.uniform(20, 120):.2f}, {random.uniform(20, 120):.2f}, \"\n",
|
|
" f\"{random.uniform(20, 120):.2f}, {random.uniform(60, 120):.2f}, \"\n",
|
|
" f\"{random.uniform(60, 120):.2f}, {random.uniform(60, 120):.2f}\",\n",
|
|
" spacegroup=random.choice(['P212121', 'C2', 'P1', 'P21', 'P21212', 'P41212']),\n",
|
|
" rmerge=round(random.uniform(0.02, 0.10), 3),\n",
|
|
" rmeas=round(random.uniform(0.02, 0.15), 3),\n",
|
|
" isig=round(random.uniform(1.0, 30.0), 2),\n",
|
|
" cc=logarithmic_decay_curve(100), # List of CurvePoint for CC curve\n",
|
|
" cchalf=logarithmic_decay_curve(100), # List of CurvePoint for CC(1/2) curve\n",
|
|
" completeness=round(random.uniform(85.0, 100.0), 2),\n",
|
|
" multiplicity=round(random.uniform(1.0, 10.0), 2),\n",
|
|
" nobs=random.randint(10000, 500000),\n",
|
|
" total_refl=random.randint(5000, 250000),\n",
|
|
" unique_refl=random.randint(5000, 100000),\n",
|
|
" comments=\"Random auto-generated test entry\"\n",
|
|
")\n",
|
|
"\n",
|
|
"payload = ResultCreate(sample_id=sample_id, run_id=run_id, result=results_data)\n",
|
|
"\n",
|
|
"# correct serialization, passing exact required dict structure\n",
|
|
"payload_dict = {\n",
|
|
" \"sample_id\": sample_id,\n",
|
|
" \"run_id\": run_id,\n",
|
|
" \"result\": results_data.model_dump(),\n",
|
|
"}\n",
|
|
"\n",
|
|
"with aareDBclient.ApiClient(configuration) as api_client:\n",
|
|
" api_instance = aareDBclient.SamplesApi(api_client)\n",
|
|
"\n",
|
|
" try:\n",
|
|
" api_response = api_instance.create_result(\n",
|
|
" result_create=payload_dict\n",
|
|
" )\n",
|
|
"\n",
|
|
" print(\"API call successful:\")\n",
|
|
" pprint(api_response)\n",
|
|
"\n",
|
|
" except ApiException as e:\n",
|
|
" print(f\"API call failed: {e}\")\n"
|
|
],
|
|
"id": "3e3974d5df795c32",
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"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/processing-results HTTP/1.1\" 200 7199\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"API call successful:\n",
|
|
"ResultResponse(id=1, sample_id=243, run_id=3, result=Results(pipeline='autoproc', resolution=1.47, unit_cell='93.58, 89.37, 32.51, 60.74, 112.89, 91.46', spacegroup='C2', rmerge=0.097, rmeas=0.093, isig=6.21, cc=[CurvePoint(resolution=3.983, value=1.0), CurvePoint(resolution=3.965, value=1.0), CurvePoint(resolution=3.939, value=0.995), CurvePoint(resolution=3.907, value=0.998), CurvePoint(resolution=3.813, value=0.996), CurvePoint(resolution=3.756, value=0.997), CurvePoint(resolution=3.737, value=1.0), CurvePoint(resolution=3.708, value=1.0), CurvePoint(resolution=3.706, value=1.0), CurvePoint(resolution=3.701, value=0.996), CurvePoint(resolution=3.674, value=0.999), CurvePoint(resolution=3.65, value=0.997), CurvePoint(resolution=3.6, value=0.998), CurvePoint(resolution=3.563, value=0.997), CurvePoint(resolution=3.519, value=0.997), CurvePoint(resolution=3.386, value=0.999), CurvePoint(resolution=3.377, value=0.997), CurvePoint(resolution=3.375, value=1.0), CurvePoint(resolution=3.253, value=0.995), CurvePoint(resolution=3.221, value=0.996), CurvePoint(resolution=3.194, value=0.999), CurvePoint(resolution=3.182, value=0.999), CurvePoint(resolution=3.149, value=0.998), CurvePoint(resolution=3.128, value=0.998), CurvePoint(resolution=3.115, value=0.998), CurvePoint(resolution=3.101, value=0.999), CurvePoint(resolution=3.072, value=0.997), CurvePoint(resolution=3.018, value=0.999), CurvePoint(resolution=3.013, value=1.0), CurvePoint(resolution=2.96, value=1.0), CurvePoint(resolution=2.935, value=1.0), CurvePoint(resolution=2.882, value=1.0), CurvePoint(resolution=2.866, value=1.0), CurvePoint(resolution=2.855, value=1.0), CurvePoint(resolution=2.695, value=1.0), CurvePoint(resolution=2.689, value=1.0), CurvePoint(resolution=2.628, value=1.0), CurvePoint(resolution=2.62, value=0.997), CurvePoint(resolution=2.595, value=0.997), CurvePoint(resolution=2.563, value=0.996), CurvePoint(resolution=2.562, value=1.0), CurvePoint(resolution=2.559, value=1.0), CurvePoint(resolution=2.542, value=1.0), CurvePoint(resolution=2.518, value=0.998), CurvePoint(resolution=2.477, value=1.0), CurvePoint(resolution=2.395, value=1.0), CurvePoint(resolution=2.388, value=0.997), CurvePoint(resolution=2.388, value=0.996), CurvePoint(resolution=2.37, value=0.999), CurvePoint(resolution=2.361, value=0.995), CurvePoint(resolution=2.359, value=0.995), CurvePoint(resolution=2.356, value=0.998), CurvePoint(resolution=2.33, value=1.0), CurvePoint(resolution=2.25, value=0.996), CurvePoint(resolution=2.246, value=0.998), CurvePoint(resolution=2.242, value=1.0), CurvePoint(resolution=2.2, value=0.995), CurvePoint(resolution=2.18, value=1.0), CurvePoint(resolution=2.165, value=1.0), CurvePoint(resolution=2.154, value=1.0), CurvePoint(resolution=2.146, value=1.0), CurvePoint(resolution=2.036, value=1.0), CurvePoint(resolution=1.995, value=1.0), CurvePoint(resolution=1.958, value=0.996), CurvePoint(resolution=1.915, value=1.0), CurvePoint(resolution=1.912, value=0.996), CurvePoint(resolution=1.866, value=0.996), CurvePoint(resolution=1.779, value=0.99), CurvePoint(resolution=1.751, value=0.994), CurvePoint(resolution=1.75, value=0.989), CurvePoint(resolution=1.739, value=0.994), CurvePoint(resolution=1.69, value=0.993), CurvePoint(resolution=1.665, value=0.985), CurvePoint(resolution=1.662, value=0.987), CurvePoint(resolution=1.613, value=0.979), CurvePoint(resolution=1.609, value=0.981), CurvePoint(resolution=1.545, value=0.97), CurvePoint(resolution=1.49, value=0.963), CurvePoint(resolution=1.476, value=0.956), CurvePoint(resolution=1.468, value=0.956), CurvePoint(resolution=1.447, value=0.947), CurvePoint(resolution=1.422, value=0.944), CurvePoint(resolution=1.413, value=0.94), CurvePoint(resolution=1.403, value=0.927), CurvePoint(resolution=1.403, value=0.934), CurvePoint(resolution=1.368, value=0.915), CurvePoint(resolution=1.35, value=0.906), CurvePoint(resolution=1.229, value=0.784), CurvePoint(resolution=1.212, value=0.757), CurvePoint(resolution=1.206, value=0.749), CurvePoint(resolution=1.192, value=0.719), CurvePoint(resolution=1.144, value=0.613), CurvePoint(resolution=1.144, value=0.616), CurvePoint(resolution=1.138, value=0.605), CurvePoint(resolution=1.124, value=0.56), CurvePoint(resolution=1.104, value=0.504), CurvePoint(resolution=1.082, value=0.424), CurvePoint(resolution=1.079, value=0.407), CurvePoint(resolution=1.026, value=0.162), CurvePoint(resolution=1.0, value=0.005)], cchalf=[CurvePoint(resolution=3.988, value=0.997), CurvePoint(resolution=3.959, value=1.0), CurvePoint(resolution=3.886, value=1.0), CurvePoint(resolution=3.828, value=1.0), CurvePoint(resolution=3.814, value=0.996), CurvePoint(resolution=3.756, value=0.997), CurvePoint(resolution=3.721, value=1.0), CurvePoint(resolution=3.696, value=0.996), CurvePoint(resolution=3.67, value=0.996), CurvePoint(resolution=3.631, value=0.997), CurvePoint(resolution=3.607, value=0.998), CurvePoint(resolution=3.556, value=1.0), CurvePoint(resolution=3.549, value=0.995), CurvePoint(resolution=3.539, value=1.0), CurvePoint(resolution=3.538, value=1.0), CurvePoint(resolution=3.517, value=1.0), CurvePoint(resolution=3.514, value=1.0), CurvePoint(resolution=3.463, value=1.0), CurvePoint(resolution=3.434, value=0.999), CurvePoint(resolution=3.433, value=1.0), CurvePoint(resolution=3.419, value=1.0), CurvePoint(resolution=3.409, value=0.999), CurvePoint(resolution=3.389, value=0.997), CurvePoint(resolution=3.384, value=0.995), CurvePoint(resolution=3.355, value=0.996), CurvePoint(resolution=3.273, value=0.998), CurvePoint(resolution=3.239, value=1.0), CurvePoint(resolution=3.235, value=1.0), CurvePoint(resolution=3.23, value=0.996), CurvePoint(resolution=3.229, value=0.998), CurvePoint(resolution=3.222, value=1.0), CurvePoint(resolution=3.208, value=1.0), CurvePoint(resolution=3.133, value=0.998), CurvePoint(resolution=3.107, value=1.0), CurvePoint(resolution=3.106, value=0.996), CurvePoint(resolution=3.072, value=1.0), CurvePoint(resolution=3.005, value=0.997), CurvePoint(resolution=2.974, value=0.999), CurvePoint(resolution=2.947, value=1.0), CurvePoint(resolution=2.901, value=0.996), CurvePoint(resolution=2.874, value=0.998), CurvePoint(resolution=2.849, value=0.997), CurvePoint(resolution=2.842, value=0.996), CurvePoint(resolution=2.812, value=1.0), CurvePoint(resolution=2.79, value=1.0), CurvePoint(resolution=2.741, value=0.995), CurvePoint(resolution=2.719, value=1.0), CurvePoint(resolution=2.704, value=1.0), CurvePoint(resolution=2.695, value=0.997), CurvePoint(resolution=2.625, value=1.0), CurvePoint(resolution=2.624, value=1.0), CurvePoint(resolution=2.519, value=1.0), CurvePoint(resolution=2.518, value=1.0), CurvePoint(resolution=2.493, value=0.996), CurvePoint(resolution=2.457, value=0.997), CurvePoint(resolution=2.436, value=0.997), CurvePoint(resolution=2.427, value=1.0), CurvePoint(resolution=2.419, value=0.995), CurvePoint(resolution=2.348, value=0.996), CurvePoint(resolution=2.293, value=1.0), CurvePoint(resolution=2.29, value=0.999), CurvePoint(resolution=2.226, value=1.0), CurvePoint(resolution=2.137, value=0.995), CurvePoint(resolution=2.114, value=0.998), CurvePoint(resolution=2.064, value=1.0), CurvePoint(resolution=2.052, value=1.0), CurvePoint(resolution=2.05, value=1.0), CurvePoint(resolution=2.04, value=1.0), CurvePoint(resolution=2.031, value=1.0), CurvePoint(resolution=1.995, value=0.996), CurvePoint(resolution=1.986, value=1.0), CurvePoint(resolution=1.97, value=0.998), CurvePoint(resolution=1.966, value=1.0), CurvePoint(resolution=1.929, value=0.996), CurvePoint(resolution=1.854, value=0.995), CurvePoint(resolution=1.845, value=0.996), CurvePoint(resolution=1.823, value=0.995), CurvePoint(resolution=1.744, value=0.995), CurvePoint(resolution=1.732, value=0.989), CurvePoint(resolution=1.722, value=0.989), CurvePoint(resolution=1.711, value=0.994), CurvePoint(resolution=1.707, value=0.992), CurvePoint(resolution=1.555, value=0.98), CurvePoint(resolution=1.505, value=0.963), CurvePoint(resolution=1.459, value=0.958), CurvePoint(resolution=1.426, value=0.938), CurvePoint(resolution=1.419, value=0.943), CurvePoint(resolution=1.406, value=0.935), CurvePoint(resolution=1.396, value=0.929), CurvePoint(resolution=1.378, value=0.918), CurvePoint(resolution=1.308, value=0.874), CurvePoint(resolution=1.252, value=0.815), CurvePoint(resolution=1.212, value=0.756), CurvePoint(resolution=1.192, value=0.719), CurvePoint(resolution=1.189, value=0.719), CurvePoint(resolution=1.144, value=0.616), CurvePoint(resolution=1.143, value=0.617), CurvePoint(resolution=1.111, value=0.521), CurvePoint(resolution=1.095, value=0.471), CurvePoint(resolution=1.023, value=0.139)], completeness=94.67, multiplicity=8.01, nobs=263890, total_refl=142999, unique_refl=47873, comments='Random auto-generated test entry'))\n"
|
|
]
|
|
}
|
|
],
|
|
"execution_count": 8
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-03-17T21:11:17.101900Z",
|
|
"start_time": "2025-03-17T21:11:17.053250Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"# get experiment results to sample database\n",
|
|
"\n",
|
|
"with aareDBclient.ApiClient(configuration) as api_client:\n",
|
|
" # Create an instance of the API class\n",
|
|
" api_instance = aareDBclient.SamplesApi(api_client)\n",
|
|
"\n",
|
|
" # GET request: Fetch all pucks in the tell\n",
|
|
" try:\n",
|
|
" # Call the API method to fetch pucks\n",
|
|
" all_results_response = api_instance.get_sample_results_samples_results_get(active_pgroup=\"p20003\")\n",
|
|
" pprint(all_results_response)\n",
|
|
" ## Debug response structure by printing it in JSON format\n",
|
|
" #formatted_response = json.dumps(\n",
|
|
" # [p.to_dict() for p in all_results_response], # Assuming the API response can be converted to dicts\n",
|
|
" # indent=4 # Use indentation for readability\n",
|
|
" #)\n",
|
|
" #print(\"The response of PucksApi->get_all_pucks_in_tell (formatted):\\n\")\n",
|
|
" #print(formatted_response)\n",
|
|
"\n",
|
|
" ## Iterate through each puck and print information\n",
|
|
" #for p in all_results_response:\n",
|
|
" # print(f\"Puck ID: {p.id}, Puck Name: {p.puck_name}\")\n",
|
|
" #\n",
|
|
" # ## Check if the puck has any samples\n",
|
|
" # if hasattr(p, 'samples') and p.samples: # Ensure 'samples' attribute exists and is not empty\n",
|
|
" # for sample in p.samples:\n",
|
|
" # print(f\" Sample ID: {sample.id}, Sample Name: {sample.sample_name}, Position: {sample.position}, Mount count: {sample.mount_count}\")\n",
|
|
" # else:\n",
|
|
" # print(\" No samples found in this puck.\")\n",
|
|
" #\n",
|
|
" except ApiException as e:\n",
|
|
" print(\"Exception when calling PucksApi->get_all_pucks_in_tell: %s\\n\" % e)"
|
|
],
|
|
"id": "6079a4f10102e906",
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): 127.0.0.1:8000\n",
|
|
"/Users/gotthardg/PycharmProjects/aaredb/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py:1097: 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 \"GET /samples/results?active_pgroup=p20003 HTTP/1.1\" 200 7927\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"[SampleResult(sample_id=215, sample_name='Sample215', puck_name='PKK004', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=216, sample_name='Sample216', puck_name='PKK004', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=217, sample_name='Sample217', puck_name='PKK005', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=218, sample_name='Sample218', puck_name='PKK005', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=219, sample_name='Sample219', puck_name='PKK005', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=220, sample_name='Sample220', puck_name='PKK005', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=221, sample_name='Sample221', puck_name='PKK005', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=222, sample_name='Sample222', puck_name='PKK005', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=223, sample_name='Sample223', puck_name='PKK005', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=224, sample_name='Sample224', puck_name='PKK005', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=225, sample_name='Sample225', puck_name='PKK005', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=226, sample_name='Sample226', puck_name='PKK005', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=227, sample_name='Sample227', puck_name='PKK005', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=228, sample_name='Sample228', puck_name='PKK005', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=229, sample_name='Sample229', puck_name='PKK005', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=230, sample_name='Sample230', puck_name='PKK005', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=231, sample_name='Sample231', puck_name='PKK006', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=232, sample_name='Sample232', puck_name='PKK006', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=233, sample_name='Sample233', puck_name='PKK006', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=234, sample_name='Sample234', puck_name='PKK006', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=235, sample_name='Sample235', puck_name='PKK006', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=236, sample_name='Sample236', puck_name='PKK007', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=237, sample_name='Sample237', puck_name='PKK007', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=238, sample_name='Sample238', puck_name='PKK007', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=239, sample_name='Sample239', puck_name='PKK007', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=240, sample_name='Sample240', puck_name='PKK007', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=241, sample_name='Sample241', puck_name='PKK007', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=242, sample_name='Sample242', puck_name='PKK007', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=243, sample_name='Sample243', puck_name='PKK007', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=244, sample_name='Sample244', puck_name='PKK007', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=245, sample_name='Sample245', puck_name='PKK007', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=246, sample_name='Sample246', puck_name='PKK007', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n",
|
|
" SampleResult(sample_id=247, sample_name='Sample247', puck_name='PKK007', dewar_name='Dewar Five', images=[ImageInfo(id=1, filepath='images/p20003/2025-03-14/Dewar Five/PKK007/16/Mounting_2025-03-13_13-39-00/mount.jpeg.jpg', comment=None, event_type='Mounting'), ImageInfo(id=2, filepath='images/p20003/2025-03-14/Dewar Five/PKK007/16/Centering_2025-03-14_20-35-49/0_200.jpg', comment=None, event_type='Centering'), ImageInfo(id=3, filepath='images/p20003/2025-03-14/Dewar Five/PKK007/16/Centering_2025-03-14_20-35-49/90_200.jpg', comment=None, event_type='Centering'), ImageInfo(id=4, filepath='images/p20003/2025-03-14/Dewar Five/PKK007/16/Centering_2025-03-14_20-35-49/0_700.jpg', comment=None, event_type='Centering'), ImageInfo(id=5, filepath='images/p20003/2025-03-14/Dewar Five/PKK007/16/Centering_2025-03-14_20-35-49/90_700.jpg', comment=None, event_type='Centering'), ImageInfo(id=6, filepath='images/p20003/2025-03-14/Dewar Five/PKK007/16/Collecting_2025-03-14_20-37-45/bb_raster_0.jpg', comment=None, event_type='Collecting'), ImageInfo(id=7, filepath='images/p20003/2025-03-14/Dewar Five/PKK007/16/Collecting_2025-03-14_20-54-05/bb_raster_90.jpg', comment=None, event_type='Collecting'), ImageInfo(id=8, filepath='images/p20003/2025-03-14/Dewar Five/PKK007/16/Collecting_2025-03-14_20-54-48/after_dc.jpeg.jpg', comment=None, event_type='Collecting')], experiment_runs=[ExperimentParametersRead(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=None, grid_scan=GridScanParamers(x_start=0.0, x_step=0.1, y_start=0.0, y_step=0.1, z_start=0.0, z_step=0.0, number_of_images=4600, exposure_time_s=0.001), jet=None, cryojet_temperature_k=None, humidifier_temperature_k=None, humidifier_humidity=None), sample_id=247, id=1), ExperimentParametersRead(run_number=2, 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=None, grid_scan=GridScanParamers(x_start=90.0, x_step=0.1, y_start=0.0, y_step=0.1, z_start=0.0, z_step=0.0, number_of_images=4600, exposure_time_s=0.001), jet=None, cryojet_temperature_k=None, humidifier_temperature_k=None, humidifier_humidity=None), sample_id=247, id=2), ExperimentParametersRead(run_number=3, 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), sample_id=247, id=3)])]\n"
|
|
]
|
|
}
|
|
],
|
|
"execution_count": 6
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-04-28T19:27:24.672540Z",
|
|
"start_time": "2025-04-28T19:25:49.421881Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"import requests\n",
|
|
"import sseclient\n",
|
|
"import json\n",
|
|
"\n",
|
|
"# Replace clearly according to backend\n",
|
|
"SSE_URL = \"https://127.0.0.1:8000/processing/jobs/stream\"\n",
|
|
"#SSE_URL = \"https://mx-aare-test.psi.ch:1492/processing/jobs/stream\"\n",
|
|
"\n",
|
|
"\n",
|
|
"def listen_and_process_jobs(url):\n",
|
|
" print(\"Starting processing pipeline...\")\n",
|
|
" with requests.get(url, stream=True, verify=False) as response:\n",
|
|
" if response.status_code != 200:\n",
|
|
" print(f\"Failed to connect with status code: {response.status_code}\")\n",
|
|
" return\n",
|
|
"\n",
|
|
" client = sseclient.SSEClient(response)\n",
|
|
"\n",
|
|
" for event in client.events():\n",
|
|
" try:\n",
|
|
" jobs = json.loads(event.data)\n",
|
|
" print(f\"Jobs received: {jobs}\")\n",
|
|
"\n",
|
|
" for job in jobs:\n",
|
|
" job_id = job[\"id\"]\n",
|
|
" parameters = job[\"parameters\"]\n",
|
|
" print(f\"Processing job ID: {job_id} with parameters: {parameters}\")\n",
|
|
"\n",
|
|
" # TODO: your custom job-processing logic clearly goes here\n",
|
|
" process_job_logic(job_id, parameters)\n",
|
|
"\n",
|
|
" # After job processing completes, send results & update job status\n",
|
|
" submit_job_result(job_id, processing_result={'success': True})\n",
|
|
" except json.JSONDecodeError as e:\n",
|
|
" print(f\"Error decoding event data: {e}\")\n",
|
|
"\n",
|
|
"\n",
|
|
"def process_job_logic(job_id, parameters):\n",
|
|
" # Here: insert your application-specific processing logic\n",
|
|
" print(f\"📦 {job_id} - Processing detailed logic clearly here: {parameters}\")\n",
|
|
" # simulate execution:\n",
|
|
" import time\n",
|
|
" time.sleep(5) # Simulating task clearly\n",
|
|
" print(f\"✅ Job {job_id} processing complete\")\n",
|
|
"\n",
|
|
"\n",
|
|
"def submit_job_result(job_id, processing_result):\n",
|
|
" # Using autogenerated client or direct HTTP calls clearly:\n",
|
|
" import backend.aareDBclient as aareDBclient\n",
|
|
" from aareDBclient.models import ResultCreate\n",
|
|
"\n",
|
|
" configuration = aareDBclient.Configuration(\n",
|
|
" host=\"https://127.0.0.1:8000\",\n",
|
|
" verify_ssl=False\n",
|
|
" )\n",
|
|
"\n",
|
|
" with aareDBclient.ApiClient(configuration) as api_client:\n",
|
|
" api_instance = aareDBclient.ProcessingApi(api_client) # assuming this exists!\n",
|
|
"\n",
|
|
" result = ResultCreate(\n",
|
|
" job_id=job_id, # Assuming you have such a field clearly\n",
|
|
" result=processing_result\n",
|
|
" )\n",
|
|
" try:\n",
|
|
" res = api_instance.submit_processing_result(result_create=result)\n",
|
|
" print(f\"Job {job_id} result submitted successfully! Backend Response: {res}\")\n",
|
|
" except aareDBclient.rest.ApiException as e:\n",
|
|
" print(f\"Failed to submit result for Job {job_id}: {e}\")\n",
|
|
"\n",
|
|
"\n",
|
|
"if __name__ == \"__main__\":\n",
|
|
" listen_and_process_jobs(SSE_URL)\n"
|
|
],
|
|
"id": "aef43f1265a23cb1",
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"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:1097: 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 \"GET /processing/jobs/stream HTTP/1.1\" 200 None\n",
|
|
"DEBUG:sseclient:Initialized SSE client from event source <Response [200]>\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Starting processing pipeline...\n"
|
|
]
|
|
},
|
|
{
|
|
"ename": "KeyboardInterrupt",
|
|
"evalue": "",
|
|
"output_type": "error",
|
|
"traceback": [
|
|
"\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
|
|
"\u001B[0;31mKeyboardInterrupt\u001B[0m Traceback (most recent call last)",
|
|
"Cell \u001B[0;32mIn[16], line 72\u001B[0m\n\u001B[1;32m 68\u001B[0m \u001B[38;5;28mprint\u001B[39m(\u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mFailed to submit result for Job \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mjob_id\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m: \u001B[39m\u001B[38;5;132;01m{\u001B[39;00me\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m\"\u001B[39m)\n\u001B[1;32m 71\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;18m__name__\u001B[39m \u001B[38;5;241m==\u001B[39m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m__main__\u001B[39m\u001B[38;5;124m\"\u001B[39m:\n\u001B[0;32m---> 72\u001B[0m \u001B[43mlisten_and_process_jobs\u001B[49m\u001B[43m(\u001B[49m\u001B[43mSSE_URL\u001B[49m\u001B[43m)\u001B[49m\n",
|
|
"Cell \u001B[0;32mIn[16], line 19\u001B[0m, in \u001B[0;36mlisten_and_process_jobs\u001B[0;34m(url)\u001B[0m\n\u001B[1;32m 15\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m\n\u001B[1;32m 17\u001B[0m client \u001B[38;5;241m=\u001B[39m sseclient\u001B[38;5;241m.\u001B[39mSSEClient(response)\n\u001B[0;32m---> 19\u001B[0m \u001B[43m\u001B[49m\u001B[38;5;28;43;01mfor\u001B[39;49;00m\u001B[43m \u001B[49m\u001B[43mevent\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;129;43;01min\u001B[39;49;00m\u001B[43m \u001B[49m\u001B[43mclient\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mevents\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m\u001B[43m:\u001B[49m\n\u001B[1;32m 20\u001B[0m \u001B[43m \u001B[49m\u001B[38;5;28;43;01mtry\u001B[39;49;00m\u001B[43m:\u001B[49m\n\u001B[1;32m 21\u001B[0m \u001B[43m \u001B[49m\u001B[43mjobs\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43m \u001B[49m\u001B[43mjson\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mloads\u001B[49m\u001B[43m(\u001B[49m\u001B[43mevent\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mdata\u001B[49m\u001B[43m)\u001B[49m\n",
|
|
"File \u001B[0;32m/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/sseclient/__init__.py:55\u001B[0m, in \u001B[0;36mSSEClient.events\u001B[0;34m(self)\u001B[0m\n\u001B[1;32m 54\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21mevents\u001B[39m(\u001B[38;5;28mself\u001B[39m):\n\u001B[0;32m---> 55\u001B[0m \u001B[43m \u001B[49m\u001B[38;5;28;43;01mfor\u001B[39;49;00m\u001B[43m \u001B[49m\u001B[43mchunk\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;129;43;01min\u001B[39;49;00m\u001B[43m \u001B[49m\u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m_read\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m\u001B[43m:\u001B[49m\n\u001B[1;32m 56\u001B[0m \u001B[43m \u001B[49m\u001B[43mevent\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43m \u001B[49m\u001B[43mEvent\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 57\u001B[0m \u001B[43m \u001B[49m\u001B[38;5;66;43;03m# Split before decoding so splitlines() only uses \\r and \\n\u001B[39;49;00m\n",
|
|
"File \u001B[0;32m/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/sseclient/__init__.py:45\u001B[0m, in \u001B[0;36mSSEClient._read\u001B[0;34m(self)\u001B[0m\n\u001B[1;32m 38\u001B[0m \u001B[38;5;250m\u001B[39m\u001B[38;5;124;03m\"\"\"Read the incoming event source stream and yield event chunks.\u001B[39;00m\n\u001B[1;32m 39\u001B[0m \n\u001B[1;32m 40\u001B[0m \u001B[38;5;124;03mUnfortunately it is possible for some servers to decide to break an\u001B[39;00m\n\u001B[1;32m 41\u001B[0m \u001B[38;5;124;03mevent into multiple HTTP chunks in the response. It is thus necessary\u001B[39;00m\n\u001B[1;32m 42\u001B[0m \u001B[38;5;124;03mto correctly stitch together consecutive response chunks and find the\u001B[39;00m\n\u001B[1;32m 43\u001B[0m \u001B[38;5;124;03mSSE delimiter (empty new line) to yield full, correct event chunks.\"\"\"\u001B[39;00m\n\u001B[1;32m 44\u001B[0m data \u001B[38;5;241m=\u001B[39m \u001B[38;5;124mb\u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124m'\u001B[39m\n\u001B[0;32m---> 45\u001B[0m \u001B[43m\u001B[49m\u001B[38;5;28;43;01mfor\u001B[39;49;00m\u001B[43m \u001B[49m\u001B[43mchunk\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;129;43;01min\u001B[39;49;00m\u001B[43m \u001B[49m\u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m_event_source\u001B[49m\u001B[43m:\u001B[49m\n\u001B[1;32m 46\u001B[0m \u001B[43m \u001B[49m\u001B[38;5;28;43;01mfor\u001B[39;49;00m\u001B[43m \u001B[49m\u001B[43mline\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;129;43;01min\u001B[39;49;00m\u001B[43m \u001B[49m\u001B[43mchunk\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43msplitlines\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;28;43;01mTrue\u001B[39;49;00m\u001B[43m)\u001B[49m\u001B[43m:\u001B[49m\n\u001B[1;32m 47\u001B[0m \u001B[43m \u001B[49m\u001B[43mdata\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;241;43m+\u001B[39;49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43m \u001B[49m\u001B[43mline\u001B[49m\n",
|
|
"File \u001B[0;32m/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/requests/models.py:820\u001B[0m, in \u001B[0;36mResponse.iter_content.<locals>.generate\u001B[0;34m()\u001B[0m\n\u001B[1;32m 818\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28mhasattr\u001B[39m(\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mraw, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mstream\u001B[39m\u001B[38;5;124m\"\u001B[39m):\n\u001B[1;32m 819\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[0;32m--> 820\u001B[0m \u001B[38;5;28;01myield from\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mraw\u001B[38;5;241m.\u001B[39mstream(chunk_size, decode_content\u001B[38;5;241m=\u001B[39m\u001B[38;5;28;01mTrue\u001B[39;00m)\n\u001B[1;32m 821\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m ProtocolError \u001B[38;5;28;01mas\u001B[39;00m e:\n\u001B[1;32m 822\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m ChunkedEncodingError(e)\n",
|
|
"File \u001B[0;32m/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/response.py:1063\u001B[0m, in \u001B[0;36mstream\u001B[0;34m(self, amt, decode_content)\u001B[0m\n\u001B[1;32m 1059\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mauto_close:\n\u001B[1;32m 1060\u001B[0m io\u001B[38;5;241m.\u001B[39mIOBase\u001B[38;5;241m.\u001B[39mclose(\u001B[38;5;28mself\u001B[39m)\n\u001B[1;32m 1062\u001B[0m \u001B[38;5;129m@property\u001B[39m\n\u001B[0;32m-> 1063\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21mclosed\u001B[39m(\u001B[38;5;28mself\u001B[39m) \u001B[38;5;241m-\u001B[39m\u001B[38;5;241m>\u001B[39m \u001B[38;5;28mbool\u001B[39m:\n\u001B[1;32m 1064\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mauto_close:\n\u001B[1;32m 1065\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m io\u001B[38;5;241m.\u001B[39mIOBase\u001B[38;5;241m.\u001B[39mclosed\u001B[38;5;241m.\u001B[39m\u001B[38;5;21m__get__\u001B[39m(\u001B[38;5;28mself\u001B[39m) \u001B[38;5;66;03m# type: ignore[no-any-return]\u001B[39;00m\n",
|
|
"File \u001B[0;32m/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/response.py:1219\u001B[0m, in \u001B[0;36mread_chunked\u001B[0;34m(self, amt, decode_content)\u001B[0m\n\u001B[1;32m 1215\u001B[0m \u001B[38;5;129m@property\u001B[39m\n\u001B[1;32m 1216\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21murl\u001B[39m(\u001B[38;5;28mself\u001B[39m) \u001B[38;5;241m-\u001B[39m\u001B[38;5;241m>\u001B[39m \u001B[38;5;28mstr\u001B[39m \u001B[38;5;241m|\u001B[39m \u001B[38;5;28;01mNone\u001B[39;00m:\n\u001B[1;32m 1217\u001B[0m \u001B[38;5;250m \u001B[39m\u001B[38;5;124;03m\"\"\"\u001B[39;00m\n\u001B[1;32m 1218\u001B[0m \u001B[38;5;124;03m Returns the URL that was the source of this response.\u001B[39;00m\n\u001B[0;32m-> 1219\u001B[0m \u001B[38;5;124;03m If the request that generated this response redirected, this method\u001B[39;00m\n\u001B[1;32m 1220\u001B[0m \u001B[38;5;124;03m will return the final redirect location.\u001B[39;00m\n\u001B[1;32m 1221\u001B[0m \u001B[38;5;124;03m \"\"\"\u001B[39;00m\n\u001B[1;32m 1222\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_request_url\n",
|
|
"File \u001B[0;32m/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/response.py:1138\u001B[0m, in \u001B[0;36m_update_chunk_length\u001B[0;34m(self)\u001B[0m\n\u001B[1;32m 1136\u001B[0m returned_chunk \u001B[38;5;241m=\u001B[39m value\n\u001B[1;32m 1137\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m: \u001B[38;5;66;03m# amt > self.chunk_left\u001B[39;00m\n\u001B[0;32m-> 1138\u001B[0m returned_chunk \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_fp\u001B[38;5;241m.\u001B[39m_safe_read(\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mchunk_left) \u001B[38;5;66;03m# type: ignore[union-attr]\u001B[39;00m\n\u001B[1;32m 1139\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_fp\u001B[38;5;241m.\u001B[39m_safe_read(\u001B[38;5;241m2\u001B[39m) \u001B[38;5;66;03m# type: ignore[union-attr] # Toss the CRLF at the end of the chunk.\u001B[39;00m\n\u001B[1;32m 1140\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mchunk_left \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;01mNone\u001B[39;00m\n",
|
|
"File \u001B[0;32m/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/socket.py:707\u001B[0m, in \u001B[0;36mSocketIO.readinto\u001B[0;34m(self, b)\u001B[0m\n\u001B[1;32m 705\u001B[0m \u001B[38;5;28;01mwhile\u001B[39;00m \u001B[38;5;28;01mTrue\u001B[39;00m:\n\u001B[1;32m 706\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[0;32m--> 707\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m_sock\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mrecv_into\u001B[49m\u001B[43m(\u001B[49m\u001B[43mb\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 708\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m timeout:\n\u001B[1;32m 709\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_timeout_occurred \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;01mTrue\u001B[39;00m\n",
|
|
"File \u001B[0;32m/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/ssl.py:1216\u001B[0m, in \u001B[0;36mSSLSocket.recv_into\u001B[0;34m(self, buffer, nbytes, flags)\u001B[0m\n\u001B[1;32m 1212\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m flags \u001B[38;5;241m!=\u001B[39m \u001B[38;5;241m0\u001B[39m:\n\u001B[1;32m 1213\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mValueError\u001B[39;00m(\n\u001B[1;32m 1214\u001B[0m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mnon-zero flags not allowed in calls to recv_into() on \u001B[39m\u001B[38;5;132;01m%s\u001B[39;00m\u001B[38;5;124m\"\u001B[39m \u001B[38;5;241m%\u001B[39m\n\u001B[1;32m 1215\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m\u001B[38;5;18m__class__\u001B[39m)\n\u001B[0;32m-> 1216\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mread\u001B[49m\u001B[43m(\u001B[49m\u001B[43mnbytes\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mbuffer\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 1217\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[1;32m 1218\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28msuper\u001B[39m()\u001B[38;5;241m.\u001B[39mrecv_into(buffer, nbytes, flags)\n",
|
|
"File \u001B[0;32m/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/ssl.py:1072\u001B[0m, in \u001B[0;36mSSLSocket.read\u001B[0;34m(self, len, buffer)\u001B[0m\n\u001B[1;32m 1070\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[1;32m 1071\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m buffer \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m:\n\u001B[0;32m-> 1072\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m_sslobj\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mread\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;28;43mlen\u001B[39;49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mbuffer\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 1073\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[1;32m 1074\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_sslobj\u001B[38;5;241m.\u001B[39mread(\u001B[38;5;28mlen\u001B[39m)\n",
|
|
"\u001B[0;31mKeyboardInterrupt\u001B[0m: "
|
|
]
|
|
}
|
|
],
|
|
"execution_count": 16
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 2
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython2",
|
|
"version": "2.7.6"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|