Ignore:
Timestamp:
Mar 3, 2009 4: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

File:
1 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) 
Note: See TracChangeset for help on using the changeset viewer.