Пример #1
0
 def manageContinuousUpdate(self, x):
     if x.getShape().size == 1:
         new_max_x = x.data()[-1]
     else:
         new_max_x = x.data()[0][-1]
     curr_max_x = float(self.args['curr_max_x' + x_idx_s][-1])
     displayed_width = float(self.args['displayed_width'][-1])
     default_num_samples = float(self.args['default_num_samples'][-1])
     num_samples = int(
         (new_max_x - curr_max_x) * default_num_samples / displayed_width)
     if new_max_x > curr_max_x and num_samples > 1:
         if issubclass(x.dtype.type, integer):
             min_req_x = floor(curr_max_x + 1)
         else:
             min_req_x = curr_max_x + finfo(new_max_x).eps
         update_function = 'MdsMisc->GetXYWave:DSC'
         infinity = sys.float_info.max
         if x.__class__.__name__ == 'Uint64Array' or x.__class__.__name__ == 'Int64Array':
             update_function = 'MdsMisc->GetXYWaveLongTimes:DSC'
             min_req_x = str(int(min_req_x)) + 'QU'
             infinity = str((1 << 63) - 1) + 'QU'
         sig = Data.execute(
             update_function + '(\'' +
             expr.replace('\\', '\\\\').replace('\'', '\\\'') + '\',' +
             str(min_req_x) + ',' + str(infinity) + ',' + str(num_samples) +
             ')')
         return makeData(sig.dim_of().data()), makeData(sig.data())
     else:
         return Float64Array([]), Float64Array([])
Пример #2
0
def do1dsignal(self):
    if len(self.path_parts) > 2:
        self.openTree(self.path_parts[1], self.path_parts[2])
    expr = self.args['expr'][-1]
    try:
        sig = Data.execute(expr)
        y = makeData(sig.data())
        x = makeData(sig.dim_of().data())
    except Exception:
        raise Exception("Error evaluating expression: '%s', error: %s" %
                        (expr, sys.exc_info()))
    response_headers = list()
    response_headers.append(
        ('Cache-Control', 'no-store, no-cache, must-revalidate'))
    response_headers.append(('Pragma', 'no-cache'))
    response_headers.append(('XDTYPE', x.__class__.__name__))
    response_headers.append(('YDTYPE', y.__class__.__name__))
    response_headers.append(('XLENGTH', str(len(x))))
    response_headers.append(('YLENGTH', str(len(y))))
    if self.tree is not None:
        response_headers.append(('TREE', self.tree))
        response_headers.append(('SHOT', self.shot))
    output = str(x.data().data) + str(y.data().data)
    status = '200 OK'
    return (status, response_headers, output)
Пример #3
0
def do1dsignal(self):
    if len(self.path_parts) > 2:
        self.openTree(self.path_parts[1],self.path_parts[2])
    expr=self.args['expr'][-1]
    try:
        sig=Data.execute(expr)
        y=makeData(sig.data())
        x=makeData(sig.dim_of().data())
    except Exception,e:
        raise Exception("Error evaluating expression: '%s', error: %s" % (expr,e))
Пример #4
0
def doPlot(self):

    viewbox=[0,0,10000,10000];
    def scale(xmin,ymin,xmax,ymax,xmin_s,ymin_s,xmax_s,ymax_s,x,y):
        px=(x-xmin)*(xmax_s-xmin_s)/(xmax-xmin)
        py=(y-ymin)*(ymax_s-ymin_s)/(ymax-ymin)
        return " %d %d" % (int(round(px)),int(round(py)))

    def gridScaling(min_in,max_in,divisions,span):
        from math import log10,pow,fabs,ceil,floor,modf
        resdivlog = log10(fabs(max_in-min_in))
        if resdivlog < 0:
            res = pow(10,ceil(resdivlog) - 4)
        else:
            res = pow(10,floor(resdivlog) - 4)
        divlog = log10(fabs(max_in - min_in) / divisions)
        fractpart,wholepart = modf(divlog)
        intinc = pow(10,fabs(fractpart))
        if intinc < 1.3333333:
            intinc=1
        elif intinc < 2.857:
            intinc=2
        else:
            intinc=10
        if divlog < 0:
            val_inc = pow(10,-log10(intinc) + wholepart)
        else:
            val_inc = pow(10,log10(intinc) + wholepart)
        grid=ceil(min_in/val_inc) * val_inc
        divs_out = floor((max_in - grid + val_inc) / val_inc)
        if max_in > min_in:
            first_pix = span * ((grid - min_in) / (max_in - min_in))
            pix_inc = span * val_inc / (max_in - min_in);
            first_val = (first_pix * ((max_in - min_in)/span)) + min_in
        else:
            divs_out = 2
            first_pix = 0
            pix_inc = span
            val_inc = 0
        return {"divisions":divs_out,
                "first_pixel":first_pix, "pixel_increment":pix_inc, 
                "first_value":first_val, "value_increment":val_inc,
                "resolution":res}
          
    if len(self.path_parts) > 2:
        self.openTree(self.path_parts[1],self.path_parts[2])
    expr=self.args['expr'][-1]
    try:
        sig=Data.execute(expr)
        y=makeData(sig.data()).data()
        x=makeData(sig.dim_of().data()).data()
    except Exception,e:
        raise Exception("Error evaluating expression: '%s', error: %s" % (expr,e))
