Changeset 6bd3a8d1 in sasview


Ignore:
Timestamp:
Mar 2, 2015 4:09:46 PM (9 years ago)
Author:
Doucet, Mathieu <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:
13e46abe
Parents:
c93122e
Message:

Remove extra white spaces

Location:
src/sas/calculator
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/sas/calculator/instrument.py

    r79492222 r6bd3a8d1  
    3030    """ 
    3131    def __init__(self): 
    32          
     32 
    3333        # assumes that all aligned at the centers 
    3434        # aperture_size [diameter] for pinhole, [dx, dy] for rectangular 
     
    3636        self.source_size = _SOURCE_A_SIZE 
    3737        self.sample_distance = _SAMPLE_DISTANCE 
    38          
     38 
    3939    def set_source_size(self, size=[]): 
    4040        """ 
     
    4646            self.source_size = size 
    4747            validate(size[0]) 
    48              
     48 
    4949    def set_sample_size(self, size=[]): 
    5050        """ 
     
    5656            self.sample_size = size 
    5757            validate(size[0]) 
    58              
     58 
    5959    def set_sample_distance(self, distance=[]): 
    6060        """ 
     
    6666            self.sample_distance = distance 
    6767            validate(distance[0]) 
    68          
    69     
     68 
     69 
    7070class Sample(object): 
    7171    """ 
     
    7373    """ 
    7474    def __init__(self): 
    75          
     75 
    7676        # assumes that all aligned at the centers 
    7777        # source2sample or sample2detector distance 
     
    8989            self.sample_size = size 
    9090            validate(size[0]) 
    91              
     91 
    9292    def set_thickness(self, thickness=0.0): 
    9393        """ 
     
    9696        self.thickness = thickness 
    9797        validate(thickness) 
    98      
     98 
    9999    def set_distance(self, distance=[]): 
    100100        """ 
     
    107107            if distance[0] != 0.0: 
    108108                validate(distance[0]) 
    109          
    110   
     109 
     110 
    111111class Detector(object): 
    112112    """ 
     
    114114    """ 
    115115    def __init__(self): 
    116          
     116 
    117117        # assumes that all aligned at the centers 
    118118        # source2sample or sample2detector distance 
     
    121121        self.pix_size = _D_PIX_SIZE 
    122122 
    123      
    124          
    125123    def set_size(self, size=[]): 
    126124        """ 
     
    132130            self.size = size 
    133131            validate(size[0]) 
    134              
     132 
    135133    def set_pix_size(self, size=[]): 
    136134        """ 
     
    142140            self.pix_size = size 
    143141            validate(size[0]) 
    144      
     142 
    145143    def set_distance(self, distance=[]): 
    146144        """ 
     
    153151            validate(distance[0]) 
    154152 
    155              
     153 
    156154class Neutron(object): 
    157155    """ 
     
    159157    """ 
    160158    def __init__(self): 
    161          
     159 
    162160        # neutron mass in cgs unit 
    163161        self.mass = _MASS 
     
    183181        # default unit of the thickness 
    184182        self.wavelength_unit = 'A' 
    185      
     183 
    186184    def set_full_band(self): 
    187185        """ 
     
    189187        """ 
    190188        self.band = self.spectrum 
    191          
     189 
    192190    def set_spectrum(self, spectrum): 
    193191        """ 
    194192        Set spectrum 
    195          
     193 
    196194        :param spectrum: numpy array 
    197195        """ 
    198196        self.spectrum = spectrum 
    199197        self.setup_spectrum() 
    200           
     198 
    201199    def setup_spectrum(self): 
    202200        """ 
     
    216214        # set default band 
    217215        self.set_band([self.min, self.max]) 
    218          
     216 
    219217    def set_band(self, band=[]): 
    220218        """ 
    221219        To set the wavelength band 
    222          
     220 
    223221        :param band: array of [min, max] 
    224222        """ 
     
    228226            raise 
    229227        self.band = band 
    230           
     228 
    231229    def set_intensity(self, intensity=368428): 
    232230        """ 
     
    235233        self.intensity = intensity 
    236234        validate(intensity) 
    237              
     235 
    238236    def set_wavelength(self, wavelength=_WAVE_LENGTH): 
    239237        """ 
     
    258256        self.mass = mass 
    259257        validate(mass) 
    260          
     258 
    261259    def set_wavelength_spread(self, spread=_WAVE_SPREAD): 
    262260        """ 
     
    266264        if spread != 0.0: 
    267265            validate(spread) 
    268          
     266 
    269267    def get_intensity(self): 
    270268        """ 
     
    272270        """ 
    273271        return self.intensity 
    274          
     272 
    275273    def get_wavelength(self): 
    276274        """ 
     
    284282        """ 
    285283        return self.mass 
    286      
     284 
    287285    def get_wavelength_spread(self): 
    288286        """ 
     
    290288        """ 
    291289        return self.wavelength_spread 
    292      
     290 
    293291    def get_ramdom_value(self): 
    294292        """ 
     
    296294        """ 
    297295        return self.wavelength 
    298              
     296 
    299297    def get_spectrum(self): 
    300298        """ 
     
    302300        """ 
    303301        return self.spectrum 
    304      
     302 
    305303    def get_default_spectrum(self): 
    306304        """ 
     
    308306        """ 
    309307        return numpy.array(_LAMBDA_ARRAY) 
    310      
     308 
    311309    def get_band(self): 
    312310        """ 
     
    314312        """ 
    315313        return self.band 
    316      
     314 
    317315    def plot_spectrum(self): 
    318316        """ 
     
    327325        except: 
    328326            raise RuntimeError, "Can't import matplotlib required to plot..." 
    329          
    330      
     327 
     328 
    331329class TOF(Neutron): 
    332330    """ 
     
    342340        self.wavelength_spread_list = [self.wavelength_spread] 
    343341        self.intensity_list = self.get_intensity_list() 
    344      
     342 
    345343    def get_intensity_list(self): 
    346344        """ 
     
    353351                                      0.0) 
    354352        return out 
    355      
     353 
    356354    def get_wave_list(self): 
    357355        """ 
     
    359357        """ 
    360358        return self.wavelength_list, self.wavelengthspread_list 
    361      
     359 
    362360    def set_wave_list(self, wavelength=[]): 
    363361        """ 
    364362        Set wavelength list 
    365          
     363 
    366364        :param wavelength: list of wavelengths 
    367365        """ 
    368366        self.wavelength_list = wavelength 
    369          
     367 
    370368    def set_wave_spread_list(self, wavelength_spread=[]): 
    371369        """ 
    372370        Set wavelength_spread list 
    373          
     371 
    374372        :param wavelength_spread: list of wavelength spreads 
    375373        """ 
    376374        self.wavelengthspread_list = wavelength_spread 
    377          
    378          
     375 
     376 
    379377def validate(value=None): 
    380378    """ 
    381379    Check if the value is folat > 0.0 
    382      
     380 
    383381    :return value: True / False 
    384382    """ 
  • src/sas/calculator/kiessig_calculator.py

    r79492222 r6bd3a8d1  
    1313    """ 
    1414    def __init__(self): 
    15          
     15 
    1616        # dq value 
    1717        self.deltaq = _DQ_DEFAULT 
     
    2020        # unit of the thickness 
    2121        self.thickness_unit = 'A' 
    22          
     22 
    2323    def set_deltaq(self, dq=None): 
    2424        """ 
    2525        Receive deltaQ value 
    26          
     26 
    2727        :param dq: q fringe width in 1/A unit 
    2828        """ 
    2929        # set dq 
    3030        self.deltaq = dq 
    31          
     31 
    3232    def get_deltaq(self): 
    3333        """ 
     
    4040        """ 
    4141        Calculate thickness. 
    42          
     42 
    4343        :return: the thickness. 
    4444        """ 
     
    5656            # return thickness value 
    5757            return thickness 
    58    
     58 
    5959    def get_thickness_unit(self): 
    6060        """ 
  • src/sas/calculator/resolution_calculator.py

    r79492222 r6bd3a8d1  
    2525    """ 
    2626    def __init__(self): 
    27          
     27 
    2828        # wavelength 
    2929        self.wave = Neutron() 
     
    8585        self.qxrange = [] 
    8686        self.qyrange = [] 
    87          
     87 
    8888    def compute_and_plot(self, qx_value, qy_value, qx_min, qx_max, 
    8989                          qy_min, qy_max, coord='cartesian'): 
     
    122122                            sigma_r, qx_min, qx_max, qy_min, qy_max, 
    123123                            coord, False) 
    124              
    125             # Non tof mode to be speed up 
    126             #if num_lamda < 2: 
    127             #    return self.plot_image(image) 
    128              
    129124            if qx_min > self.qx_min: 
    130125                qx_min = self.qx_min 
     
    135130            if qy_max < self.qy_max: 
    136131                qy_max = self.qy_max 
    137                  
     132 
    138133            # set max qranges 
    139134            self.qxrange = [qx_min, qx_max] 
     
    167162            sigma1d += sigma1d_list[ind] * sigma1d_list[ind] * self.intensity 
    168163            total_intensity += self.intensity 
    169          
     164 
    170165        if total_intensity != 0: 
    171166            # average variance 
     
    195190        else: 
    196191            self.image = image_out 
    197          
     192 
    198193        # plot image 
    199194        return self.plot_image(self.image) 
    200      
     195 
    201196    def setup_tof(self, wavelength, wavelength_spread): 
    202197        """ 
    203198        Setup all parameters in instrument 
    204          
     199 
    205200        : param ind: index of lambda, etc 
    206201        """ 
     
    210205        self.set_wavelength_spread(wavelength_spread) 
    211206        self.intensity = self.wave.get_intensity() 
    212          
     207 
    213208        if wavelength == 0: 
    214209            msg = "Can't compute the resolution: the wavelength is zero..." 
    215210            raise RuntimeError, msg 
    216211        return self.intensity 
    217          
     212 
    218213    def compute(self, wavelength, wavelength_spread, qx_value, qy_value, 
    219214                coord='cartesian', tof=False): 
     
    260255        # sample to detector distance 
    261256        l_two = l_sad - l_sas 
    262          
     257 
    263258        # Sample offset correction for l_one and Lp on variance calculation 
    264259        l1_cor = (l_ssa * l_two) / (l_sas + l_two) 
     
    297292        # normalize 
    298293        variance_1d_1 = knot * knot * variance_1d_1 / 12 
    299          
     294 
    300295        # for 2d 
    301296        #sigma_1 += sigma_wave_1 
     
    328323        # normalize 
    329324        variance_1d_2 = knot * knot * variance_1d_2 / 12 
    330          
     325 
    331326        # for 2d 
    332327        #sigma_2 =  knot*sqrt(sigma_2/12) 
     
    341336        self.sigma_1d = sigma1d 
    342337        return qr_value, phi, sigma_1, sigma_2, sigma_r, sigma1d 
    343      
     338 
    344339    def _within_detector_range(self, qx_value, qy_value): 
    345340        """ 
     
    364359            return False 
    365360        return True 
    366      
     361 
    367362    def get_image(self, qx_value, qy_value, sigma_1, sigma_2, sigma_r, 
    368363                  qx_min, qx_max, qy_min, qy_max, 
     
    378373        # Get  qx_max and qy_max... 
    379374        self._get_detector_qxqy_pixels() 
    380         
     375 
    381376        qr_value, phi = self._get_polar_value(qx_value, qy_value) 
    382377 
     
    397392        if not full_cal: 
    398393            return None 
    399   
     394 
    400395        # Make an empty graph in the detector scale 
    401396        dx_size = (self.qx_max - self.qx_min) / (1000 - 1) 
     
    421416            # qy_center 
    422417            qc_2 = qy_value 
    423              
     418 
    424419            # Calculate the 2D Gaussian distribution image 
    425420            image = self._gaussian2d(q_1, q_2, qc_1, qc_2, 
     
    436431        else: 
    437432            self.image_lam = image * self.intensity 
    438          
     433 
    439434        return self.image_lam 
    440      
     435 
    441436    def plot_image(self, image): 
    442437        """ 
    443438        Plot image using pyplot 
    444439        : image: 2d resolution image 
    445          
     440 
    446441        : return plt: pylab object 
    447442        """ 
     
    463458 
    464459        return plt 
    465      
     460 
    466461    def reset_image(self): 
    467462        """ 
     
    469464        """ 
    470465        self.image = [] 
    471          
     466 
    472467    def get_variance(self, size=[], distance=0, phi=0, comp='radial'): 
    473468        """ 
     
    476471        : distance: [z, x] where z along the incident beam, x // qx_value 
    477472        : comp: direction of the sigma; can be 'phi', 'y', 'x', and 'radial' 
    478          
     473 
    479474        : return variance: sigma^2 
    480475        """ 
    481476        # check the length of size (list) 
    482477        len_size = len(size) 
    483          
     478 
    484479        # define sigma component direction 
    485480        if comp == 'radial': 
     
    522517        """ 
    523518        Get the variance when the wavelength spread is given 
    524          
     519 
    525520        : radius: the radial distance from the beam center to the pix of q 
    526521        : distance: sample to detector distance 
    527522        : spread: wavelength spread (ratio) 
    528523        : comp: direction of the sigma; can be 'phi', 'y', 'x', and 'radial' 
    529          
     524 
    530525        : return variance: sigma^2 for 2d, sigma^2 for 1d [tuple] 
    531526        """ 
     
    560555            else: 
    561556                sigma *= 1 
    562                  
     557 
    563558            return sigma, sigma1d 
    564559 
     
    567562        """ 
    568563        Get the variance from gravity when the wavelength spread is given 
    569          
     564 
    570565        : s_distance: source to sample distance 
    571566        : d_distance: sample to detector distance 
     
    573568        : spread: wavelength spread (ratio) 
    574569        : comp: direction of the sigma; can be 'phi', 'y', 'x', and 'radial' 
    575          
     570 
    576571        : return variance: sigma^2 
    577572        """ 
     
    590585            sigma *= math.pow(spread, 2) 
    591586            sigma *= 8 
    592              
    593             # only for the polar coordinate 
    594             #if comp == 'radial': 
    595             #    sigma *= (math.sin(phi) * math.sin(phi)) 
    596             #elif comp == 'phi': 
    597             #    sigma *= (math.cos(phi) * math.cos(phi)) 
    598              
    599587            return sigma 
    600      
     588 
    601589    def _cal_A_value(self, lamda, s_distance, d_distance): 
    602590        """ 
    603591        Calculate A value for gravity 
    604          
     592 
    605593        : s_distance: source to sample distance 
    606594        : d_distance: sample to detector distance 
     
    624612            a_value *= (4 * lamda * lamda) 
    625613        return a_value 
    626      
     614 
    627615    def get_intensity(self): 
    628616        """ 
     
    636624        """ 
    637625        return self.wave.wavelength 
    638      
    639     #TODO: why was this method duplicated? 
    640     #def get_spectrum(self): 
    641     #    """ 
    642     #    Get spectrum 
    643     #    """ 
    644     #    return self.wave.spectrum 
    645      
     626 
    646627    def get_default_spectrum(self): 
    647628        """ 
     
    649630        """ 
    650631        return self.wave.get_default_spectrum() 
    651      
     632 
    652633    def get_spectrum(self): 
    653634        """ 
     
    655636        """ 
    656637        return self.wave.get_spectrum() 
    657           
     638 
    658639    def get_wavelength_spread(self): 
    659640        """ 
     
    661642        """ 
    662643        return self.wave.wavelength_spread 
    663      
     644 
    664645    def get_neutron_mass(self): 
    665646        """ 
     
    667648        """ 
    668649        return self.wave.mass 
    669      
     650 
    670651    def get_source_aperture_size(self): 
    671652        """ 
     
    673654        """ 
    674655        return self.aperture.source_size 
    675      
     656 
    676657    def get_sample_aperture_size(self): 
    677658        """ 
     
    679660        """ 
    680661        return self.aperture.sample_size 
    681      
     662 
    682663    def get_detector_pix_size(self): 
    683664        """ 
     
    685666        """ 
    686667        return self.detector.pix_size 
    687         
     668 
    688669    def get_detector_size(self): 
    689670        """ 
     
    691672        """ 
    692673        return self.detector.size 
    693       
     674 
    694675    def get_source2sample_distance(self): 
    695676        """ 
     
    697678        """ 
    698679        return self.aperture.sample_distance 
    699      
     680 
    700681    def get_sample2sample_distance(self): 
    701682        """ 
     
    703684        """ 
    704685        return self.sample.distance 
    705      
     686 
    706687    def get_sample2detector_distance(self): 
    707688        """ 
     
    709690        """ 
    710691        return self.detector.distance 
    711      
     692 
    712693    def set_intensity(self, intensity): 
    713694        """ 
     
    715696        """ 
    716697        self.wave.set_intensity(intensity) 
    717          
     698 
    718699    def set_wave(self, wavelength): 
    719700        """ 
     
    727708        else: 
    728709            raise 
    729      
     710 
    730711    def set_wave_spread(self, wavelength_spread): 
    731712        """ 
     
    736717        elif wavelength_spread.__class__.__name__ == 'float': 
    737718            self.wave.set_wave_spread_list([wavelength_spread]) 
    738             #self.set_wavelength_spread(wavelength_spread) 
    739719        else: 
    740720            raise 
    741          
     721 
    742722    def set_wavelength(self, wavelength): 
    743723        """ 
     
    746726        self.wavelength = wavelength 
    747727        self.wave.set_wavelength(wavelength) 
    748          
     728 
    749729    def set_spectrum(self, spectrum): 
    750730        """ 
     
    753733        self.spectrum = spectrum 
    754734        self.wave.set_spectrum(spectrum) 
    755            
     735 
    756736    def set_wavelength_spread(self, wavelength_spread): 
    757737        """ 
     
    760740        self.wavelength_spread = wavelength_spread 
    761741        self.wave.set_wavelength_spread(wavelength_spread) 
    762          
     742 
    763743    def set_wave_list(self, wavelength_list, wavelengthspread_list): 
    764744        """ 
     
    767747        self.wave.set_wave_list(wavelength_list) 
    768748        self.wave.set_wave_spread_list(wavelengthspread_list) 
    769      
     749 
    770750    def get_wave_list(self): 
    771751        """ 
     
    773753        """ 
    774754        return self.wave.get_wave_list() 
    775      
     755 
    776756    def get_intensity_list(self): 
    777757        """ 
     
    779759        """ 
    780760        return self.wave.get_intensity_list() 
    781             
     761 
    782762    def set_source_aperture_size(self, size): 
    783763        """ 
    784764        Set source aperture size 
    785          
     765 
    786766        : param size: [dia_value] or [x_value, y_value] 
    787767        """ 
     
    789769            raise RuntimeError, "The length of the size must be one or two." 
    790770        self.aperture.set_source_size(size) 
    791          
     771 
    792772    def set_neutron_mass(self, mass): 
    793773        """ 
     
    796776        self.wave.set_mass(mass) 
    797777        self.mass = mass 
    798          
     778 
    799779    def set_sample_aperture_size(self, size): 
    800780        """ 
    801781        Set sample aperture size 
    802          
     782 
    803783        : param size: [dia_value] or [xheight_value, yheight_value] 
    804784        """ 
     
    806786            raise RuntimeError, "The length of the size must be one or two." 
    807787        self.aperture.set_sample_size(size) 
    808      
     788 
    809789    def set_detector_pix_size(self, size): 
    810790        """ 
     
    812792        """ 
    813793        self.detector.set_pix_size(size) 
    814          
     794 
    815795    def set_detector_size(self, size): 
    816796        """ 
     
    819799        """ 
    820800        self.detector.set_size(size) 
    821          
     801 
    822802    def set_source2sample_distance(self, distance): 
    823803        """ 
    824804        Set detector source2sample_distance 
    825          
     805 
    826806        : param distance: [distance, x_offset] 
    827807        """ 
     
    833813        """ 
    834814        Set detector sample_slit2sample_distance 
    835          
     815 
    836816        : param distance: [distance, x_offset] 
    837817        """ 
     
    839819            raise RuntimeError, "The length of the size must be one or two." 
    840820        self.sample.set_distance(distance) 
    841     
     821 
    842822    def set_sample2detector_distance(self, distance): 
    843823        """ 
    844824        Set detector sample2detector_distance 
    845          
     825 
    846826        : param distance: [distance, x_offset] 
    847827        """ 
     
    849829            raise RuntimeError, "The length of the size must be one or two." 
    850830        self.detector.set_distance(distance) 
    851          
     831 
    852832    def get_all_instrument_params(self): 
    853833        """ 
    854834        Get all instrumental parameters 
    855835        """ 
    856         #self.intensity = self.get_intensity() 
    857         #self.wavelength = self.get_wavelength() 
    858         #self.wavelength_spread = self.get_wavelength_spread() 
    859836        self.mass = self.get_neutron_mass() 
    860837        self.spectrum = self.get_spectrum() 
     
    866843        self.sample2sample_distance = self.get_sample2sample_distance() 
    867844        self.sample2detector_distance = self.get_sample2detector_distance() 
    868      
     845 
    869846    def get_detector_qrange(self): 
    870847        """ 
    871848        get max detector q ranges 
    872          
     849 
    873850        : return: qx_min, qx_max, qy_min, qy_max tuple 
    874851        """ 
     
    879856        qy_min = self.qyrange[0] 
    880857        qy_max = self.qyrange[1] 
    881          
     858 
    882859        return qx_min, qx_max, qy_min, qy_max 
    883      
     860 
    884861    def _rotate_z(self, x_value, y_value, theta=0.0): 
    885862        """ 
     
    888865        : y_value: numpy array of y values 
    889866        : theta: angle to rotate by in rad 
    890          
     867 
    891868        :return: x_prime, y-prime 
    892         """         
     869        """ 
    893870        # rotate by theta 
    894871        x_prime = x_value * math.cos(theta) + y_value * math.sin(theta) 
    895872        y_prime = -x_value * math.sin(theta) + y_value * math.cos(theta) 
    896      
     873 
    897874        return x_prime, y_prime 
    898      
     875 
    899876    def _gaussian2d(self, x_val, y_val, x0_val, y0_val, 
    900877                    sigma_x, sigma_y, sigma_r): 
     
    907884        : sigma_x: variance in x-direction 
    908885        : sigma_y: variance in y-direction 
    909          
     886 
    910887        : return: gaussian (value) 
    911888        """ 
     
    914891        y_value = y_val - y0_val 
    915892        phi_i = numpy.arctan2(y_val, x_val) 
    916          
     893 
    917894        # phi correction due to the gravity shift (in phi) 
    918895        phi_0 = math.atan2(y0_val, x0_val) 
     
    921898        sin_phi = numpy.sin(self.gravity_phi) 
    922899        cos_phi = numpy.cos(self.gravity_phi) 
    923          
     900 
    924901        x_p = x_value * cos_phi + y_value * sin_phi 
    925902        y_p = -x_value * sin_phi + y_value * cos_phi 
    926          
     903 
    927904        new_sig_x = sqrt(sigma_r * sigma_r / (sigma_x * sigma_x) + 1) 
    928905        new_sig_y = sqrt(sigma_r * sigma_r / (sigma_y * sigma_y) + 1) 
     
    951928        : sigma_y: variance in phi-direction 
    952929        : sigma_r: wavelength variance in r-direction 
    953          
     930 
    954931        : return: gaussian (value) 
    955932        """ 
     
    958935        gaussian  = self._gaussian1d(x_val, x0_val, sigma_x) 
    959936        gaussian *= self._gaussian1d(y_val, y0_val, sigma_y) 
    960   
     937 
    961938        # normalizing factor correction 
    962939        if sigma_x != 0 and sigma_y != 0: 
    963940            gaussian *= sqrt(2 * pi) 
    964941        return gaussian 
    965      
     942 
    966943    def _gaussian1d(self, value, mean, sigma): 
    967944        """ 
     
    970947        : mean: mean value 
    971948        : sigma: variance 
    972          
     949 
    973950        : return: gaussian (value) 
    974951        """ 
     
    984961            # normalize 
    985962            gaussian /= sqrt(2 * pi) 
    986              
     963 
    987964        return gaussian 
    988      
     965 
    989966    def _atan_phi(self, qy_value, qx_value): 
    990967        """ 
     
    992969        : qx_value: x component of q 
    993970        : qy_value: y component of q 
    994          
     971 
    995972        : return phi: the azimuthal angle of q on x-y plane 
    996973        """ 
     
    1019996        Get the pixel positions of the detector in the qx_value-qy_value space 
    1020997        """ 
    1021          
     998 
    1022999        # update all param values 
    10231000        self.get_all_instrument_params() 
    1024          
     1001 
    10251002        # wavelength 
    10261003        wavelength = self.wave.wavelength 
    10271004        # Gavity correction 
    10281005        delta_y = self._get_beamcenter_drop()  # in cm 
    1029          
     1006 
    10301007        # detector_pix size 
    10311008        detector_pix_size = self.detector_pix_size 
     
    10501027        except: 
    10511028            pass 
    1052          
     1029 
    10531030        # detector size in [no of pix_x,no of pix_y] 
    10541031        detector_pix_nums_x = self.detector_size[0] 
    1055          
     1032 
    10561033        # get pix_y if it exists, otherwse take it from [0] 
    10571034        try: 
     
    10591036        except: 
    10601037            detector_pix_nums_y = self.detector_size[0] 
    1061          
     1038 
    10621039        # detector offset in pix number 
    10631040        offset_x = detector_offset / pix_x_size 
    10641041        offset_y = delta_y / pix_y_size 
    1065          
     1042 
    10661043        # beam center position in pix number (start from 0) 
    10671044        center_x, center_y = self._get_beamcenter_position(detector_pix_nums_x, 
     
    10781055        detector_ind_x = detector_ind_x - center_x 
    10791056        detector_ind_y = detector_ind_y - center_y 
    1080          
     1057 
    10811058        # unit correction in cm 
    10821059        detector_ind_x = detector_ind_x * pix_x_size 
    10831060        detector_ind_y = detector_ind_y * pix_y_size 
    1084          
     1061 
    10851062        qx_value = numpy.zeros(len(detector_ind_x)) 
    10861063        qy_value = numpy.zeros(len(detector_ind_y)) 
     
    10941071            qy_value[i] = self._get_qx(indy, sample2detector_distance, wavelength) 
    10951072            i += 1 
    1096              
     1073 
    10971074        # qx_value and qy_value values in array 
    10981075        qx_value = qx_value.repeat(detector_pix_nums_y) 
     
    11071084        self.qy_min = numpy.min(qy_value) 
    11081085        self.qy_max = numpy.max(qy_value) 
    1109                  
     1086 
    11101087        # Appr. min and max values of the detector display limits 
    11111088        # i.e., edges of the last pixels. 
     
    11191096        self.qx_max += self._get_qx(0.5 * pix_x_size, 
    11201097                                    sample2detector_distance, wavelength) 
    1121          
     1098 
    11221099        # min and max values of detecter 
    11231100        self.detector_qx_min = self.qx_min 
     
    11251102        self.detector_qy_min = self.qy_min 
    11261103        self.detector_qy_max = self.qy_max 
    1127          
     1104 
    11281105        # try to set it as a Data2D otherwise pass (not required for now) 
    11291106        try: 
     
    11361113        except: 
    11371114            pass 
    1138          
     1115 
    11391116        return output 
    1140          
     1117 
    11411118    def _get_qx(self, dx_size, det_dist, wavelength): 
    11421119        """ 
    11431120        :param dx_size: x-distance from beam center [cm] 
    11441121        :param det_dist: sample to detector distance [cm] 
    1145          
     1122 
    11461123        :return: q-value at the given position 
    11471124        """ 
     
    11521129        qx_value = (2.0 * pi / wavelength) * numpy.sin(theta) 
    11531130        return qx_value 
    1154      
     1131 
    11551132    def _get_polar_value(self, qx_value, qy_value): 
    11561133        """ 
    11571134        Find qr_value and phi from qx_value and qy_value values 
    1158          
     1135 
    11591136        : return qr_value, phi 
    11601137        """ 
     
    11631140        # find angle phi 
    11641141        phi = self._atan_phi(qy_value, qx_value) 
    1165          
     1142 
    11661143        return qr_value, phi 
    1167      
     1144 
    11681145    def _get_beamcenter_position(self, num_x, num_y, offset_x, offset_y): 
    11691146        """ 
     
    11711148        :param num_y: number of pixel in y-direction 
    11721149        :param offset: detector offset in x-direction in pix number 
    1173          
     1150 
    11741151        :return: pix number; pos_x, pos_y in pix index 
    11751152        """ 
     
    11881165        """ 
    11891166        Get the beam center drop (delta y) in y diection due to gravity 
    1190          
     1167 
    11911168        :return delta y: the beam center drop in cm 
    11921169        """ 
  • src/sas/calculator/slit_length_calculator.py

    r79492222 r6bd3a8d1  
    1111    """ 
    1212    def __init__(self): 
    13          
     13 
    1414        # x data 
    1515        self.x = None 
     
    1818        #default slit length 
    1919        self.slit_length = 0.0 
    20          
     20 
    2121        # The unit is unknown from SAXSess profile: 
    2222        # It seems 1/nm but it could be not fixed, 
    2323        # so users should be notified to determine the unit by themselves. 
    2424        self.slit_length_unit = "unknown" 
    25      
     25 
    2626    def set_data(self, x=None, y=None): 
    2727        """ 
    2828         Receive two vector x, y and prepare the slit calculator for 
    2929         computation. 
    30          
     30 
    3131        :param x: array 
    3232        :param y: array 
     
    3434        self.x = x 
    3535        self.y = y 
    36          
     36 
    3737    def calculate_slit_length(self): 
    3838        """ 
    3939        Calculate slit length. 
    40          
     40 
    4141        :return: the slit length calculated value. 
    4242        """ 
     
    5050        # find max y 
    5151        max_y = y.max() 
    52          
     52 
    5353        # initial values 
    5454        y_sum = 0.0 
    5555        y_max = 0.0 
    5656        ind = 0.0 
    57          
     57 
    5858        # sum 10 or more y values until getting max_y, 
    5959        while (True): 
     
    6464                y_max = y[ind] 
    6565            ind += 1 
    66       
     66 
    6767        # find the average value/2 of the top values 
    6868        y_half = y_sum/(2.0*ind) 
    69          
     69 
    7070        # defaults 
    7171        y_half_d = 0.0 
     
    7979            if y[ind] < y_half: 
    8080                break 
    81          
     81 
    8282        # y value and ind just before passed the spot of the half height 
    8383        y_half_u = y[ind-1] 
    84          
     84 
    8585        # get corresponding x values 
    8686        x_half_d = x[ind] 
    8787        x_half_u = x[ind-1] 
    88          
     88 
    8989        # calculate x at y = y_half using linear interpolation 
    9090        if y_half_u == y_half_d: 
     
    9494                       + x_half_d * (y_half_u - y_half)) \ 
    9595                        / (y_half_u - y_half_d) 
    96          
     96 
    9797        # Our slit length is half width, so just give half beam value 
    9898        slit_length = x_half 
    99          
     99 
    100100        # set slit_length 
    101101        self.slit_length = slit_length 
    102102        return self.slit_length 
    103    
     103 
    104104    def get_slit_length_unit(self): 
    105105        """ 
Note: See TracChangeset for help on using the changeset viewer.