Element

Import modules/packages


In [1]:
import phantasy

Model Machine


In [2]:
mp = phantasy.MachinePortal(machine='FRIB_FE', segment='LEBT')


WARNING: 2017-05-31 13:27:04,751: phantasy.library.operation.core: Load new machine: FRIB_FE segment: LEBT

Get Element by type


In [3]:
mp.get_all_types()


Out[3]:
[u'EQUAD', u'HCOR', u'SOL', u'VCOR', u'BEND', u'EBEND', u'PM']

Example: Electric static Quadrupole

Get the first equad

In [4]:
equads = mp.get_elements(type='EQUAD')

In [5]:
equads


Out[5]:
[FE_SCS1:QHE_D0726 [EQUAD] @ sb=1.800000,
 FE_SCS1:QVE_D0730 [EQUAD] @ sb=2.135000,
 FE_SCS1:QHE_D0733 [EQUAD] @ sb=2.470000,
 FE_SCS1:QHE_D0743 [EQUAD] @ sb=3.430000,
 FE_SCS1:QVE_D0746 [EQUAD] @ sb=3.765000,
 FE_SCS1:QHE_D0749 [EQUAD] @ sb=4.100000,
 FE_LEBT:QVE_D0767 [EQUAD] @ sb=5.875000,
 FE_LEBT:QHE_D0770 [EQUAD] @ sb=6.210000,
 FE_LEBT:QHE_D0776 [EQUAD] @ sb=6.805000,
 FE_LEBT:QVE_D0780 [EQUAD] @ sb=7.140000,
 FE_LEBT:QHE_D0844 [EQUAD] @ sb=13.615300,
 FE_LEBT:QVE_D0848 [EQUAD] @ sb=13.950300,
 FE_LEBT:QHE_D0851 [EQUAD] @ sb=14.285300,
 FE_LEBT:QVE_D0871 [EQUAD] @ sb=16.264050,
 FE_LEBT:QHE_D0874 [EQUAD] @ sb=16.599050,
 FE_LEBT:QVE_D0878 [EQUAD] @ sb=16.934050,
 FE_LEBT:QVE_D0891 [EQUAD] @ sb=18.294050,
 FE_LEBT:QHE_D0895 [EQUAD] @ sb=18.629050,
 FE_LEBT:QVE_D0898 [EQUAD] @ sb=18.964050,
 FE_LEBT:QHE_D0918 [EQUAD] @ sb=20.942800,
 FE_LEBT:QVE_D0921 [EQUAD] @ sb=21.277800,
 FE_LEBT:QHE_D0924 [EQUAD] @ sb=21.612800]

In [6]:
# first equad
equad0 = equads[0]
equad0


Out[6]:
FE_SCS1:QHE_D0726 [EQUAD] @ sb=1.800000
Investigate the equad

In [7]:
print("Index    : %d" % equad0.index)
print("Name     : %s" % equad0.name)
print("Family   : %s" % equad0.family)
print("Location : (begin) %f (end) %f" % (equad0.sb, equad0.se))
print("Length   : %f" % equad0.length)
print("Groups   : %s" % equad0.group)
print("PVs      : %s" % equad0.pv())
print("Tags     : %s" % equad0.tags)
print("Fields   : %s" % equad0.fields)


Index    : 10
Name     : FE_SCS1:QHE_D0726
Family   : EQUAD
Location : (begin) 1.800000 (end) 2.000000
Length   : 0.200000
Groups   : set([u'EQUAD'])
PVs      : [u'VA:FE_SCS1:QHE_D726:V_CSET', u'VA:FE_SCS1:QHE_D726:V_RSET', u'VA:FE_SCS1:QHE_D726:V_RD']
Tags     : {u'VA:FE_SCS1:QHE_D726:V_CSET': set([u'phyutil.sys.LEBT', u'phyutil.sub.SCS1', u'phyutil.sys.FE']), u'VA:FE_SCS1:QHE_D726:V_RSET': set([u'phyutil.sys.LEBT', u'phyutil.sub.SCS1', u'phyutil.sys.FE']), u'VA:FE_SCS1:QHE_D726:V_RD': set([u'phyutil.sys.LEBT', u'phyutil.sub.SCS1', u'phyutil.sys.FE'])}
Fields   : [u'V']
Dynamic field: V

All available dynamic fields could be retrieved by equad0.fields (for equad0 here, there is only one field, i.e. V).


In [8]:
equad0.V


Out[8]:
1500.9503378615887

Get values

If only readback value is of interest, Approach 1 is recommanded and most natural.


In [9]:
# Approach 1: dynamic field feature (readback PV)
print("Readback: %f" % equad0.V)


Readback: 1500.950338

In [10]:
# Approach 2: caget(pv_name)
pv_rdbk = equad0.pv(field='V', handle='readback')
print("Readback: %s" % phantasy.caget(pv_rdbk))


Readback: [1500.9503378615887]

In [11]:
# Approach 3: CaField
v_field = equad0.get_field('V')
print("Readback: %f" % v_field.get(handle='readback'))
print("Setpoint: %f" % v_field.get(handle='setpoint'))
print("Readset : %f" % v_field.get(handle='readset'))


Readback: 1500.950338
Setpoint: 1500.000000
Readset : 1500.000000

Set values

Always Approach 1 is recommanded.


In [12]:
# Save orignal set value for 'V' field
v0 = equad0.get_field('V').get(handle='setpoint')

In [13]:
# Approach 1: dynamic field feature (setpoint PV)
equad0.V = 2000

In [14]:
# Approach 2: caput(pv_name)
pv_cset = equad0.pv(field='V', handle='setpoint')
phantasy.caput(pv_cset, 1000)


Out[14]:
[cothread.catools.ca_nothing()]

In [15]:
# Approach 3: CaField
v_field = equad0.get_field('V')
v_field.set(handle='setpoint', value=1500)