Пример #5
0
def do1darray(self):
    if len(self.path_parts) > 2:
        self.openTree(self.path_parts[1],self.path_parts[2])
    expr=self.args['expr'][-1]
    try:
        a=makeData(Data.execute(expr).data())
    except Exception,e:
        raise Exception("Error evaluating expression: '%s', error: %s" % (expr,e))
Пример #6
0
def do1dsignal(self):
    if len(self.path_parts) > 2:
        self.openTree(self.path_parts[1],self.path_parts[2])
    expr=self.args['expr'][-1]
    try:
        sig=Data.execute(expr)
        y=makeData(sig.data())
        x=makeData(sig.dim_of().data())
    except Exception:
        raise Exception("Error evaluating expression: '%s', error: %s" % (expr,sys.exc_info()))
    response_headers=list()
    response_headers.append(('Cache-Control','no-store, no-cache, must-revalidate'))
    response_headers.append(('Pragma','no-cache'))
    response_headers.append(('XDTYPE',x.__class__.__name__))
    response_headers.append(('YDTYPE',y.__class__.__name__))
    response_headers.append(('XLENGTH',str(len(x))))
    response_headers.append(('YLENGTH',str(len(y))))
    if self.tree is not None:
        response_headers.append(('TREE',self.tree))
        response_headers.append(('SHOT',self.shot))
    output=str(x.data().data)+str(y.data().data)
    status = '200 OK'
    return (status, response_headers, output)
Пример #7
0
def doFrame(self):
    def getStringExp(self, name, response_headers):
        if name in self.args:
            try:
                response_headers.append(
                    (name, str(Data.execute(self.args[name][-1]).data())))
            except Exception:
                response_headers.append((name, str(sys.exc_info())))

    response_headers = list()
    response_headers.append(
        ('Cache-Control', 'no-store, no-cache, must-revalidate'))
    response_headers.append(('Pragma', 'no-cache'))
    response_headers.append(('Content-Type', 'application/octet-stream'))

    if 'tree' in self.args:
        Tree.usePrivateCtx()
        try:
            t = Tree(self.args['tree'][-1],
                     int(self.args['shot'][-1].split(',')[0]))
        except:
            response_headers.append(('ERROR', 'Error opening tree'))

    for name in ('title', 'xlabel', 'ylabel'):
        getStringExp(self, name, response_headers)

    if 'frame_idx' in self.args:
        frame_idx = self.args['frame_idx'][-1]
    else:
        frame_idx = '0'

    expr = self.args['y'][-1]
    try:
        sig = Data.execute('GetSegment(' + expr + ',' + frame_idx + ')')
        frame_data = makeData(sig.data())
    except Exception:
        response_headers.append(
            ('ERROR', 'Error evaluating expression: "%s", error: %s' %
             (expr, sys.exc_info())))

    if 'init' in self.args:
        if 'x' in self.args:
            expr = self.args['x'][-1]
            try:
                times = Data.execute(expr)
                times = makeData(times.data())
            except Exception:
                response_headers.append(
                    ('ERROR', 'Error evaluating expression: "%s", error: %s' %
                     (expr, sys.exc_info())))
        else:
            try:
                #times = Data.execute('dim_of(' + expr + ')')
                times = list()
                numSegments = Data.execute('GetNumSegments(' + expr +
                                           ')').data()
                for i in range(0, numSegments):
                    times.append(
                        Data.execute('GetSegmentLimits(' + expr + ',' +
                                     str(i) + ')').data()[0])
                times = Float64Array(times)
            except Exception:
                response_headers.append(
                    ('ERROR', 'Error getting x axis of: "%s", error: %s' %
                     (expr, sys.exc_info())))

    response_headers.append(('FRAME_WIDTH', str(sig.getShape()[0])))
    response_headers.append(('FRAME_HEIGHT', str(sig.getShape()[1])))
    response_headers.append(
        ('FRAME_BYTES_PER_PIXEL', str(frame_data.data().itemsize)))
    response_headers.append(('FRAME_LENGTH', str(len(frame_data))))

    output = str(frame_data.data().data)

    if 'init' in self.args:
        response_headers.append(('TIMES_DATATYPE', times.__class__.__name__))
        response_headers.append(('TIMES_LENGTH', str(len(times))))
        output = output + str(times.data().data)

    status = '200 OK'
    return (status, response_headers, output)
