Ignore:
Timestamp:
Mar 3, 2009 2:12:26 PM (15 years ago)
Author:
Gervaise Alina <gervyh@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
fe2ade9
Parents:
18a3ee9
Message:

add comments

Location:
guiframe/local_perspectives/plotting
Files:
6 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • guiframe/local_perspectives/plotting/AnnulusSlicer.py

    r6d920cd reba08f1a  
    1616class AnnulusInteractor(_BaseInteractor): 
    1717    """ 
    18          Select an annulus through a 2D plot 
     18         Select an annulus through a 2D plot. 
     19         This interactor is used to average 2D data  with the region  
     20         defined by 2 radius. 
     21         this class is defined by 2 Ringinterators. 
    1922    """ 
    2023    def __init__(self,base,axes,color='black', zorder=3): 
     
    2629        self.qmax = min(math.fabs(self.base.data2D.xmax),math.fabs(self.base.data2D.xmin))  #must be positive 
    2730        self.connect = self.base.connect 
    28          
    29  
     31     
    3032        ## Number of points on the plot 
    3133        self.nbins = 20 
     
    3537        self.xmind=self.base.data2D.xmin 
    3638 
    37         #self.sign=1 
    38          
    3939        if (self.xmaxd+self.xmind)>0: 
    4040            self.sign=1 
     
    5757 
    5858    def _onEVT_SLICER_PARS(self, event): 
     59        """ 
     60            receive an event containing parameters values to reset the slicer 
     61            @param event: event of type SlicerParameterEvent with params as  
     62            attribute 
     63        """ 
    5964        wx.PostEvent(self.base, StatusEvent(status="AnnulusSlicer._onEVT_SLICER_PARS")) 
    6065        event.Skip() 
     
    6368            self.base.update() 
    6469 
    65     def update_and_post(self): 
    66         self.update() 
    67         self._post_data() 
    68  
    69     def save_data(self, path, image, x, y): 
    70         output = open(path, 'w') 
    71          
    72         data_x, data_y = self.get_data(image, x, y) 
    73          
    74         output.write("<phi>  <average>\n") 
    75         for i in range(len(data_x)): 
    76             output.write("%g  %g\n" % (data_x[i], data_y[i])) 
    77         output.close() 
    78  
    7970    def set_layer(self, n): 
     71        """ 
     72             Allow adding plot to the same panel 
     73             @param n: the number of layer 
     74        """ 
    8075        self.layernum = n 
    8176        self.update() 
    8277         
    8378    def clear(self): 
     79        """ 
     80            Clear the slicer and all connected events related to this slicer 
     81        """ 
    8482        self.clear_markers() 
    8583        self.outer_circle.clear() 
    8684        self.inner_circle.clear() 
    8785        self.base.connect.clearall() 
    88        
    8986        self.base.Unbind(EVT_SLICER_PARS) 
    9087         
     88         
    9189    def update(self): 
    9290        """ 
    93         Respond to changes in the model by recalculating the profiles and 
    94         resetting the widgets. 
     91            Respond to changes in the model by recalculating the profiles and 
     92            resetting the widgets. 
    9593        """ 
    9694        # Update locations         
     
    9896        self.outer_circle.update() 
    9997         
    100    
    10198 
    10299    def save(self, ev): 
    103100        """ 
    104         Remember the roughness for this layer and the next so that we 
    105         can restore on Esc. 
     101            Remember the roughness for this layer and the next so that we 
     102            can restore on Esc. 
    106103        """ 
    107104        self.base.freeze_axes() 
     
    110107 
    111108    def _post_data(self,nbins=None): 
    112          # Compute data 
     109        """ 
     110            Uses annulus parameters to plot averaged data into 1D data. 
     111            @param nbins: the number of points to plot  
     112        """ 
     113        #Data to average 
    113114        data = self.base.data2D 
    114115        # If we have no data, just return 
     
    117118         
    118119        from DataLoader.manipulations import SectorPhi 
    119         #radius = self.qmax#math.sqrt(math.pow(self.qmax,2)+math.pow(self.qmax,2)) 
     120     
    120121        rmin= min(math.fabs(self.inner_circle.get_radius()), 
    121122                  math.fabs(self.outer_circle.get_radius())) 
    122123        rmax = max(math.fabs(self.inner_circle.get_radius()), 
    123124                   math.fabs(self.outer_circle.get_radius())) 
    124         #print "rmin, rmax", rmin, rmax 
     125        #if the user does not specify the numbers of points to plot  
     126        # the default number will be nbins= 20 
    125127        if nbins==None: 
    126             nbins = 20 
     128            self.nbins= 20 
     129        else: 
     130            self.nbins = nbins 
     131        ## create the data1D Q average of data2D     
    127132        sect = SectorPhi(r_min=rmin , r_max= rmax, 
    128                           phi_min=0, phi_max=2*math.pi , nbins=nbins) 
    129          
    130          
     133                          phi_min=0, phi_max=2*math.pi , nbins=self.nbins) 
    131134        sector = sect(self.base.data2D) 
    132135         
     
    144147        new_plot.name = "SectorPhi" +"("+ self.base.data2D.name+")" 
    145148         
    146         
    147          
    148149        new_plot.source=self.base.data2D.source 
    149150        #new_plot.info=self.base.data2D.info 
     151         
    150152        new_plot.interactive = True 
    151         #print "loader output.detector",output.source 
    152153        new_plot.detector =self.base.data2D.detector 
    153154        # If the data file does not tell us what the axes are, just assume... 
     
    162163         
    163164          
    164          
    165          
    166165    def moveend(self, ev): 
     166        """ 
     167            Called when any dragging motion ends. 
     168            Post an event (type =SlicerParameterEvent) 
     169            to plotter 2D with a copy  slicer parameters 
     170            Call  _post_data method 
     171        """ 
    167172        self.base.thaw_axes() 
    168          
    169         # Post paramters 
     173        # Post parameters to plotter 2D 
    170174        event = SlicerParameterEvent() 
    171175        event.type = self.__class__.__name__ 
    172176        event.params = self.get_params() 
    173         #wx.PostEvent(self.base.parent, event) 
    174177        wx.PostEvent(self.base, event) 
     178        # create a 1D data plot 
    175179        self._post_data() 
    176180             
     
    192196         
    193197    def get_params(self): 
     198        """ 
     199            Store a copy of values of parameters of the slicer into a dictionary. 
     200            @return params: the dictionary created 
     201        """ 
    194202        params = {} 
    195203        params["inner_radius"] = math.fabs(self.inner_circle._inner_mouse_x) 
     
    199207     
    200208    def set_params(self, params): 
    201          
     209        """ 
     210            Receive a dictionary and reset the slicer with values contained  
     211            in the values of the dictionary. 
     212            @param params: a dictionary containing name of slicer parameters and  
     213            values the user assigned to the slicer. 
     214        """ 
    202215        inner = math.fabs(params["inner_radius"] ) 
    203216        outer = math.fabs(params["outer_radius"] ) 
    204217        self.nbins = int(params["nbins"]) 
     218        ## Update the picture 
    205219        self.inner_circle.set_cursor(inner, self.inner_circle._inner_mouse_y) 
    206220        self.outer_circle.set_cursor(outer, self.outer_circle._inner_mouse_y) 
     221        ## Post the data given the nbins entered by the user  
    207222        self._post_data(self.nbins) 
    208223         
     
    219234class RingInteractor(_BaseInteractor): 
    220235    """ 
    221          Select an annulus through a 2D plot 
     236         Draw a ring Given a radius  
     237         @param: the color of the line that defined the ring 
     238         @param r: the radius of the ring 
     239         @param sign: the direction of motion the the marker  
    222240    """ 
    223241    def __init__(self,base,axes,color='black', zorder=5, r=1.0,sign=1): 
     
    226244        self.markers = [] 
    227245        self.axes = axes 
     246        # Current radius of the ring 
    228247        self._inner_mouse_x = r 
     248        #Value of the center of the ring 
    229249        self._inner_mouse_y = 0 
     250        # previous value of that radius 
    230251        self._inner_save_x  = r 
     252        #Save value of the center of the ring 
    231253        self._inner_save_y  = 0 
    232         self.scale = 10.0 
     254        #Class instantiating RingIterator class 
    233255        self.base= base 
     256        #the direction of the motion of the marker 
    234257        self.sign=sign 
    235           
    236          
    237         #print "sign",self.sign,self.sign*math.fabs(self._inner_mouse_x) 
    238                                                      
     258        ## Create a marker  
    239259        try: 
    240260            # Inner circle marker 
     
    254274            message += "Get the SVN version that is at least as recent as June 1, 2007" 
    255275             
    256             #raise "Version error", message 
    257              
    258         # Inner circle 
    259  
    260             
     276            owner=self.base.base.parent 
     277            wx.PostEvent(owner, StatusEvent(status="AnnulusSlicer: %s"%message)) 
     278             
     279        # Draw a circle  
    261280        [self.inner_circle] = self.axes.plot([],[], 
    262281                                      linestyle='-', marker='', 
    263282                                      color=self.color) 
     283        # the number of points that make the ring line 
    264284        self.npts = 40 
    265285             
     
    268288 
    269289    def set_layer(self, n): 
     290        """ 
     291             Allow adding plot to the same panel 
     292             @param n: the number of layer 
     293        """ 
    270294        self.layernum = n 
    271295        self.update() 
    272296         
    273297    def clear(self): 
     298        """ 
     299            Clear the slicer and all connected events related to this slicer 
     300        """ 
    274301        self.clear_markers() 
    275302        try: 
     
    284311         
    285312    def get_radius(self): 
     313        """ 
     314            @return self._inner_mouse_x: the current radius of the ring 
     315        """ 
    286316        return self._inner_mouse_x 
    287317         
    288318    def update(self): 
    289319        """ 
    290         Draw the new roughness on the graph. 
     320            Draw the new roughness on the graph. 
    291321        """ 
    292322        # Plot inner circle 
     
    315345 
    316346    def moveend(self, ev): 
     347        """ 
     348            Called after a dragging motion 
     349        """ 
    317350        self.base.moveend(ev) 
    318351             
     
    333366         
    334367    def set_cursor(self, x, y): 
     368        """ 
     369            draw the ring given x, y value  
     370        """ 
    335371        self.move(x, y, None) 
    336372        self.update() 
     
    338374         
    339375    def get_params(self): 
     376        """ 
     377            Store a copy of values of parameters of the slicer into a dictionary. 
     378            @return params: the dictionary created 
     379        """ 
    340380        params = {} 
    341381        params["radius"] = math.fabs(self._inner_mouse_x) 
     
    343383     
    344384    def set_params(self, params): 
    345  
     385        """ 
     386            Receive a dictionary and reset the slicer with values contained  
     387            in the values of the dictionary. 
     388            @param params: a dictionary containing name of slicer parameters and  
     389            values the user assigned to the slicer. 
     390        """ 
    346391        x = params["radius"]  
    347392        self.set_cursor(x, self._inner_mouse_y) 
  • guiframe/local_perspectives/plotting/Plotter2D.py

    r6d920cd reba08f1a  
    237237        slicerpop.Append(id, '&Box averaging in Qy') 
    238238        wx.EVT_MENU(self, id, self.onBoxavgY)  
    239         if self.slicer !=None: 
     239        if self.slicer !=None : 
    240240            id = wx.NewId() 
    241241            slicerpop.Append(id, '&Clear slicer') 
    242242            wx.EVT_MENU(self, id,  self.onClearSlicer)  
    243          
    244             id = wx.NewId() 
    245             slicerpop.Append(id, '&Edit Slicer Parameters') 
    246             wx.EVT_MENU(self, id, self._onEditSlicer)  
     243            if self.slicer.__class__.__name__ !="BoxSum": 
     244                id = wx.NewId() 
     245                slicerpop.Append(id, '&Edit Slicer Parameters') 
     246                wx.EVT_MENU(self, id, self._onEditSlicer)  
    247247        slicerpop.AppendSeparator()  
    248248        
    249       
    250249        id = wx.NewId() 
    251250        slicerpop.Append(id, '&Toggle Linear/Log scale') 
    252251        wx.EVT_MENU(self, id, self._onToggleScale)  
    253252                  
    254        
    255253        pos = event.GetPosition() 
    256254        pos = self.ScreenToClient(pos) 
  • guiframe/local_perspectives/plotting/boxSlicer.py

    r18eba35 reba08f1a  
    2020class BoxInteractor(_BaseInteractor): 
    2121    """ 
    22          Select an annulus through a 2D plot 
     22         BoxInteractor define a rectangle that return data1D average of Data2D 
     23         in a rectangle area defined by -x, x ,y, -y 
    2324    """ 
    2425    def __init__(self,base,axes,color='black', zorder=3): 
     
    3839        ## Number of points on the plot 
    3940        self.nbins = 30 
    40         self.count=0 
    41         self.error=0 
     41        
    4242        self.averager=None 
    4343         
     
    5353                                      y= self.y) 
    5454        self.horizontal_lines.qmax= self.qmax 
    55          
    56        
    5755         
    5856        self.update() 
     
    459457 
    460458class BoxInteractorX(BoxInteractor): 
     459    """ 
     460        Average in Qx direction 
     461    """ 
    461462    def __init__(self,base,axes,color='black', zorder=3): 
    462463        BoxInteractor.__init__(self, base, axes, color=color) 
     
    469470 
    470471class BoxInteractorY(BoxInteractor): 
     472    """ 
     473         Average in Qy direction 
     474    """ 
    471475    def __init__(self,base,axes,color='black', zorder=3): 
    472476        BoxInteractor.__init__(self, base, axes, color=color) 
  • guiframe/local_perspectives/plotting/boxSum.py

    r6d920cd reba08f1a  
    1 #TODO: the line slicer should listen to all 2DREFRESH events, get the data and slice it 
    2 #      before pushing a new 1D data update. 
    3  
    4 # 
    5 #TODO: NEED MAJOR REFACTOR 
    6 # 
    7  
    8  
    9 # Debug printout 
    10 #from config import printEVT 
     1 
     2 
     3 
     4import math 
     5import wx 
     6from copy import deepcopy 
    117from BaseInteractor import _BaseInteractor 
    12 from copy import deepcopy 
    13 import math 
    14  
    15 #from Plotter1D import AddPlotEvent 
    16 import SlicerParameters 
    17 import wx 
    18  
    198from sans.guicomm.events import SlicerParamUpdateEvent,EVT_SLICER_PARS,StatusEvent 
     9 
     10 
    2011class BoxSum(_BaseInteractor): 
    2112    """ 
    22          Select an annulus through a 2D plot 
     13        Boxsum Class: determine 2 rectangular area to compute the sum of pixel of 
     14        a Data.  
     15        Uses PointerInteractor , VerticalDoubleLine,HorizontalDoubleLine. 
     16        @param zorder:  Artists with lower zorder values are drawn first. 
     17        @param x_min: the minimum value of the x coordinate 
     18        @param x_max: the maximum value of the x coordinate 
     19        @param y_min: the minimum value of the y coordinate 
     20        @param y_max: the maximum value of the y coordinate 
     21 
    2322    """ 
    24     def __init__(self,base,axes,color='black', zorder=3, x_min=0.008, x_max=0.008, y_min=0.0025, y_max=0.0025): 
     23    def __init__(self,base,axes,color='black', zorder=3, x_min=0.008, 
     24                  x_max=0.008, y_min=0.0025, y_max=0.0025): 
    2525         
    2626        _BaseInteractor.__init__(self, base, axes, color=color) 
     27        ## class initialization 
     28        ## list of Boxsmun markers 
    2729        self.markers = [] 
    2830        self.axes = axes 
     31        ## connect the artist for the motion 
     32        self.connect = self.base.connect 
     33        ## when qmax is reached the selected line is reset the its previous value 
    2934        self.qmax = min(self.base.data2D.xmax, self.base.data2D.xmin) 
    30         self.connect = self.base.connect 
     35        ## Define the boxsum limits 
    3136        self.xmin= -1* 0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin)) 
    3237        self.ymin= -1* 0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin)) 
    33         #self.xmax= x_max 
    34         #self.ymax=  y_max 
     38        
    3539        self.xmax= 0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin)) 
    3640        self.ymax=  0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin)) 
    37         # center of the figure 
     41        ## center of the boxSum 
    3842        self.center_x= 0.0002 
    3943        self.center_y= 0.0003 
    40         
    4144        ## Number of points on the plot 
    4245        self.nbins = 20 
     46        ## Define initial result the summation  
    4347        self.count=0 
    4448        self.error=0 
     49        ## Flag to determine if the current figure has moved 
     50        ## set to False == no motion , set to True== motion 
    4551        self.has_move= False 
    46      
    47         self.horizontal_lines= Horizontal_DoubleLine(self, self.base.subplot,color='blue', 
     52        ## Create Boxsum edges  
     53        self.horizontal_lines= HorizontalDoubleLine(self, self.base.subplot,color='blue', 
    4854                                                      zorder=zorder, 
    4955                                    y= self.ymax, 
     
    5359        self.horizontal_lines.qmax = self.qmax 
    5460         
    55         self.vertical_lines= Vertical_DoubleLine(self, self.base.subplot,color='black', 
     61        self.vertical_lines= VerticalDoubleLine(self, self.base.subplot,color='black', 
    5662                                                      zorder=zorder, 
    5763                                    y= self.ymax, 
     
    6066                                    center_y= self.center_y) 
    6167        self.vertical_lines.qmax = self.qmax 
     68         
    6269        self.center= PointInteractor(self, self.base.subplot,color='grey', 
    6370                                                      zorder=zorder, 
    6471                                    center_x= self.center_x, 
    6572                                    center_y= self.center_y) 
    66        
    67              
    68         #self.connect_markers([]) 
    69         self.panel_name=""       
     73        ## Save the name of the slicer panel associate with this slicer  
     74        self.panel_name=""     
     75        ## Update and post slicer parameters   
    7076        self.update() 
    7177        self._post_data() 
    72          
    73         # Bind to slice parameter events 
    74         #print "box sum  self.base.parent",self.base.parent 
     78        ## Bind to slice parameter events 
    7579        self.base.Bind(EVT_SLICER_PARS, self._onEVT_SLICER_PARS) 
    7680         
     81         
    7782    def set_panel_name(self, name): 
     83        """ 
     84            Store the name of the panel associated to this slicer 
     85            @param name: the name of this panel 
     86        """ 
    7887        self.panel_name= name 
    7988         
    8089         
    8190    def _onEVT_SLICER_PARS(self, event): 
     91        """ 
     92            receive an event containing parameters values to reset the slicer 
     93            @param event: event of type SlicerParameterEvent with params as  
     94            attribute 
     95        """ 
     96        ## Post e message to declare what kind of event has being received 
    8297        wx.PostEvent(self.base.parent, StatusEvent(status="Boxsum._onEVT_SLICER_PARS")) 
    83         #print "receiving value ",event.params 
    8498        event.Skip() 
     99        ## reset the slicer with the values contains the event.params dictionary 
    85100        if event.type == self.__class__.__name__: 
    86101            self.set_params(event.params) 
    87102            self.base.update() 
    88103 
    89     def update_and_post(self): 
    90         self.update() 
    91         self._post_data() 
    92  
    93     def save_data(self, path, image, x, y): 
    94         output = open(path, 'w') 
    95          
    96         data_x, data_y = self.get_data(image, x, y) 
    97          
    98         output.write("<phi>  <average>\n") 
    99         for i in range(len(data_x)): 
    100             output.write("%g  %g\n" % (data_x[i], data_y[i])) 
    101         output.close() 
    102104 
    103105    def set_layer(self, n): 
     106        """ 
     107             Allow adding plot to the same panel 
     108             @param n: the number of layer 
     109        """ 
    104110        self.layernum = n 
    105111        self.update() 
    106112         
     113         
    107114    def clear(self): 
     115        """ 
     116            Clear the slicer and all connected events related to this slicer 
     117        """ 
    108118        self.clear_markers() 
    109119        self.horizontal_lines.clear() 
     
    111121        self.center.clear() 
    112122        self.base.connect.clearall() 
    113         #self.base.connect.disconnect() 
    114123        self.base.Unbind(EVT_SLICER_PARS) 
    115124         
     125         
    116126    def update(self): 
    117127        """ 
    118         Respond to changes in the model by recalculating the profiles and 
    119         resetting the widgets. 
    120         """ 
     128            Respond to changes in the model by recalculating the profiles and 
     129            resetting the widgets. 
     130        """ 
     131        ## check if the center point has moved and update the figure accordingly  
    121132        if self.center.has_move: 
    122             #print "center has move" 
    123133            self.center.update() 
    124134            self.horizontal_lines.update( center= self.center) 
    125135            self.vertical_lines.update( center= self.center) 
    126              
     136        ## check if the horizontal lines have moved and update the figure accordingly     
    127137        if self.horizontal_lines.has_move: 
    128             #print "top has moved" 
    129138            self.horizontal_lines.update() 
    130139            self.vertical_lines.update(y1=self.horizontal_lines.y1, 
    131140                                       y2=self.horizontal_lines.y2, 
    132141                                       height= self.horizontal_lines.half_height ) 
     142        ## check if the vertical lines have moved and update the figure accordingly     
    133143        if self.vertical_lines.has_move: 
    134             #print "right has moved" 
    135144            self.vertical_lines.update() 
    136145            self.horizontal_lines.update(x1=self.vertical_lines.x1, 
     
    150159         
    151160    def _post_data(self): 
    152         # Compute data 
    153         print  
    154          
     161        """ 
     162            Get the limits of the boxsum and compute the sum of the pixel 
     163            contained in that region and the error on that sum 
     164        """ 
     165        ## Data 2D for which the pixel will be summed 
    155166        data = self.base.data2D 
    156         from DataLoader.manipulations import  Boxavg 
    157         #radius = math.sqrt(math.pow(self.qmax,2)+math.pow(self.qmax,2)) 
     167        ## the region of the summation 
    158168        x_min= self.horizontal_lines.x2  
    159169        x_max= self.horizontal_lines.x1  
    160170        y_min= self.vertical_lines.y2 
    161171        y_max= self.vertical_lines.y1 
    162         #print "xmin, xmax, ymin , ymax", x_min, x_max, y_min, y_max 
     172        ##computation of the sum and its error 
     173        from DataLoader.manipulations import  Boxavg 
    163174        box =  Boxavg (x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max) 
    164175        self.count, self.error = box(self.base.data2D) 
    165         #print "box_sum output",box(self.base.data2D) 
     176 
    166177                           
    167178    def moveend(self, ev): 
     179        """ 
     180            After a dragging motion this function is called to compute 
     181            the error and the sum of pixel of a given data 2D  
     182        """ 
    168183        self.base.thaw_axes() 
    169         # Post paramters 
     184        ## compute error an d sum of data's pixel 
    170185        self._post_data() 
    171         
     186        ## Create and event ( posted to guiframe)that  set the  
     187        ##current slicer parameter to a panel of name self.panel_name 
    172188        self.type= self.__class__.__name__ 
    173189        params= self.get_params() 
     
    184200        self.vertical_lines.restore() 
    185201        self.center.restore() 
     202         
     203         
    186204    def move(self, x, y, ev): 
    187205        """ 
     
    189207        """ 
    190208        pass 
     209     
    191210     
    192211    def set_cursor(self, x, y): 
    193212        pass 
    194213         
     214         
    195215    def get_params(self): 
     216        """ 
     217            Store a copy of values of parameters of the slicer into a dictionary. 
     218            @return params: the dictionary created 
     219        """ 
    196220        params = {} 
    197         
    198221        params["Width"] = math.fabs(self.vertical_lines.half_width)*2 
    199222        params["Height"] = math.fabs(self.horizontal_lines.half_height)*2  
    200          
    201223        params["center_x"] = self.center.x 
    202224        params["center_y"] =self.center.y 
    203225        params["count"] = self.count 
    204226        params["errors"]= self.error 
    205          
    206227        return params 
    207228     
     
    218239         
    219240    def set_params(self, params): 
    220          
     241        """ 
     242            Receive a dictionary and reset the slicer with values contained  
     243            in the values of the dictionary. 
     244            @param params: a dictionary containing name of slicer parameters and  
     245            values the user assigned to the slicer. 
     246        """ 
    221247        x_max = math.fabs(params["Width"] )/2 
    222248        y_max = math.fabs(params["Height"] )/2 
     
    224250        self.center_x=params["center_x"]  
    225251        self.center_y=params["center_y"] 
    226         
     252        #update the slicer given values of params 
    227253        self.center.update(center_x=self.center_x,center_y=self.center_y) 
    228         
    229254        self.horizontal_lines.update(center= self.center, 
    230255                                     width=x_max, 
     
    233258                                    width=x_max, 
    234259                                    height=y_max) 
    235          
     260        #compute the new error and sum given values of params 
    236261        self._post_data() 
    237262         
     
    241266        self.base.freeze_axes() 
    242267         
     268         
    243269    def thaw_axes(self): 
    244270        self.base.thaw_axes() 
    245271 
     272 
    246273    def draw(self): 
    247274        self.base.draw() 
     275         
     276         
     277         
    248278class PointInteractor(_BaseInteractor): 
    249279    """ 
    250          Select an annulus through a 2D plot 
     280         Draw a point that can be dragged with the marker. 
     281         this class controls the motion the center of the BoxSum  
    251282    """ 
    252283    def __init__(self,base,axes,color='black', zorder=5, 
     
    255286         
    256287        _BaseInteractor.__init__(self, base, axes, color=color) 
     288        ## Initialization the class  
    257289        self.markers = [] 
    258290        self.axes = axes 
    259         # center 
     291        # center coordinates 
    260292        self.x = center_x 
    261293        self.y = center_y 
    262          
     294        ## saved value of the center coordinates 
    263295        self.save_x = center_x 
    264296        self.save_y = center_y 
    265           
    266          
     297        ## Create a marker  
    267298        try: 
    268299            self.center_marker = self.axes.plot([self.x],[self.y], linestyle='', 
     
    280311            message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" 
    281312            message += "Get the SVN version that is at least as recent as June 1, 2007" 
    282              
    283             #raise "Version error", message 
    284              
    285         # line 
     313            owner=self.base.base.parent 
     314            wx.PostEvent(owner, StatusEvent(status="AnnulusSlicer: %s"%message)) 
     315             
     316        ## Draw a point 
    286317        self.center = self.axes.plot([self.x],[self.y], 
    287318                                      linestyle='-', marker='', 
    288319                                      color=self.color, 
    289320                                      visible=True)[0] 
    290      
    291         self.npts = 30 
    292         self.has_move=False     
     321        ## Flag to determine the motion this point  
     322        self.has_move=False    
     323        ## connecting the marker to allow them to move  
    293324        self.connect_markers([self.center_marker]) 
    294         self.update() 
     325        ## Update the figure 
     326        self.update() 
     327     
    295328     
    296329    def set_layer(self, n): 
     330        """ 
     331            Allow adding plot to the same panel 
     332            @param n: the number of layer 
     333        """ 
    297334        self.layernum = n 
    298335        self.update() 
    299336         
     337         
    300338    def clear(self): 
     339        """ 
     340            Clear this figure and its markers 
     341        """ 
    301342        self.clear_markers() 
    302343        try: 
     
    307348            for item in range(len(self.axes.lines)): 
    308349                del self.axes.lines[0] 
    309          
    310     def get_radius(self): 
    311          
    312         return 0 
     350   
    313351    
    314352    def update(self, center_x=None,center_y=None): 
    315353        """ 
    316         Draw the new roughness on the graph. 
     354            Draw the new roughness on the graph. 
    317355        """ 
    318356        if center_x !=None: self.x= center_x 
     
    323361         
    324362         
    325          
    326          
    327363    def save(self, ev): 
    328364        """ 
     
    332368        self.save_x= self.x 
    333369        self.save_y= self.y 
    334          
    335370        self.base.freeze_axes() 
     371 
    336372 
    337373    def moveend(self, ev): 
     
    346382        self.y= self.save_y 
    347383        self.x= self.save_x 
     384         
    348385         
    349386    def move(self, x, y, ev): 
     
    357394        self.base.base.update() 
    358395         
     396         
    359397    def set_cursor(self, x, y): 
    360398        self.move(x, y, None) 
     
    366404        params["x"] = self.x 
    367405        params["y"] = self.y 
    368          
    369406        return params 
     407     
    370408     
    371409    def set_params(self, params): 
     
    375413        
    376414         
    377 class Vertical_DoubleLine(_BaseInteractor): 
     415class VerticalDoubleLine(_BaseInteractor): 
    378416    """ 
    379          Select an annulus through a 2D plot 
     417         Draw 2 vertical lines moving in opposite direction and centered on  
     418         a point (PointInteractor) 
    380419    """ 
    381420    def __init__(self,base,axes,color='black', zorder=5, x=0.5,y=0.5, 
     
    384423         
    385424        _BaseInteractor.__init__(self, base, axes, color=color) 
     425        ## Initialization the class  
    386426        self.markers = [] 
    387427        self.axes = axes 
    388         # center 
     428        ## Center coordinates 
    389429        self.center_x = center_x 
    390430        self.center_y = center_y 
    391          
    392         
    393          
     431        ## defined end points vertical lignes and their saved values 
    394432        self.y1     = y + self.center_y 
    395433        self.save_y1= self.y1 
     
    405443        self.x2= self.center_x - delta 
    406444        self.save_x2 = self.x2 
    407          
    408         self.color=color 
    409          
     445        ## save the color of the line 
     446        self.color = color 
     447        ## the height of the rectangle 
    410448        self.half_height= math.fabs(y) 
    411449        self.save_half_height= math.fabs(y) 
    412          
     450        ## the with of the rectangle 
    413451        self.half_width= math.fabs(self.x1- self.x2)/2 
    414452        self.save_half_width=math.fabs(self.x1- self.x2)/2 
    415          
     453        ## Create marker  
    416454        try: 
    417455            self.right_marker = self.axes.plot([self.x1],[0], linestyle='', 
     
    429467            message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" 
    430468            message += "Get the SVN version that is at least as recent as June 1, 2007" 
    431              
    432             #raise "Version error", message 
    433              
    434         # line 
     469            owner=self.base.base.parent 
     470            wx.PostEvent(owner, StatusEvent(status="AnnulusSlicer: %s"%message)) 
     471             
     472        ## define the left and right lines of the rectangle 
    435473        self.right_line = self.axes.plot([self.x1,self.x1],[self.y1,self.y2], 
    436474                                      linestyle='-', marker='', 
     
    441479                                      color=self.color, 
    442480                                      visible=True)[0] 
    443      
    444         self.npts = 30 
    445         self.has_move=False     
     481        ## Flag to determine if the lines have moved 
     482        self.has_move=False   
     483        ## connection the marker and draw the pictures   
    446484        self.connect_markers([self.right_marker]) 
    447485        self.update() 
     
    449487 
    450488    def set_layer(self, n): 
     489        """ 
     490            Allow adding plot to the same panel 
     491            @param n: the number of layer 
     492        """ 
    451493        self.layernum = n 
    452494        self.update() 
    453495         
     496         
    454497    def clear(self): 
     498        """ 
     499            Clear this figure and its markers 
     500        """ 
    455501        self.clear_markers() 
    456502        try: 
     
    462508            for item in range(len(self.axes.lines)): 
    463509                del self.axes.lines[0] 
    464          
    465     def get_radius(self): 
    466          
    467         return 0 
     510    
    468511    
    469512    def update(self,x1=None,x2=None, y1=None,y2=None,width=None, height=None, center=None): 
    470513        """ 
    471         Draw the new roughness on the graph. 
    472         """ 
    473         #print "self.half_height",self.half_height,self.half_width 
     514            Draw the new roughness on the graph. 
     515            @param x1: new maximum value of x coordinates 
     516            @param x2: new minimum value of x coordinates 
     517            @param y1: new maximum value of y coordinates 
     518            @param y2: new minimum value of y coordinates 
     519            @param width: is the width of the new rectangle 
     520            @param height: is the height of the new rectangle 
     521            @param center: provided x, y  coordinates of the center point 
     522        """ 
     523        ## save the new height, witdh of the rectangle if given as a param 
    474524        if width!=None: 
    475525            self.half_width= width 
    476526        if height!=None: 
    477527            self.half_height= height 
     528        ## If new  center coordinates are given draw the rectangle  
     529        ##given these value  
    478530        if center!=None: 
    479531            self.center_x= center.x 
    480532            self.center_y= center.y 
    481             #print "vertical width",self.half_width ,self.center_x 
     533             
    482534            self.x1 = self.half_width + self.center_x 
    483535            self.x2= -self.half_width + self.center_x 
     
    490542            self.left_line.set(xdata=[self.x2,self.x2], ydata=[self.y1,self.y2]) 
    491543            return  
     544        ## if x1, y1, y2, y3 are given draw the rectangle with this value 
    492545        if x1 !=None:  
    493546            self.x1= x1 
     
    498551        if y2 !=None:  
    499552            self.y2= y2 
    500          
    501         
    502         
     553        ## Draw 2 vertical lines and a marker  
    503554        self.right_marker.set(xdata=[self.x1],ydata=[self.center_y]) 
    504555        self.right_line.set(xdata=[self.x1,self.x1], ydata=[self.y1,self.y2]) 
     
    518569         
    519570        self.save_half_height= self.half_height 
    520         #self.save_half_width = math.fabs(self.x1-self.x2)/2 
    521571        self.save_half_width = self.half_width 
     572         
    522573        self.base.freeze_axes() 
    523574 
     575 
    524576    def moveend(self, ev): 
    525          
     577        """ 
     578            After a dragging motion reset the flag self.has_move to False 
     579        """ 
    526580        self.has_move=False 
    527581        self.base.moveend(ev) 
    528582             
     583             
    529584    def restore(self): 
    530585        """ 
     
    538593         
    539594        self.half_height= self.save_half_height 
    540         #self.half_width= math.fabs(self.x1-self.x2)/2 
    541595        self.half_width= self.save_half_width 
     596        
    542597        
    543598    def move(self, x, y, ev): 
     
    550605         
    551606        self.half_width= math.fabs(self.x1-self.x2)/2 
    552         #print "Move vert: vertical width",self.half_width ,self.center_x 
     607         
    553608        self.has_move=True 
    554609        self.base.base.update() 
    555610         
     611         
    556612    def set_cursor(self, x, y): 
     613        """ 
     614            Update the figure given x and y  
     615        """ 
    557616        self.move(x, y, None) 
    558617        self.update() 
     
    560619         
    561620    def get_params(self): 
     621        """ 
     622            Store a copy of values of parameters of the slicer into a dictionary. 
     623            @return params: the dictionary created 
     624        """ 
    562625        params = {} 
    563626        params["x"] = self.x1 
     
    567630     
    568631    def set_params(self, params): 
     632        """ 
     633            Receive a dictionary and reset the slicer with values contained  
     634            in the values of the dictionary. 
     635            @param params: a dictionary containing name of slicer parameters and  
     636            values the user assigned to the slicer. 
     637        """ 
    569638        x = params["x"]  
    570639        y = params["y"]  
    571640        self.update(x=x, y=y, center_x=None,center_y=None) 
    572641 
    573 class Horizontal_DoubleLine(_BaseInteractor): 
     642 
     643class HorizontalDoubleLine(_BaseInteractor): 
    574644    """ 
    575645         Select an annulus through a 2D plot 
     
    580650         
    581651        _BaseInteractor.__init__(self, base, axes, color=color) 
     652        ## Initialization the class  
    582653        self.markers = [] 
    583654        self.axes = axes 
    584         # center 
     655        ## Center coordinates 
    585656        self.center_x = center_x 
    586657        self.center_y = center_y 
     
    623694            message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" 
    624695            message += "Get the SVN version that is at least as recent as June 1, 2007" 
    625              
    626             #raise "Version error", message 
    627              
    628         # line 
     696            owner=self.base.base.parent 
     697            wx.PostEvent(owner, StatusEvent(status="AnnulusSlicer: %s"%message)) 
     698             
     699        # Define 2 horizotnal lines 
    629700        self.top_line = self.axes.plot([self.x1,-self.x1],[self.y1,self.y1], 
    630701                                      linestyle='-', marker='', 
     
    635706                                      color=self.color, 
    636707                                      visible=True)[0] 
    637      
    638         self.npts = 30 
     708        ## Flag to determine if the lines have moved 
    639709        self.has_move=False     
     710        ## connection the marker and draw the pictures  
    640711        self.connect_markers([self.top_marker]) 
    641712        self.update() 
     
    643714 
    644715    def set_layer(self, n): 
     716        """ 
     717            Allow adding plot to the same panel 
     718            @param n: the number of layer 
     719        """ 
    645720        self.layernum = n 
    646721        self.update() 
    647722         
     723         
    648724    def clear(self): 
     725        """ 
     726            Clear this figure and its markers 
     727        """ 
    649728        self.clear_markers() 
    650729        try: 
     
    656735            for item in range(len(self.axes.lines)): 
    657736                del self.axes.lines[0] 
    658          
    659     def get_radius(self): 
    660          
    661         return 0 
     737     
    662738    
    663739    def update(self,x1=None,x2=None, y1=None,y2=None,width=None,height=None, center=None): 
    664740        """ 
    665         Draw the new roughness on the graph. 
    666         """ 
    667         #print "self.half_width",self.half_width 
    668         if width!=None: 
    669             self.half_width= width 
    670         if height!=None: 
     741            Draw the new roughness on the graph. 
     742            @param x1: new maximum value of x coordinates 
     743            @param x2: new minimum value of x coordinates 
     744            @param y1: new maximum value of y coordinates 
     745            @param y2: new minimum value of y coordinates 
     746            @param width: is the width of the new rectangle 
     747            @param height: is the height of the new rectangle 
     748            @param center: provided x, y  coordinates of the center point 
     749        """ 
     750        ## save the new height, witdh of the rectangle if given as a param 
     751        if width != None: 
     752            self.half_width = width 
     753        if height!= None: 
    671754            self.half_height= height 
     755        ## If new  center coordinates are given draw the rectangle  
     756        ##given these value  
    672757        if center!=None: 
    673758            self.center_x= center.x 
     
    684769            self.bottom_line.set(xdata=[self.x1,self.x2], ydata=[self.y2,self.y2]) 
    685770            return  
     771        ## if x1, y1, y2, y3 are given draw the rectangle with this value 
    686772        if x1 !=None:  
    687773            self.x1= x1 
     
    692778        if y2 !=None:  
    693779            self.y2= y2 
    694         
    695               
     780        ## Draw 2 vertical lines and a marker  
    696781        self.top_marker.set(xdata=[self.center_x],ydata=[self.y1]) 
    697782        self.top_line.set(xdata=[self.x1,self.x2], ydata=[self.y1,self.y1]) 
     
    699784        
    700785         
    701          
    702786    def save(self, ev): 
    703787        """ 
     
    717801 
    718802    def moveend(self, ev): 
    719          
     803        """ 
     804            After a dragging motion reset the flag self.has_move to False 
     805        """ 
    720806        self.has_move=False 
    721807        self.base.moveend(ev) 
     808            
    722809             
    723810    def restore(self): 
     
    732819        self.half_height= self.save_half_height 
    733820        self.half_width= self.save_half_width 
     821         
    734822         
    735823    def move(self, x, y, ev): 
     
    744832        self.base.base.update() 
    745833         
     834         
    746835    def set_cursor(self, x, y): 
     836        """ 
     837            Update the figure given x and y  
     838        """ 
    747839        self.move(x, y, None) 
    748840        self.update() 
     
    750842         
    751843    def get_params(self): 
     844        """ 
     845            Store a copy of values of parameters of the slicer into a dictionary. 
     846            @return params: the dictionary created 
     847        """ 
    752848        params = {} 
    753849        params["x"] = self.x 
    754850        params["y"] = self.y 
    755          
    756851        return params 
    757852     
     853     
    758854    def set_params(self, params): 
     855        """ 
     856            Receive a dictionary and reset the slicer with values contained  
     857            in the values of the dictionary. 
     858            @param params: a dictionary containing name of slicer parameters and  
     859            values the user assigned to the slicer. 
     860        """ 
    759861        x = params["x"]  
    760862        y = params["y"]  
    761863        self.update(x=x, y=y, center_x=None,center_y=None) 
    762864          
     865          
     866          
  • guiframe/local_perspectives/plotting/detector_dialog.py

    r9a585d0 reba08f1a  
    88from sans.guiframe.utils import format_number 
    99from sans.guicomm.events import StatusEvent ,NewPlotEvent,SlicerEvent 
     10 
     11 
    1012class DetectorDialog(wx.Dialog): 
    1113    """ 
     
    1719        kwds["style"] = wx.DEFAULT_DIALOG_STYLE 
    1820        wx.Dialog.__init__(self,parent,id=1, *args, **kwds) 
     21     
    1922        self.parent=base 
    2023        self.label_xnpts = wx.StaticText(self, -1, "Detector width in pixels") 
     
    2427        self.label_zmax = wx.StaticText(self, -1, "Max amplitude for color map (optional)") 
    2528        self.label_beam = wx.StaticText(self, -1, "Beam stop radius in units of q") 
    26         #self.label_sym  = wx.StaticText(self, -1, 'Use 4-fold symmetry') 
    27          
    28         # Npts, q max 
    29         #self.npts_ctl = wx.TextCtrl(self, -1, size=(60,20)) 
    30         #self.qmax_ctl = wx.TextCtrl(self, -1, size=(60,20)) 
    31         #self.beam_ctl = wx.TextCtrl(self, -1, size=(60,20)) 
     29         
    3230        self.xnpts_ctl = wx.StaticText(self, -1, "") 
    3331        self.ynpts_ctl = wx.StaticText(self, -1, "") 
     
    3735        self.zmin_ctl = wx.TextCtrl(self, -1, size=(60,20)) 
    3836        self.zmax_ctl = wx.TextCtrl(self, -1, size=(60,20)) 
    39         #self.chk_sym  = wx.CheckBox(self, -1, '') 
    40  
     37     
    4138        self.static_line_3 = wx.StaticLine(self, -1) 
    4239         
     
    6158         
    6259    def checkValues(self, event): 
     60        """ 
     61            Check the valitidity of zmin and zmax value 
     62            zmax should be a float and zmin less than zmax 
     63        """ 
    6364        flag = True 
    6465        try: 
     
    9798     
    9899    def setContent(self, xnpts,ynpts, qmax, beam,zmin=None,zmax=None, sym=False): 
     100        """ 
     101            received value and displayed them 
     102            @param xnpts: the number of point of the x_bins of data 
     103            @param ynpts: the number of point of the y_bins of data 
     104            @param qmax: the maxmimum value of data pixel 
     105            @param beam : the radius of the beam 
     106            @param zmin:  the value to get the minimum color 
     107            @param zmax:  the value to get the maximum color 
     108            @param sym: 
     109        """ 
    99110        self.xnpts_ctl.SetLabel(str(format_number(xnpts))) 
    100111        self.ynpts_ctl.SetLabel(str(format_number(ynpts))) 
    101112        self.qmax_ctl.SetLabel(str(format_number(qmax))) 
    102113        self.beam_ctl.SetLabel(str(format_number(beam))) 
    103         #self.chk_sym.SetValue(sym) 
     114        
    104115        if zmin !=None: 
    105116            self.zmin_ctl.SetValue(str(format_number(zmin))) 
     
    108119 
    109120    def getContent(self): 
     121        """ 
     122            @return event containing value to reset the detector of a given data 
     123        """ 
    110124        event = self.Event() 
    111         #event.npts = int(self.npts_ctl.GetValue()) 
    112         #event.qmax = float(self.qmax_ctl.GetValue()) 
    113         #event.beam = float(self.beam_ctl.GetValue()) 
    114         #event.sym4 = self.chk_sym.GetValue() 
    115          
     125        
    116126        t_min = self.zmin_ctl.GetValue() 
    117127        t_max = self.zmax_ctl.GetValue() 
     
    137147 
    138148    def __set_properties(self): 
     149        """ 
     150            set proprieties of the dialog window 
     151        """ 
    139152        self.SetTitle("Detector parameters") 
    140153        self.SetSize((600, 595)) 
    141154 
     155 
    142156    def __do_layout(self): 
     157        """ 
     158            fill the dialog window . 
     159        """ 
    143160        sizer_main = wx.BoxSizer(wx.VERTICAL) 
    144161        sizer_button = wx.BoxSizer(wx.HORIZONTAL) 
     
    164181        sizer_params.Add(self.zmax_ctl,   (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    165182        iy += 1 
    166         #sizer_params.Add(self.label_sym,  (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    167         #sizer_params.Add(self.chk_sym,    (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    168  
     183        
    169184        sizer_main.Add(sizer_params, 0, wx.EXPAND|wx.ALL, 10) 
    170185        sizer_main.Add(self.static_line_3, 0, wx.EXPAND, 0) 
Note: See TracChangeset for help on using the changeset viewer.