Exemple #1
0
class Plot:
        
    def __init__(self):
        self.verbose = True
        self.origin = (0,0)
        self.data2 = []
        self.data3 = []
        self.g = Gnuplot()
        self.g('set data style points')
        self.g('set key left top Left title \'Legend\' box 3')
        self.title = 'title'
        self.xlabel = 'x'
        self.ylabel = 'y'
        self.zlabel = 'z'
        
    def __call__(self,value):
        self.g(value)
        
    def setOrigin(self,x,y):
        """
        @type x: float
        @type y: float
        """
        self.origin = (x,y)
        
    def setVerbose(self,verbose):
        """
        @type verbose: binary
        """
        self.verbose = verbose
        
    def addArrayTuples(self, data, name = ''):
        """
        @param data: data to be added to 2d plot
        @type data: (float,float)[]
        """
        d = Data(data, title = name)
        self.data2.append(d)
 
         
    def add2Arrays(self,x,y):
        """
        @type x: float[]
        @type y: float[]
        """
        if len(x) != len(y):
            return 'arrays not of equal length'
        else:
            array2 = []
            for i in range(len(array)):
                value = (x[i],y[i])
                array2.append(value)
            self.addArrayTuples(array2)
            
    def addArrayTriples(self, data):
        """
        @param data: data to be added to 3d plot
        @type data: (float, float, float)[]
        """        
        self.data3.append(data)
                  
    def add3Arrays(self,x,y,z):
        """
        @type x: float[]
        @type y: float[]
        @type z: float[]
        """        
        if (len(x) == len(y) == len(z)):
            array3 = []
            for i in range(len(x)):
                value = (x[i],y[i],z[i])
                array3.append(value)
            self.addArrayTriples(array3)
            
        else:
           print 'arrays not of equal length'
            
    def setLabels(self,title='title',xlabel='x',ylabel='y',zlabel='z'):
        """
        @type title: string
        @type xlabel: string
        @type ylable: string
        @type zlable: string
        """
        self.title = title
        self.xlabel = xlabel
        self.ylabel = ylabel
        self.zlabel = zlabel
        
    def _plot2D(self):
        self.g.title(self.title)
        self.g.xlabel(self.xlabel)
        self.g.ylabel(self.ylabel)
        if len(self.data2) == 0:
            return False
        self.g.title(self.title)
        self.g.xlabel(self.xlabel)
        self.g.ylabel(self.ylabel)
        self.g.plot(self.data2[0])
        for d in self.data2[1:]:
            self.g.replot(d)
        return True
    
    def plot2DtoScreen(self):
        if not self._plot2D():
            return None
        raw_input('Please press return to continue...\n')
    
    def plot2DtoFile(self, fileName):
        """
        @type fileName: string
        """
        self.g('set term post eps')
        self.g('set output \'%s\'' % fileName)
        if not self._plot2D():
            return None
        self.g.hardcopy(fileName, enhanced=1, color=1)
        if self.verbose: print ('\n******** Saved plot to postscript file %s ********\n' % fileName)
         
    def _plot3d(self):
        if len(self.data3) == 0:
            return False
        self.g.title(self.title)
        self.g.xlabel(self.xlabel)
        self.g.ylabel(self.ylabel)
        self.g('set zlabel \"%s\"' % self.zlabel)
        self.g.plot([self.data3[0]])
        for d in self.data3[1:]:
            self.g.replot(d)
        return True
    
    def plot3DtoScreen(self):
        if not self._plot3D():
            return None  
        raw_input('Please press return to continue...\n')
        
    def plot3DtoFile(self,fileName):
        """
        @type fileName: string
        """
        self.g('set term post eps')
        self.g('set output \'%s\'' % fileName)
        if not self._plot3d():
            return None
        self.g.hardcopy(fileName, enhanced=1, color=1)
        if self.verbose: print ('\n******** Saved plot to postscript file %s ********\n' % fileName)
Exemple #2
0
    def __init__(self, data_dic):

        print data_dic
        try:
            self.port = int(data_dic["port"])
        except:
            raise MissingInformation("port")
        try:
            self.ip = data_dic["ip"]
        except:
            raise MissingInformation("ip")
        self.register_list = data_dic["reg"]
        self.bof_path = data_dic["bof_path"]
        self.bitstream = str(data_dic["name"] + ".bof")
        self.brams_info = data_dic["bram"]
        self.program = data_dic["progdev"]

        self.plot_brams = []
        self.store_drams = []

        for cont in range(len(self.brams_info)):
            self.brams_info[cont]["prev_acc"] = 0

        for cont in range(len(self.brams_info)):
            aplot = lambda x: x
            if self.brams_info[cont]["plot"]:
                aplot = Gnuplot(debug=1)
                aplot.clear()
                aplot("set style data linespoints")
                aplot.ylabel("Power AU (dB)")
                aplot("set xrange [-50:2098]")
                aplot("set yrange [0:100]")
                aplot("set ytics 10")
                aplot("set xtics 256")
                aplot("set grid y")
                aplot("set grid x")

            self.brams_info[cont]["plot_"] = aplot

            class a:
                def close(self):
                    pass

                def writerow(self, x):
                    pass

            astore = (a(), a())

            if self.brams_info[cont]["store"]:
                ts = time.time()
                time_stamp = datetime.datetime.fromtimestamp(ts).strftime("%Y-%m-%d %H:%M:%S")
                print self.brams_info[cont].keys()
                file_name = (
                    self.bof_path[: -len(".bof")] + "-" + self.brams_info[cont]["array_id"] + "-" + time_stamp + ".csv"
                )
                file = open(file_name, "w")

                csv_writer = csv.writer(file, delimiter=",")
                astore = (csv_writer, file)
            self.brams_info[cont]["store_"] = astore

        self.fpga = None
        self.last_acc_count = {}

        self.handler = corr.log_handlers.DebugLogHandler()
        self.logger = logging.getLogger(self.ip)
        self.logger.addHandler(self.handler)
        self.logger.setLevel(10)