Commit 16743c2d authored by Simone Liuzzo's avatar Simone Liuzzo

reverted to only matlab repository

parent 9f5f11ab
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="projectConfiguration" value="Nosetests" />
<option name="PROJECT_TEST_RUNNER" value="Nosetests" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 2.7 (BBA)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/BBA.iml" filepath="$PROJECT_DIR$/.idea/BBA.iml" />
</modules>
</component>
</project>
\ No newline at end of file
This diff is collapsed.
import scipy.io as sio
class Bumps():
def __init__(self,debug=True):
self._bpms = []
self.path = '/mntdirect/_machfs/swhite/Commissioning/BBA/'
for i in range(10):
self._bpms.append(sio.loadmat(self.path+'bpm'+str(i+1)+'.mat')['bump'])
def get_bump(self,bpm_nb,plane):
bump = self._bpms[bpm_nb-1]
if plane =='H':
bump = bump[0]
elif plane=='V':
bump = bump[1]
return bump
This diff is collapsed.
import tango
import csv
import numpy as np
import os
from enum import Enum
class EbsMode(Enum):
TbT = 0
Atlinopt = 1
Atx = 2
Mixed = 3
DetailedAtx = 4
class OrbitController():
# Class to get data from BPM
# Read/correct/set closed orbit
#drive bumps, correctors, quadrupoles
def __init__(self,debug=True):
if debug:
os.environ['TANGO_HOST'] = 'ebs-simu:10000'
simulator = tango.DeviceProxy('sys/ringsimulator/ebs')
simulator.write_attribute('Mode',EbsMode.Atlinopt.value)
self._BPMsdev = tango.DeviceProxy('srdiag/beam-position/all')
self._Quadsdev = tango.DeviceProxy('srmag/m-q/all')
self._corHdev = tango.DeviceProxy('srmag/hst/all')
self._corVdev = tango.DeviceProxy('srmag/vst/all')
self._autocor = tango.DeviceProxy('sr/beam-orbitcor/svd-auto')
self._svd_h = tango.DeviceProxy('sr/beam-orbitcor/svd-h')
self._svd_v = tango.DeviceProxy('sr/beam-orbitcor/svd-v')
self._quad_map = {1: ['qf1', 'a'],
2: ['qf4', 'a'],
3: ['qf4', 'b'],
4: ['qf6', 'b'],
5: ['qf8', 'b'],
6: ['qf8', 'd'],
7: ['qf6', 'd'],
8: ['qf4', 'd'],
9: ['qf4', 'e'],
10: ['qf1', 'e']}
hmfile = self._svd_h.get_property('SVDFileName')
vmfile = self._svd_v.get_property('SVDFileName')
hmfile = hmfile['SVDFileName'][0]
vmfile = vmfile['SVDFileName'][0]
self._hmat = self.load_respmat(hmfile)
self._vmat = self.load_respmat(vmfile)
def load_respmat(self, mfile):
mat = []
f = open(mfile,'r')
r = csv.reader(f)
for line in r:
ld = [float(x) for x in line]
mat.append(ld)
f.close()
return mat
def get_cor_name(self, index, plane):
names = []
if plane == 'H':
names = self._corHdev.read_attribute('CorrectorNames').value
elif plane == 'V':
names = self._corVdev.read_attribute('CorrectorNames').value
elif plane == 'HV':
names = [self._corHdev.read_attribute('CorrectorNames').value,
self._corVdev.read_attribute('CorrectorNames').value]
return [names[0][index[0]],names[1][index[1]]]
else:
print 'Plane is H,V or HV'
return names[index]
def get_cor_index(self, name):
if 'hst' in name:
names = self._corHdev.read_attribute('CorrectorNames').value
elif 'vst' in name:
names = self._corVdev.read_attribute('CorrectorNames').value
else:
print 'Error Corrector name: '+name
return names.index(name)
def get_cor_values(self, plane):
values=np.nan
if plane == 'H':
values = self._corHdev.read_attribute('Strengths').w_value
elif plane == 'V':
values = self._corVdev.read_attribute('Strengths').w_value
elif plane == 'HV':
values = [self._corHdev.read_attribute('Strengths').w_value,
self._corVdev.read_attribute('Strengths').w_value]
else:
print 'Plane is H,V or HV'
return values
def set_cor_values(self, plane,values):
if 'H' in plane:
self._corHdev.write_attribute('Strengths',values)
if 'V' in plane:
self._corVdev.write_attribute('Strengths',values)
def trim_cor(self,name,value,increment=False):
cor = tango.DeviceProxy(name)
corval = cor.read_attribute('Strength').w_value
if increment:
corval = corval + value
else:
corval = value
cor.write_attribute('Strength',corval)
def trim_cor_all(self,name,plane,value,increment=False):
cori = self.get_cor_index(name)
vals = self.get_cor_values(plane)
if increment:
vals[cori] = vals[cori]+value
else:
vals[cori] = value
self.set_cor_values(plane,vals)
def get_bpm_name(self, index):
return self._BPMsdev.command_inout('GetBPMName',index)
def get_bpm_index(self, name):
return self._BPMsdev.command_inout('GetBPMIndex',name)
def get_orbit(self):
orbit = [self._BPMsdev.read_attribute('SA_HPositions').value,
self._BPMsdev.read_attribute('SA_VPositions').value]
return orbit
def get_offets(self):
offsets = [self._BPMsdev.read_attribute('HOffsets').value,
self._BPMsdev.read_attribute('VOffsets').value]
return offsets
def reset_offets(self):
self._BPMsdev.write_attribute('HOffsets',np.zeros(320))
self._BPMsdev.write_attribute('VOffsets',np.zeros(320))
def set_offsets(self,bpmi,values,plane):
offsets = self.get_offets()
offsets[0][bpmi] += -values[0][0]
offsets[1][bpmi] += -values[1][0]
if 'H' in plane:
self._BPMsdev.write_attribute('HOffsets', offsets[0])
if 'V' in plane:
self._BPMsdev.write_attribute('VOffsets', offsets[1])
def get_ref_orbit(self,plane):
orbit = []
if plane == 'H':
orbit = self._svd_h.read_attribute('RefOrbit').value
elif plane == 'V':
orbit = self._svd_v.read_attribute('RefOrbit').value
elif plane == 'HV':
orbit = [self._svd_h.read_attribute('RefOrbit').value,
self._svd_v.read_attribute('RefOrbit').value]
else:
print 'Plane is H, V or HV'
return orbit
def set_ref_orbit(self,plane,orbit):
if 'H' in plane:
self._svd_h.write_attribute('RefOrbit',orbit)
if 'V' in plane:
self._svd_v.write_attribute('RefOrbit',orbit)
def reset_ref_orbit(self):
self.set_ref_orbit('HV',np.zeros((2,320)))
def set_bump(self,plane,bump,bpmi,amp):
amp = amp*1.0e3
indm = len(bump)/2+1
ref_orbit = self.get_ref_orbit(plane)
if plane == 'H' or plane == 'V':
norm = bump[indm]
new_ref = ref_orbit
new_ref[bpmi-indm+1:bpmi+indm] = bump[:]*amp/norm
elif plane == 'HV':
norm = bump[:][indm]
new_ref = ref_orbit
new_ref[0][bpmi - indm+1:bpmi + indm] = bump[0][:] * amp / norm[0]
new_ref[1][bpmi - indm+1:bpmi + indm] = bump[1][:] * amp / norm[1]
self.set_ref_orbit(plane,new_ref)
def get_quad_name(self, index):
names = self._Quadsdev.read_attribute('MagnetNames').value
return names[index]
def get_quad_index(self, name):
names = self._Quadsdev.read_attribute('MagnetNames').value
return names.index(name)
def get_quad_values(self):
return self._Quadsdev.read_attribute('CorrectionStrengths').w_value
def get_quad_value(self,name):
quad = tango.DeviceProxy(name)
quadval = quad.read_attribute('CorrectionStrength').w_value
return quadval
def set_quad_values(self,strength):
self._Quadsdev.write_attribute('CorrectionStrengths',strength)
def trim_quad_all(self,name,value,increment=False):
quadi = self.get_quad_index(name)
vals = self.get_quad_values()
if increment:
vals[quadi] = vals[quadi]+value
else:
vals[quadi] = value
self.set_quad_values(vals)
def trim_quad(self,name,value,increment=False):
quad = tango.DeviceProxy(name)
quadval = quad.read_attribute('CorrectionStrength').w_value
if increment:
quadval = quadval + value
else:
quadval = value
quad.write_attribute('CorrectionStrength',quadval)
def get_mec(self, bpm_index,plane):
mec=-1
if plane == 'H':
mec = np.argmax(self._hmat[bpm_index][:])
elif plane == 'V':
mec = np.argmax(self._vmat[bpm_index][:])
elif plane == 'HV':
mec = [np.argmax(self._hmat[bpm_index][:]),
np.argmax(self._vmat[bpm_index][:])]
else:
print 'Plane is H, V or HV'
return mec
def get_bpm_number_cell(self,bpm_name):
nsplit = bpm_name.split('/')
nsplit = nsplit[2].split('-')
cell = nsplit[0]
bpm_nb = int(nsplit[1])
return bpm_nb,cell
def get_quad_to_align(self, bpm_name):
bpm_nb, cell = self.get_bpm_number_cell(bpm_name)
quad_name = 'srmag/m-' + self._quad_map[bpm_nb][0] + \
'/' + cell + '-' + self._quad_map[bpm_nb][1]
return quad_name, self.get_quad_index(quad_name)
\ No newline at end of file
import numpy as np
import os
import OrbitController as oc
import time
from scipy.optimize import curve_fit
from scipy.interpolate import interp1d
import matplotlib.pyplot as plt
class Quadrespmat():
def __init__(self,debug=True):
if debug:
os.environ['TANGO_HOST'] = 'ebs-simu:10000'
self.oc = oc.OrbitController()
self.dk = 0
self.quadi = []
self.nbpms=320
self.matrix=[]
def load_settings(self,dk,quadi):
self.dk = dk
self.quadi = quadi
self.matrix = np.zeros((len(quadi),2,self.nbpms))
def run_scan(self,ts):
for ind,i in enumerate(self.quadi):
name = self.oc.get_quad_name(i)
o0 = self.oc.get_orbit()
plt.plot(o0[0])
print name, self.oc.get_quad_value(name)
self.oc.trim_quad(name,self.dk,True)
time.sleep(ts)
print name, self.oc.get_quad_value(name)
op = self.oc.get_orbit()
plt.plot(np.subtract(op,o0)[0])
self.oc.trim_quad(name,-2*self.dk,True)
time.sleep(ts)
print name, self.oc.get_quad_value(name)
om = self.oc.get_orbit()
plt.plot(np.subtract(om, o0)[0])
self.oc.trim_quad(name,+self.dk,True)
time.sleep(ts)
print name, self.oc.get_quad_value(name)
orb = np.subtract(op,om)/2.0
plt.plot(orb[0])
print np.std(orb,1)
self.matrix[ind] = orb
plt.show()
The List of Excluded Files
Excluded files Exclusion Message ID Reason For Exclusion Exclusion Rule
/mntdirect/_sware/com/matlab_2016a/toolbox/local/+matlab/+internal/+toolboxes/addInstalledToolboxesToPath.m MATLAB:Completion:ExcludedBy Cannot be packaged for use in the target environment MCR. Removed from the parts list by license Compiler. /mntdirect/_sware/com/matlab_2016a/toolbox/local/[+]matlab/[+]internal/[+]toolboxes/addInstalledToolboxesToPath[.]m
/mntdirect/_sware/com/matlab_2016a/toolbox/local/+matlab/+internal/+zipAddOns/addInstalledZipAddOnsToPath.m MATLAB:Completion:ExcludedBy Cannot be packaged for use in the target environment MCR. Removed from the parts list by license Compiler. /mntdirect/_sware/com/matlab_2016a/toolbox/local/[+]matlab/[+]internal/[+]zipAddOns/addInstalledZipAddOnsToPath[.]m
/mntdirect/_sware/com/matlab_2016a/toolbox/local/pathdef.m MATLAB:Completion:ExcludedBy Cannot be packaged for use in the target environment MCR. Removed from the parts list by license Compiler. /mntdirect/_sware/com/matlab_2016a/toolbox/local/pathdef[.]m
/mntdirect/_sware/com/matlab_2016a/toolbox/matlab/codetools/initdesktoputils.m MATLAB:Completion:ExcludedBy Cannot be packaged for use in the target environment MCR. Removed from the parts list by license Compiler. /mntdirect/_sware/com/matlab_2016a/toolbox/matlab/codetools
function passmethodlist()
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
AperturePass
BendLinearPass
BndMPoleSymplectic4E2Pass
BndMPoleSymplectic4E2RadPass
BndMPoleSymplectic4E2QuantPass
BndMPolePass
BndMPoleSymplectic4Pass
BndMPoleSymplectic4KinPass
BndMPoleSymplectic4FrgFPass
BndMPoleSymplectic4KinFrgFPass
BndMPoleSymplectic4ExactPass
BndMPoleSymplectic4ExactFrgFRadPass
BndMPoleSymplectic4RadPass
BndMPoleSymplectic4QuantPass
BndMPoleSymplectic4KinRadPass
BndMPoleSymplectic4FrgFRadPass
BndMPoleSymplectic4FrgFQuantPass
BndMPoleSymplectic4KinFrgFRadPass
BndMPoleSymplectic4ExactRadPass
BndMPoleSymplectic4ExactFrgFRadPass
BndMPoleSymplecticFringes4Pass
BndMPoleSymplecticFringesStrMpole4Pass
BndMPoleSymplecticFringesGeneral4Pass
CavityPass
CorrectorPass
DriftPass
DriftKinPass
DriftExactPass
KinematicPass
EAperturePass
IdentityPass
Matrix66Pass
QuadLinearPass
QuadMPoleFringePass
QuadMPoleFringeRadPass
QuadMPoleFringeQuantPass
SolenoidLinearPass
StrMPolePass
StrMPoleSymplectic4Pass
StrMPoleSymplectic4KinPass
StrMPoleSymplectic4ExactPass
StrMPoleSymplectic4FrgFPass
StrMPoleSymplectic4KinFrgFPass
StrMPoleSymplectic4ExactFrgFPass
StrMPoleSymplecticFringes4Pass
StrMPoleSymplecticFringesGeneral4Pass
StrMPoleSymplectic4RadPass
StrMPoleSymplectic4KinRadPass
StrMPoleSymplectic4ExactRadPass
StrMPoleSymplectic4FrgFRadPass
StrMPoleSymplectic4KinFrgFRadPass
StrMPoleSymplectic4ExactFrgFRadPass
StrMPoleSymplecticFringes4Pass
StrMPoleSymplecticFringesGeneral4Pass
ThinMPolePass
WiggLinearPass
impedance_RWPass
impedance_BBRPass
impedance_BBRZPass
impedance_LplusRPass
impedance_tablePass
DeltaQPass
SimpleDampingPass
SimpleNLRFPass
QuantDiffPass
NL_kickerPass
end
Packaging and Deploying test_class
1. Prerequisites for Deployment
A. If MATLAB Runtime version 9.0.1 (R2016a) has not been installed, install it in one of
these ways:
i. Run the package installer, which will also install the MATLAB Runtime.
ii. Download the Linux 64-bit version of the MATLAB Runtime for R2016a from:
http://www.mathworks.com/products/compiler/mcr/index.html
iii. Run the MATLAB Runtime installer provided with MATLAB.
B. Verify that a Linux 64-bit version of Python 2.7, 3.3, and/or 3.4 is installed.
2. Installing the test_class Package
A. Go to the directory that contains the file setup.py and the subdirectory test_class.
If you do not have write permissions, copy all its contents to a temporary location
and go there.
B. Execute the command:
python setup.py install [options]
If you have full administrator privileges, and install to the default location, you do
not need to specify any options. Otherwise, use --user to install to your home folder,
or --prefix="installdir" to install to "installdir". In the latter case, add
"installdir" to the PYTHONPATH environment variable. For details, refer to:
https://docs.python.org/2/install/index.html
C. Copy the following to a text editor:
setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:<MCR_ROOT>/v90/runtime/glnxa64:<MCR_ROOT>/v90/bin/glnxa64:<MCR_ROOT>/v90/sys/os/glnxa64:<MCR_ROOT>/v90/sys/opengl/lib/glnxa64
setenv XAPPLRESDIR <MCR_ROOT>/v90/X11/app-defaults
Make the following changes:
- If LD_LIBRARY_PATH is not yet defined, remove the string "${LD_LIBRARY_PATH}:".
- Replace "<MCR_ROOT>" with the directory where the MATLAB Runtime is installed.
- If your shell does not support setenv, use a different command to set the environment
variables.
Finally, execute the commands or add them to your shell initialization file.
3. Using the test_class Package
The test_class package is on your Python path. To import it into a Python script or
session, simply execute:
import test_class
35000 35010
\ No newline at end of file
# Copyright 2015 The MathWorks, Inc.
from distutils.core import setup
from distutils.command.clean import clean
from distutils.command.install import install
class InstallRuntime(install):
# Calls the default run command, then deletes the build area
# (equivalent to "setup clean --all").
def run(self):
install.run(self)
c = clean(self.distribution)
c.all = True
c.finalize_options()
c.run()
if __name__ == '__main__':
setup(
name="matlabruntimeforpython",
version="R2016a",
description='A module to call MATLAB from Python',
author='MathWorks',
url='http://www.mathworks.com/',
platforms=['Linux', 'Windows', 'MacOS'],
packages=[
'test_class'
],
package_data={'test_class': ['*.ctf']},
# Executes the custom code above in order to delete the build area.
cmdclass={'install': InstallRuntime}
)
import Loops as loops
import Bumps as bumps
import OrbitController as oc
import Quadrespmat as qmat
import numpy as np
import time
loops = loops.Loops()
bumps = bumps.Bumps()
oc = oc.OrbitController()
qmat = qmat.Quadrespmat()
plane='H'
bpmi = 11
dk0_min = -2.0e-4
dk0_max = 0.0e-4
dk1 = 0.1
dk0 = 0.5e-4
nsteps=5
ts = 5
#loops.scan_single_cor(bpmi,plane,dk0_min,dk0_max,nsteps,dk1,ts)
#loops.find_mini_cor(bpmi,plane,dk0,dk1,ts)
#loops.scan_single_bump(bpmi,plane,dk0_min,dk0_max,nsteps,dk1,ts)
#oc.set_bump(plane,bumps.get_bump(10,plane),9,1.0e-3)
#oc