Пример #8
0
def doScopepanel(self):
    def getStringExp(self, name, response_headers):
        if name in self.args:
            try:
                response_headers.append(
                    (name, str(Data.execute(self.args[name][-1]).data())))
            except Exception:
                response_headers.append(
                    (name + '_error:', str(sys.exc_info())))

    def manageContinuousUpdate(self, x):
        if x.getShape().size == 1:
            new_max_x = x.data()[-1]
        else:
            new_max_x = x.data()[0][-1]
        curr_max_x = float(self.args['curr_max_x' + x_idx_s][-1])
        displayed_width = float(self.args['displayed_width'][-1])
        default_num_samples = float(self.args['default_num_samples'][-1])
        num_samples = int(
            (new_max_x - curr_max_x) * default_num_samples / displayed_width)
        if new_max_x > curr_max_x and num_samples > 1:
            if issubclass(x.dtype.type, integer):
                min_req_x = floor(curr_max_x + 1)
            else:
                min_req_x = curr_max_x + finfo(new_max_x).eps
            update_function = 'MdsMisc->GetXYWave:DSC'
            infinity = sys.float_info.max
            if x.__class__.__name__ == 'Uint64Array' or x.__class__.__name__ == 'Int64Array':
                update_function = 'MdsMisc->GetXYWaveLongTimes:DSC'
                min_req_x = str(int(min_req_x)) + 'QU'
                infinity = str((1 << 63) - 1) + 'QU'
            sig = Data.execute(
                update_function + '(\'' +
                expr.replace('\\', '\\\\').replace('\'', '\\\'') + '\',' +
                str(min_req_x) + ',' + str(infinity) + ',' + str(num_samples) +
                ')')
            return makeData(sig.dim_of().data()), makeData(sig.data())
        else:
            return Float64Array([]), Float64Array([])

    response_headers = list()
    response_headers.append(
        ('Cache-Control', 'no-store, no-cache, must-revalidate'))
    response_headers.append(('Pragma', 'no-cache'))
    if 'tree' in self.args:
        Tree.usePrivateCtx()
        try:
            t = Tree(self.args['tree'][-1],
                     int(self.args['shot'][-1].split(',')[0]))
        except:
            pass

    for name in ('title', 'xlabel', 'ylabel', 'xmin', 'xmax', 'ymin', 'ymax'):
        getStringExp(self, name, response_headers)

    continuous_update = 'continuous_update' in self.args

    sig_idx = 0
    output = ''
    if 'tree' in self.args:
        shots = self.args['shot'][-1].split(',')
        for shot in shots:
            y_idx = 1
            y_idx_s = '%d' % (y_idx, )
            while 'y' + y_idx_s in self.args:
                x_idx_s = y_idx_s
                sig_idx = sig_idx + 1
                sig_idx_s = '%d' % (sig_idx, )
                expr = self.args['y' + y_idx_s][-1]
                y_idx = y_idx + 1
                y_idx_s = '%d' % (y_idx, )
                try:
                    t = Tree(self.args['tree'][-1], int(shot))
                    response_headers.append(('SHOT' + sig_idx_s, str(t.shot)))
                except Exception:
                    response_headers.append(
                        ('ERROR' + sig_idx_s,
                         'Error opening tree %s, shot %s, error: %s' %
                         (self.args['tree'][-1], shot, sys.exc_info())))
                    continue
                if 'default_node' in self.args:
                    try:
                        t.setDefault(t.getNode(self.args['default_node'][-1]))
                    except Exception:
                        response_headers.append((
                            'ERROR' + sig_idx_s,
                            'Error setting default to %s in tree %s, shot %s, error: %s'
                            % (self.args['default_node'][-1],
                               self.args['tree'][-1], shot, sys.exc_info())))
                        continue
                try:
                    sig = Data.execute(expr)
                    if not continuous_update:
                        y = makeData(sig.data())
                except Exception:
                    response_headers.append(
                        ('ERROR' + sig_idx_s,
                         'Error evaluating expression: "%s", error: %s' %
                         (expr, sys.exc_info())))
                    continue
                if 'x' + x_idx_s in self.args:
                    expr = self.args['x' + x_idx_s][-1]
                    try:
                        x = Data.execute(expr)
                        x = makeData(x.data())
                        if continuous_update:
                            x, y = manageContinuousUpdate(self, x)
                    except Exception:
                        response_headers.append(
                            ('ERROR' + sig_idx_s,
                             'Error evaluating expression: "%s", error: %s' %
                             (expr, sys.exc_info())))
                        continue
                else:
                    try:
                        x = makeData(sig.dim_of().data())
                        if continuous_update:
                            x, y = manageContinuousUpdate(self, x)
                    except Exception:
                        response_headers.append(
                            ('ERROR' + sig_idx_s,
                             'Error getting x axis of %s:, error: %s' %
                             (expr, sys.exc_info())))
                        continue
                if x.__class__.__name__ == 'Uint64Array' or x.__class__.__name__ == 'Int64Array':
                    x = Float64Array(
                        x)  # Javascript doesn't support 64 bit integers
                    response_headers.append(('X_IS_DATETIME', 'true'))
                response_headers.append(
                    ('X' + sig_idx_s + '_DATATYPE', x.__class__.__name__))
                response_headers.append(
                    ('Y' + sig_idx_s + '_DATATYPE', y.__class__.__name__))
                response_headers.append(
                    ('X' + sig_idx_s + '_LENGTH', str(len(x))))
                response_headers.append(
                    ('Y' + sig_idx_s + '_LENGTH', str(len(y))))
                output = output + str(x.data().data) + str(y.data().data)
    else:
        y_idx = 1
        y_idx_s = '%d' % (y_idx, )
        while 'y' + y_idx_s in self.args:
            x_idx_s = y_idx_s
            expr = self.args['y' + y_idx_s][-1]
            y_idx = y_idx + 1
            y_idx_s = '%d' % (y_idx, )
            sig_idx = sig_idx + 1
            sig_idx_s = '%d' % (sig_idx, )
            try:
                sig = Data.execute(expr)
                if not continuous_update:
                    y = makeData(sig.data())
            except Exception:
                response_headers.append(
                    ('ERROR' + sig_idx_s,
                     'Error evaluating expression: "%s", error: %s' %
                     (expr, sys.exc_info())))
                continue
            if 'x' + x_idx_s in self.args:
                expr = self.args['x' + x_idx_s][-1]
                try:
                    x = Data.execute(expr)
                    x = makeData(x.data())
                    if continuous_update:
                        x, y = manageContinuousUpdate(self, x)
                except Exception:
                    response_headers.append(
                        ('ERROR' + sig_idx_s,
                         'Error evaluating expression: "%s", error: %s' %
                         (expr, sys.exc_info())))
                    continue
            else:
                try:
                    x = makeData(sig.dim_of().data())
                    if continuous_update:
                        x, y = manageContinuousUpdate(self, x)
                except Exception:
                    response_headers.append(
                        ('ERROR' + sig_idx_s,
                         'Error getting x axis of %s: "%s", error: %s' %
                         (expr, sys.exc_info())))
                    continue
            if x.__class__.__name__ == 'Uint64Array' or x.__class__.__name__ == 'Int64Array':
                x = Float64Array(
                    x)  # Javascript doesn't support 64 bit integers
                response_headers.append(('X_IS_DATETIME', 'true'))
            response_headers.append(
                ('X' + sig_idx_s + '_DATATYPE', x.__class__.__name__))
            response_headers.append(
                ('Y' + sig_idx_s + '_DATATYPE', y.__class__.__name__))
            response_headers.append(('X' + sig_idx_s + '_LENGTH', str(len(x))))
            response_headers.append(('Y' + sig_idx_s + '_LENGTH', str(len(y))))
            output = output + str(x.data().data) + str(y.data().data)
    return ('200 OK', response_headers, output)
