Skip to content
Snippets Groups Projects
Commit fe282302 authored by Jean-François Denis's avatar Jean-François Denis
Browse files

ExtracData.py created online with Bitbucket

parent 0242f178
No related branches found
No related tags found
No related merge requests found
from org.csstudio.opibuilder.scriptUtil import PVUtil
#! /usr/bin/env python
#from org.csstudio.opibuilder.scriptUtil import PVUtil
import struct
#import matplotlib.pyplot as plt
#import urllib2
import json
from random import betavariate
import math
import array
import datetime
import time
localtime=time.localtime(time.time())
##### VARS #########
NameFile="emittance"
NameFile=NameFile+"_"+str(localtime.tm_year)+"-"+str(localtime.tm_mon)+"-"+str(localtime.tm_mday)+"_"+str(localtime.tm_hour)+"-"+str(localtime.tm_min)+".dat"
NbAngle = 0
NbAngle= PVUtil.getLong(pvs[1])
NbPos = 0
NbPos= PVUtil.getLong(pvs[2])
Energie = 0
Energie= PVUtil.getDouble(pvs[3])
Frequence = 0
Frequence=PVUtil.getDouble(pvs[4])
PasMM = 0
PasMM=PVUtil.getDouble(pvs[5])
tabCurr=0
tabCurr=PVUtil.getDoubleArray(pvs[6])
tabAng=0
tabAng=PVUtil.getDoubleArray(pvs[7])
tabPos=0
tabPos=PVUtil.getDoubleArray(pvs[8])
###################################################################################
############################### PLOTWIN ###########################################
###################################################################################
#### OPEN FILE
PlotFile = open('C:\\temp/'+NameFile, 'w+')
PlotFile.write("fichier emittance: X\n")
PlotFile.write("HT ion (kV) : %d\n"%(Energie))
PlotFile.write("frequence (Hz) : %d\n"%(Frequence))
PlotFile.write("N points temps : 1\n")
PlotFile.write("pas de position (mm) : %d\n"%(PasMM))
PlotFile.write("N points position (mm) : %i\n"%(NbPos))
PlotFile.write("N points angle (mrad) : %i\n"%(NbAngle))
## POSITION
PlotFile.write("vecteur positions (mm) : ")
for value in range(0,NbPos):
PlotFile.write("%d "%tabPos[value]);
value=value+1
## ANGLES
PlotFile.write("\nvecteur angles (mrad) : ")
indAngle=0
for value in range(0,NbAngle):
PlotFile.write("%f "%tabAng[indAngle]);
indAngle=indAngle+NbPos
PlotFile.write("\ntype d'ion : PROTON...")
PlotFile.write("\ncolonnes de 1 a 4 : indice de temps / indice position / indice angle / I [Volt] :\n")
## POSITION/ANGLE/INTENSITY
indCurrent=NbPos-1
indPos=NbPos-1
for valuePos in range(0,NbPos):
for valueAngle in range(0,NbAngle):
PlotFile.write("0\t%i\t%i\t%f\n" %(valuePos,valueAngle,tabCurr[indCurrent]));
indCurrent=indCurrent+NbPos
indPos=indPos-1
indCurrent=indPos
PlotFile.close()
###################################################################################
############################### EXTRACT DATA ######################################
###################################################################################
#### OPEN FILE
PlotFile = open('C:\\temp/'+NameFile+"-avg.txt", 'w+')
## POSITION/ANGLE/INTENSITY
indTab=NbPos-1
indPos=NbPos-1
for valuePos in tabPos:
for valueAngle in range(0,NbAngle):
#PlotFile.write("0\t%d\t%d\t%d\n" %(valuePos[indPos],valueAngle[indAngle],tabCurr[indCurrent]));
PlotFile.write("%d\t%d\t%d\n" %(valuePos,tabAng[indTab],tabCurr[indTab]));
#indCurrent=indCurrent+NbPos
indTab=indTab+NbPos
indPos=indPos-1
#indCurrent=indPos
indTab=indPos
PlotFile.close()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment