示例#1
0
 def calculate(self):
      attr1=[]
      attr2=[]
      
      for fileName in self.fileName:
          error=False
          try:
              value1=readHdf5.getAttr(fileName,self.attr1.text(),self.env)
              if isinstance(value1,float) or isinstance(value1,int):                    
                  attr1.append(value1)
              else:
                  attr1.append(value1[0])
              error=True
              value2=readHdf5.getAttr(fileName,self.attr2.text(),self.env)
              if isinstance(value2,float)  or isinstance(value2,int):
                  print value2                    
                  attr2.append(value2)
              else:
                  attr2.append(value2[0])
          except:
              if error:
                  attr2.append(0.0)
              continue
          #print attr1,attr2[0]
      #print attr1,attr2
      self.p1.plot(attr1,attr2,pen=None,symbol='o')
      fit = np.polyfit(attr1,attr2,1)
      xx=np.linspace(min(attr1),max(attr1),200)
      self.p1.plot(xx,np.poly1d(fit)(xx))
      print fit
 def start(self):
     smallcoils=float(self.smallC.text())
     addcoil=float(self.addC.text())
     text=self.bigC.text()
     if text=='auto':
         try:
             bigcoil=readHdf5.getAttr(self.fileName,'magnetic',self.env)
         except:
             text='2000'
             self.smallC.setText('2000')
     if not(text=='auto'):
         bigcoil=float(text)
     file = open('2015_07_22_MFC_003_adBcoil.FEM', 'r')
     i=1
     for line in file:
         if i==55:
             line=line.split('=')[0]+'='+str(smallcoils)+'\n'
         if i==61:
             line=line.split('=')[0]+'='+str(-smallcoils)+'\n'
         if i==67:
             line=line.split('=')[0]+'='+str(bigcoil)+'\n'
         if i==73:
             line=line.split('=')[0]+'='+str(-bigcoil)+'\n'
         if i==79:
             line=line.split('=')[0]+'='+str(addcoil)+'\n'
         if i==85:
             line=line.split('=')[0]+'='+str(-addcoil)+'\n'
         i=i+1
     command="C:"+os.sep+"femm42"+os.sep+"bin"+os.sep+"femm.exe"
     path=r"D:"+os.sep+"DATA"+os.sep+"IShTAR_Process"            
     script1="-lua-script="+path+os.sep+"LUA_code_003.lua"
     script2=" -windowhide"
     command=command+' '+script1+' '+script2
     print command
     print script1,script2
     call(command,shell=True)
示例#3
0
    def start(self):
         def calibr(x):
             slope=(76.-23.)/(400.-1400.)
             return (x-400.)*slope+76.-33     
             
         def calibr2(x):
             return 10**(((x-0.02- 2.2503)/0.0520+10)/10)
         pos=[]           
         data1=[]
         data2=[]
         data3=[]
         data4=[]
         data1max=[]
         data2max=[]
         data3max=[]
         data4max=[]
         data1min=[]
         data2min=[]
         data3min=[]
         data4min=[]
         for x in self.fileName:
            try:
                pos.append(readHdf5.getAttr(x,'positionSpace',self.env))
            except:
                continue
            try:
                attr=self.l1.text()
                print attr
                if attr=='':
                    data1.append(0.)
                    data1min.append(0.) 
                    data1max.append(0.) 
                else:
#                    attr2=attr
#                    if attr=='VplasmaHP' or attr=='VplasmaLP':
#                        attr2='density'+attr[-1:-2]
#                    if attr=='VfloatHP' or attr=='VfloatLP':
#                        
#                        attr2='density'+attr[-1:-2]
#                    if attr=='tempHP' or attr=='tempLP':
#                        attr2='density'+attr[-1:-2]                   
#                    data=readHdf5.getAttr(x,attr2,self.env)
#                    attr=attr2
                    data=readHdf5.getAttr(x,attr,self.env)
#                    if (attr=='fastHP' or attr=='fastLP' or attr=='slowLP' or attr=='slowHP'):
#                        data=calibr2(data[0])
#                    if attr=='densityHP' or attr=='densityLP':
#                        data=data[1]
#                    if attr=='vplasmaHP' or attr=='vplasmaLP':
#                        data=data[3]
#                    if attr=='vfloatHP' or attr=='vfloatLP':
#                        
#                        data=data[2]
#                    if attr=='tempHP' or attr=='tempLP':
#                        data=data[0]                        
                        
                    data1.append(data[0]) 
                    data1max.append(data[1])
                    data1min.append(data[2])                             
            except:
                 pass
            try:
                attr=self.l2.text()
                if attr=='':
                    data2.append(0.)    
                    data2min.append(0.)  
                    data2max.append(0.)  
                else:
                    data=readHdf5.getAttr(x,attr,self.env)
                    data2.append(data[0]) 
                    data2max.append(data[1])
                    data2min.append(data[2])                             
            except:
                 pass
            try:
                attr=self.l3.text()
                if attr=='':
                    data3.append(0.)    
                    data3min.append(0.)  
                    data3max.append(0.)  
                else:
                    data=readHdf5.getAttr(x,attr,self.env)
                    data3.append(data[0]) 
                    data3max.append(data[1])
                    data3min.append(data[2])                             
            except:
                 pass
            try:
                attr=self.l4.text()
                if attr=='':
                    data4.append(0.)    
                    data4min.append(0.)  
                    data4max.append(0.)  
                else:
                    data=readHdf5.getAttr(x,attr,self.env)
                    data4.append(data[0]) 
                    data4max.append(data[1])
                    data4min.append(data[2])                             
            except:
                 pass
   
         #self.p1.plot(title='Fast Wave profile High Power')
         self.p0.clear()
         self.p0.plot(pos,data1,pen=None,symbolPen='w')
         self.p0.setLabel('bottom', "Position/Center (cm)")
         self.p1.clear()
         self.p1.plot(pos,data2,pen=None,symbolPen='w')
         self.p1.setLabel('bottom', "Position/Center (cm)")
         self.p2.clear()
         self.p2.plot(pos,data3,pen=None,symbolPen='w')
         self.p2.setLabel('bottom', "Position/Center (cm)")
         self.p3.clear()
         self.p3.plot(pos,data4,pen=None,symbolPen='w')
         self.p3.setLabel('bottom', "Position/Center (cm)")
         self.p1.setXLink(self.p0)
         self.p2.setXLink(self.p0)
         self.p3.setXLink(self.p0)
         err = pg.ErrorBarItem(x=np.array(pos), y=np.array(data1), top=np.array(data1max), bottom=np.array(data1min), beam=0.5)
         self.p0.addItem(err)
         err = pg.ErrorBarItem(x=np.array(pos), y=np.array(data2), top=np.array(data2max), bottom=np.array(data2min), beam=0.5)
         self.p1.addItem(err)
         err = pg.ErrorBarItem(x=np.array(pos), y=np.array(data3), top=np.array(data3max), bottom=np.array(data3min), beam=0.5)
         self.p2.addItem(err)
         err = pg.ErrorBarItem(x=np.array(pos), y=np.array(data4), top=np.array(data4max), bottom=np.array(data4min), beam=0.5)
         self.p3.addItem(err)
         
#         indices = np.argsort(pos)
#         pos=np.array(pos)[indices]
#         pos,idx=np.unique(pos,return_index=True)
#         fast=np.array(fast)[indices]
#         fast=fast[idx]
#         tck = splrep(pos,fast,s=100 )
#         x2 = np.linspace(pos[0], pos[-1], 200)
#         y2 = splev(x2, tck)
#         p1.plot(x2,y2,pen=(255,0,0))
         self.show()
示例#4
0
def convertGenerator(fileN, firstShot, lastShot, env):
    # filename=r'D:\DATA\IShTAR_Process\data_20150119_20150715.csv'
    filename = os.path.normpath(fileN)
    shotstart = firstShot
    shotend = lastShot
    included_cols = [1, 2, 3, 11, 12]

    df = pd.read_csv(filename, sep="\t", parse_dates=[0])
    print df.dtypes
    df.loc[df["ForwardPower[W]"] != 0, "Run"] = 1
    #
    df["block"] = (df.Run.shift(1) != df.Run).astype(int).cumsum()
    df.reset_index().groupby(["Run", "block"])["index"].apply(lambda x: np.array(x))
    df = df[df["Run"] == 1]
    nbr = np.max(df["block"]) / 2
    # print nbr
    liste = np.arange(shotstart, shotend)
    listefile = []
    for x in liste:
        listefile.append(str(x).zfill(5) + "_Data")

    # print listefile
    j = 2
    timediff = datetime.timedelta(minutes=1, seconds=0)
    timecorrection = datetime.timedelta(minutes=11, seconds=10)
    # path=r"D:"+os.sep+"DATA"+os.sep+"Acquired_data"
    path = env.path
    for x in listefile:
        # timei=datetime.datetime.strptime(time.ctime(os.path.getmtime(path+os.sep+x+'.h5')),"%a %b %d %H:%M:%S %Y")
        try:
            timea = readHdf5.getAttr(x, "date", env)
            timei = datetime.datetime.strptime(timea, "%d.%m.%Y %H:%M:%S")
            # print x
            matched = False
            while not (matched):
                data0 = df[df["block"] == j]["Time"].values
                timef = datetime.datetime.utcfromtimestamp(
                    (data0[0] - np.datetime64("1970-01-01T00:00:00Z")) / np.timedelta64(1, "s")
                )
                print timei, (timef + timecorrection), timef
                timef = timef + timecorrection
                if timei > timef:
                    deltat = timei - timef
                else:
                    deltat = timef - timei
                print deltat
                if deltat <= timediff:
                    data = df[df["block"] == j]["ForwardPower[W]"].values
                    data2 = df[df["block"] == j]["ReflectedPower[W]"].values
                    sampling = 1 / (float((data0[1] - data0[0]).item()) * 1e-9)
                    hdf5 = h5py.File(path + os.sep + x + ".h5", "a")
                    grouph = hdf5.create_group("Generator")
                    grouph.create_dataset("Fpower", data=data, compression="gzip")
                    grouph.create_dataset("Rpower", data=data2, compression="gzip")
                    grouph.attrs["sampling"] = sampling
                    j = j + 2
                    matched = True
                    print "Generator for " + x

                if (deltat > timediff) and (timei > timef) and (j < nbr):
                    j = j + 2
                    print "Power without discharge"
                if (deltat > timediff) and (timei > timef) and (j >= nbr):
                    matched = True
                if (deltat > timediff) and (timei < timef):
                    matched = True
                    print "No generator for " + x
        except:
            pass