Пример #9
0
def doScopepanel(self):
    def getStringExp(self,name,response_headers):
        if name in self.args:
            try:
                response_headers.append((name,str(Data.execute(self.args[name][-1]).data())))
            except Exception:
                response_headers.append((name,str(sys.exc_info()[1])))

    response_headers=list()
    response_headers.append(('Cache-Control','no-store, no-cache, must-revalidate'))
    response_headers.append(('Pragma','no-cache'))
    if 'tree' in self.args:
        Tree.usePrivateCtx()
        try:
            t=Tree(self.args['tree'][-1],int(self.args['shot'][-1].split(',')[0]))
        except:
            pass

    for name in ('title','xlabel','ylabel','xmin','xmax','ymin','ymax'):
        getStringExp(self,name,response_headers)

    sig_idx=0
    output=''
    if 'tree' in self.args:
        shots=self.args['shot'][-1].split(',')
        for shot in shots:
            y_idx=1
            y_idx_s='%d' % (y_idx,)
            while 'y'+y_idx_s in self.args:
                x_idx_s=y_idx_s
                sig_idx=sig_idx+1
                sig_idx_s='%d' % (sig_idx,)
                expr=self.args['y'+y_idx_s][-1]
                y_idx=y_idx+1
                y_idx_s='%d' % (y_idx,)
                try:
                    t=Tree(self.args['tree'][-1],int(shot))
                    response_headers.append(('SHOT'+sig_idx_s,str(t.shot)))
                except Exception:
                    response_headers.append(('ERROR'+sig_idx_s,'Error opening tree %s, shot %s, error: %s' % (self.args['tree'][-1],shot,sys.exc_info()[1])))
                    continue
                if 'default_node' in self.args:
                    try:
                        t.setDefault(t.getNode(self.args['default_node'][-1]))
                    except Exception:
                        response_headers.append(('ERROR'+sig_idx_s,'Error setting default to %s in tree %s, shot %s, error: %s' % (self.args['default_node'][-1],
                                                                                                                                    self.args['tree'][-1],shot,sys.exc_info()[1])))
                        continue
                try:
                    sig=Data.execute(expr)
                    y=makeData(sig.data())
                except Exception:
                    response_headers.append(('ERROR' + sig_idx_s,'Error evaluating expression: "%s", error: %s' % (expr,sys.exc_info()[1])))
                    continue
                if 'x'+x_idx_s in self.args:
                    expr=self.args['x'+x_idx_s][-1]
                    try:
                        x=Data.execute(expr)
                        x=makeData(x.data())
                    except Exception:
                        response_headers.append(('ERROR'+sig_idx_s,'Error evaluating expression: "%s", error: %s' % (expr,sys.exc_info()[1])))
                        continue
                else:
                    try:
                        x=makeData(sig.dim_of().data())
                    except Exception:
                        response_headers.append(('ERROR'+sig_idx_s,'Error getting x axis of %s: "%s", error: %s' % (expr,sys.exc_info()[1])))
                        continue
                response_headers.append(('X'+sig_idx_s+'_DATATYPE',x.__class__.__name__))
                response_headers.append(('Y'+sig_idx_s+'_DATATYPE',y.__class__.__name__))
                response_headers.append(('X'+sig_idx_s+'_LENGTH',str(len(x))))
                response_headers.append(('Y'+sig_idx_s+'_LENGTH',str(len(y))))
                output=output+str(x.data().data)+str(y.data().data)
    else:            
        y_idx=1
        y_idx_s='%d' % (y_idx,)
        while 'y'+y_idx_s in self.args:
            x_idx_s = y_idx_s
            expr=self.args['y'+y_idx_s][-1]
            y_idx=y_idx+1
            y_idx_s='%d' % (y_idx,)
            sig_idx=sig_idx+1
            sig_idx_s='%d' % (sig_idx,)
            try:
                sig=Data.execute(expr)
                y=makeData(sig.data())
            except Exception:
                response_headers.append(('ERROR' + sig_idx_s,'Error evaluating expression: "%s", error: %s' % (expr,sys.exc_info()[1])))
                continue
            if 'x'+x_idx_s in self.args:
                expr=self.args['x'+x_idx_s][-1]
                try:
                    x=Data.execute(expr)
                    x=makeData(x.data())
                except Exception:
                    response_headers.append(('ERROR'+sig_idx_s,'Error evaluating expression: "%s", error: %s' % (expr,sys.exc_info()[1])))
                    continue
            else:
                try:
                    x=makeData(sig.dim_of().data())
                except Exception:
                    response_headers.append(('ERROR'+sig_idx_s,'Error getting x axis of %s: "%s", error: %s' % (expr,sys.exc_info()[1])))
                    continue
            response_headers.append(('X'+sig_idx_s+'_DATATYPE',x.__class__.__name__))
            response_headers.append(('Y'+sig_idx_s+'_DATATYPE',y.__class__.__name__))
            response_headers.append(('X'+sig_idx_s+'_LENGTH',str(len(x))))
            response_headers.append(('Y'+sig_idx_s+'_LENGTH',str(len(y))))
            output=output+str(x.data().data)+str(y.data().data)
    return ('200 OK', response_headers, output)
