From 337549573fb9fb4ac11f638638e3964d288a4805 Mon Sep 17 00:00:00 2001 From: Nuno Duarte <nuno.duarte@xfel.eu> Date: Mon, 26 Jun 2023 22:16:29 +0200 Subject: [PATCH] update paths of receiver slow data --- .../Characterize_Darks_ePix100_NBC.ipynb | 33 ++++++++++--- .../ePix100/Correction_ePix100_NBC.ipynb | 46 +++++++++++++------ src/cal_tools/epix100/epix100lib.py | 30 +++++++----- 3 files changed, 79 insertions(+), 30 deletions(-) diff --git a/notebooks/ePix100/Characterize_Darks_ePix100_NBC.ipynb b/notebooks/ePix100/Characterize_Darks_ePix100_NBC.ipynb index 7a174bdd7..8a2e065f8 100644 --- a/notebooks/ePix100/Characterize_Darks_ePix100_NBC.ipynb +++ b/notebooks/ePix100/Characterize_Darks_ePix100_NBC.ipynb @@ -27,14 +27,14 @@ "metadata": {}, "outputs": [], "source": [ - "in_folder = '/gpfs/exfel/exp/HED/202201/p002804/raw' # input folder, required\n", - "out_folder = '' # output folder, required\n", + "in_folder = '/gpfs/exfel/exp/MID/202330/p900329/raw' # input folder, required\n", + "out_folder = ''\n", "metadata_folder = '' # Directory containing calibration_metadata.yml when run by xfel-calibrate\n", "sequence = 0 # sequence file to use\n", - "run = 281 # which run to read data from, required\n", + "run = 106 # which run to read data from, required\n", "\n", "# Parameters for accessing the raw data.\n", - "karabo_id = \"HED_IA1_EPX100-1\" # karabo karabo_id\n", + "karabo_id = \"MID_EXP_EPIX-1\" # karabo karabo_id\n", "karabo_da = [\"EPIX01\"] # data aggregators\n", "receiver_template = \"RECEIVER\" # detector receiver template for accessing raw data files\n", "path_template = 'RAW-R{:04d}-{}-S{{:05d}}.h5' # the template to use to access data\n", @@ -75,6 +75,7 @@ "source": [ "import os\n", "import warnings\n", + "from datetime import datetime\n", "\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", @@ -173,6 +174,24 @@ "print(f\"Number of dark images to analyze: {n_trains}\")" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Get timestamp of first train\n", + "train_time_stamp = run_dir.train_timestamps()[0].astype(datetime)/1e9\n", + "train_time_stamp = datetime.fromtimestamp(train_time_stamp)\n", + "\n", + "# Acessing receiver slow data through new device configuration\n", + "if train_time_stamp > datetime(2023,5,19): # date of device upgrade\n", + " rcvr_src = f\"{karabo_id}/DET/RECEIVER\"\n", + "# Acessing receiver slow data through old device configuration\n", + "else:\n", + " rcvr_src = f\"{karabo_id}/DET/RECEIVER:daqOutput\"" + ] + }, { "cell_type": "code", "execution_count": null, @@ -181,7 +200,7 @@ "source": [ "ctrl_data = epix100lib.epix100Ctrl(\n", " run_dc=run_dir,\n", - " instrument_src=instrument_src,\n", + " rcvr_src=rcvr_src,\n", " ctrl_src=f\"{karabo_id}/DET/CONTROL\",\n", " )\n", "# Read integration time\n", @@ -212,7 +231,9 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "tags": [] + }, "outputs": [], "source": [ "# Passing repetitive code along the notebook to a function \n", diff --git a/notebooks/ePix100/Correction_ePix100_NBC.ipynb b/notebooks/ePix100/Correction_ePix100_NBC.ipynb index 57c48072c..ae2579f91 100644 --- a/notebooks/ePix100/Correction_ePix100_NBC.ipynb +++ b/notebooks/ePix100/Correction_ePix100_NBC.ipynb @@ -24,15 +24,15 @@ "metadata": {}, "outputs": [], "source": [ - "in_folder = \"/gpfs/exfel/exp/HED/202202/p003121/raw\" # input folder, required\n", - "out_folder = \"\" # output folder, required\n", + "in_folder = '/gpfs/exfel/exp/MID/202330/p900329/raw' # input folder, required\n", + "out_folder = ''\n", "metadata_folder = \"\" # Directory containing calibration_metadata.yml when run by xfel-calibrate\n", "sequences = [-1] # sequences to correct, set to -1 for all, range allowed\n", "sequences_per_node = 1 # number of sequence files per cluster node if run as slurm job, set to 0 to not run SLURM parallel\n", - "run = 156 # which run to read data from, required\n", + "run = 106 # which run to read data from, required\n", "\n", "# Parameters for accessing the raw data.\n", - "karabo_id = \"HED_IA1_EPX100-1\" # karabo karabo_id\n", + "karabo_id = \"MID_EXP_EPIX-1\" # karabo karabo_id\n", "karabo_da = \"EPIX01\" # data aggregators\n", "db_module = \"\" # module id in the database\n", "receiver_template = \"RECEIVER\" # detector receiver template for accessing raw data files\n", @@ -89,6 +89,7 @@ "import h5py\n", "import pasha as psh\n", "import numpy as np\n", + "from datetime import datetime\n", "import matplotlib.pyplot as plt\n", "from IPython.display import Latex, Markdown, display\n", "from extra_data import RunDirectory, H5File\n", @@ -189,6 +190,27 @@ "step_timer = StepTimer()" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Get timestamp of first train\n", + "train_time_stamp = run_dc.train_timestamps()[0].astype(datetime)/1e9\n", + "train_time_stamp = datetime.fromtimestamp(train_time_stamp)\n", + "\n", + "# Acessing receiver slow data through new device configuration\n", + "if train_time_stamp > datetime(2023,5,19): # date of device upgrade\n", + " rcvr_src = f\"{karabo_id}/DET/RECEIVER\"\n", + " key_prefix = 'slowdata'\n", + "# Acessing receiver slow data through old device configuration\n", + "else:\n", + " rcvr_src = f\"{karabo_id}/DET/RECEIVER:daqOutput\"\n", + " key_prefix = 'data'\n", + " " + ] + }, { "cell_type": "code", "execution_count": null, @@ -207,7 +229,7 @@ "# Read control data.\n", "ctrl_data = epix100lib.epix100Ctrl(\n", " run_dc=run_dc,\n", - " instrument_src=instrument_src,\n", + " rcvr_src=rcvr_src,\n", " ctrl_src=f\"{karabo_id}/DET/CONTROL\",\n", " )\n", "\n", @@ -250,7 +272,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -602,9 +623,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "scrolled": false - }, + "metadata": {}, "outputs": [], "source": [ "empty_seq = 0\n", @@ -646,6 +665,7 @@ " step_timer.start() # Correct data. \n", "\n", " # Overwrite seq_dc after eliminating empty trains or/and applying limited images.\n", + " slow_data_dc = seq_dc.select(rcvr_src,require_all=True).select_trains(np.s_[:corr_ntrains])\n", " seq_dc = seq_dc.select(\n", " instrument_src, \"*\", require_all=True).select_trains(np.s_[:corr_ntrains])\n", "\n", @@ -684,7 +704,7 @@ " \"digitalInputVolt\", \"guardCurr\", \"relHumidity\", \"digitalCurr\"\n", " ]\n", " for field in data_raw_fields:\n", - " field_arr = seq_dc[instrument_src, f\"data.{field}\"].ndarray()\n", + " field_arr = slow_data_dc[rcvr_src, f\"{key_prefix}.{field}\"].ndarray()\n", "\n", " outp_source.create_key(\n", " f\"data.{field}\", data=field_arr,\n", @@ -902,9 +922,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "cal_venv", "language": "python", - "name": "python3" + "name": "cal_venv" }, "language_info": { "codemirror_mode": { @@ -916,7 +936,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.12" + "version": "3.8.11" }, "latex_envs": { "LaTeX_envs_menu_present": true, diff --git a/src/cal_tools/epix100/epix100lib.py b/src/cal_tools/epix100/epix100lib.py index 9cea56634..c54002a44 100644 --- a/src/cal_tools/epix100/epix100lib.py +++ b/src/cal_tools/epix100/epix100lib.py @@ -6,16 +6,16 @@ class epix100Ctrl(): self, run_dc: extra_data.DataCollection, ctrl_src: str, - instrument_src: str, + rcvr_src: str, ): """Read epix100 parameters to use later while quering CALCAT. :param run_dir: EXtra-data RunDirectory DataCollection object. - :param ctrl_src: CONTROL source for accessing slow data. - :param instrument_src: INSTRUMENT source for accessing fast data. + :param ctrl_src: CONTROL/*/DET/CONTROL source for accessing slow data from controler. + :param rcvr_src: CONTROL/*/DET/RECEIVER source for accessing slow data from receiver. """ self.run_dc = run_dc self.ctrl_src = ctrl_src - self.instrument_src = instrument_src + self.rcvr_src = rcvr_src def get_integration_time(self): return self.run_dc[ @@ -23,12 +23,20 @@ class epix100Ctrl(): def get_temprature(self): """Get temperature value from CONTROL. - Temprature is stored in Celsius/100 units. - Therefore, we are dividing by 100 and - there is an absolute tolerance of 100. - atol=100 is a 1 degree variation tolerance. + Temprature is stored in Celsius + atol is degree variation tolerance. """ - # data.backTemp shape evolved from (n_trains,) to (n_trains, 1) + + # older device configuration + if self.rcvr_src.find('daqOutput') > 0: + atol = 100 # temperature was in C/100 + data_key = 'data.backTemp' + # new device configuration + else: + atol = 1 + data_key = 'slowdata.backTemp' + + # data.backTemp shape evolved from (n_trains,) to (n_trains, 1) return self.run_dc[ - self.instrument_src, 'data.backTemp'].as_single_value( - reduce_by='mean', atol=100).item() / 100 + self.rcvr_src, data_key].as_single_value( + reduce_by='mean', atol=atol).item() / atol \ No newline at end of file -- GitLab