Changeset 917850d in sasview


Ignore:
Timestamp:
Dec 2, 2008 10:02:04 AM (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:
45c1a35
Parents:
a92d51b
Message:

unsaved changed committed for sector slicer

File:
1 edited

Legend:

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

    rb06ef8c r917850d  
    1313import math 
    1414 
    15  
     15from sans.guicomm.events import NewPlotEvent, StatusEvent 
    1616import SlicerParameters 
    1717import wx 
     
    5454                                            theta=math.pi/2) 
    5555        self.update() 
    56         #self._post_data() 
     56        self._post_data() 
    5757         
    5858        # Bind to slice parameter events 
     
    6767            self.base.update() 
    6868 
     69 
    6970    def update_and_post(self): 
    7071        self.update() 
    7172        self._post_data() 
     73 
    7274 
    7375    def save_data(self, path, image, x, y): 
     
    8789    def clear(self): 
    8890        self.clear_markers() 
    89         #self.outer_circle.clear() 
     91        self.outer_circle.clear() 
    9092        self.inner_circle.clear() 
    9193        #self.base.connect.disconnect() 
    92         self.base.parent.Unbind(SlicerParameters.EVT_SLICER_PARS) 
     94        #self.base.parent.Unbind(SlicerParameters.EVT_SLICER_PARS) 
    9395         
    9496    def update(self): 
     
    102104        r1=self.inner_circle.get_radius() 
    103105        r2=self.outer_circle.get_radius() 
    104         print"annulus update",r1, r2 
     106        #print"annulus update",r1, r2 
    105107        if self.inner_radius.update(r1,r2)==1: 
    106             print "went here" 
     108            #print "went here" 
    107109            self.inner_circle.update(theta1=self.inner_radius.get_radius(), theta2=None) 
    108110            self.outer_circle.update(theta1=self.inner_radius.get_radius(),theta2=None) 
    109         if self.outer_radius.update(r1,r2)==1: 
    110              #self.outer_circle.update(self.outer_radius.get_radius()) 
     111         
     112        if self.outer_radius.update(r1,r2)==1:#self.outer_circle.update(self.outer_radius.get_radius()) 
    111113             self.inner_circle.update(theta1=None, theta2=self.outer_radius.get_radius()) 
    112114             self.outer_circle.update(theta1=None,theta2=self.outer_radius.get_radius()) 
    113     def get_data(self, image, x, y): 
    114         """  
    115             Return a 1D vector corresponding to the slice 
    116             @param image: data matrix 
    117             @param x: x matrix 
    118             @param y: y matrix 
    119         """ 
    120         # If we have no data, just return 
    121         if image == None: 
    122             return         
    123          
    124         nbins = self.nbins 
    125          
    126         data_x = nbins*[0] 
    127         data_y = nbins*[0] 
    128         counts = nbins*[0] 
    129         length = len(image) 
    130          
    131          
    132         for i_x in range(length): 
    133             for i_y in range(length): 
    134                          
    135                 q = math.sqrt(x[i_x]*x[i_x] + y[i_y]*y[i_y]) 
    136                 if (q>self.inner_circle._inner_mouse_x \ 
    137                     and q<self.outer_circle._inner_mouse_x) \ 
    138                     or (q<self.inner_circle._inner_mouse_x \ 
    139                     and q>self.outer_circle._inner_mouse_x): 
    140                              
    141                     i_bin = int(math.ceil(nbins*(math.atan2(y[i_y], x[i_x])+math.pi)/(2.0*math.pi)) - 1) 
    142                      
    143                      
    144                     #data_y[i_bin] += math.exp(image[i_x][i_y]) 
    145                     data_y[i_bin] += image[i_y][i_x] 
    146                     counts[i_bin] += 1.0 
    147                      
    148         for i in range(nbins): 
    149             data_x[i] = (1.0*i+0.5)*2.0*math.pi/nbins 
    150             if counts[i]>0: 
    151                 data_y[i] = data_y[i]/counts[i] 
    152          
    153         return data_x, data_y 
     115     
    154116 
    155117    def save(self, ev): 
     
    160122        self.base.freeze_axes() 
    161123        self.inner_circle.save(ev) 
    162         #self.outer_circle.save(ev) 
     124        self.outer_circle.save(ev) 
    163125 
    164126    def _post_data(self): 
    165         # Compute data 
    166         data = self.base.get_corrected_data() 
    167         # If we have no data, just return 
    168         if data == None: 
    169             return 
    170  
    171         data_x, data_y = self.get_data(data, self.base.x, self.base.y) 
    172          
    173         name = "Ring" 
    174         if hasattr(self.base, "name"): 
    175             name += " %s" % self.base.name 
    176          
    177         wx.PostEvent(self.base.parent, AddPlotEvent(name=name, 
    178                                                x = data_x, 
    179                                                y = data_y, 
    180                                                qmin = self.inner_circle._inner_mouse_x, 
    181                                                qmax = self.outer_circle._inner_mouse_x, 
    182                                                yscale = 'log', 
    183                                                variable = 'ANGLE', 
    184                                                ylabel = "\\rm{Intensity} ", 
    185                                                yunits = "cm^{-1}", 
    186                                                xlabel = "\\rm{\phi}", 
    187                                                xunits = "rad", 
    188                                                parent = self.base.__class__.__name__)) 
    189                                                 
     127        """ post data""" 
     128        rmin=self.inner_circle.get_radius() 
     129        rmax=self.outer_circle.get_radius() 
     130        phimin=self.inner_radius.get_radius() 
     131        phimax=self.outer_radius.get_radius() 
     132        from DataLoader.manipulations import SectorQ, SectorPhi 
     133        sectQ = SectorQ(r_min=rmin, r_max=rmax, phi_min=phimin, phi_max=phimax) 
     134        sectorQ = sectQ(self.base.data2D) 
     135         
     136        sectPhi = SectorPhi(r_min=rmin, r_max=rmax, phi_min=phimin, phi_max=phimax) 
     137        sectorPhi = sectPhi(self.base.data2D) 
     138        from sans.guiframe.dataFitting import Data1D 
     139        if hasattr(sectorQ,"dxl"): 
     140            dxl= sectorQ.dxl 
     141        else: 
     142            dxl= None 
     143        if hasattr(sectorQ,"dxw"): 
     144            dxw= sectorQ.dxw 
     145        else: 
     146            dxw= None 
     147             
     148        new_plot1 = Data1D(x=sectorQ.x,y=sectorQ.y,dy=sectorQ.dy,dxl=dxl,dxw=dxw) 
     149        new_plot1.name = "SectorQ ("+ self.base.data2D.name+")" 
     150        if hasattr(sectorPhi,"dxl"): 
     151            dxl= sectorPhi.dxl 
     152        else: 
     153            dxl= None 
     154        if hasattr(sectorPhi,"dxw"): 
     155            dxw= sectorPhi.dxw 
     156        else: 
     157            dxw= None 
     158        new_plot2 = Data1D(x=sectorPhi.x,y=sectorPhi.y,dy=sectorPhi.dy,dxl=dxl,dxw=dxw) 
     159        new_plot2.name = "SectorPhi ("+ self.base.data2D.name+")" 
     160        self.plot_data( new_plot1) 
     161        self.plot_data( new_plot2) 
     162         
     163         
     164    def plot_data(self, new_plot):  
     165        """ 
     166             plot a new data 1D corresponding to the phi and Q sector average 
     167        """ 
     168        new_plot.source=self.base.data2D.source 
     169        new_plot.info=self.base.data2D.info 
     170        new_plot.interactive = True 
     171        #print "loader output.detector",output.source 
     172        new_plot.detector =self.base.data2D.detector 
     173        # If the data file does not tell us what the axes are, just assume... 
     174        new_plot.xaxis(self.base.data2D._xaxis,self.base.data2D._xunit) 
     175        new_plot.yaxis(self.base.data2D._yaxis,self.base.data2D._yunit) 
     176        new_plot.group_id = "sector"+self.base.data2D.name 
     177        wx.PostEvent(self.base.parent, NewPlotEvent(plot=new_plot, title=new_plot.name)) 
     178         
    190179         
    191180    def moveend(self, ev): 
     
    226215         
    227216        inner = params["inner_radius"]  
    228         #outer = params["outer_radius"]  
     217        outer = params["outer_radius"]  
    229218        self.nbins = int(params["nbins"]) 
    230219        self.inner_circle.set_cursor(inner, self.inner_circle._inner_mouse_y) 
    231         #self.outer_circle.set_cursor(outer, self.outer_circle._inner_mouse_y) 
    232         self._post_data() 
     220        self.outer_circle.set_cursor(outer, self.outer_circle._inner_mouse_y) 
     221        #self._post_data() 
    233222         
    234223    def freeze_axes(self): 
Note: See TracChangeset for help on using the changeset viewer.