Пример #10
0
def doScopepanel(self):
    def getStringExp(self, name, response_headers):
        if name in self.args:
            try:
                response_headers.append(
                    (name, str(Data.execute(self.args[name][-1]).data())))
            except Exception:
                response_headers.append((name, str(sys.exc_info()[1])))

    response_headers = list()
    response_headers.append(
        ('Cache-Control', 'no-store, no-cache, must-revalidate'))
    response_headers.append(('Pragma', 'no-cache'))
    if 'tree' in self.args:
        Tree.usePrivateCtx()
        try:
            t = Tree(self.args['tree'][-1],
                     int(self.args['shot'][-1].split(',')[0]))
        except:
            pass

    for name in ('title', 'xlabel', 'ylabel', 'xmin', 'xmax', 'ymin', 'ymax'):
        getStringExp(self, name, response_headers)

    sig_idx = 0
    output = ''
    if 'tree' in self.args:
        shots = self.args['shot'][-1].split(',')
        for shot in shots:
            y_idx = 1
            y_idx_s = '%d' % (y_idx, )
            while 'y' + y_idx_s in self.args:
                x_idx_s = y_idx_s
                sig_idx = sig_idx + 1
                sig_idx_s = '%d' % (sig_idx, )
                expr = self.args['y' + y_idx_s][-1]
                y_idx = y_idx + 1
                y_idx_s = '%d' % (y_idx, )
                try:
                    t = Tree(self.args['tree'][-1], int(shot))
                    response_headers.append(('SHOT' + sig_idx_s, str(t.shot)))
                except Exception:
                    response_headers.append(
                        ('ERROR' + sig_idx_s,
                         'Error opening tree %s, shot %s, error: %s' %
                         (self.args['tree'][-1], shot, sys.exc_info()[1])))
                    continue
                if 'default_node' in self.args:
                    try:
                        t.setDefault(t.getNode(self.args['default_node'][-1]))
                    except Exception:
                        response_headers.append((
                            'ERROR' + sig_idx_s,
                            'Error setting default to %s in tree %s, shot %s, error: %s'
                            %
                            (self.args['default_node'][-1],
                             self.args['tree'][-1], shot, sys.exc_info()[1])))
                        continue
                try:
                    sig = Data.execute(expr)
                    y = makeData(sig.data())
                except Exception:
                    response_headers.append(
                        ('ERROR' + sig_idx_s,
                         'Error evaluating expression: "%s", error: %s' %
                         (expr, sys.exc_info()[1])))
                    continue
                if 'x' + x_idx_s in self.args:
                    expr = self.args['x' + x_idx_s][-1]
                    try:
                        x = Data.execute(expr)
                        x = makeData(x.data())
                    except Exception:
                        response_headers.append(
                            ('ERROR' + sig_idx_s,
                             'Error evaluating expression: "%s", error: %s' %
                             (expr, sys.exc_info()[1])))
                        continue
                else:
                    try:
                        x = makeData(sig.dim_of().data())
                    except Exception:
                        response_headers.append(
                            ('ERROR' + sig_idx_s,
                             'Error getting x axis of %s: "%s", error: %s' %
                             (expr, sys.exc_info()[1])))
                        continue
                response_headers.append(
                    ('X' + sig_idx_s + '_DATATYPE', x.__class__.__name__))
                response_headers.append(
                    ('Y' + sig_idx_s + '_DATATYPE', y.__class__.__name__))
                response_headers.append(
                    ('X' + sig_idx_s + '_LENGTH', str(len(x))))
                response_headers.append(
                    ('Y' + sig_idx_s + '_LENGTH', str(len(y))))
                output = output + str(x.data().data) + str(y.data().data)
    else:
        y_idx = 1
        y_idx_s = '%d' % (y_idx, )
        while 'y' + y_idx_s in self.args:
            x_idx_s = y_idx_s
            expr = self.args['y' + y_idx_s][-1]
            y_idx = y_idx + 1
            y_idx_s = '%d' % (y_idx, )
            sig_idx = sig_idx + 1
            sig_idx_s = '%d' % (sig_idx, )
            try:
                sig = Data.execute(expr)
                y = makeData(sig.data())
            except Exception:
                response_headers.append(
                    ('ERROR' + sig_idx_s,
                     'Error evaluating expression: "%s", error: %s' %
                     (expr, sys.exc_info()[1])))
                continue
            if 'x' + x_idx_s in self.args:
                expr = self.args['x' + x_idx_s][-1]
                try:
                    x = Data.execute(expr)
                    x = makeData(x.data())
                except Exception:
                    response_headers.append(
                        ('ERROR' + sig_idx_s,
                         'Error evaluating expression: "%s", error: %s' %
                         (expr, sys.exc_info()[1])))
                    continue
            else:
                try:
                    x = makeData(sig.dim_of().data())
                except Exception:
                    response_headers.append(
                        ('ERROR' + sig_idx_s,
                         'Error getting x axis of %s: "%s", error: %s' %
                         (expr, sys.exc_info()[1])))
                    continue
            response_headers.append(
                ('X' + sig_idx_s + '_DATATYPE', x.__class__.__name__))
            response_headers.append(
                ('Y' + sig_idx_s + '_DATATYPE', y.__class__.__name__))
            response_headers.append(('X' + sig_idx_s + '_LENGTH', str(len(x))))
            response_headers.append(('Y' + sig_idx_s + '_LENGTH', str(len(y))))
            output = output + str(x.data().data) + str(y.data().data)
    return ('200 OK', response_headers, output)
