From 1f6bbefaffaba49d433dda41786ff64217f36884 Mon Sep 17 00:00:00 2001 From: Philipp Schmidt <philipp.schmidt@xfel.eu> Date: Wed, 10 Apr 2024 11:36:09 +0200 Subject: [PATCH] Create Shimadzu constants first in a temporary location and copy to local storage as needed --- .../Characterize_DynamicFF_NBC.ipynb | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/notebooks/DynamicFF/Characterize_DynamicFF_NBC.ipynb b/notebooks/DynamicFF/Characterize_DynamicFF_NBC.ipynb index 2ca437be4..dc41c2ed4 100644 --- a/notebooks/DynamicFF/Characterize_DynamicFF_NBC.ipynb +++ b/notebooks/DynamicFF/Characterize_DynamicFF_NBC.ipynb @@ -47,6 +47,8 @@ "import os\n", "import warnings\n", "from logging import warning\n", + "from shutil import copyfile\n", + "from tempfile import NamedTemporaryFile\n", "\n", "warnings.filterwarnings('ignore')\n", "\n", @@ -285,7 +287,8 @@ "step_timer.start()\n", "\n", "# Output Folder Creation:\n", - "os.makedirs(out_folder, exist_ok=True)\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", @@ -307,20 +310,23 @@ " 'data': constant[\"data\"],\n", " }}}}\n", "\n", - " ofile = f\"{out_folder}/const_{constant_name}_{db_module}.h5\"\n", - " if os.path.isfile(ofile):\n", - " print(f'File {ofile} already exists and will be overwritten')\n", - "\n", - " save_dict_to_hdf5(data_to_store, ofile)\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", - "\n", - " if not local_output:\n", - " os.unlink(ofile)" + " with NamedTemporaryFile() as tempf:\n", + " save_dict_to_hdf5(data_to_store, tempf)\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", + " \n", + " if local_output:\n", + " ofile = f\"{out_folder}/const_{constant_name}_{db_module}.h5\"\n", + " \n", + " if os.path.isfile(ofile):\n", + " print(f'File {ofile} already exists and will be overwritten')\n", + " \n", + " copyfile(tempf.name, ofile)" ] }, { -- GitLab