From 6509af20ecf279b0d35a802b9f54cb73be8cb7e4 Mon Sep 17 00:00:00 2001 From: Steffen Hauf <haufs@max-exfl015.desy.de> Date: Tue, 14 Aug 2018 11:29:05 +0200 Subject: [PATCH] Make defaults available --- .../generic/DB_Constants_to_HDF5_NBC.ipynb | 44 ++++++++++++++----- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/notebooks/generic/DB_Constants_to_HDF5_NBC.ipynb b/notebooks/generic/DB_Constants_to_HDF5_NBC.ipynb index 671479d9c..3aa953a03 100644 --- a/notebooks/generic/DB_Constants_to_HDF5_NBC.ipynb +++ b/notebooks/generic/DB_Constants_to_HDF5_NBC.ipynb @@ -6,7 +6,9 @@ "source": [ "# Constants from DB to HDF5 #\n", "\n", - "Version 0.1, Author: S. Hauf" + "Version 0.1, Author: S. Hauf\n", + "\n", + "Currently available instances are LPD1M1 and AGIPD1M1" ] }, { @@ -17,7 +19,7 @@ }, "outputs": [], "source": [ - "detector_instance = \"LPD1M1\" # the detector instance to get constants for, required\n", + "detector_instance = \"LPD1M1\" # the detector instance to get constants for e.g. LPD1M1, required\n", "out_file = \"/gpfs/exfel/data/scratch/haufs/test/test.h5\" # HDF5 file to output constants into, required\n", "valid_at = \"\" # ISO formatted date for which constants shoudl be valid. Leave empty to get most current ones\n", "cal_db_interface = \"tcp://max-exfl015:5005\"\n", @@ -45,18 +47,29 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 20, "metadata": { "collapsed": false }, "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Skipping capacitor\n", + "Skipping pixels_y\n", + "Skipping pixels_x\n", + "Skipping bias_voltage\n", + "Skipping memory_cells\n" + ] + }, { "data": { "text/plain": [ - "'pixels_y = 0. # required\\ncapacitor = \"\" # required\\nmemory_cells = 0. # required\\npixels_x = 0. # required\\nphoton_energy = 0. # required\\nbias_voltage = 0. # required\\nbeam_energy = \"\" # required'" + "'memory_cells = 0. # required\\npixels_y = 256 # required\\ncapacitor = \"5pF\" # required\\nbias_voltage = 0. # required\\nphoton_energy = 0. # required\\nbeam_energy = \"\" # required\\npixels_x = 256 # required'" ] }, - "execution_count": 13, + "execution_count": 20, "metadata": {}, "output_type": "execute_result" } @@ -72,19 +85,24 @@ "def extend_parms(detector_instance):\n", " from iCalibrationDB import Conditions\n", " import inspect\n", - " \n", + " existing = set()\n", " def extract_parms(cls):\n", " args, varargs, varkw, defaults = inspect.getargspec(cls.__init__)\n", - " pList = []\n", + " pList = [] \n", " for i, arg in enumerate(args[1:][::-1]):\n", + " if arg in existing:\n", + " continue\n", + " \n", + " existing.add(arg)\n", + " \n", " if i < len(defaults):\n", - " default = defaults[::-1][i]\n", + " default = defaults[::-1][i] \n", " if str(default).isdigit():\n", - " pList.append(\"{} = 0. # required\".format(arg))\n", + " pList.append(\"{} = {}\".format(arg, default))\n", " elif default is None or default == \"None\":\n", - " pList.append(\"{} = \\\"\\\" # required\".format(arg))\n", + " pList.append(\"{} = \\\"None\\\"\".format(arg))\n", " else:\n", - " pList.append(\"{} = \\\"\\\" # required\".format(arg))\n", + " pList.append(\"{} = \\\"{}\\\"\".format(arg, default))\n", " else:\n", " pList.append(\"{} = 0. # required\".format(arg))\n", " return set(pList[::-1]) # mandatories first\n", @@ -95,7 +113,9 @@ " condition = getattr(Conditions, c)\n", " parms = extract_parms(getattr(condition, dtype))\n", " [all_conditions.add(p) for p in parms]\n", - " return \"\\n\".join(all_conditions)" + " return \"\\n\".join(all_conditions)\n", + "\n", + "extend_parms(\"LPD1M1\")" ] }, { -- GitLab