Skip to content
Snippets Groups Projects

[Generic] Injection code for DynamicFF corrections

Merged Philipp Schmidt requested to merge feat/shimadzu-injection into feat/shimadzu-correction
All threads resolved!
3 files
+ 343
27
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -64,10 +64,12 @@
"from cal_tools.step_timing import StepTimer\n",
"from cal_tools.tools import (\n",
" get_dir_creation_date,\n",
" run_prop_seq_from_path,\n",
" save_dict_to_hdf5\n",
")\n",
"from cal_tools.restful_config import calibration_client, extra_calibration_client\n",
"from cal_tools.shimadzu import ShimadzuHPVX2\n",
"from cal_tools.constants import write_ccv, inject_ccv\n",
"\n",
"import dynflatfield as dffc\n",
"from dynflatfield.draw import plot_images, plot_camera_image"
@@ -168,7 +170,7 @@
" module_constants = constants.setdefault(meta[\"db_module\"], {})\n",
" module_constants[\"Offset\"] = dict(\n",
" conditions=conditions, data=dark, pdu_no=meta[\"pdu_no\"],\n",
" creation_time=dark_creation_time\n",
" creation_time=dark_creation_time, dims=['ss', 'fs']\n",
" )\n",
" step_timer.done_step(\"Process dark images\")\n",
" display()\n",
@@ -243,7 +245,7 @@
" module_constants = constants.setdefault(meta[\"db_module\"], {})\n",
" module_constants[\"DynamicFF\"] = dict(\n",
" conditions=conditions, data=flat_data, pdu_no=meta[\"pdu_no\"],\n",
" creation_time=flat_creation_time\n",
" creation_time=flat_creation_time, dims=['component', 'ss', 'fs']\n",
" )\n",
" step_timer.done_step(\"Process flat-field images\")\n",
"\n",
@@ -283,39 +285,27 @@
"source": [
"step_timer.start()\n",
"\n",
"_, proposal, _ = run_prop_seq_from_path(in_folder)\n",
"\n",
"# Output Folder Creation:\n",
"if local_output:\n",
" os.makedirs(out_folder, exist_ok=True)\n",
"\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(\" -\", begin_at)\n",
"\n",
"for db_module, module_constants in constants.items():\n",
" for constant_name, constant in module_constants.items():\n",
" conditions = constant[\"conditions\"]\n",
" conditions_dict = conditions.make_dict(\n",
" conditions.calibration_types[constant_name])\n",
"\n",
" data_to_store = {db_module: {constant_name: {'0': {\n",
" 'conditions': conditions_dict,\n",
" 'data': constant[\"data\"],\n",
" }}}}\n",
" pdu = pdus[\"data\"][constant[\"pdu_no\"]]\n",
"\n",
" with NamedTemporaryFile() as tempf:\n",
" save_dict_to_hdf5(data_to_store, tempf)\n",
" ccv_root = write_ccv(\n",
" tempf.name,\n",
" pdu['physical_name'], pdu['uuid'], pdu['detector_type']['name'],\n",
" constant_name, conditions, constant['creation_time'],\n",
" proposal, [dark_run, flat_run],\n",
" constant[\"data\"], constant['dims'])\n",
" \n",
" if db_output:\n",
" inject_ccv(\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",
" inject_ccv(tempf.name, ccv_root, metadata_folder)\n",
" \n",
" if local_output:\n",
" ofile = f\"{out_folder}/const_{constant_name}_{db_module}.h5\"\n",
Loading