예제 #1
0
 def __init__(self, *args, **kargs):
     kargs['style'] = (wx.FRAME_FLOAT_ON_PARENT | wx.MINIMIZE_BOX
                       | wx.MAXIMIZE_BOX | wx.RESIZE_BORDER
                       | wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX
                       | wx.CLIP_CHILDREN)
     #        print kargs
     BookViewer.__init__(self, *args, **kargs)
     f_page = self.get_page(0)
     f_page.set_section(2)
     f_axes = self.get_axes(0, 0)
     for name, child in f_axes.get_children():
         child.destroy()
     obj = FigPlot([0], [0])
     f_axes.add_child('xslice_plot1', obj)
     obj.set_suppress(True)
     obj = FigPlot([0], [0])
     f_axes.add_child('xslice_plot2', obj)
     obj.set_suppress(True)
     f_axes.realize()
     f_axes = self.get_axes(0, 1)
     for name, child in f_axes.get_children():
         child.destroy()
     obj = FigPlot([0], [0])
     f_axes.add_child('xslice_plot1', obj)
     obj.set_suppress(True)
     obj = FigPlot([0], [0])
     f_axes.add_child('xslice_plot2', obj)
     obj.set_suppress(True)
     f_axes.realize()
예제 #2
0
    def postprocess_data(
        self,
        ana,
        viewer,
        color_order=['red', 'blue', 'yellow'],
    ):
        def set_auto_color_to_color(kargs, name, col):
            if (not name in kargs) or (kargs[name] == 'auto'):
                kargs[name] = col
            return kargs

        from ifigure.mto.fig_plot import FigPlot, TimeTrace, StepPlot
        from ifigure.mto.fig_contour import FigContour
        from ifigure.mto.fig_image import FigImage
        from ifigure.mto.fig_surface import FigSurface
        from ifigure.mto.fig_axline import FigAxline
        from ifigure.mto.fig_axspan import FigAxspan
        from ifigure.mto.fig_text import FigText

        self._color_order = color_order
        dprint2('process_data', self)
        if ana.skipped:
            if ana.do_title:
                self.process_title(ana)
            return True

        if (self.isempty() and not self.get_figaxes().isempty()
                and not self._suppress):
            self.generate_artist()
#        app = self.get_app()
#        ax = self.get_container()
#        fig_ax = ax.figobj

        ishot = ana.ishot

        self._analysis_flag[ishot] = False
        col = color_order[ishot % len(color_order)]

        for x in range(ishot - self.num_child() + 1):
            plot_options = self.getvar('plot_options')
            if self._plot_type == 'plot':
                kargs = plot_options['plot'][1].copy()
                kargs = set_auto_color_to_color(kargs, 'color', col)
                kargs = set_auto_color_to_color(kargs, 'markerfacecolor', col)
                kargs = set_auto_color_to_color(kargs, 'markeredgecolor', col)
                obj = FigPlot([0], [0], *(plot_options['plot'][0]), **kargs)
            elif self._plot_type == 'timetrace':
                kargs = plot_options['timetrace'][1].copy()
                kargs = set_auto_color_to_color(kargs, 'color', col)
                kargs = set_auto_color_to_color(kargs, 'markerfacecolor', col)
                kargs = set_auto_color_to_color(kargs, 'markeredgecolor', col)
                obj = TimeTrace([0], [0], *(plot_options['timetrace'][0]),
                                **kargs)
            elif self._plot_type == 'stepplot':
                kargs = plot_options['stepplot'][1].copy()
                kargs = set_auto_color_to_color(kargs, 'color', col)
                kargs = set_auto_color_to_color(kargs, 'markerfacecolor', col)
                kargs = set_auto_color_to_color(kargs, 'markeredgecolor', col)
                obj = StepPlot([0], [0], *(plot_options['stepplot'][0]),
                               **kargs)
            elif self._plot_type == 'contour':
                obj = FigContour([0, 1], [0, 1],
                                 np.arange(4).reshape(2, 2),
                                 *(plot_options['contour'][0]))
            elif self._plot_type == 'image':
                obj = FigImage(np.zeros([2, 2]))
            elif self._plot_type == 'surface':
                obj = FigSurface(np.zeros([2, 2]))
            elif self._plot_type == 'axspan':
                obj = FigAxspan([0, 1])
            elif self._plot_type == 'axline':
                obj = FigAxline(np.zeros([1]))
            elif self._plot_type == 'text':
                obj = FigText(0, 0, '')
            name = self._plot_type + str(self.num_child() + 1)
            self.add_child(name, obj)
            obj.set_container_idx(self._container_idx)
            obj.set_suppress(True)
        if self.get_script_local():
            txt = self.make_script(ana.shot, short=True)
            debug_mode = viewer.debug_mode
            if txt is not None:
                try:
                    vars = viewer.get_globals_for_figmds(ana.shot)
                    #                  print vars
                    for key in vars:
                        ana.result[key] = vars[key]
                    for key in viewer.startup_values:
                        ana.result[key] = viewer.startup_values[key]
                    ana.result['shot'] = ana.shot
                    if self.getvar('posvars') is not None:
                        a = {}
                        b = {}
                        exec self.getvar('posvars') in a, b
                        for key in b:
                            ana.result[key] = b[key]
                    filepath = os.path.join(self.owndir(), script_file_name)
                    from ifigure.widgets.debugger_core import get_breakpoint
                    code = compile(txt, filepath, 'exec')
                    if (len(get_breakpoint(filepath)) != 0 and debug_mode):
                        app = wx.GetApp().TopWindow
                        se = app.script_editor
                        import threading
                        if not se.CheckDebuggerStatus():
                            se.QueueSEDRequest(code, viewer.g, ana.result,
                                               filepath)
