From c19567e893cb135f7963eb5dbf90003132ccbee5 Mon Sep 17 00:00:00 2001 From: ximenes Date: Thu, 13 Feb 2020 14:13:38 -0300 Subject: [PATCH 1/3] Clean up normalizer code. --- siriuspy/siriuspy/factory.py | 24 +++++++-------------- siriuspy/siriuspy/magnet/normalizer.py | 29 +++++++------------------- 2 files changed, 14 insertions(+), 39 deletions(-) diff --git a/siriuspy/siriuspy/factory.py b/siriuspy/siriuspy/factory.py index b94b88b15..f7af1b316 100644 --- a/siriuspy/siriuspy/factory.py +++ b/siriuspy/siriuspy/factory.py @@ -20,20 +20,10 @@ def create(maname): ma_class = _mutil.magnet_class(maname) if ma_class == 'dipole': return _norm.DipoleNormalizer(maname, magnet_conv_sign=-1.0) - elif ma_class == 'trim': - return _norm.TrimNormalizer( - maname, magnet_conv_sign=-1.0, - dipole_name=_mutil.get_section_dipole_name(maname), - family_name=_mutil.get_magnet_family_name(maname)) - elif magfunc == 'corrector-horizontal': - return _norm.MagnetNormalizer( - maname, magnet_conv_sign=+1.0, - dipole_name=_mutil.get_section_dipole_name(maname)) - elif 'TB' in maname and 'QD' in maname: - return _norm.MagnetNormalizer( - maname, magnet_conv_sign=+1.0, - dipole_name=_mutil.get_section_dipole_name(maname)) - else: - return _norm.MagnetNormalizer( - maname, magnet_conv_sign=-1.0, - dipole_name=_mutil.get_section_dipole_name(maname)) + if ma_class == 'trim': + return _norm.TrimNormalizer(maname, magnet_conv_sign=-1.0) + if magfunc == 'corrector-horizontal': + return _norm.MagnetNormalizer(maname, magnet_conv_sign=+1.0) + if 'TB' in maname and 'QD' in maname: + return _norm.MagnetNormalizer(maname, magnet_conv_sign=+1.0,) + return _norm.MagnetNormalizer(maname, magnet_conv_sign=-1.0) diff --git a/siriuspy/siriuspy/magnet/normalizer.py b/siriuspy/siriuspy/magnet/normalizer.py index 057a0a797..298cf289b 100644 --- a/siriuspy/siriuspy/magnet/normalizer.py +++ b/siriuspy/siriuspy/magnet/normalizer.py @@ -39,6 +39,11 @@ def magfunc(self): """Return magnet function string.""" return self._magfunc + @property + def maname(self): + """Return magnet name.""" + return self._maname + # --- normalizer interface --- def conv_current_2_strength(self, currents, **kwargs): @@ -95,17 +100,6 @@ def _conv_current_2_multipoles(self, currents): msum = _mutil.sum_magnetic_multipoles(msum, m) return msum - def _get_energy(self, currents_dipole): - return self._dip.conv_current_2_strength(currents=currents_dipole) - - def _get_brho(self, currents_dipole): - """Get Magnetic Rigidity.""" - if currents_dipole is None: - return 0 # TODO: is this really necessary?! in what case? - energies = self._get_energy(currents_dipole) - brho, *_ = _util.beam_rigidity(energies) - return brho - def _power_supplies(self): psname = self._maname.replace(":MA", ":PS").replace(':PM', ':PU') return [psname] @@ -202,9 +196,6 @@ def _set_reference_dipole_data(self): else: raise NotImplementedError - def _get_energy(self, currents_dipole): - return self.conv_current_2_strength(currents=currents_dipole) - def _conv_strength_2_intfield(self, strengths, **kwargs): if isinstance(strengths, list): strengths = _np.array(strengths) @@ -280,10 +271,9 @@ class MagnetNormalizer(_MagnetNormalizer): TYPE = 'MagnetNormalizer' - def __init__(self, maname, dipole_name, **kwargs): + def __init__(self, maname, **kwargs): """Call superclass init and initializes a dipole.""" super(MagnetNormalizer, self).__init__(maname, **kwargs) - self._dip = DipoleNormalizer(dipole_name, **kwargs) def _conv_strength_2_intfield(self, strengths, **kwargs): if isinstance(strengths, list): @@ -316,19 +306,14 @@ class TrimNormalizer(_MagnetNormalizer): TYPE = 'TrimNormalizer' - def __init__(self, maname, dipole_name, family_name, magnet_conv_sign=-1.0, + def __init__(self, maname, magnet_conv_sign=-1.0, **kwargs): """Call super and initializes a dipole and the family magnet.""" super(TrimNormalizer, self).__init__(maname, **kwargs) - self._dip = DipoleNormalizer(dipole_name, **kwargs) - self._fam = MagnetNormalizer(family_name, dipole_name, **kwargs) def _conv_strength_2_intfield(self, strengths, **kwargs): if isinstance(strengths, list): strengths = _np.array(strengths) - # strengths_fam = self._fam.conv_current_2_strength( - # currents=kwargs["strengths_family"], - # currents_dipole=kwargs["strengths_dipole"]) strengths_fam = kwargs['strengths_family'] brho, *_ = _util.beam_rigidity(kwargs['strengths_dipole']) intfields = self._magnet_conv_sign * brho * (strengths - strengths_fam) From 8135034e7b9de0b25c0492e76803beb10ca3313f Mon Sep 17 00:00:00 2001 From: ximenes Date: Thu, 13 Feb 2020 18:52:42 -0300 Subject: [PATCH 2/3] Update strength PV precision values. --- siriuspy/siriuspy/csdevice/pwrsupply.py | 45 +++++++++++++------------ 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/siriuspy/siriuspy/csdevice/pwrsupply.py b/siriuspy/siriuspy/csdevice/pwrsupply.py index b7862be34..ff701c055 100644 --- a/siriuspy/siriuspy/csdevice/pwrsupply.py +++ b/siriuspy/siriuspy/csdevice/pwrsupply.py @@ -387,7 +387,6 @@ class ETypes(_cutil.ETypes): 'Bit0', 'Bit1', 'Bit2', 'Bit3', 'Bit4', 'Bit5', 'Bit6', 'Bit7') - _et = ETypes # syntatic sugar @@ -1626,7 +1625,10 @@ def _get_model_db(psmodel): def _insert_strengths(database, pstype): - prec = 5 + prec_kick = 3 + prec_energy = 5 + prec_kl = 5 + prec_sl = 5 pulsed_pstypes = ( 'tb-injseptum', 'bo-injkicker', 'bo-ejekicker', @@ -1635,49 +1637,50 @@ def _insert_strengths(database, pstype): 'si-injdpk', 'si-injnlk', 'si-hping', 'si-vping') if pstype in pulsed_pstypes: database['Kick-SP'] = { - 'type': 'float', 'value': 0.0, 'prec': prec, 'unit': 'mrad'} + 'type': 'float', 'value': 0.0, 'prec': prec_kick, 'unit': 'mrad'} database['Kick-RB'] = { - 'type': 'float', 'value': 0.0, 'prec': prec, 'unit': 'mrad'} + 'type': 'float', 'value': 0.0, 'prec': prec_kick, 'unit': 'mrad'} database['Kick-Mon'] = { - 'type': 'float', 'value': 0.0, 'prec': prec, 'unit': 'mrad'} + 'type': 'float', 'value': 0.0, 'prec': prec_kick, 'unit': 'mrad'} return database magfunc = _PSSearch.conv_pstype_2_magfunc(pstype) if magfunc in {'quadrupole', 'quadrupole-skew'}: database['KL-SP'] = { - 'type': 'float', 'value': 0.0, 'prec': prec, 'unit': '1/m'} + 'type': 'float', 'value': 0.0, 'prec': prec_kl, 'unit': '1/m'} database['KL-RB'] = { - 'type': 'float', 'value': 0.0, 'prec': prec, 'unit': '1/m'} + 'type': 'float', 'value': 0.0, 'prec': prec_kl, 'unit': '1/m'} database['KLRef-Mon'] = { - 'type': 'float', 'value': 0.0, 'prec': prec, 'unit': '1/m'} + 'type': 'float', 'value': 0.0, 'prec': prec_kl, 'unit': '1/m'} database['KL-Mon'] = { - 'type': 'float', 'value': 0.0, 'prec': prec, 'unit': '1/m'} + 'type': 'float', 'value': 0.0, 'prec': prec_kl, 'unit': '1/m'} elif magfunc == 'sextupole': database['SL-SP'] = { - 'type': 'float', 'value': 0.0, 'prec': prec, 'unit': '1/m^2'} + 'type': 'float', 'value': 0.0, 'prec': prec_sl, 'unit': '1/m^2'} database['SL-RB'] = { - 'type': 'float', 'value': 0.0, 'prec': prec, 'unit': '1/m^2'} + 'type': 'float', 'value': 0.0, 'prec': prec_sl, 'unit': '1/m^2'} database['SLRef-Mon'] = { - 'type': 'float', 'value': 0.0, 'prec': prec, 'unit': '1/m^2'} + 'type': 'float', 'value': 0.0, 'prec': prec_sl, 'unit': '1/m^2'} database['SL-Mon'] = { - 'type': 'float', 'value': 0.0, 'prec': prec, 'unit': '1/m^2'} + 'type': 'float', 'value': 0.0, 'prec': prec_sl, 'unit': '1/m^2'} elif magfunc == 'dipole': database['Energy-SP'] = { - 'type': 'float', 'value': 0.0, 'prec': prec, 'unit': 'GeV'} + 'type': 'float', 'value': 0.0, 'prec': prec_energy, 'unit': 'GeV'} database['Energy-RB'] = { - 'type': 'float', 'value': 0.0, 'prec': prec, 'unit': 'GeV'} + 'type': 'float', 'value': 0.0, 'prec': prec_energy, 'unit': 'GeV'} database['EnergyRef-Mon'] = { - 'type': 'float', 'value': 0.0, 'prec': prec, 'unit': 'GeV'} + 'type': 'float', 'value': 0.0, 'prec': prec_energy, 'unit': 'GeV'} database['Energy-Mon'] = { - 'type': 'float', 'value': 0.0, 'prec': prec, 'unit': 'GeV'} + 'type': 'float', 'value': 0.0, 'prec': prec_energy, 'unit': 'GeV'} elif magfunc in {'corrector-horizontal', 'corrector-vertical'}: + prec = 3 database['Kick-SP'] = { - 'type': 'float', 'value': 0.0, 'prec': prec, 'unit': 'urad'} + 'type': 'float', 'value': 0.0, 'prec': prec_kick, 'unit': 'urad'} database['Kick-RB'] = { - 'type': 'float', 'value': 0.0, 'prec': prec, 'unit': 'urad'} + 'type': 'float', 'value': 0.0, 'prec': prec_kick, 'unit': 'urad'} database['KickRef-Mon'] = { - 'type': 'float', 'value': 0.0, 'prec': prec, 'unit': 'urad'} + 'type': 'float', 'value': 0.0, 'prec': prec_kick, 'unit': 'urad'} database['Kick-Mon'] = { - 'type': 'float', 'value': 0.0, 'prec': prec, 'unit': 'urad'} + 'type': 'float', 'value': 0.0, 'prec': prec_kick, 'unit': 'urad'} return database From f14053f6575d2d97ac8612c5fc9ef29a82b11e6f Mon Sep 17 00:00:00 2001 From: ximenes Date: Thu, 13 Feb 2020 19:15:45 -0300 Subject: [PATCH 3/3] Remove unused normalizers in SConvEpics --- siriuspy/siriuspy/pwrsupply/psconv.py | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/siriuspy/siriuspy/pwrsupply/psconv.py b/siriuspy/siriuspy/pwrsupply/psconv.py index 0f56c138b..fb5e6fa10 100644 --- a/siriuspy/siriuspy/pwrsupply/psconv.py +++ b/siriuspy/siriuspy/pwrsupply/psconv.py @@ -133,8 +133,7 @@ def __init__(self, psname, proptype, connection_timeout=PSEpicsConn.CONNECTION_TIMEOUT): """.""" self._psname = _SiriusPVName(psname) - self._norm_mag, self._norm_dip, self._norm_fam = \ - self._create_normalizer() + self._norm_mag = self._create_normalizer() self._conn_dip, self._conn_fam = \ self._create_connectors(proptype, connection_timeout) @@ -193,7 +192,6 @@ def conv_strength_2_current(self, strengths, return currents def _create_normalizer(self): - norm_mag, norm_dip, norm_fam = None, None, None if self._psname.sec == 'TB' and self._psname.dev == 'B': norm_mag = _NormalizerFactory.create('TB-Fam:MA-B') elif self._psname.sec == 'BO' and self._psname.dev == 'B': @@ -204,17 +202,8 @@ def _create_normalizer(self): norm_mag = _NormalizerFactory.create('SI-Fam:MA-B1B2') else: maname = self._psname.replace(':PS', ':MA').replace(':PU', ':PM') - # mag norm_mag = _NormalizerFactory.create(maname) - # dip - dipname = _mutil.get_section_dipole_name(maname) - norm_dip = _NormalizerFactory.create(dipname) - # trim - famname = _mutil.get_magnet_family_name(maname) - if famname: - norm_fam = _NormalizerFactory.create(famname) - - return norm_mag, norm_dip, norm_fam + return norm_mag @staticmethod def _is_trim(psname):