Пример #11
0
def doPlot(self):

    viewbox=[0,0,10000,10000];
    def scale(xmin,ymin,xmax,ymax,xmin_s,ymin_s,xmax_s,ymax_s,x,y):
        px=(x-xmin)*(xmax_s-xmin_s)/(xmax-xmin)
        py=(y-ymin)*(ymax_s-ymin_s)/(ymax-ymin)
        return " %d %d" % (int(round(px)),int(round(py)))

    def gridScaling(min_in,max_in,divisions,span):
        from math import log10,pow,fabs,ceil,floor,modf
        resdivlog = log10(fabs(max_in-min_in))
        if resdivlog < 0:
            res = pow(10,ceil(resdivlog) - 4)
        else:
            res = pow(10,floor(resdivlog) - 4)
        divlog = log10(fabs(max_in - min_in) / divisions)
        fractpart,wholepart = modf(divlog)
        intinc = pow(10,fabs(fractpart))
        if intinc < 1.3333333:
            intinc=1
        elif intinc < 2.857:
            intinc=2
        else:
            intinc=10
        if divlog < 0:
            val_inc = pow(10,-log10(intinc) + wholepart)
        else:
            val_inc = pow(10,log10(intinc) + wholepart)
        grid=ceil(min_in/val_inc) * val_inc
        divs_out = floor((max_in - grid + val_inc) / val_inc)
        if max_in > min_in:
            first_pix = span * ((grid - min_in) / (max_in - min_in))
            pix_inc = span * val_inc / (max_in - min_in);
            first_val = (first_pix * ((max_in - min_in)/span)) + min_in
        else:
            divs_out = 2
            first_pix = 0
            pix_inc = span
            val_inc = 0
        return {"divisions":divs_out,
                "first_pixel":first_pix, "pixel_increment":pix_inc, 
                "first_value":first_val, "value_increment":val_inc,
                "resolution":res}
          
    if len(self.path_parts) > 2:
        self.openTree(self.path_parts[1],self.path_parts[2])
    expr=self.args['expr'][-1]
    try:
        sig=Data.execute(expr)
        y=makeData(sig.data()).data()
        x=makeData(sig.dim_of().data()).data()
    except Exception:
        raise Exception("Error evaluating expression: '%s', error: %s" % (expr,sys.exc_info()[1]))
    response_headers=list()
    response_headers.append(('Cache-Control','no-store, no-cache, must-revalidate'))
    response_headers.append(('Pragma','no-cache'))
    response_headers.append(('XDTYPE',x.__class__.__name__))
    response_headers.append(('YDTYPE',y.__class__.__name__))
    response_headers.append(('XLENGTH',str(len(x))))
    response_headers.append(('YLENGTH',str(len(y))))
    response_headers.append(('Content-type','text/xml'))
    if self.tree is not None:
        response_headers.append(('TREE',self.tree))
        response_headers.append(('SHOT',self.shot))
        
    output="""<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg viewBox="%d %d %d %d"
     xmlns="http://www.w3.org/2000/svg" version="1.1">
""" % (viewbox[0],viewbox[1],viewbox[2],viewbox[3])
    output += "<title>Plot of %s </title>" % (expr,)
    output += """
  <path fill="none" stroke="black" stroke-width="30" d="M """
    xmin=float(min(x))
    xmax=float(max(x))
    ymin=float(min(y))
    ymax=float(max(y))
    xmin_s=float(viewbox[0])
    ymin_s=float(viewbox[1])
    xmax_s=float(viewbox[2])
    ymax_s=float(viewbox[3])
    for i in range(len(x)):
        output += scale(xmin-(xmax-xmin)*.1,
                        ymin-(ymax-ymin)*.1,
                        xmax+(xmax-xmin)*.1,
                        ymax+(ymax-ymin)*.1,xmin_s,ymin_s,xmax_s,ymax_s,x[i],y[i])
    output +=""" " />
"""
    scaling=gridScaling(xmin,xmax,5,viewbox[2]-viewbox[0])
    for i in range(scaling['divisions']):
        output +="""<text text-anchor="middle" x="%d" y="%d" font-size="300" >%g</text>
<path fill="none" stroke="black" stroke-width="5" stroke-dasharray="200,100,50,50,50,100" d="M%d %d %d %d" />
""" % (scaling["first_pixel"]+i*scaling["pixel_increment"],
       viewbox[2]-200,
       round(scaling['first_value']+i*scaling["value_increment"],scaling["resolution"]),
       scaling["first_pixel"]+i*scaling["pixel_increment"],
       viewbox[2],
       scaling["first_pixel"]+i*scaling["pixel_increment"],
       viewbox[0])
        
    scaling=gridScaling(ymin,ymax,5,viewbox[3]-viewbox[1])
    for i in range(scaling['divisions']):
        output +="""<text text-anchor="left" x="%d" y="%d" font-size="300" >%g</text>
<path fill="none" stroke="black" stroke-width="5" stroke-dasharray="200,100,50,50,50,100" d="M%d %d %d %d" />
""" % (100,
       scaling["first_pixel"]+i*scaling["pixel_increment"],
       round(scaling['first_value']+i*scaling["value_increment"],scaling["resolution"]),
       0,
       scaling["first_pixel"]+i*scaling["pixel_increment"],
       10000,
       scaling["first_pixel"]+i*scaling["pixel_increment"])
    output +="""</svg>
"""
    status = '200 OK'
    return (status, response_headers, output)