#                          print threading.current_thread().name
#                          wx.Yield()
#                          time.sleep(3)
                        else:
                            se.RunSED(code, viewer.g, ana.result, filepath)
                    else:
                        exec code in viewer.g, ana.result
                except:
                    dprint1('error occured when processing data by script')
                    print(
                        'error occured when processing data by following script'
                    )
                    print('#####')
                    print(txt)
                    print('#####')
                    print(traceback.format_exc())
                    self.change_suppress(True, self.get_child(ishot))
                    return False

        if ana.do_title:
            self.process_title(ana)
        if self._plot_type == 'plot':
            self._update_plot(ana, ishot)  #, color_order)
        elif self._plot_type == 'timetrace':
            self._update_plot(ana, ishot)  #, color_order)
        elif self._plot_type == 'stepplot':
            self._update_plot(ana, ishot)  #, color_order)
        elif self._plot_type == 'contour':
            self._update_contour(ana, ishot)
        elif self._plot_type == 'image':
            self._update_image(ana, ishot)
        elif self._plot_type == 'surface':
            self._update_surface(ana, ishot)
        elif self._plot_type == 'axspan':
            self._update_axspan(ana, ishot)
        elif self._plot_type == 'axline':
            self._update_axline(ana, ishot)
        elif self._plot_type == 'text':
            self._update_text(ana, ishot)

        obj = self.get_child(idx=ishot)
        if obj.is_suppress():
            return False

        obj._data_extent = None
        try:
            if (self.get_figaxes() is not None):
                self.get_figaxes().adjust_axes_range()
        except:
            dprint1(
                "failed in adjusting axes at postprocess_data, continuing...")
            pass
        return True
예제 #3
0
파일: fig_mds.py 프로젝트: piScope/piScope
    def postprocess_data(self, ana, viewer,
                         color_order=['red','blue','yellow'],
                         ):
        def set_auto_color_to_color(kargs, name, col):
            if (not name in kargs) or (kargs[name] == 'auto'):
                 kargs[name] = col
            return kargs

        from ifigure.mto.fig_plot import FigPlot, TimeTrace, StepPlot
        from ifigure.mto.fig_contour import FigContour
        from ifigure.mto.fig_image import FigImage
        from ifigure.mto.fig_surface import FigSurface
        from ifigure.mto.fig_axline import FigAxline
        from ifigure.mto.fig_axspan import FigAxspan
        from ifigure.mto.fig_text import FigText

        self._color_order = color_order
        dprint2('process_data', self) 
        if ana.skipped:
            if ana.do_title:
                self.process_title(ana)
            return True

        if (self.isempty() and 
            not self.get_figaxes().isempty() and
            not self._suppress):
             self.generate_artist()
