Skip to content

Commit

Permalink
Merge pull request #371 from lnls-sirius/PR-cleanup-normalizer
Browse files Browse the repository at this point in the history
Pr cleanup normalizer
  • Loading branch information
xresende authored Feb 14, 2020
2 parents 058141b + 498944e commit b23550e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 73 deletions.
45 changes: 24 additions & 21 deletions siriuspy/siriuspy/csdevice/pwrsupply.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,6 @@ class ETypes(_cutil.ETypes):
'Bit0', 'Bit1', 'Bit2', 'Bit3', 'Bit4', 'Bit5', 'Bit6', 'Bit7')



_et = ETypes # syntatic sugar


Expand Down Expand Up @@ -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',
Expand All @@ -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
24 changes: 7 additions & 17 deletions siriuspy/siriuspy/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
29 changes: 7 additions & 22 deletions siriuspy/siriuspy/magnet/normalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 2 additions & 13 deletions siriuspy/siriuspy/pwrsupply/psconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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':
Expand All @@ -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):
Expand Down

0 comments on commit b23550e

Please sign in to comment.