Пример #12
0
def doPlot(self):

    viewbox = [0, 0, 10000, 10000]

    def scale(xmin, ymin, xmax, ymax, xmin_s, ymin_s, xmax_s, ymax_s, x, y):
        px = (x - xmin) * (xmax_s - xmin_s) / (xmax - xmin)
        py = (y - ymin) * (ymax_s - ymin_s) / (ymax - ymin)
        return " %d %d" % (int(round(px)), int(round(py)))

    def gridScaling(min_in, max_in, divisions, span):
        from math import log10, pow, fabs, ceil, floor, modf
        resdivlog = log10(fabs(max_in - min_in))
        if resdivlog < 0:
            res = pow(10, ceil(resdivlog) - 4)
        else:
            res = pow(10, floor(resdivlog) - 4)
        divlog = log10(fabs(max_in - min_in) / divisions)
        fractpart, wholepart = modf(divlog)
        intinc = pow(10, fabs(fractpart))
        if intinc < 1.3333333:
            intinc = 1
        elif intinc < 2.857:
            intinc = 2
        else:
            intinc = 10
        if divlog < 0:
            val_inc = pow(10, -log10(intinc) + wholepart)
        else:
            val_inc = pow(10, log10(intinc) + wholepart)
        grid = ceil(min_in / val_inc) * val_inc
        divs_out = floor((max_in - grid + val_inc) / val_inc)
        if max_in > min_in:
            first_pix = span * ((grid - min_in) / (max_in - min_in))
            pix_inc = span * val_inc / (max_in - min_in)
            first_val = (first_pix * ((max_in - min_in) / span)) + min_in
        else:
            divs_out = 2
            first_pix = 0
            pix_inc = span
            val_inc = 0
        return {
            "divisions": divs_out,
            "first_pixel": first_pix,
            "pixel_increment": pix_inc,
            "first_value": first_val,
            "value_increment": val_inc,
            "resolution": res
        }

    if len(self.path_parts) > 2:
        self.openTree(self.path_parts[1], self.path_parts[2])
    expr = self.args['expr'][-1]
    try:
        sig = Data.execute(expr)
        y = makeData(sig.data()).data()
        x = makeData(sig.dim_of().data()).data()
    except Exception:
        raise Exception("Error evaluating expression: '%s', error: %s" %
                        (expr, sys.get_info()))
    response_headers = list()
    response_headers.append(
        ('Cache-Control', 'no-store, no-cache, must-revalidate'))
    response_headers.append(('Pragma', 'no-cache'))
    response_headers.append(('XDTYPE', x.__class__.__name__))
    response_headers.append(('YDTYPE', y.__class__.__name__))
    response_headers.append(('XLENGTH', str(len(x))))
    response_headers.append(('YLENGTH', str(len(y))))
    response_headers.append(('Content-type', 'text/xml'))
    if self.tree is not None:
        response_headers.append(('TREE', self.tree))
        response_headers.append(('SHOT', self.shot))

    output = """<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg viewBox="%d %d %d %d"
     xmlns="http://www.w3.org/2000/svg" version="1.1">
""" % (viewbox[0], viewbox[1], viewbox[2], viewbox[3])
    output += "<title>Plot of %s </title>" % (expr, )
    output += """
  <path fill="none" stroke="black" stroke-width="30" d="M """
    xmin = float(min(x))
    xmax = float(max(x))
    ymin = float(min(y))
    ymax = float(max(y))
    xmin_s = float(viewbox[0])
    ymin_s = float(viewbox[1])
    xmax_s = float(viewbox[2])
    ymax_s = float(viewbox[3])
    for i in range(len(x)):
        output += scale(xmin - (xmax - xmin) * .1, ymin - (ymax - ymin) * .1,
                        xmax + (xmax - xmin) * .1, ymax + (ymax - ymin) * .1,
                        xmin_s, ymin_s, xmax_s, ymax_s, x[i], y[i])
    output += """ " />
"""
    scaling = gridScaling(xmin, xmax, 5, viewbox[2] - viewbox[0])
    for i in range(scaling['divisions']):
        output += """<text text-anchor="middle" x="%d" y="%d" font-size="300" >%g</text>
<path fill="none" stroke="black" stroke-width="5" stroke-dasharray="200,100,50,50,50,100" d="M%d %d %d %d" />
""" % (scaling["first_pixel"] + i * scaling["pixel_increment"],
        viewbox[2] - 200,
        round(scaling['first_value'] + i * scaling["value_increment"],
             scaling["resolution"]),
        scaling["first_pixel"] + i * scaling["pixel_increment"], viewbox[2],
        scaling["first_pixel"] + i * scaling["pixel_increment"], viewbox[0])

    scaling = gridScaling(ymin, ymax, 5, viewbox[3] - viewbox[1])
    for i in range(scaling['divisions']):
        output += """<text text-anchor="left" x="%d" y="%d" font-size="300" >%g</text>
<path fill="none" stroke="black" stroke-width="5" stroke-dasharray="200,100,50,50,50,100" d="M%d %d %d %d" />
""" % (100, scaling["first_pixel"] + i * scaling["pixel_increment"],
        round(scaling['first_value'] + i * scaling["value_increment"],
             scaling["resolution"]), 0,
        scaling["first_pixel"] + i * scaling["pixel_increment"], 10000,
        scaling["first_pixel"] + i * scaling["pixel_increment"])
    output += """</svg>
"""
    status = '200 OK'
    return (status, response_headers, output)
