Changeset e3f77d8b in sasview


Ignore:
Timestamp:
Mar 2, 2015 3:31:50 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:
c93122e
Parents:
e4f421c
Message:

More pylint fixes. Ignore bumpy since it's know not to behave well with pylint and is too noisy.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • build_tools/pylint.rc

    raba5876 re3f77d8b  
    171171#  
    172172[TYPECHECK] 
     173ignored-modules = numpy 
    173174 
    174175# Tells whether missing members accessed in mixin class should be ignored. A 
  • src/sas/calculator/sas_gen.py

    rfd5ac0d re3f77d8b  
    1010import copy 
    1111 
    12 MFactor_AM = 2.853E-12 
    13 MFactor_mT = 2.3164E-9 
     12MFACTOR_AM = 2.853E-12 
     13MFACTOR_MT = 2.3164E-9 
    1414METER2ANG = 1.0E+10 
    1515#Avogadro constant [1/mol] 
     
    2121    sldm = Dm * mag where Dm = gamma * classical elec. radius/(2*Bohr magneton) 
    2222    Dm ~ 2.853E-12 [A^(-2)] ==> Shouldn't be 2.90636E-12 [A^(-2)]??? 
    23     """  
     23    """ 
    2424    if v_unit == "A/m": 
    25         factor = MFactor_AM 
     25        factor = MFACTOR_AM 
    2626    elif v_unit == "mT": 
    27         factor = MFactor_mT 
     27        factor = MFACTOR_MT 
    2828    else: 
    2929        raise ValueError, "Invalid valueunit" 
     
    3333def transform_center(pos_x, pos_y, pos_z): 
    3434    """ 
    35     re-center  
    36      
     35    re-center 
    3736    :return: posx, posy, posz   [arrays] 
    38     """  
     37    """ 
    3938    posx = pos_x - (min(pos_x) + max(pos_x)) / 2.0 
    4039    posy = pos_y - (min(pos_y) + max(pos_y)) / 2.0 
    41     posz = pos_z - (min(pos_z) + max(pos_z)) / 2.0   
    42     return posx, posy, posz    
     40    posz = pos_z - (min(pos_z) + max(pos_z)) / 2.0 
     41    return posx, posy, posz 
    4342 
    4443class GenSAS(BaseComponent): 
     
    4948        """ 
    5049        Init 
    51          
    5250        :Params sld_data: MagSLD object 
    5351        """ 
     
    6967        ## Define parameters 
    7068        self.params = {} 
    71         self.params['scale']       = 1.0 
    72         self.params['background']  = 0.0 
    73         self.params['solvent_SLD']     = 0.0 
     69        self.params['scale'] = 1.0 
     70        self.params['background'] = 0.0 
     71        self.params['solvent_SLD'] = 0.0 
    7472        self.params['total_volume'] = 1.0 
    75         self.params['Up_frac_in']     = 1.0 
    76         self.params['Up_frac_out']    = 1.0 
    77         self.params['Up_theta']  = 0.0 
     73        self.params['Up_frac_in'] = 1.0 
     74        self.params['Up_frac_out'] = 1.0 
     75        self.params['Up_theta'] = 0.0 
    7876        self.description = 'GenSAS' 
    7977        ## Parameter details [units, min, max] 
    8078        self.details = {} 
    81         self.details['scale']      = ['', None, None] 
     79        self.details['scale'] = ['', None, None] 
    8280        self.details['background'] = ['[1/cm]', None, None] 
    83         self.details['solvent_SLD']    = ['1/A^(2)', None, None] 
    84         self.details['total_volume']    = ['A^(3)', None, None] 
    85         self.details['Up_frac_in']    = ['[u/(u+d)]', None, None] 
    86         self.details['Up_frac_out']   = ['[u/(u+d)]', None, None] 
     81        self.details['solvent_SLD'] = ['1/A^(2)', None, None] 
     82        self.details['total_volume'] = ['A^(3)', None, None] 
     83        self.details['Up_frac_in'] = ['[u/(u+d)]', None, None] 
     84        self.details['Up_frac_out'] = ['[u/(u+d)]', None, None] 
    8785        self.details['Up_theta'] = ['[deg]', None, None] 
    8886        # fixed parameters 
    8987        self.fixed = [] 
    90          
    91     def set_pixel_volumes(self, volume):      
     88 
     89    def set_pixel_volumes(self, volume): 
    9290        """ 
    9391        Set the volume of a pixel in (A^3) unit 
     
    9795            raise 
    9896        self.data_vol = volume 
    99      
    100     def set_is_avg(self, is_avg=False):   
     97 
     98    def set_is_avg(self, is_avg=False): 
    10199        """ 
    102100        Sets is_avg: [bool] 
    103101        """ 
    104102        self.is_avg = is_avg 
    105            
     103 
    106104    def _gen(self, x, y, i): 
    107105        """ 
     
    109107        :Param x: array of x-values 
    110108        :Param y: array of y-values 
    111         :Param i: array of initial i-value  
     109        :Param i: array of initial i-value 
    112110        :return: function value 
    113111        """ 
     
    122120        sldn = copy.deepcopy(self.data_sldn) 
    123121        sldn -= self.params['solvent_SLD'] 
    124         model = mod.new_GenI(len_x, pos_x, pos_y, pos_z,  
    125                              sldn, self.data_mx, self.data_my,  
     122        model = mod.new_GenI(len_x, pos_x, pos_y, pos_z, 
     123                             sldn, self.data_mx, self.data_my, 
    126124                             self.data_mz, self.data_vol, 
    127                              self.params['Up_frac_in'],  
    128                              self.params['Up_frac_out'],  
     125                             self.params['Up_frac_in'], 
     126                             self.params['Up_frac_out'], 
    129127                             self.params['Up_theta']) 
    130128        if y == []: 
     
    135133        return  self.params['scale'] * vol_correction * i + \ 
    136134                        self.params['background'] 
    137          
    138     def set_sld_data(self, sld_data=None):    
     135 
     136    def set_sld_data(self, sld_data=None): 
    139137        """ 
    140138        Sets sld_data 
     
    152150        self.data_total_volume = sum(sld_data.vol_pix) 
    153151        self.params['total_volume'] = sum(sld_data.vol_pix) 
    154          
     152 
    155153    def getProfile(self): 
    156154        """ 
    157         Get SLD profile  
    158          
     155        Get SLD profile 
    159156        : return: sld_data 
    160157        """ 
    161158        return self.sld_data 
    162       
    163     def run(self, x = 0.0): 
    164         """  
     159 
     160    def run(self, x=0.0): 
     161        """ 
    165162        Evaluate the model 
    166163        :param x: simple value 
     
    173170            i_out = numpy.zeros_like(x[0]) 
    174171            # 1D I is found at y =0 in the 2D pattern 
    175             out = self._gen(x[0], [], i_out ) 
     172            out = self._gen(x[0], [], i_out) 
    176173            return out 
    177174        else: 
    178175            msg = "Q must be given as list of qx's and qy's" 
    179176            raise ValueError, msg 
    180     
    181     def runXY(self, x = 0.0): 
    182         """  
     177 
     178    def runXY(self, x=0.0): 
     179        """ 
    183180        Evaluate the model 
    184181        :param x: simple value 
     
    193190            msg = "Q must be given as list of qx's and qy's" 
    194191            raise ValueError, msg 
    195          
     192 
    196193    def evalDistribution(self, qdist): 
    197194        """ 
    198195        Evaluate a distribution of q-values. 
    199         * For 1D, a numpy array is expected as input: evalDistribution(q) where q is a numpy array. 
    200         * For 2D, a list of numpy arrays are expected: [qx_prime,qy_prime], where 1D arrays. 
    201         :param qdist: ndarray of scalar q-values or list [qx,qy] where qx,qy are 1D ndarrays  
     196        * For 1D, a numpy array is expected as input: 
     197            evalDistribution(q) where q is a numpy array. 
     198        * For 2D, a list of numpy arrays are expected: 
     199            [qx_prime,qy_prime], where 1D arrays. 
     200        :param qdist: ndarray of scalar q-values or list [qx,qy] 
     201                      where qx,qy are 1D ndarrays 
    202202        """ 
    203203        if qdist.__class__.__name__ == 'list': 
     
    211211            mesg += "a list [qx,qy] where qx,qy are arrays." 
    212212            raise RuntimeError, mesg 
    213        
    214 class OMF2SLD: 
     213 
     214class OMF2SLD(object): 
    215215    """ 
    216216    Convert OMFData to MAgData 
    217217    """ 
    218     def __init__(self):  
     218    def __init__(self): 
    219219        """ 
    220220        Init 
     
    230230        self.output = None 
    231231        self.omfdata = None 
    232      
     232 
    233233    def set_data(self, omfdata, shape='rectangular'): 
    234234        """ 
     
    237237        self.omfdata = omfdata 
    238238        length = int(omfdata.xnodes * omfdata.ynodes * omfdata.znodes) 
    239         pos_x = numpy.arange(omfdata.xmin,  
    240                              omfdata.xnodes*omfdata.xstepsize + omfdata.xmin,  
     239        pos_x = numpy.arange(omfdata.xmin, 
     240                             omfdata.xnodes*omfdata.xstepsize + omfdata.xmin, 
    241241                             omfdata.xstepsize) 
    242         pos_y = numpy.arange(omfdata.ymin,   
    243                              omfdata.ynodes*omfdata.ystepsize + omfdata.ymin,  
     242        pos_y = numpy.arange(omfdata.ymin, 
     243                             omfdata.ynodes*omfdata.ystepsize + omfdata.ymin, 
    244244                             omfdata.ystepsize) 
    245         pos_z = numpy.arange(omfdata.zmin,  
    246                              omfdata.znodes*omfdata.zstepsize + omfdata.zmin,  
     245        pos_z = numpy.arange(omfdata.zmin, 
     246                             omfdata.znodes*omfdata.zstepsize + omfdata.zmin, 
    247247                             omfdata.zstepsize) 
    248248        self.pos_x = numpy.tile(pos_x, int(omfdata.ynodes * omfdata.znodes)) 
     
    254254        self.mz = omfdata.mz 
    255255        self.sld_n = numpy.zeros(length) 
    256              
     256 
    257257        if omfdata.mx == None: 
    258258            self.mx = numpy.zeros(length) 
     
    261261        if omfdata.mz == None: 
    262262            self.mz = numpy.zeros(length) 
    263          
     263 
    264264        self._check_data_length(length) 
    265265        self.remove_null_points(False, False) 
     
    286286            except: 
    287287                pass 
    288         self.output = MagSLD(self.pos_x[mask], self.pos_y[mask],  
    289                              self.pos_z[mask], self.sld_n[mask],  
     288        self.output = MagSLD(self.pos_x[mask], self.pos_y[mask], 
     289                             self.pos_z[mask], self.sld_n[mask], 
    290290                             self.mx[mask], self.my[mask], self.mz[mask]) 
    291291        self.output.set_pix_type('pixel') 
    292292        self.output.set_pixel_symbols('pixel') 
    293          
     293 
    294294    def get_omfdata(self): 
    295295        """ 
     
    297297        """ 
    298298        return self.omfdata 
    299      
     299 
    300300    def get_output(self): 
    301301        """ 
     
    303303        """ 
    304304        return self.output 
    305      
     305 
    306306    def _check_data_length(self, length): 
    307307        """ 
     
    322322        if len(self.mz) != length: 
    323323            raise ValueError, msg 
    324          
     324 
    325325    def remove_null_points(self, remove=False, recenter=False): 
    326326        """ 
     
    328328        """ 
    329329        if remove: 
    330             is_nonzero = (numpy.fabs(self.mx) + numpy.fabs(self.my) +  
    331                           numpy.fabs(self.mz)).nonzero()   
    332             if len(is_nonzero[0]) > 0:  
     330            is_nonzero = (numpy.fabs(self.mx) + numpy.fabs(self.my) + 
     331                          numpy.fabs(self.mz)).nonzero() 
     332            if len(is_nonzero[0]) > 0: 
    333333                self.pos_x = self.pos_x[is_nonzero] 
    334334                self.pos_y = self.pos_y[is_nonzero] 
     
    342342            self.pos_y -= (min(self.pos_y) + max(self.pos_y)) / 2.0 
    343343            self.pos_z -= (min(self.pos_z) + max(self.pos_z)) / 2.0 
    344   
     344 
    345345    def get_magsld(self): 
    346346        """ 
     
    348348        """ 
    349349        return self.output 
    350      
    351          
    352 class OMFReader: 
     350 
     351 
     352class OMFReader(object): 
    353353    """ 
    354354    Class to load omf/ascii files (3 columns w/header). 
     
    356356    ## File type 
    357357    type_name = "OMF ASCII" 
    358      
     358 
    359359    ## Wildcards 
    360360    type = ["OMF files (*.OMF, *.omf)|*.omf"] 
    361361    ## List of allowed extensions 
    362362    ext = ['.omf', '.OMF'] 
    363          
     363 
    364364    def read(self, path): 
    365365        """ 
     
    368368        :return: x, y, z, sld_n, sld_mx, sld_my, sld_mz 
    369369        """ 
    370         #data_conv_m = None 
    371370        desc = "" 
    372371        mx = numpy.zeros(0) 
     
    374373        mz = numpy.zeros(0) 
    375374        try: 
    376             data_conv_val = None 
    377             data_conv_mesh = None 
    378375            input_f = open(path, 'rb') 
    379376            buff = input_f.read() 
     
    454451                    valuerangemaxmag = s_line[1].lstrip() 
    455452                if s_line[0].lower().count("end") > 0: 
    456                     #output.set_sldms(mx, my, mz)     
    457453                    output.filename = os.path.basename(path) 
    458454                    output.oommf = oommf 
     
    487483            raise RuntimeError, msg 
    488484 
    489 class PDBReader: 
     485class PDBReader(object): 
    490486    """ 
    491487    PDB reader class: limited for reading the lines starting with 'ATOM' 
     
    495491    type = ["pdb files (*.PDB, *.pdb)|*.pdb"] 
    496492    ## List of allowed extensions 
    497     ext = ['.pdb', '.PDB']    
    498      
     493    ext = ['.pdb', '.PDB'] 
     494 
    499495    def read(self, path): 
    500496        """ 
    501497        Load data file 
    502          
     498 
    503499        :param path: file path 
    504          
    505500        :return: MagSLD 
    506          
    507501        :raise RuntimeError: when the file can't be opened 
    508502        """ 
     
    521515        x_lines = [] 
    522516        y_lines = [] 
    523         z_lines = []         
     517        z_lines = [] 
    524518        try: 
    525519            input_f = open(path, 'rb') 
     
    527521            lines = buff.split('\n') 
    528522            input_f.close() 
    529             pre_num = 0 
    530523            num = 0 
    531524            for line in lines: 
     
    535528                                line[0:6].strip() == 'ATOM': 
    536529                        # define fields of interest 
    537                         atom_id = line[6:11].strip() 
    538530                        atom_name = line[12:16].strip() 
    539531                        try: 
     
    543535                            if len(atom_name) == 4: 
    544536                                atom_name = atom_name[0].upper() 
    545                             elif line[12] != ' ':  
     537                            elif line[12] != ' ': 
    546538                                atom_name = atom_name[0].upper() + \ 
    547                                         atom_name[1].lower()  
     539                                        atom_name[1].lower() 
    548540                            else: 
    549541                                atom_name = atom_name[0].upper() 
    550                         #res_name = line[17:20].strip() 
    551                         #chain_name = line[21:22].strip() 
    552542                        _pos_x = float(line[30:38].strip()) 
    553543                        _pos_y = float(line[38:46].strip()) 
    554544                        _pos_z = float(line[46:54].strip()) 
    555                          
    556545                        pos_x = numpy.append(pos_x, _pos_x) 
    557546                        pos_y = numpy.append(pos_y, _pos_y) 
    558547                        pos_z = numpy.append(pos_z, _pos_z) 
    559548                        try: 
    560                             # sld in Ang unit (from fm) 
    561                             #val = formula(atom_name).atoms.keys()[0].neutron.b_c 
    562                             #val *= 1.0e-5 
    563549                            val = nsf.neutron_sld(atom_name)[0] 
    564550                            # sld in Ang^-2 unit 
     
    571557                        except: 
    572558                            print "Error: set the sld of %s to zero"% atom_name 
    573                             sld_n = numpy.append(sld_n,  0.0)                      
     559                            sld_n = numpy.append(sld_n, 0.0) 
    574560                        sld_mx = numpy.append(sld_mx, 0) 
    575561                        sld_my = numpy.append(sld_my, 0) 
    576562                        sld_mz = numpy.append(sld_mz, 0) 
    577563                        pix_symbol = numpy.append(pix_symbol, atom_name) 
    578                     elif line[0:6].strip().count('CONECT') > 0 : 
     564                    elif line[0:6].strip().count('CONECT') > 0: 
    579565                        toks = line.split() 
    580                         num = int(toks[1]) - 1   
    581                         val_list = []  
     566                        num = int(toks[1]) - 1 
     567                        val_list = [] 
    582568                        for val in toks[2:]: 
    583569                            try: 
     
    588574                                break 
    589575                            val_list.append(int_val) 
    590                         #need val_list ordered       
     576                        #need val_list ordered 
    591577                        for val in val_list: 
    592578                            index = val - 1 
     
    599585                            z_line.append((pos_z[num], pos_z[index])) 
    600586                    if len(x_line) > 0: 
    601                         x_lines.append(x_line)  
     587                        x_lines.append(x_line) 
    602588                        y_lines.append(y_line) 
    603                         z_lines.append(z_line)             
     589                        z_lines.append(z_line) 
    604590                except: 
    605591                    pass 
    606             #re-centering 
    607             #pos_x -= (min(pos_x) + max(pos_x)) / 2.0 
    608             #pos_y -= (min(pos_y) + max(pos_y)) / 2.0 
    609             #pos_z -= (min(pos_z) + max(pos_z)) / 2.0 
    610              
     592 
    611593            output = MagSLD(pos_x, pos_y, pos_z, sld_n, sld_mx, sld_my, sld_mz) 
    612594            output.set_conect_lines(x_line, y_line, z_line) 
     
    619601            return output 
    620602        except: 
    621             RuntimeError, "%s is not a sld file" % path 
     603            raise RuntimeError, "%s is not a sld file" % path 
    622604 
    623605    def write(self, path, data): 
     
    625607        Write 
    626608        """ 
    627         #Not implemented  
    628609        print "Not implemented... " 
    629610 
    630 class SLDReader: 
     611class SLDReader(object): 
    631612    """ 
    632613    Class to load ascii files (7 columns). 
     
    634615    ## File type 
    635616    type_name = "SLD ASCII" 
    636      
    637617    ## Wildcards 
    638618    type = ["sld files (*.SLD, *.sld)|*.sld", 
     
    641621    ## List of allowed extensions 
    642622    ext = ['.sld', '.SLD', '.txt', '.TXT', '.*'] 
    643      
    644623    def read(self, path): 
    645624        """ 
    646625        Load data file 
    647          
    648626        :param path: file path 
    649          
    650627        :return MagSLD: x, y, z, sld_n, sld_mx, sld_my, sld_mz 
    651          
    652628        :raise RuntimeError: when the file can't be opened 
    653629        :raise ValueError: when the length of the data vectors are inconsistent 
     
    663639            try: 
    664640                # Use numpy to speed up loading 
    665                 input_f = numpy.loadtxt(path, dtype='float', skiprows=1,  
     641                input_f = numpy.loadtxt(path, dtype='float', skiprows=1, 
    666642                                        ndmin=1, unpack=True) 
    667643                pos_x = numpy.array(input_f[0]) 
     
    676652                    vol_pix = numpy.array(input_f[7]) 
    677653                elif ncols == 7: 
    678                      vol_pix = None 
     654                    vol_pix = None 
    679655            except: 
    680656                # For older version of numpy 
     
    693669                        _sld_my = float(toks[5]) 
    694670                        _sld_mz = float(toks[6]) 
    695      
    696671                        pos_x = numpy.append(pos_x, _pos_x) 
    697672                        pos_y = numpy.append(pos_y, _pos_y) 
     
    702677                        sld_mz = numpy.append(sld_mz, _sld_mz) 
    703678                        try: 
    704                             _vol_pix =  float(toks[7]) 
     679                            _vol_pix = float(toks[7]) 
    705680                            vol_pix = numpy.append(vol_pix, _vol_pix) 
    706681                        except: 
     
    709684                        # Skip non-data lines 
    710685                        pass 
    711              
    712             # re-center      
    713             #pos_x -= (min(pos_x) + max(pos_x)) / 2.0 
    714             #pos_y -= (min(pos_y) + max(pos_y)) / 2.0 
    715             #pos_z -= (min(pos_z) + max(pos_z)) / 2.0 
    716  
    717             output = MagSLD(pos_x, pos_y, pos_z, sld_n,  
     686            output = MagSLD(pos_x, pos_y, pos_z, sld_n, 
    718687                            sld_mx, sld_my, sld_mz) 
    719  
    720688            output.filename = os.path.basename(path) 
    721689            output.set_pix_type('pixel') 
     
    725693            return output 
    726694        except: 
    727             RuntimeError, "%s is not a sld file" % path 
    728          
     695            raise RuntimeError, "%s is not a sld file" % path 
     696 
    729697    def write(self, path, data): 
    730698        """ 
    731699        Write sld file 
    732          
    733         :Param path: file path  
     700        :Param path: file path 
    734701        :Param data: MagSLD data object 
    735702        """ 
     
    738705        if data == None: 
    739706            raise ValueError, "Missing the data to save." 
    740          
    741707        x_val = data.pos_x 
    742708        y_val = data.pos_y 
    743709        z_val = data.pos_z 
    744710        vol_pix = data.vol_pix 
    745          
    746711        length = len(x_val) 
    747          
    748712        sld_n = data.sld_n 
    749713        if sld_n == None: 
    750             sld_n = numpy.zerros(length) 
    751              
     714            sld_n = numpy.zeros(length) 
    752715        sld_mx = data.sld_mx 
    753716        if sld_mx == None: 
    754             sld_mx = numpy.zerros(length) 
    755             sld_my = numpy.zerros(length) 
    756             sld_mz = numpy.zerros(length) 
     717            sld_mx = numpy.zeros(length) 
     718            sld_my = numpy.zeros(length) 
     719            sld_mz = numpy.zeros(length) 
    757720        else: 
    758721            sld_my = data.sld_my 
    759722            sld_mz = data.sld_mz 
    760              
    761723        out = open(path, 'w') 
    762724        # First Line: Column names 
    763725        out.write("X  Y  Z  SLDN SLDMx  SLDMy  SLDMz VOLUMEpix") 
    764726        for ind in range(length): 
    765             out.write("\n%g  %g  %g  %g  %g  %g  %g %g" % (x_val[ind], y_val[ind],  
    766                                                     z_val[ind], sld_n[ind],  
    767                                                     sld_mx[ind], sld_my[ind],  
    768                                                     sld_mz[ind], vol_pix[ind]))   
    769         out.close()        
    770              
    771              
    772 class OMFData: 
     727            out.write("\n%g  %g  %g  %g  %g  %g  %g %g" % \ 
     728                      (x_val[ind], y_val[ind], z_val[ind], sld_n[ind], 
     729                       sld_mx[ind], sld_my[ind], sld_mz[ind], vol_pix[ind])) 
     730        out.close() 
     731 
     732 
     733class OMFData(object): 
    773734    """ 
    774735    OMF Data. 
     
    808769        self.valuerangeminmag = 0 
    809770        self.valuerangemaxmag = 0 
    810          
     771 
    811772    def __str__(self): 
    812773        """ 
    813774        doc strings 
    814775        """ 
    815         _str =  "Type:            %s\n" % self.__class__.__name__ 
     776        _str = "Type:            %s\n" % self.__class__.__name__ 
    816777        _str += "File:            %s\n" % self.filename 
    817778        _str += "OOMMF:           %s\n" % self.oommf 
     
    823784        _str += "ybase:           %s [%s]\n" % (str(self.ybase), self.meshunit) 
    824785        _str += "zbase:           %s [%s]\n" % (str(self.zbase), self.meshunit) 
    825         _str += "xstepsize:       %s [%s]\n" % (str(self.xstepsize),  
     786        _str += "xstepsize:       %s [%s]\n" % (str(self.xstepsize), 
    826787                                                self.meshunit) 
    827         _str += "ystepsize:       %s [%s]\n" % (str(self.ystepsize),  
     788        _str += "ystepsize:       %s [%s]\n" % (str(self.ystepsize), 
    828789                                                self.meshunit) 
    829         _str += "zstepsize:       %s [%s]\n" % (str(self.zstepsize),  
     790        _str += "zstepsize:       %s [%s]\n" % (str(self.zstepsize), 
    830791                                                self.meshunit) 
    831792        _str += "xnodes:          %s\n" % str(self.xnodes) 
     
    840801        _str += "valueunit:       %s\n" % self.valueunit 
    841802        _str += "valuemultiplier: %s\n" % str(self.valuemultiplier) 
    842         _str += "ValueRangeMinMag:%s [%s]\n" % (str(self.valuerangeminmag),  
    843                                                  self.valueunit) 
    844         _str += "ValueRangeMaxMag:%s [%s]\n" % (str(self.valuerangemaxmag),  
    845                                                  self.valueunit) 
     803        _str += "ValueRangeMinMag:%s [%s]\n" % (str(self.valuerangeminmag), 
     804                                                self.valueunit) 
     805        _str += "ValueRangeMaxMag:%s [%s]\n" % (str(self.valuerangemaxmag), 
     806                                                self.valueunit) 
    846807        return _str 
    847      
     808 
    848809    def set_m(self, mx, my, mz): 
    849810        """ 
     
    853814        self.my = my 
    854815        self.mz = mz 
    855                 
    856 class MagSLD: 
     816 
     817class MagSLD(object): 
    857818    """ 
    858819    Magnetic SLD. 
     
    869830    _sld_unit = '1/A^(2)' 
    870831    _pix_type = 'pixel' 
    871      
    872     def __init__(self, pos_x, pos_y, pos_z, sld_n=None,  
     832 
     833    def __init__(self, pos_x, pos_y, pos_z, sld_n=None, 
    873834                 sld_mx=None, sld_my=None, sld_mz=None, vol_pix=None): 
    874835        """ 
     
    907868            self.set_sldms(sld_mx, sld_my, sld_mz) 
    908869        self.set_nodes() 
    909                     
     870 
    910871    def __str__(self): 
    911872        """ 
    912873        doc strings 
    913874        """ 
    914         _str =  "Type:       %s\n" % self.__class__.__name__ 
     875        _str = "Type:       %s\n" % self.__class__.__name__ 
    915876        _str += "File:       %s\n" % self.filename 
    916877        _str += "Axis_unit:  %s\n" % self.pos_unit 
    917878        _str += "SLD_unit:   %s\n" % self.sld_unit 
    918879        return _str 
    919      
     880 
    920881    def set_pix_type(self, pix_type): 
    921882        """ 
     
    924885        """ 
    925886        self.pix_type = pix_type 
    926          
     887 
    927888    def set_sldn(self, sld_n): 
    928889        """ 
     
    931892        if sld_n.__class__.__name__ == 'float': 
    932893            if self.is_data: 
    933                 # For data, put the value to only the pixels w non-zero M  
    934                 is_nonzero = (numpy.fabs(self.sld_mx) +  
    935                                   numpy.fabs(self.sld_my) +  
    936                                   numpy.fabs(self.sld_mz)).nonzero()  
     894                # For data, put the value to only the pixels w non-zero M 
     895                is_nonzero = (numpy.fabs(self.sld_mx) + 
     896                              numpy.fabs(self.sld_my) + 
     897                              numpy.fabs(self.sld_mz)).nonzero() 
    937898                self.sld_n = numpy.zeros(len(self.pos_x)) 
    938899                if len(self.sld_n[is_nonzero]) > 0: 
     
    945906        else: 
    946907            self.sld_n = sld_n 
    947             
     908 
    948909    def set_sldms(self, sld_mx, sld_my, sld_mz): 
    949910        """ 
    950         Sets (\|m\|, m_theta, m_phi) 
     911        Sets (|m|, m_theta, m_phi) 
    951912        """ 
    952913        if sld_mx.__class__.__name__ == 'float': 
     
    964925 
    965926        sld_m = numpy.sqrt(sld_mx * sld_mx + sld_my * sld_my + \ 
    966                                 sld_mz * sld_mz)   
     927                                sld_mz * sld_mz) 
    967928        self.sld_m = sld_m 
    968      
    969     def set_pixel_symbols(self, symbol='pixel'):   
     929 
     930    def set_pixel_symbols(self, symbol='pixel'): 
    970931        """ 
    971932        Set pixel 
     
    978939        else: 
    979940            self.pix_symbol = symbol 
    980              
    981     def set_pixel_volumes(self, vol):   
     941 
     942    def set_pixel_volumes(self, vol): 
    982943        """ 
    983944        Set pixel volumes 
     
    998959        """ 
    999960        return self.sld_n 
    1000      
    1001     def get_sld_mxyz(self): 
    1002         """ 
    1003         Returns (sld_mx, sldmy, sld_mz) 
    1004         """ 
    1005         return (self.sld_mx, self.sldmy, self.sld_mz) 
    1006      
    1007     def get_sld_m(self): 
    1008         """ 
    1009         Returns (sldm, sld_theta, sld_phi) 
    1010         """ 
    1011         return (self.sldm, self.sld_theta, self.sld_phi) 
    1012      
     961 
    1013962    def set_nodes(self): 
    1014963        """ 
     
    1032981            self.ynodes = None 
    1033982            self.znodes = None 
    1034        
     983 
    1035984    def set_stepsize(self): 
    1036985        """ 
     
    10831032            return 
    10841033        self.has_conect = True 
    1085         self.line_x = line_x  
    1086         self.line_y = line_y  
     1034        self.line_x = line_x 
     1035        self.line_y = line_y 
    10871036        self.line_z = line_z 
    1088          
    10891037 
    10901038def test_load(): 
    10911039    from sas.plottools.arrow3d import Arrow3D 
    1092     import os 
    1093     dir = os.path.abspath(os.path.curdir) 
    1094     print dir 
     1040    current_dir = os.path.abspath(os.path.curdir) 
     1041    print current_dir 
    10951042    for i in range(6): 
    1096         dir, _ = os.path.split(dir) 
    1097         tfile = os.path.join(dir, "test", "CoreXY_ShellZ.txt") 
    1098         ofile = os.path.join(dir, "test", "A_Raw_Example-1.omf") 
     1043        current_dir, _ = os.path.split(current_dir) 
     1044        tfile = os.path.join(current_dir, "test", "CoreXY_ShellZ.txt") 
     1045        ofile = os.path.join(current_dir, "test", "A_Raw_Example-1.omf") 
    10991046        if os.path.isfile(tfile): 
    11001047            tfpath = tfile 
     
    11091056 
    11101057    import matplotlib.pyplot as plt 
    1111     from mpl_toolkits.mplot3d import Axes3D 
    11121058    fig = plt.figure() 
    11131059    ax = fig.gca(projection='3d') 
    1114     ax.plot(output.pos_x, output.pos_y, output.pos_z, '.', c="g",  
    1115             alpha = 0.7, markeredgecolor='gray',rasterized=True) 
     1060    ax.plot(output.pos_x, output.pos_y, output.pos_z, '.', c="g", 
     1061            alpha=0.7, markeredgecolor='gray', rasterized=True) 
    11161062    gap = 7 
    11171063    max_mx = max(output.sld_mx) 
    11181064    max_my = max(output.sld_my) 
    11191065    max_mz = max(output.sld_mz) 
    1120     max_m = max(max_mx,max_my,max_mz) 
     1066    max_m = max(max_mx, max_my, max_mz) 
    11211067    x2 = output.pos_x+output.sld_mx/max_m * gap 
    11221068    y2 = output.pos_y+output.sld_my/max_m * gap 
    11231069    z2 = output.pos_z+output.sld_mz/max_m * gap 
    1124     x_arrow = numpy.column_stack((output.pos_x,x2)) 
    1125     y_arrow = numpy.column_stack((output.pos_y,y2)) 
    1126     z_arrow = numpy.column_stack((output.pos_z,z2)) 
     1070    x_arrow = numpy.column_stack((output.pos_x, x2)) 
     1071    y_arrow = numpy.column_stack((output.pos_y, y2)) 
     1072    z_arrow = numpy.column_stack((output.pos_z, z2)) 
    11271073    unit_x2 = output.sld_mx / max_m 
    11281074    unit_y2 = output.sld_my / max_m 
     
    11311077    color_y = numpy.fabs(unit_y2 * 0.8) 
    11321078    color_z = numpy.fabs(unit_z2 * 0.8) 
    1133     colors =  numpy.column_stack((color_x, color_y, color_z)) 
    1134     a = Arrow3D(None, x_arrow,y_arrow,z_arrow, colors, mutation_scale=10, lw=1,  
    1135                 arrowstyle="->", color="y", alpha = 0.5) 
    1136  
     1079    colors = numpy.column_stack((color_x, color_y, color_z)) 
     1080    a = Arrow3D(None, x_arrow, y_arrow, z_arrow, colors, 
     1081                mutation_scale=10, lw=1, arrowstyle="->", 
     1082                color="y", alpha=0.5) 
    11371083    ax.add_artist(a) 
    11381084    plt.show() 
    1139      
    11401085def test(): 
    1141     import os 
    1142     dir = os.path.abspath(os.path.curdir) 
     1086    current_dir = os.path.abspath(os.path.curdir) 
    11431087    for i in range(3): 
    1144         dir, _ = os.path.split(dir) 
    1145         #tfile = os.path.join(dir, "test", "C_Example_Converted.txt") 
    1146         ofile = os.path.join(dir, "test", "A_Raw_Example-1.omf") 
     1088        current_dir, _ = os.path.split(current_dir) 
     1089        ofile = os.path.join(current_dir, "test", "A_Raw_Example-1.omf") 
    11471090        if os.path.isfile(ofile): 
    1148             #tfpath = tfile 
    11491091            ofpath = ofile 
    11501092            break 
    1151     #reader = SLDReader() 
    11521093    oreader = OMFReader() 
    1153     #output = reader.read(tfpath) 
    11541094    ooutput = oreader.read(ofpath) 
    1155     foutput = OMF2SLD()  
    1156     foutput.set_data(ooutput)   
    1157     writer =  SLDReader()  
    1158     writer.write(os.path.join(os.path.dirname(ofpath), "out.txt"),  
     1095    foutput = OMF2SLD() 
     1096    foutput.set_data(ooutput) 
     1097    writer = SLDReader() 
     1098    writer.write(os.path.join(os.path.dirname(ofpath), "out.txt"), 
    11591099                 foutput.output) 
    11601100    model = GenSAS() 
    1161     model.set_sld_data(foutput.output)  
     1101    model.set_sld_data(foutput.output) 
    11621102    x = numpy.arange(1000)/10000. + 1e-5 
    11631103    y = numpy.arange(1000)/10000. + 1e-5 
    1164     #z = numpy.arange(1000)/10000. + 1e-5 
    11651104    i = numpy.zeros(1000) 
    1166     out = model.runXY([x,y,i]) 
    1167          
    1168 if __name__ == "__main__":  
     1105    model.runXY([x, y, i]) 
     1106 
     1107if __name__ == "__main__": 
    11691108    test() 
    11701109    test_load() 
Note: See TracChangeset for help on using the changeset viewer.