diff --git a/notebooks/Jungfrau/Jungfrau_dark_analysis_all_gains_burst_mode_NBC.ipynb b/notebooks/Jungfrau/Jungfrau_dark_analysis_all_gains_burst_mode_NBC.ipynb index 2de27f67dd66fe68d530e011c629f08d30d1ec96..a290aa8a2c667bbdbdb5c3ff1d71ea84a28e6ee6 100644 --- a/notebooks/Jungfrau/Jungfrau_dark_analysis_all_gains_burst_mode_NBC.ipynb +++ b/notebooks/Jungfrau/Jungfrau_dark_analysis_all_gains_burst_mode_NBC.ipynb @@ -204,7 +204,7 @@ " else:\n", " gain_mode = ctrl_data.get_gain_mode()\n", "\n", - " med_low_settings.append(str(run_settings))\n", + " med_low_settings.append(run_settings)\n", "\n", "# A transperent workaround for old raw data with wrong/missing medium and low settings\n", "if med_low_settings == [None, None]:\n", diff --git a/src/cal_tools/enums.py b/src/cal_tools/enums.py index 823b825294ec6b643d34bf5a298f6d093375fe0b..d734bc23dac0a23ee0b1b0da3755c69097c89a33 100644 --- a/src/cal_tools/enums.py +++ b/src/cal_tools/enums.py @@ -1,8 +1,8 @@ from enum import Enum, IntEnum, IntFlag, EnumMeta -class MetaValueCheck(EnumMeta): - def __contains__(cls, item): +class MetaValueCheck(EnumMeta): + def __contains__(cls, item): return item in [i.value for i in cls.__members__.values()] @@ -34,6 +34,7 @@ class BadPixels(IntFlag): WRONG_GAIN_VALUE = 1 << 21 # bit 22 NON_STANDARD_SIZE = 1 << 22 # bit 23 + class SnowResolution(Enum): """ An Enum specifying how to resolve snowy pixels """ @@ -51,7 +52,7 @@ class AgipdGainMode(IntEnum): class JungfrauOldSettings(Enum, metaclass=MetaValueCheck): - """ Jungfrau run gain settings before changes in jungfrau software. + """Jungfrau run gain settings before changes in jungfrau software. https://git.xfel.eu/karaboDevices/slsDetectors/-/commit/4433ae9c00edcca3309bec8b7515e0938f5f502c # noqa """ DYNAMIC_GAIN = "dynamicgain" @@ -60,22 +61,27 @@ class JungfrauOldSettings(Enum, metaclass=MetaValueCheck): FIX_GAIN_2 = "fixgain2" FORCE_SWITCH_HG1 = "forceswitchg1" FORCE_SWITCH_HG2 = "forceswitchg2" + def __str__(self): return str(self.value) + class JungfrauSettings(Enum, metaclass=MetaValueCheck): - """ Jungfrau run gain settings.""" + """Jungfrau run gain settings.""" DYNAMIC_GAIN = "gain0" DYNAMIC_GAIN_HG0 = "highgain0" + def __str__(self): return str(self.value) + class JungfrauGainModes(Enum, metaclass=MetaValueCheck): - """ Jungfrau run gain modes.""" + """Jungfrau run gain modes.""" DYNAMIC = "dynamic" FIX_GAIN_1 = "fixg1" FIX_GAIN_2 = "fixg2" FORCE_SWITCH_HG1 = "forceswitchg1" FORCE_SWITCH_HG2 = "forceswitchg2" + def __str__(self): - return str(self.value) \ No newline at end of file + return str(self.value) diff --git a/src/cal_tools/jungfraulib.py b/src/cal_tools/jungfraulib.py index df9e8b65fa95e49fb8dbdaa3222f48f368a8b118..2ff8d9d92b1a1fcff49b8a2b88b06df032b6b5b0 100644 --- a/src/cal_tools/jungfraulib.py +++ b/src/cal_tools/jungfraulib.py @@ -1,4 +1,4 @@ -from typing import Tuple +from typing import Tuple, Union from cal_tools.enums import ( JungfrauSettings, @@ -11,7 +11,8 @@ import extra_data def _get_settings( run_dc: extra_data.DataCollection, ctrl_src: str - ) -> Tuple[str, "enum"] : + ) -> Tuple[ + str, Union[JungfrauSettings, JungfrauOldSettings]]: """Get run settings string value and identify the enum to use for the jungfau run settings. """ @@ -58,7 +59,7 @@ class JungfrauCtrl(): """Get run gain settings to identify if run is in High CDS or Low CDS. """ - if self.run_settings == self.settings_enum.DYNAMIC_GAIN_HG0: + if self.run_settings == str(self.settings_enum.DYNAMIC_GAIN_HG0): gain_setting = 1 else: # JungfrauOldSettings.DYNAMIC_GAIN gain_setting = 0 @@ -74,7 +75,9 @@ class JungfrauCtrl(): is fixgain1 or fixgain2. """ if self.run_settings in [ - self.settings_enum.FIX_GAIN_1, self.settings_enum.FIX_GAIN_2]: + str(self.settings_enum.FIX_GAIN_1), + str(self.settings_enum.FIX_GAIN_2), + ]: return 1 else: return 0 @@ -89,7 +92,9 @@ class JungfrauCtrl(): """ gain_mode = self.run_dc[self.ctrl_src, "gainMode"].as_single_value() if gain_mode in [ - JungfrauGainModes.FIX_GAIN_1, JungfrauGainModes.FIX_GAIN_2]: + str(JungfrauGainModes.FIX_GAIN_1), + str(JungfrauGainModes.FIX_GAIN_2) + ]: return 1 else: return 0 @@ -98,4 +103,4 @@ class JungfrauCtrl(): if "gainMode.value" in self.run_dc.keys_for_source(self.ctrl_src): return self._get_gain_mode_ctrl() else: - return self._get_gain_mode_settings() \ No newline at end of file + return self._get_gain_mode_settings()