Changeset 8a621ac in sasview


Ignore:
Timestamp:
Apr 27, 2012 9:22:40 AM (12 years ago)
Author:
Mathieu Doucet <doucetm@…>
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:
10bfeb3
Parents:
34f3ad0
Message:

make pylint happier

Location:
sanscalculator/src/sans/calculator
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • sanscalculator/src/sans/calculator/instrument.py

    rf93b6a1e r8a621ac  
    11""" 
    2 This module is a small tool to allow user to  
    3 control instrumental parameters  
     2This module is a small tool to allow user to 
     3control instrumental parameters 
    44""" 
    55import numpy 
     
    77# defaults in cgs unit 
    88_SAMPLE_A_SIZE = [1.27] 
    9 _SOURCE_A_SIZE = [3.81]  
    10 _SAMPLE_DISTANCE = [1627, 0]  
    11 _SAMPLE_OFFSET = [0, 0]  
    12 _SAMPLE_SIZE = [2.54]  
    13 _SAMPLE_THICKNESS = 0.2   
    14 _D_DISTANCE = [1000, 0]  
     9_SOURCE_A_SIZE = [3.81] 
     10_SAMPLE_DISTANCE = [1627, 0] 
     11_SAMPLE_OFFSET = [0, 0] 
     12_SAMPLE_SIZE = [2.54] 
     13_SAMPLE_THICKNESS = 0.2 
     14_D_DISTANCE = [1000, 0] 
    1515_D_SIZE = [128, 128] 
    16 _D_PIX_SIZE = [0.5, 0.5]   
     16_D_PIX_SIZE = [0.5, 0.5] 
    1717 
    1818_MIN = 0.0 
     
    2121_WAVE_LENGTH = 6.0 
    2222_WAVE_SPREAD = 0.125 
    23 _MASS = 1.67492729E-24 #[gr] 
    24 _LAMBDA_ARRAY = [[0, 1e+16],[_INTENSITY, _INTENSITY]] 
     23_MASS = 1.67492729E-24  # [gr] 
     24_LAMBDA_ARRAY = [[0, 1e+16], [_INTENSITY, _INTENSITY]] 
     25 
    2526 
    2627class Aperture(object): 
     
    3637        self.sample_distance = _SAMPLE_DISTANCE 
    3738         
    38     def set_source_size(self, size =[]): 
     39    def set_source_size(self, size=[]): 
    3940        """ 
    4041        Set the source aperture size 
    4142        """ 
    4243        if len(size) == 0: 
    43             self.source_size = 0.0  
     44            self.source_size = 0.0 
    4445        else: 
    4546            self.source_size = size 
    4647            validate(size[0]) 
    47     def set_sample_size(self, size =[]): 
     48             
     49    def set_sample_size(self, size=[]): 
    4850        """ 
    4951        Set the sample aperture size 
    5052        """ 
    5153        if len(size) == 0: 
    52             self.sample_size = 0.0  
     54            self.sample_size = 0.0 
    5355        else: 
    5456            self.sample_size = size 
    5557            validate(size[0]) 
    5658             
    57     def set_sample_distance(self, distance = []): 
     59    def set_sample_distance(self, distance=[]): 
    5860        """ 
    5961        Set the sample aperture distance 
    6062        """ 
    6163        if len(distance) == 0: 
    62             self.sample_distance = 0.0  
     64            self.sample_distance = 0.0 
    6365        else: 
    6466            self.sample_distance = distance 
     
    7880        self.thickness = _SAMPLE_THICKNESS 
    7981 
    80      
    81     def set_size(self, size =[]): 
     82    def set_size(self, size=[]): 
    8283        """ 
    8384        Set the sample size 
    8485        """ 
    8586        if len(size) == 0: 
    86             self.sample_size = 0.0  
     87            self.sample_size = 0.0 
    8788        else: 
    8889            self.sample_size = size 
    8990            validate(size[0]) 
    9091             
    91     def set_thickness(self, thickness = 0.0): 
     92    def set_thickness(self, thickness=0.0): 
    9293        """ 
    9394        Set the sample thickness 
     
    9697        validate(thickness) 
    9798     
    98     def set_distance(self, distance = []): 
     99    def set_distance(self, distance=[]): 
    99100        """ 
    100101        Set the sample distance 
    101102        """ 
    102103        if len(distance) == 0: 
    103             self.distance = 0.0  
     104            self.distance = 0.0 
    104105        else: 
    105106            self.distance = distance 
     
    122123     
    123124         
    124     def set_size(self, size =[]): 
     125    def set_size(self, size=[]): 
    125126        """ 
    126127        Set the detector  size 
     
    132133            validate(size[0]) 
    133134             
    134     def set_pix_size(self, size = []): 
     135    def set_pix_size(self, size=[]): 
    135136        """ 
    136137        Set the detector pix_size 
    137138        """ 
    138139        if len(size) == 0: 
    139             self.pix_size = 0  
     140            self.pix_size = 0 
    140141        else: 
    141142            self.pix_size = size 
    142143            validate(size[0]) 
    143144     
    144     def set_distance(self, distance = []): 
     145    def set_distance(self, distance=[]): 
    145146        """ 
    146147        Set the detector distance 
     
    166167        # wavelength spread (FWHM) 
    167168        self.wavelength_spread = _WAVE_SPREAD 
    168         # wavelength spectrum  
    169         self.spectrum = self.get_default_spectrum()         
     169        # wavelength spectrum 
     170        self.spectrum = self.get_default_spectrum() 
    170171        # intensity in counts/sec 
    171         self.intensity = numpy.interp(self.wavelength,  
     172        self.intensity = numpy.interp(self.wavelength, 
    172173                                      self.spectrum[0], 
    173174                                      self.spectrum[1], 
     
    188189        """ 
    189190        self.band = self.spectrum 
    190     def set_spectrum(self, spectrum):   
     191         
     192    def set_spectrum(self, spectrum): 
    191193        """ 
    192194        Set spectrum 
     
    194196        :param spectrum: numpy array 
    195197        """ 
    196         self.spectrum = spectrum  
     198        self.spectrum = spectrum 
    197199        self.setup_spectrum() 
    198200          
    199201    def setup_spectrum(self): 
    200202        """ 
    201         To set the wavelength spectrum, and intensity, assumes  
     203        To set the wavelength spectrum, and intensity, assumes 
    202204        wavelength is already within the spectrum 
    203205        """ 
    204206        spectrum = self.spectrum 
    205         intensity = numpy.interp(self.wavelength,  
     207        intensity = numpy.interp(self.wavelength, 
    206208                                      spectrum[0], 
    207209                                      spectrum[1], 
     
    213215        self.max = max(self.spectrum[0]) 
    214216        # set default band 
    215         self.set_band([self.min,self.max]) 
     217        self.set_band([self.min, self.max]) 
    216218         
    217219    def set_band(self, band=[]): 
     
    224226        if min(band) < self.min or\ 
    225227                max(band) > self.max: 
    226             raise  
     228            raise 
    227229        self.band = band 
    228  
    229230          
    230     def set_intensity(self, intensity = 368428): 
     231    def set_intensity(self, intensity=368428): 
    231232        """ 
    232233        Sets the intensity in counts/sec 
    233234        """ 
    234         self.intensity = intensity   
    235         validate(intensity)  
    236              
    237     def set_wavelength(self, wavelength = _WAVE_LENGTH): 
     235        self.intensity = intensity 
     236        validate(intensity) 
     237             
     238    def set_wavelength(self, wavelength=_WAVE_LENGTH): 
    238239        """ 
    239240        Sets the wavelength 
     
    242243        if wavelength < min(self.band) or\ 
    243244                wavelength > max(self.band): 
    244             raise  
     245            raise 
    245246        self.wavelength = wavelength 
    246247        validate(wavelength) 
    247         self.intensity = numpy.interp(self.wavelength,  
     248        self.intensity = numpy.interp(self.wavelength, 
    248249                                  self.spectrum[0], 
    249250                                  self.spectrum[1], 
     
    251252                                  0.0) 
    252253 
    253  
    254     def set_mass(self, mass = _MASS): 
     254    def set_mass(self, mass=_MASS): 
    255255        """ 
    256256        Sets the wavelength 
     
    259259        validate(mass) 
    260260         
    261     def set_wavelength_spread(self, spread = _WAVE_SPREAD): 
     261    def set_wavelength_spread(self, spread=_WAVE_SPREAD): 
    262262        """ 
    263263        Sets the wavelength spread 
     
    302302        """ 
    303303        return self.spectrum 
     304     
    304305    def get_default_spectrum(self): 
    305306        """ 
     
    307308        """ 
    308309        return numpy.array(_LAMBDA_ARRAY) 
     310     
    309311    def get_band(self): 
    310312        """ 
    311313        To get the wavelength band 
    312314        """ 
    313         return self.band  
     315        return self.band 
    314316     
    315317    def plot_spectrum(self): 
     
    320322        try: 
    321323            import matplotlib.pyplot as plt 
    322             plt.plot(self.spectrum[0], self.spectrum[1], linewidth = 2, color = 'r') 
    323             plt.legend(['Spectrum'], loc = 'best') 
     324            plt.plot(self.spectrum[0], self.spectrum[1], linewidth=2, color='r') 
     325            plt.legend(['Spectrum'], loc='best') 
    324326            plt.show() 
    325327        except: 
     
    345347        get list of the intensity wrt wavelength_list 
    346348        """ 
    347         out = numpy.interp(self.wavelength_list,  
     349        out = numpy.interp(self.wavelength_list, 
    348350                                      self.spectrum[0], 
    349351                                      self.spectrum[1], 
     
    375377         
    376378         
    377 def validate(value = None): 
     379def validate(value=None): 
    378380    """ 
    379381    Check if the value is folat > 0.0 
     
    389391    except: 
    390392        val = False 
    391     #if not val: 
    392     #    raise ValueError, "Got improper value..." 
  • sanscalculator/src/sans/calculator/kiessig_calculator.py

    rf93b6a1e r8a621ac  
    11""" 
    22This module is a small tool to allow user to quickly 
    3 determine the size value in real space  from the  
     3determine the size value in real space  from the 
    44fringe width in q space. 
    55""" 
    66from math import pi, fabs 
    77_DQ_DEFAULT = 0.05 
     8 
     9 
    810class KiessigThicknessCalculator(object): 
    911    """ 
     
    1315         
    1416        # dq value 
    15         self.deltaq = _DQ_DEFAULT  
     17        self.deltaq = _DQ_DEFAULT 
    1618        # thickenss value 
    1719        self.thickness = None 
     
    2628        """ 
    2729        # set dq 
    28         self.deltaq  = dq 
     30        self.deltaq = dq 
    2931         
    3032    def get_deltaq(self): 
     
    3335        """ 
    3436        # return dq 
    35         return self.deltaq  
     37        return self.deltaq 
    3638 
    3739    def compute_thickness(self): 
     
    5153        else: 
    5254            # calculate thickness 
    53             thickness = 2*pi/fabs(dq)  
    54             # return thickness value       
     55            thickness = 2*pi/fabs(dq) 
     56            # return thickness value 
    5557            return thickness 
    5658   
    57     def get_thickness_unit(self):  
     59    def get_thickness_unit(self): 
    5860        """ 
    5961        :return: the thickness unit. 
     
    6163        # unit of thickness 
    6264        return self.thickness_unit 
    63  
    64  
  • sanscalculator/src/sans/calculator/resolution_calculator.py

    r5f3164c r8a621ac  
    11""" 
    22This object is a small tool to allow user to quickly 
    3 determine the variance in q  from the  
     3determine the variance in q  from the 
    44instrumental parameters. 
    55""" 
     
    1111from math import pi 
    1212from math import sqrt 
    13 import math  
    14 import scipy 
     13import math 
    1514import numpy 
    1615 
     
    1918#Gravitational acc. in cgs unit 
    2019_GRAVITY = 981.0 
     20 
    2121 
    2222class ResolutionCalculator(object): 
     
    8686        self.qyrange = [] 
    8787         
    88     def compute_and_plot(self, qx_value, qy_value, qx_min, qx_max,  
    89                           qy_min, qy_max, coord = 'cartesian'): 
     88    def compute_and_plot(self, qx_value, qy_value, qx_min, qx_max, 
     89                          qy_min, qy_max, coord='cartesian'): 
    9090        """ 
    9191        Compute the resolution 
     
    9898        # wavelength etc. 
    9999        lamda_list, dlamb_list = self.get_wave_list() 
    100         intens_list = []#self.get_intensity_list() 
    101  
     100        intens_list = [] 
    102101        sig1_list = [] 
    103102        sig2_list = [] 
     
    120119                        self.compute(lam, dlam, qx_value, qy_value, coord, tof) 
    121120            # make image 
    122             image = self.get_image(qx_value, qy_value, sigma_1, sigma_2,  
     121            image = self.get_image(qx_value, qy_value, sigma_1, sigma_2, 
    123122                            sigma_r, qx_min, qx_max, qy_min, qy_max, 
    124123                            coord, False) 
    125124             
    126             # Non tof mode to be speed up  
     125            # Non tof mode to be speed up 
    127126            #if num_lamda < 2: 
    128127            #    return self.plot_image(image) 
     
    140139            self.qxrange = [qx_min, qx_max] 
    141140            self.qyrange = [qy_min, qy_max] 
    142             #print qy_max+qy_min,qy_max,qy_min 
    143141            sig1_list.append(sigma_1) 
    144142            sig2_list.append(sigma_2) 
    145143            sigr_list.append(sigma_r) 
    146144            sigma1d_list.append(sigma1d) 
    147         # redraw image in global 2d q-space.    
     145        # redraw image in global 2d q-space. 
    148146        self.image_lam = [] 
    149147        total_intensity = 0 
     
    156154            dlam = dlamb_list[ind] 
    157155            intens = self.setup_tof(lam, dlam) 
    158             out = self.get_image(qx_value, qy_value, sig1_list[ind],  
    159                                    sig2_list[ind], sigr_list[ind],  
     156            out = self.get_image(qx_value, qy_value, sig1_list[ind], 
     157                                   sig2_list[ind], sigr_list[ind], 
    160158                                   qx_min, qx_max, qy_min, qy_max, coord) 
    161159            # this is the case of q being outside the detector 
     
    164162            image = out 
    165163            # set variance as sigmas 
    166             sigma_1 += sig1_list[ind] *  sig1_list[ind] * self.intensity 
     164            sigma_1 += sig1_list[ind] * sig1_list[ind] * self.intensity 
    167165            sigma_r += sigr_list[ind] * sigr_list[ind] * self.intensity 
    168166            sigma_2 += sig2_list[ind] * sig2_list[ind] * self.intensity 
     
    182180            self.sigma_2 = sqrt(sigma_2) 
    183181            self.sigma_1d = sqrt(sigma1d) 
    184             # rescale  
    185             max_im_val = 1 #image_out.max() 
     182            # rescale 
     183            max_im_val = 1 
    186184            if max_im_val > 0: 
    187185                image_out /= max_im_val 
     
    199197         
    200198        # plot image 
    201         return self.plot_image(self.image)  
     199        return self.plot_image(self.image) 
    202200     
    203201    def setup_tof(self, wavelength, wavelength_spread): 
     
    214212         
    215213        if wavelength == 0: 
    216             msg = "Can't compute the resolution: the wavelength is zero..."  
     214            msg = "Can't compute the resolution: the wavelength is zero..." 
    217215            raise RuntimeError, msg 
    218216        return self.intensity 
    219217         
    220     def compute(self, wavelength, wavelength_spread, qx_value, qy_value,  
    221                 coord = 'cartesian', tof=False): 
     218    def compute(self, wavelength, wavelength_spread, qx_value, qy_value, 
     219                coord='cartesian', tof=False): 
    222220        """ 
    223221        Compute the Q resoltuion in || and + direction of 2D 
     
    232230        if tof: 
    233231            # rectangular 
    234             tof_factor =  2 
     232            tof_factor = 2 
    235233        else: 
    236234            # triangular 
    237             tof_factor =  1 
     235            tof_factor = 1 
    238236        # Find polar values 
    239237        qr_value, phi = self._get_polar_value(qx_value, qy_value) 
     
    285283        sigma_1 += self.get_variance(rthree, l_two, phi, comp1) 
    286284        # for gravity term for 1d 
    287         sigma_1grav1d =  self.get_variance_gravity(l_ssa, l_sad, lamb, lamb_spread,  
    288                             phi, comp1, 'on') / tof_factor 
     285        sigma_1grav1d = self.get_variance_gravity(l_ssa, l_sad, lamb, 
     286                            lamb_spread, phi, comp1, 'on') / tof_factor 
    289287        # for wavelength spread 
    290288        # reserve for 1d calculation 
    291289        A_value = self._cal_A_value(lamb, l_ssa, l_sad) 
    292         sigma_wave_1, sigma_wave_1_1d = self.get_variance_wave(A_value,  
    293                                           radius, l_two, lamb_spread,  
     290        sigma_wave_1, sigma_wave_1_1d = self.get_variance_wave(A_value, 
     291                                          radius, l_two, lamb_spread, 
    294292                                          phi, 'radial', 'on') 
    295293        sigma_wave_1 /= tof_factor 
    296         sigma_wave_1_1d /=  tof_factor 
     294        sigma_wave_1_1d /= tof_factor 
    297295        # for 1d 
    298         variance_1d_1 = (sigma_1 + sigma_1grav1d) /2 + sigma_wave_1_1d 
     296        variance_1d_1 = (sigma_1 + sigma_1grav1d) / 2 + sigma_wave_1_1d 
    299297        # normalize 
    300298        variance_1d_1 = knot * knot * variance_1d_1 / 12 
     
    303301        #sigma_1 += sigma_wave_1 
    304302        # normalize 
    305         sigma_1 = knot*sqrt(sigma_1 / 12) 
    306         sigma_r = knot*sqrt(sigma_wave_1 / (tof_factor *12)) 
     303        sigma_1 = knot * sqrt(sigma_1 / 12) 
     304        sigma_r = knot * sqrt(sigma_wave_1 / (tof_factor *12)) 
    307305        # sigma in the phi/y direction 
    308306        # for source apperture 
     
    316314 
    317315        # for gravity term for 1d 
    318         sigma_2grav1d =  self.get_variance_gravity(l_ssa, l_sad, lamb, lamb_spread,  
    319                              phi, comp2, 'on') / tof_factor 
    320  
    321          
     316        sigma_2grav1d = self.get_variance_gravity(l_ssa, l_sad, lamb, 
     317                                lamb_spread, phi, comp2, 'on') / tof_factor 
     318 
    322319        # for wavelength spread 
    323320        # reserve for 1d calculation 
    324         sigma_wave_2, sigma_wave_2_1d = self.get_variance_wave(A_value,  
    325                                           radius, l_two, lamb_spread,  
    326                                           phi, 'phi', 'on')  
    327         sigma_wave_2 /=  tof_factor 
    328         sigma_wave_2_1d /=  tof_factor 
     321        sigma_wave_2, sigma_wave_2_1d = self.get_variance_wave(A_value, 
     322                                          radius, l_two, lamb_spread, 
     323                                          phi, 'phi', 'on') 
     324        sigma_wave_2 /= tof_factor 
     325        sigma_wave_2_1d /= tof_factor 
    329326        # for 1d 
    330327        variance_1d_2 = (sigma_2 + sigma_2grav1d) / 2 + sigma_wave_2_1d 
    331328        # normalize 
    332         variance_1d_2 = knot*knot*variance_1d_2 / 12 
     329        variance_1d_2 = knot * knot * variance_1d_2 / 12 
    333330         
    334331        # for 2d 
     
    336333        #sigma_2 += sigma_wave_2 
    337334        # normalize 
    338         sigma_2 =  knot * sqrt(sigma_2 / 12) 
     335        sigma_2 = knot * sqrt(sigma_2 / 12) 
    339336        sigma1d = sqrt(variance_1d_1 + variance_1d_2) 
    340337        # set sigmas 
     
    345342        return qr_value, phi, sigma_1, sigma_2, sigma_r, sigma1d 
    346343     
    347     def _within_detector_range(self,qx_value, qy_value): 
     344    def _within_detector_range(self, qx_value, qy_value): 
    348345        """ 
    349346        check if qvalues are within detector range 
     
    369366     
    370367    def get_image(self, qx_value, qy_value, sigma_1, sigma_2, sigma_r, 
    371                   qx_min, qx_max, qy_min, qy_max,  
    372                   coord = 'cartesian', full_cal=True):  
     368                  qx_min, qx_max, qy_min, qy_max, 
     369                  coord='cartesian', full_cal=True): 
    373370        """ 
    374371        Get the resolution in polar coordinate ready to plot 
     
    380377        """ 
    381378        # Get  qx_max and qy_max... 
    382         output = self._get_detector_qxqy_pixels() 
     379        self._get_detector_qxqy_pixels() 
    383380        
    384381        qr_value, phi = self._get_polar_value(qx_value, qy_value) 
    385382 
    386383        # Check whether the q value is within the detector range 
    387         msg = "Invalid input: Q value out of the detector range..." 
     384        #msg = "Invalid input: Q value out of the detector range..." 
    388385        if qx_min < self.qx_min: 
    389386            self.qx_min = qx_min 
     
    416413            qc_2 = 0.0 
    417414            # Calculate the 2D Gaussian distribution image 
    418             image = self._gaussian2d_polar(q_1, q_2, qc_1, qc_2,  
     415            image = self._gaussian2d_polar(q_1, q_2, qc_1, qc_2, 
    419416                                 sigma_1, sigma_2, sigma_r) 
    420417        else: 
     
    426423             
    427424            # Calculate the 2D Gaussian distribution image 
    428             image = self._gaussian2d(q_1, q_2, qc_1, qc_2,  
     425            image = self._gaussian2d(q_1, q_2, qc_1, qc_2, 
    429426                                     sigma_1, sigma_2, sigma_r) 
    430427        # out side of detector 
     
    445442        """ 
    446443        Plot image using pyplot 
    447         : image: 2d resolution image  
     444        : image: 2d resolution image 
    448445         
    449446        : return plt: pylab object 
     
    455452        plt.ylabel('$\\rm{Q}_{y} [A^{-1}]$') 
    456453        # Max value of the image 
    457         max = numpy.max(image) 
     454        # max = numpy.max(image) 
    458455        qx_min, qx_max, qy_min, qy_max = self.get_detector_qrange() 
    459456 
    460457        # Image 
    461         im = plt.imshow(image,  
    462                 extent = [qx_min, qx_max, qy_min, qy_max]) 
     458        im = plt.imshow(image, 
     459                extent=[qx_min, qx_max, qy_min, qy_max]) 
    463460 
    464461        # bilinear interpolation to make it smoother 
     
    473470        self.image = [] 
    474471         
    475     def get_variance(self, size = [], distance = 0, phi = 0, comp = 'radial'): 
     472    def get_variance(self, size=[], distance=0, phi=0, comp='radial'): 
    476473        """ 
    477474        Get the variance when the slit/pinhole size is given 
    478         : size: list that can be one(diameter for circular)  
     475        : size: list that can be one(diameter for circular) 
    479476                or two components(lengths for rectangular) 
    480477        : distance: [z, x] where z along the incident beam, x // qx_value 
     
    482479         
    483480        : return variance: sigma^2 
    484         """    
     481        """ 
    485482        # check the length of size (list) 
    486483        len_size = len(size) 
     
    509506        # for rectangular slit 
    510507        elif len_size == 2: 
    511             x_comp = size[0] * phi_x  
     508            x_comp = size[0] * phi_x 
    512509            y_comp = size[1] * phi_y 
    513510        # otherwise 
    514511        else: 
    515512            raise ValueError, " Improper input..." 
    516         # get them squared   
    517         sigma  = x_comp * x_comp  
     513        # get them squared 
     514        sigma  = x_comp * x_comp 
    518515        sigma += y_comp * y_comp 
    519516        # normalize by distance 
     
    522519        return sigma 
    523520 
    524     def get_variance_wave(self, A_value, radius, distance, spread, phi,  
    525                           comp = 'radial', switch = 'on'): 
     521    def get_variance_wave(self, A_value, radius, distance, spread, phi, 
     522                          comp='radial', switch='on'): 
    526523        """ 
    527524        Get the variance when the wavelength spread is given 
     
    547544                sigma1d *= (math.sin(phi)*math.sin(phi)) 
    548545            else: 
    549                 sigma1d *= 1   
    550             # sigma^2 for 2d   
     546                sigma1d *= 1 
     547            # sigma^2 for 2d 
    551548            # shift the coordinate due to the gravitational shift 
    552549            rad_x = radius * math.cos(phi) 
    553550            rad_y = A_value - radius * math.sin(phi) 
    554551            radius = math.sqrt(rad_x * rad_x + rad_y * rad_y) 
    555             # new phi  
     552            # new phi 
    556553            phi = math.atan2(-rad_y, rad_x) 
    557             self.gravity_phi = phi  
     554            self.gravity_phi = phi 
    558555            # calculate sigma^2 
    559556            sigma = 2 * math.pow(radius/distance*spread, 2) 
     
    563560                sigma *= (math.sin(phi)*math.sin(phi)) 
    564561            else: 
    565                 sigma *= 1           
     562                sigma *= 1 
    566563                 
    567564            return sigma, sigma1d 
    568565 
    569     def get_variance_gravity(self, s_distance, d_distance, wavelength, spread,  
    570                              phi, comp = 'radial', switch = 'on'): 
     566    def get_variance_gravity(self, s_distance, d_distance, wavelength, spread, 
     567                             phi, comp='radial', switch='on'): 
    571568        """ 
    572569        Get the variance from gravity when the wavelength spread is given 
     
    603600            return sigma 
    604601     
    605     def _cal_A_value(self, lamda, s_distance, d_distance):     
     602    def _cal_A_value(self, lamda, s_distance, d_distance): 
    606603        """ 
    607604        Calculate A value for gravity 
     
    617614        gravy = _GRAVITY 
    618615        # m/h 
    619         m_over_h = self.mass /h_constant 
     616        m_over_h = self.mass / h_constant 
    620617        # A value 
    621618        a_value = d_distance * (s_distance + d_distance) 
     
    641638        return self.wave.wavelength 
    642639     
     640    #TODO: why was this method duplicated? 
     641    #def get_spectrum(self): 
     642    #    """ 
     643    #    Get spectrum 
     644    #    """ 
     645    #    return self.wave.spectrum 
     646     
     647    def get_default_spectrum(self): 
     648        """ 
     649        Get default_spectrum 
     650        """ 
     651        return self.wave.get_default_spectrum() 
     652     
    643653    def get_spectrum(self): 
    644654        """ 
    645         Get spectrum 
    646         """ 
    647         return self.wave.spectrum    
    648      
    649     def get_default_spectrum(self): 
    650         """ 
    651         Get default_spectrum 
    652         """ 
    653         return self.wave.get_default_spectrum()     
    654      
    655     def get_spectrum(self): 
    656         """ 
    657655        Get _spectrum 
    658656        """ 
    659         return self.wave.get_spectrum()  
     657        return self.wave.get_spectrum() 
    660658          
    661659    def get_wavelength_spread(self): 
     
    693691        Get detector size 
    694692        """ 
    695         return self.detector.size    
     693        return self.detector.size 
    696694      
    697695    def get_source2sample_distance(self): 
     
    755753        """ 
    756754        self.spectrum = spectrum 
    757         self.wave.set_spectrum(spectrum)   
     755        self.wave.set_spectrum(spectrum) 
    758756           
    759757    def set_wavelength_spread(self, wavelength_spread): 
     
    787785         
    788786        : param size: [dia_value] or [x_value, y_value] 
    789         """         
     787        """ 
    790788        if len(size) < 1 or len(size) > 2: 
    791789            raise RuntimeError, "The length of the size must be one or two." 
     
    884882        return qx_min, qx_max, qy_min, qy_max 
    885883     
    886     def _rotate_z(self, x_value, y_value, theta= 0.0): 
     884    def _rotate_z(self, x_value, y_value, theta=0.0): 
    887885        """ 
    888886        Rotate x-y cordinate around z-axis by theta 
     
    895893        # rotate by theta 
    896894        x_prime = x_value * math.cos(theta) + y_value * math.sin(theta) 
    897         y_prime =  -x_value * math.sin(theta) + y_value * math.cos(theta) 
     895        y_prime = -x_value * math.sin(theta) + y_value * math.cos(theta) 
    898896     
    899897        return x_prime, y_prime 
    900898     
    901     def _gaussian2d(self, x_val, y_val, x0_val, y0_val,  
     899    def _gaussian2d(self, x_val, y_val, x0_val, y0_val, 
    902900                    sigma_x, sigma_y, sigma_r): 
    903901        """ 
     
    927925        y_p = -x_value * sin_phi + y_value * cos_phi 
    928926         
    929         new_sig_x = sqrt(sigma_r * sigma_r / (sigma_x * sigma_x ) + 1) 
    930         new_sig_y = sqrt(sigma_r * sigma_r / (sigma_y * sigma_y ) + 1) 
     927        new_sig_x = sqrt(sigma_r * sigma_r / (sigma_x * sigma_x) + 1) 
     928        new_sig_y = sqrt(sigma_r * sigma_r / (sigma_y * sigma_y) + 1) 
    931929        new_x = x_p * cos_phi / new_sig_x - y_p * sin_phi 
    932930        new_x /= sigma_x 
     
    934932        new_y /= sigma_y 
    935933 
    936         nu_value = -0.5 *(new_x * new_x + new_y * new_y) 
     934        nu_value = -0.5 * (new_x * new_x + new_y * new_y) 
    937935 
    938936        gaussian = numpy.exp(nu_value) 
     
    942940        return gaussian 
    943941 
    944     def _gaussian2d_polar(self, x_val, y_val, x0_val, y0_val,  
     942    def _gaussian2d_polar(self, x_val, y_val, x0_val, y0_val, 
    945943                        sigma_x, sigma_y, sigma_r): 
    946944        """ 
    947         Calculate 2D Gaussian distribution for polar coodinate  
     945        Calculate 2D Gaussian distribution for polar coodinate 
    948946        : x_val: x value 
    949947        : y_val: y value 
     
    957955        """ 
    958956        sigma_x = sqrt(sigma_x * sigma_x + sigma_r * sigma_r) 
    959         # call gaussian1d  
     957        # call gaussian1d 
    960958        gaussian  = self._gaussian1d(x_val, x0_val, sigma_x) 
    961959        gaussian *= self._gaussian1d(y_val, y0_val, sigma_y) 
     
    971969        : value: value 
    972970        : mean: mean value 
    973         : sigma: variance  
     971        : sigma: variance 
    974972         
    975973        : return: gaussian (value) 
     
    10281026        wavelength = self.wave.wavelength 
    10291027        # Gavity correction 
    1030         delta_y = self._get_beamcenter_drop() # in cm 
     1028        delta_y = self._get_beamcenter_drop()  # in cm 
    10311029         
    10321030        # detector_pix size 
     
    10421040        else: 
    10431041            raise ValueError, " Input value format error..." 
    1044         # Sample to detector distance = sample slit to detector  
     1042        # Sample to detector distance = sample slit to detector 
    10451043        # minus sample offset 
    10461044        sample2detector_distance = self.sample2detector_distance[0] - \ 
     
    10981096             
    10991097        # qx_value and qy_value values in array 
    1100         qx_value = qx_value.repeat(detector_pix_nums_y)  
     1098        qx_value = qx_value.repeat(detector_pix_nums_y) 
    11011099        qx_value = qx_value.reshape(detector_pix_nums_x, detector_pix_nums_y) 
    1102         qy_value = qy_value.repeat(detector_pix_nums_x)   
     1100        qy_value = qy_value.repeat(detector_pix_nums_x) 
    11031101        qy_value = qy_value.reshape(detector_pix_nums_y, detector_pix_nums_x) 
    11041102        qy_value = qy_value.transpose() 
     
    11101108        self.qy_max = numpy.max(qy_value) 
    11111109                 
    1112         # Appr. min and max values of the detector display limits  
     1110        # Appr. min and max values of the detector display limits 
    11131111        # i.e., edges of the last pixels. 
    1114         self.qy_min += self._get_qx(-0.5 * pix_y_size,  
     1112        self.qy_min += self._get_qx(-0.5 * pix_y_size, 
    11151113                                sample2detector_distance, wavelength) 
    1116         self.qy_max += self._get_qx(0.5 * pix_y_size,  
     1114        self.qy_max += self._get_qx(0.5 * pix_y_size, 
    11171115                                sample2detector_distance, wavelength) 
    11181116        #if self.qx_min == self.qx_max: 
    1119         self.qx_min += self._get_qx(-0.5 * pix_x_size,  
     1117        self.qx_min += self._get_qx(-0.5 * pix_x_size, 
    11201118                                sample2detector_distance, wavelength) 
    1121         self.qx_max += self._get_qx(0.5 * pix_x_size,  
     1119        self.qx_max += self._get_qx(0.5 * pix_x_size, 
    11221120                                    sample2detector_distance, wavelength) 
    11231121         
     
    11281126        self.detector_qy_max = self.qy_max 
    11291127         
    1130          
    1131  
    11321128        # try to set it as a Data2D otherwise pass (not required for now) 
    11331129        try: 
     
    11351131            output = Data2D() 
    11361132            inten = numpy.zeros_like(qx_value) 
    1137             output.data     = inten 
    1138             output.qx_data  = qx_value 
    1139             output.qy_data  = qy_value             
     1133            output.data    = inten 
     1134            output.qx_data = qx_value 
     1135            output.qy_data = qy_value 
    11401136        except: 
    11411137            pass 
    11421138         
    1143         return output#qx_value,qy_value 
     1139        return output 
    11441140         
    11451141    def _get_qx(self, dx_size, det_dist, wavelength): 
     
    11531149        plane_dist = dx_size 
    11541150        # full scattering angle on the x-axis 
    1155         theta  = numpy.arctan(plane_dist / det_dist) 
    1156         qx_value     = (2.0 * pi / wavelength) * numpy.sin(theta) 
    1157         return qx_value   
     1151        theta = numpy.arctan(plane_dist / det_dist) 
     1152        qx_value = (2.0 * pi / wavelength) * numpy.sin(theta) 
     1153        return qx_value 
    11581154     
    11591155    def _get_polar_value(self, qx_value, qy_value): 
     
    11871183        pos_y -= offset_y 
    11881184 
    1189         return pos_x, pos_y      
     1185        return pos_x, pos_y 
    11901186 
    11911187    def _get_beamcenter_drop(self): 
     
    11951191        :return delta y: the beam center drop in cm 
    11961192        """ 
    1197         # Check if mass == 0 (X-ray).  
     1193        # Check if mass == 0 (X-ray). 
    11981194        if self.mass == 0: 
    11991195            return 0 
     
    12111207        delta_y /= (velocity * velocity) 
    12121208 
    1213         return delta_y      
    1214  
    1215      
     1209        return delta_y 
  • sanscalculator/src/sans/calculator/slit_length_calculator.py

    rf93b6a1e r8a621ac  
    33determine the slit length value of data. 
    44""" 
     5 
    56 
    67class SlitlengthCalculator(object): 
     
    1819        self.slit_length = 0.0 
    1920         
    20         # The unit is unknown from SAXSess profile:  
    21         # It seems 1/nm but it could be not fixed,  
     21        # The unit is unknown from SAXSess profile: 
     22        # It seems 1/nm but it could be not fixed, 
    2223        # so users should be notified to determine the unit by themselves. 
    2324        self.slit_length_unit = "unknown" 
     
    2526    def set_data(self, x=None, y=None): 
    2627        """ 
    27          Receive two vector x, y and prepare the slit calculator for  
     28         Receive two vector x, y and prepare the slit calculator for 
    2829         computation. 
    2930         
     
    5051        max_y = y.max() 
    5152         
    52         # initial values  
     53        # initial values 
    5354        y_sum = 0.0 
    5455        y_max = 0.0 
    5556        ind = 0.0 
    5657         
    57         # sum 10 or more y values until getting max_y,  
     58        # sum 10 or more y values until getting max_y, 
    5859        while (True): 
    5960            if ind >= 10 and y_max == max_y: 
    6061                break 
    6162            y_sum = y_sum + y[ind] 
    62             if y[ind] > y_max:  
     63            if y[ind] > y_max: 
    6364                y_max = y[ind] 
    6465            ind += 1 
    6566      
    66         # find the average value/2 of the top values   
     67        # find the average value/2 of the top values 
    6768        y_half = y_sum/(2.0*ind) 
    6869         
     
    7374        while (True): 
    7475            # no need to check when ind == 0 
    75             ind += 1      
    76             # y value and ind just after passed the spot of the half height             
    77             y_half_d = y[ind]        
    78             if y[ind] < y_half:  
     76            ind += 1 
     77            # y value and ind just after passed the spot of the half height 
     78            y_half_d = y[ind] 
     79            if y[ind] < y_half: 
    7980                break 
    8081         
    8182        # y value and ind just before passed the spot of the half height 
    82         y_half_u = y[ind-1]         
     83        y_half_u = y[ind-1] 
    8384         
    8485        # get corresponding x values 
    8586        x_half_d = x[ind] 
    86         x_half_u = x[ind-1]  
     87        x_half_u = x[ind-1] 
    8788         
    8889        # calculate x at y = y_half using linear interpolation 
     
    9192        else: 
    9293            x_half = (x_half_u * (y_half - y_half_d)  \ 
    93                        + x_half_d*(y_half_u-y_half)) \ 
    94                         /(y_half_u - y_half_d) 
     94                       + x_half_d * (y_half_u - y_half)) \ 
     95                        / (y_half_u - y_half_d) 
    9596         
    9697        # Our slit length is half width, so just give half beam value 
     
    101102        return self.slit_length 
    102103   
    103     def get_slit_length_unit(self):  
     104    def get_slit_length_unit(self): 
    104105        """ 
    105106        :return: the slit length unit. 
Note: See TracChangeset for help on using the changeset viewer.