from jpype import *
from numpy import *
JAVA_JVM='/usr/lib/jvm/java-1.7.0-oracle-1.7.0.17.x86_64/jre/lib/amd64/server/libjvm.so'
JAVA_OpenXAL='/home/shared/OpenXAL/lib/openxal/openxal.library-1.0.2.jar'
JAVA_ClassPath='-Djava.class.path='+JAVA_OpenXAL
JAVA_Flags='-ea'
startJVM(JAVA_JVM, JAVA_Flags, JAVA_ClassPath)
_XMLDataManager = JClass("xal.smf.data.XMLDataManager")
Accelerator = _XMLDataManager.acceleratorWithPath('/home/shared/OpenXAL/etc/main.xal')
http://xaldev.sourceforge.net/javadoc/xal/smf/Accelerator.html
print Accelerator.getAllSeqs()
print Accelerator.getComboSequences()
http://xaldev.sourceforge.net/javadoc/xal/smf/AcceleratorSeq.html
#Sequence = Accelerator.getSequence('mebt')
Sequence = Accelerator.getComboSequence('from-mebt')
Sequence.getNodeCount()
print Sequence.nodes
print Sequence.getAllNodesOfType('Quad')
print Sequence.getAllNodesOfType('BPM')
Sequence.getLength()
http://xaldev.sourceforge.net/javadoc/xal/smf/AcceleratorNode.html
MyQuad = Sequence.getNodeWithId('QP1')
MyQuad.getField()
MyQuad.field
MyQuad.isMagnet()
Sequence.getNodeWithId('BPM1').isMagnet()
print MyQuad.handles
MyQuad.handles.toString()
MyQuad.getChannel('fieldSet').getId()
MyQuad.getChannel('fieldRB').getId()
http://xaldev.sourceforge.net/javadoc/xal/model/alg/EnvTrackerAdapt.html
_AlgorithFactory = JClass("xal.sim.scenario.AlgorithmFactory")
EnvelopeTracker = _AlgorithFactory.createEnvTrackerAdapt(Sequence)
EnvelopeTracker.setMaxIterations(1000)
EnvelopeTracker.setAccuracyOrder(1)
EnvelopeTracker.setErrorTolerance(0.001)
http://xaldev.sourceforge.net/javadoc/xal/model/alg/EnvTrackerAdapt.html
_ProbeFactory = JClass("xal.sim.scenario.ProbeFactory")
Probe = _ProbeFactory.getEnvelopeProbe(Sequence, EnvelopeTracker)
http://xaldev.sourceforge.net/javadoc/xal/sim/scenario/Scenario.html
_Scenario = JClass("xal.sim.scenario.Scenario")
Model = _Scenario.newScenarioFor(Sequence)
Model.setProbe(Probe)
Model.setSynchronizationMode('LIVE')
#Model.setSynchronizationMode('DESIGN')
Model.resync()
Model.run()
Probe = Model.getProbe()
http://xaldev.sourceforge.net/javadoc/xal/model/probe/traj/Trajectory.html
Trajectory = Probe.getTrajectory()
Positions=[]
for State in Trajectory.stateIterator():
Positions.append(State.getPosition())
CovarianceMatrices=[]
for State in Trajectory.stateIterator():
CovarianceMatrices.append(State.getCovarianceMatrix())
SigmaX=[]
SigmaY=[]
SigmaZ=[]
for CovarianceMatrix in CovarianceMatrices:
SigmaX.append(CovarianceMatrix.getSigmaX())
SigmaY.append(CovarianceMatrix.getSigmaY())
SigmaZ.append(CovarianceMatrix.getSigmaZ())
fig, (ax1, ax2, ax3) = subplots(ncols=3, figsize=(18,8))
ax1.set_xlabel('Position [m]')
ax1.set_ylabel('$\sigma_x$ [m]')
ax1.ticklabel_format(style='sci', axis='y', scilimits=(0,0))
ax1.plot(Positions, SigmaX, color='r')
ax2.plot(Positions, SigmaY, color='g')
ax2.set_xlabel('Position [m]')
ax2.set_ylabel('$\sigma_y$ [m]')
ax2.ticklabel_format(style='sci', axis='y', scilimits=(0,0))
ax3.plot(Positions, SigmaZ, color='b')
ax3.set_xlabel('Position [m]')
ax3.set_ylabel('$\sigma_z$ [m]')
ax3.ticklabel_format(style='sci', axis='y', scilimits=(0,0))
show()
from epics import caget, caput
caget('QP1:B')
caput('QP1:FldSet', 20)
caget('QP1:B')
from IPython.html.widgets import interact, interactive
def PlayWithQuad(QP1Field=-16.1578):
caput('QP1:FldSet', QP1Field) # This is not part of OpenXAL, with this command we are changing the "Hardware".
# MyQuad.setDfltField(QP1Field) # This modifies a variable in OpenXAL.
Probe = _ProbeFactory.getEnvelopeProbe(Sequence, EnvelopeTracker)
Model.setProbe(Probe)
Model.resync()
Model.run()
Probe = Model.getProbe()
Trajectory = Probe.getTrajectory()
Positions=[]
CovarianceMatrices=[]
for State in Trajectory.stateIterator():
Positions.append(State.getPosition())
CovarianceMatrices.append(State.getCovarianceMatrix())
SigmaX=[]
SigmaY=[]
SigmaZ=[]
for CovarianceMatrix in CovarianceMatrices:
SigmaX.append(CovarianceMatrix.getSigmaX())
SigmaY.append(CovarianceMatrix.getSigmaY())
SigmaZ.append(CovarianceMatrix.getSigmaZ())
fig, (ax1, ax2, ax3) = subplots(ncols=3, figsize=(18,8))
ax1.set_xlabel('Position [m]')
ax1.set_ylabel('$\sigma_x$ [m]')
ax1.ticklabel_format(style='sci', axis='y', scilimits=(0,0))
ax1.plot(Positions, SigmaX, color='r')
ax2.plot(Positions, SigmaY, color='g')
ax2.set_xlabel('Position [m]')
ax2.set_ylabel('$\sigma_y$ [m]')
ax2.ticklabel_format(style='sci', axis='y', scilimits=(0,0))
ax3.plot(Positions, SigmaZ, color='b')
ax3.set_xlabel('Position [m]')
ax3.set_ylabel('$\sigma_z$ [m]')
ax3.ticklabel_format(style='sci', axis='y', scilimits=(0,0))
show()
interactive(PlayWithQuad, QP1Field=(-20.0, 20.0))
def PlayWithCav(CAV1Amp=0.125):
caput('GAP1:AmpCtl', CAV1Amp)
Probe = _ProbeFactory.getEnvelopeProbe(Sequence, EnvelopeTracker)
Model.setProbe(Probe)
Model.resync()
Model.run()
Probe = Model.getProbe()
Trajectory = Probe.getTrajectory()
Positions=[]
CovarianceMatrices=[]
for State in Trajectory.stateIterator():
Positions.append(State.getPosition())
CovarianceMatrices.append(State.getCovarianceMatrix())
SigmaX=[]
SigmaY=[]
SigmaZ=[]
for CovarianceMatrix in CovarianceMatrices:
SigmaX.append(CovarianceMatrix.getSigmaX())
SigmaY.append(CovarianceMatrix.getSigmaY())
SigmaZ.append(CovarianceMatrix.getSigmaZ())
fig, (ax1, ax2, ax3) = subplots(ncols=3, figsize=(18,8))
ax1.set_xlabel('Position [m]')
ax1.set_ylabel('$\sigma_x$ [m]')
ax1.ticklabel_format(style='sci', axis='y', scilimits=(0,0))
ax1.plot(Positions, SigmaX, color='r')
ax2.plot(Positions, SigmaY, color='g')
ax2.set_xlabel('Position [m]')
ax2.set_ylabel('$\sigma_y$ [m]')
ax2.ticklabel_format(style='sci', axis='y', scilimits=(0,0))
ax3.plot(Positions, SigmaZ, color='b')
ax3.set_xlabel('Position [m]')
ax3.set_ylabel('$\sigma_z$ [m]')
ax3.ticklabel_format(style='sci', axis='y', scilimits=(0,0))
show()
interactive(PlayWithCav, CAV1Amp=(0, 10.0))
#shutdownJVM()