From 8b07d324b7939cff09bd0ac37e79cc9b55031349 Mon Sep 17 00:00:00 2001 From: Egor Sobolev <egor.sobolev@xfel.eu> Date: Thu, 28 Mar 2024 11:55:06 +0100 Subject: [PATCH] Fix parameters and inject_cvv signature according to the webserver call --- .../Characterize_DynamicFF_NBC.ipynb | 67 +++++++------------ 1 file changed, 26 insertions(+), 41 deletions(-) diff --git a/notebooks/DynamicFF/Characterize_DynamicFF_NBC.ipynb b/notebooks/DynamicFF/Characterize_DynamicFF_NBC.ipynb index 40897d331..54c4412b7 100644 --- a/notebooks/DynamicFF/Characterize_DynamicFF_NBC.ipynb +++ b/notebooks/DynamicFF/Characterize_DynamicFF_NBC.ipynb @@ -20,29 +20,21 @@ "in_folder = \"/gpfs/exfel/exp/SPB/202430/p900425/raw\" # input folder, required\n", "out_folder = '/gpfs/exfel/data/scratch/esobolev/test/shimadzu' # output folder, required\n", "metadata_folder = \"\" # Directory containing calibration_metadata.yml when run by xfel-calibrate\n", - "runs = [1, 2] # list of two run numbers: dark field and flat field\n", + "run_high = 1 # run number in which dark data was recorded, required\n", + "run_low = 2 # run number in which flat-field data was recorded, required\n", + "operation_mode = \"TI_DynamicFF\" # Detector operation mode, optional (defaults to \"TI_DynamicFF\")\n", "\n", "# Data files parameters.\n", "karabo_da = ['-1'] # data aggregators\n", "karabo_id = \"SPB_MIC_HPVX2\" # karabo prefix of Shimadzu HPV-X2 devices\n", "\n", - "#receiver_id = \"PNCCD_FMT-0\" # inset for receiver devices\n", - "#path_template = 'RAW-R{:04d}-{}-S{{:05d}}.h5' # the template to use to access data\n", - "#instrument_source_template = 'SPB_EHD_MIC/CAM/HPVX2_{module}:daqOutput' # data source path in h5file.\n", - "#instrument_source_template = 'SPB_EHD_HPVX2_{module}/CAM/CAMERA:daqOutput'\n", - "#image_key = \"data.image.pixels\" # image data key in Karabo or exdf notation\n", - "\n", - "#db_module_template = \"Shimadzu_HPVX2_{}\"\n", - "\n", "# Database access parameters.\n", - "use_dir_creation_date = True # use dir creation date as data production reference date\n", "cal_db_interface = \"tcp://max-exfl-cal001:8021\" # calibration DB interface to use\n", - "cal_db_timeout = 300000 # timeout on caldb requests\n", "db_output = True # if True, the notebook sends dark constants to the calibration database\n", "local_output = True # if True, the notebook saves dark constants locally\n", - "creation_time = \"\" # To overwrite the measured creation_time. Required Format: YYYY-MM-DD HR:MN:SC.00 e.g. 2019-07-04 11:02:41.00\n", "\n", - "n_components = 50 # Number of principal components to compute" + "# Calibration constants parameters\n", + "n_components = 50 # Number of principal components of flat-field to compute (default: 50)" ] }, { @@ -68,12 +60,9 @@ "from cal_tools.step_timing import StepTimer\n", "from cal_tools.tools import (\n", " get_dir_creation_date,\n", - "# get_pdu_from_db,\n", " get_random_db_interface,\n", " get_report,\n", - "# save_const_to_h5,\n", " save_dict_to_hdf5,\n", - "# send_to_db,\n", " run_prop_seq_from_path,\n", ")\n", "from cal_tools.restful_config import calibration_client\n", @@ -89,19 +78,6 @@ "metadata": {}, "outputs": [], "source": [ - "creation_time=None\n", - "if use_dir_creation_date:\n", - " creation_time = get_dir_creation_date(in_folder, max(runs))\n", - "\n", - "print(f\"Using {creation_time} as creation time of constant.\")\n", - "\n", - "run, proposal, seq = run_prop_seq_from_path(in_folder)\n", - "#file_loc = f'proposal: {prop}, runs: {dark_run} {flat_run}'\n", - "\n", - "# Read report path and create file location tuple to add with the injection\n", - "#file_loc = f\"proposal:{proposal} runs:\" + ' '.join(str(run) for run in runs)\n", - "\n", - "report = get_report(metadata_folder)\n", "cal_db_interface = get_random_db_interface(cal_db_interface)\n", "print(f'Calibration database interface: {cal_db_interface}')\n", "print()\n", @@ -154,7 +130,10 @@ "metadata": {}, "outputs": [], "source": [ - "dark_run = runs[0]\n", + "dark_run = run_high\n", + "dark_creation_time = get_dir_creation_date(in_folder, dark_run)\n", + "print(f\"Using {dark_creation_time} as creation time of Offset constant.\")\n", + "\n", "for da, meta in modules.items():\n", " source_name = detector.instrument_source(meta[\"module\"])\n", " image_key = detector.image_key\n", @@ -184,7 +163,9 @@ " conditions = detector.conditions(dark_dc, meta[\"module\"])\n", " module_constants = constants.setdefault(meta[\"db_module\"], {})\n", " module_constants[\"Offset\"] = dict(\n", - " conditions=conditions, data=dark, pdu_no=meta[\"pdu_no\"])\n", + " conditions=conditions, data=dark, pdu_no=meta[\"pdu_no\"],\n", + " creation_time=dark_creation_time\n", + " )\n", " step_timer.done_step(\"Process dark images\")\n", " display()\n", "\n", @@ -210,7 +191,10 @@ }, "outputs": [], "source": [ - "flat_run = runs[1]\n", + "flat_run = run_low\n", + "flat_creation_time = get_dir_creation_date(in_folder, flat_run)\n", + "print(f\"Using {flat_creation_time} as creation time of DynamicFF constant.\")\n", + "\n", "for da, meta in modules.items():\n", " source_name = detector.instrument_source(meta[\"module\"])\n", " image_key = detector.image_key\n", @@ -242,7 +226,8 @@ " conditions = detector.conditions(flat_dc, meta[\"module\"])\n", " module_constants = constants.setdefault(meta[\"db_module\"], {})\n", " module_constants[\"DynamicFF\"] = dict(\n", - " conditions=conditions, data=flat_data, pdu_no=meta[\"pdu_no\"]\n", + " conditions=conditions, data=flat_data, pdu_no=meta[\"pdu_no\"],\n", + " creation_time=flat_creation_time\n", " )\n", " step_timer.done_step(\"Process flat-field images\")\n", "\n", @@ -285,13 +270,13 @@ "# Output Folder Creation:\n", "os.makedirs(out_folder, exist_ok=True)\n", "\n", - "def inject_ccv(metadata_folder, calibration, cond, pdu, proposal, runs, const_file, begin_at):\n", - " print(\"* Send to db:\", const_file)\n", - " print(\" -\", metadata_folder)\n", + "def inject_ccv(in_folder, metadata_folder, runs, calibration, cond, pdu, const_input, begin_at):\n", + " print(\"* Send to db:\", const_input)\n", + " print(\" - in folder:\", in_folder)\n", + " print(\" - metadata folder:\", metadata_folder)\n", + " print(\" - runs:\", runs)\n", " print(\" -\", calibration)\n", " print(\" -\", cond)\n", - " print(\" - proposal\", proposal)\n", - " print(\" - runs\", runs)\n", " print(\" -\", begin_at)\n", "\n", "for db_module, module_constants in constants.items():\n", @@ -312,9 +297,9 @@ " save_dict_to_hdf5(data_to_store, ofile)\n", " if db_output:\n", " inject_ccv(\n", - " metadata_folder, constant_name, conditions,\n", - " pdus[\"data\"][constant[\"pdu_no\"]],\n", - " proposal, runs, ofile, creation_time\n", + " in_folder, metadata_folder, [dark_run, flat_run],\n", + " constant_name, conditions, pdus[\"data\"][constant[\"pdu_no\"]],\n", + " ofile, constant[\"creation_time\"]\n", " )\n", "\n", " if not local_output:\n", -- GitLab