#        app = self.get_app()
#        ax = self.get_container()
#        fig_ax = ax.figobj

        ishot = ana.ishot

        self._analysis_flag[ishot] = False
        col = color_order[ishot % len(color_order)]

        for x in range(ishot - self.num_child()+1):
           plot_options = self.getvar('plot_options')
           if self._plot_type == 'plot':
               kargs = plot_options['plot'][1].copy()
               kargs = set_auto_color_to_color(kargs, 'color', col)
               kargs = set_auto_color_to_color(kargs, 'markerfacecolor', col)
               kargs = set_auto_color_to_color(kargs, 'markeredgecolor', col)
               obj=FigPlot([0],[0], 
                           *(plot_options['plot'][0]),
                           **kargs)
           elif self._plot_type == 'timetrace':
               kargs = plot_options['timetrace'][1].copy()
               kargs = set_auto_color_to_color(kargs, 'color', col)
               kargs = set_auto_color_to_color(kargs, 'markerfacecolor', col)
               kargs = set_auto_color_to_color(kargs, 'markeredgecolor', col)
               obj=TimeTrace([0],[0], 
                           *(plot_options['timetrace'][0]),
                           **kargs)
           elif self._plot_type == 'stepplot':
               kargs = plot_options['stepplot'][1].copy()
               kargs = set_auto_color_to_color(kargs, 'color', col)
               kargs = set_auto_color_to_color(kargs, 'markerfacecolor', col)
               kargs = set_auto_color_to_color(kargs, 'markeredgecolor', col)
               obj=StepPlot([0],[0], 
                           *(plot_options['stepplot'][0]),
                           **kargs)
           elif self._plot_type == 'contour':
               obj=FigContour([0,1], [0,1], np.arange(4).reshape(2,2), 
                           *(plot_options['contour'][0]))
           elif self._plot_type == 'image':
               obj=FigImage(np.zeros([2,2]))
           elif self._plot_type == 'surface':
               obj=FigSurface(np.zeros([2,2]))
           elif self._plot_type == 'axspan':
               obj=FigAxspan([0,1])
           elif self._plot_type == 'axline':
               obj=FigAxline(np.zeros([1]))
           elif self._plot_type == 'text':
               obj=FigText(0, 0, '')
           name = self._plot_type + str(self.num_child()+1)
           self.add_child(name, obj)
           obj.set_container_idx(self._container_idx)
           obj.set_suppress(True)
        if self.get_script_local():
            txt = self.make_script(ana.shot, short = True)
            debug_mode = viewer.debug_mode
            if txt is not None:
               try:
                  vars = viewer.get_globals_for_figmds(ana.shot)
#                  print vars
                  for key in vars:
                      ana.result[key] = vars[key]
                  for key in viewer.startup_values:
                      ana.result[key] =  viewer.startup_values[key]
                  ana.result['shot'] = ana.shot
                  if self.getvar('posvars') is not None:
                      a = {}; b = {}
                      exec self.getvar('posvars') in  a, b
                      for key in b:
                          ana.result[key] = b[key]
                  filepath = os.path.join(self.owndir(), script_file_name)
                  from ifigure.widgets.debugger_core import get_breakpoint
                  code = compile(txt, filepath, 'exec')
                  if (len(get_breakpoint(filepath)) != 0 and debug_mode):
                      app = wx.GetApp().TopWindow
                      se = app.script_editor
                      import threading
                      if not se.CheckDebuggerStatus():
                          se.QueueSEDRequest(code, viewer.g, ana.result, 
                                             filepath)
#                          print threading.current_thread().name
#                          wx.Yield()
#                          time.sleep(3)
                      else:
                          se.RunSED(code, viewer.g, ana.result, filepath)
                  else:
                      exec code in viewer.g, ana.result
               except:
                  dprint1('error occured when processing data by script')
                  print('error occured when processing data by following script')
                  print('#####')
                  print(txt)
                  print('#####')
                  print(traceback.format_exc())
                  self.change_suppress(True, self.get_child(ishot))
                  return False

        if ana.do_title:
             self.process_title(ana)
        if self._plot_type == 'plot':
            self._update_plot(ana, ishot)#, color_order)
        elif self._plot_type == 'timetrace':
            self._update_plot(ana, ishot)#, color_order)
        elif self._plot_type == 'stepplot':
            self._update_plot(ana, ishot)#, color_order)
        elif self._plot_type == 'contour':
            self._update_contour(ana, ishot)
        elif self._plot_type == 'image':
            self._update_image(ana, ishot)
        elif self._plot_type == 'surface':
            self._update_surface(ana, ishot)
        elif self._plot_type == 'axspan':
            self._update_axspan(ana, ishot)
        elif self._plot_type == 'axline':
            self._update_axline(ana, ishot)
        elif self._plot_type == 'text':
            self._update_text(ana, ishot)

        obj = self.get_child(idx=ishot)
        if obj.is_suppress():
            return False

        obj._data_extent = None
        try:
            if (self.get_figaxes() is not None):
               self.get_figaxes().adjust_axes_range()
        except: 
            dprint1("failed in adjusting axes at postprocess_data, continuing...")
            pass
        return True