Пример #13
0
 try:
     t=Tree(self.args['tree'][-1],int(shot))
     response_headers.append(('SHOT'+sig_idx_s,str(t.shot)))
 except Exception,e:
     response_headers.append(('ERROR'+sig_idx_s,'Error opening tree %s, shot %s, error: %s' % (self.args['tree'][-1],shot,e)))
     continue
 if 'default_node' in self.args:
     try:
         t.setDefault(t.getNode(self.args['default_node'][-1]))
     except Exception,e:
         response_headers.append(('ERROR'+sig_idx_s,'Error setting default to %s in tree %s, shot %s, error: %s' % (self.args['default_node'][-1],
                                                                                                                     self.args['tree'][-1],shot,e)))
         continue
 try:
     sig=Data.execute(expr)
     y=makeData(sig.data())
 except Exception,e:
     response_headers.append(('ERROR' + sig_idx_s,'Error evaluating expression: "%s", error: %s' % (expr,e)))
     continue
 if 'x'+x_idx_s in self.args:
     expr=self.args['x'+x_idx_s][-1]
     try:
         x=Data.execute(expr)
         x=makeData(x.data())
     except Exception,e:
         response_headers.append(('ERROR'+sig_idx_s,'Error evaluating expression: "%s", error: %s' % (expr,e)))
         continue
 else:
     try:
         x=makeData(sig.dim_of().data())
     except Exception,e: