Changeset 574adc7 in sasview for src/sas/sascalc/calculator


Ignore:
Timestamp:
Sep 22, 2017 2:01:32 PM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
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, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
34d7b35
Parents:
9706d88
Message:

convert sascalc to python 2/3 syntax

Location:
src/sas/sascalc/calculator
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/calculator/BaseComponent.py

    r9a5097c r574adc7  
    143143                qdist[1].__class__.__name__ != 'ndarray': 
    144144                msg = "evalDistribution expects a list of 2 ndarrays" 
    145                 raise RuntimeError, msg 
     145                raise RuntimeError(msg) 
    146146 
    147147            # Extract qx and qy for code clarity 
     
    167167            mesg = "evalDistribution is expecting an ndarray of scalar q-values" 
    168168            mesg += " or a list [qx,qy] where qx,qy are 2D ndarrays." 
    169             raise RuntimeError, mesg 
     169            raise RuntimeError(mesg) 
    170170 
    171171 
     
    228228                    return 
    229229 
    230         raise ValueError, "Model does not contain parameter %s" % name 
     230        raise ValueError("Model does not contain parameter %s" % name) 
    231231 
    232232    def getParam(self, name): 
     
    250250                    return self.params[item] 
    251251 
    252         raise ValueError, "Model does not contain parameter %s" % name 
     252        raise ValueError("Model does not contain parameter %s" % name) 
    253253 
    254254    def getParamList(self): 
     
    294294        add 
    295295        """ 
    296         raise ValueError, "Model operation are no longer supported" 
     296        raise ValueError("Model operation are no longer supported") 
    297297    def __sub__(self, other): 
    298298        """ 
    299299        sub 
    300300        """ 
    301         raise ValueError, "Model operation are no longer supported" 
     301        raise ValueError("Model operation are no longer supported") 
    302302    def __mul__(self, other): 
    303303        """ 
    304304        mul 
    305305        """ 
    306         raise ValueError, "Model operation are no longer supported" 
     306        raise ValueError("Model operation are no longer supported") 
    307307    def __div__(self, other): 
    308308        """ 
    309309        div 
    310310        """ 
    311         raise ValueError, "Model operation are no longer supported" 
     311        raise ValueError("Model operation are no longer supported") 
    312312 
    313313 
  • src/sas/sascalc/calculator/instrument.py

    r9a5097c r574adc7  
    222222        """ 
    223223        # check if the wavelength is in range 
    224         if min(band) < self.min or\ 
    225                 max(band) > self.max: 
    226             raise 
     224        if min(band) < self.min or max(band) > self.max: 
     225            raise ValueError("band out of range") 
    227226        self.band = band 
    228227 
     
    239238        """ 
    240239        # check if the wavelength is in range 
    241         if wavelength < min(self.band) or\ 
    242                 wavelength > max(self.band): 
    243             raise 
     240        if wavelength < min(self.band) or wavelength > max(self.band): 
     241            raise ValueError("wavelength out of range") 
    244242        self.wavelength = wavelength 
    245243        validate(wavelength) 
     
    324322            plt.show() 
    325323        except: 
    326             raise RuntimeError, "Can't import matplotlib required to plot..." 
     324            raise RuntimeError("Can't import matplotlib required to plot...") 
    327325 
    328326 
  • src/sas/sascalc/calculator/resolution_calculator.py

    r7432acb r574adc7  
    44instrumental parameters. 
    55""" 
    6 from instrument import Sample 
    7 from instrument import Detector 
    8 from instrument import TOF as Neutron 
    9 from instrument import Aperture 
    10 # import math stuffs 
    11 from math import pi 
    12 from math import sqrt 
     6import sys 
     7from math import pi, sqrt 
    138import math 
     9import logging 
     10 
    1411import numpy as np 
    15 import sys 
    16 import logging 
     12 
     13from .instrument import Sample 
     14from .instrument import Detector 
     15from .instrument import TOF as Neutron 
     16from .instrument import Aperture 
    1717 
    1818logger = logging.getLogger(__name__) 
     
    208208        if wavelength == 0: 
    209209            msg = "Can't compute the resolution: the wavelength is zero..." 
    210             raise RuntimeError, msg 
     210            raise RuntimeError(msg) 
    211211        return self.intensity 
    212212 
     
    379379        if qx_min < self.qx_min: 
    380380            self.qx_min = qx_min 
    381             #raise ValueError, msg 
     381            #raise ValueError(msg) 
    382382        if qx_max > self.qx_max: 
    383383            self.qx_max = qx_max 
    384             #raise ValueError, msg 
     384            #raise ValueError(msg) 
    385385        if qy_min < self.qy_min: 
    386386            self.qy_min = qy_min 
    387             #raise ValueError, msg 
     387            #raise ValueError(msg) 
    388388        if qy_max > self.qy_max: 
    389389            self.qy_max = qy_max 
    390             #raise ValueError, msg 
     390            #raise ValueError(msg) 
    391391        if not full_cal: 
    392392            return None 
     
    503503        # otherwise 
    504504        else: 
    505             raise ValueError, " Improper input..." 
     505            raise ValueError(" Improper input...") 
    506506        # get them squared 
    507507        sigma = x_comp * x_comp 
     
    706706            #self.set_wavelength(wavelength) 
    707707        else: 
    708             raise 
     708            raise TypeError("invalid wavlength---should be list or float") 
    709709 
    710710    def set_wave_spread(self, wavelength_spread): 
     
    717717            self.wave.set_wave_spread_list([wavelength_spread]) 
    718718        else: 
    719             raise 
     719            raise TypeError("invalid wavelength spread---should be list or float") 
    720720 
    721721    def set_wavelength(self, wavelength): 
     
    766766        """ 
    767767        if len(size) < 1 or len(size) > 2: 
    768             raise RuntimeError, "The length of the size must be one or two." 
     768            raise RuntimeError("The length of the size must be one or two.") 
    769769        self.aperture.set_source_size(size) 
    770770 
     
    783783        """ 
    784784        if len(size) < 1 or len(size) > 2: 
    785             raise RuntimeError, "The length of the size must be one or two." 
     785            raise RuntimeError("The length of the size must be one or two.") 
    786786        self.aperture.set_sample_size(size) 
    787787 
     
    806806        """ 
    807807        if len(distance) < 1 or len(distance) > 2: 
    808             raise RuntimeError, "The length of the size must be one or two." 
     808            raise RuntimeError("The length of the size must be one or two.") 
    809809        self.aperture.set_sample_distance(distance) 
    810810 
     
    816816        """ 
    817817        if len(distance) < 1 or len(distance) > 2: 
    818             raise RuntimeError, "The length of the size must be one or two." 
     818            raise RuntimeError("The length of the size must be one or two.") 
    819819        self.sample.set_distance(distance) 
    820820 
     
    826826        """ 
    827827        if len(distance) < 1 or len(distance) > 2: 
    828             raise RuntimeError, "The length of the size must be one or two." 
     828            raise RuntimeError("The length of the size must be one or two.") 
    829829        self.detector.set_distance(distance) 
    830830 
     
    998998            pix_y_size = detector_pix_size[1] 
    999999        else: 
    1000             raise ValueError, " Input value format error..." 
     1000            raise ValueError(" Input value format error...") 
    10011001        # Sample to detector distance = sample slit to detector 
    10021002        # minus sample offset 
  • src/sas/sascalc/calculator/sas_gen.py

    rf2ea95a r574adc7  
    3434        factor = MFACTOR_MT 
    3535    else: 
    36         raise ValueError, "Invalid valueunit" 
     36        raise ValueError("Invalid valueunit") 
    3737    sld_m = factor * mag 
    3838    return sld_m 
     
    100100        """ 
    101101        if self.data_vol is None: 
    102             raise 
     102            raise TypeError("data_vol is missing") 
    103103        self.data_vol = volume 
    104104 
     
    174174            if len(x[1]) > 0: 
    175175                msg = "Not a 1D." 
    176                 raise ValueError, msg 
     176                raise ValueError(msg) 
    177177            i_out = np.zeros_like(x[0]) 
    178178            # 1D I is found at y =0 in the 2D pattern 
     
    181181        else: 
    182182            msg = "Q must be given as list of qx's and qy's" 
    183             raise ValueError, msg 
     183            raise ValueError(msg) 
    184184 
    185185    def runXY(self, x=0.0): 
     
    196196        else: 
    197197            msg = "Q must be given as list of qx's and qy's" 
    198             raise ValueError, msg 
     198            raise ValueError(msg) 
    199199 
    200200    def evalDistribution(self, qdist): 
     
    214214            mesg = "evalDistribution is expecting an ndarray of " 
    215215            mesg += "a list [qx,qy] where qx,qy are arrays." 
    216             raise RuntimeError, mesg 
     216            raise RuntimeError(mesg) 
    217217 
    218218class OMF2SLD(object): 
     
    313313        :Params length: data length 
    314314        """ 
    315         msg = "Error: Inconsistent data length." 
    316         if len(self.pos_x) != length: 
    317             raise ValueError, msg 
    318         if len(self.pos_y) != length: 
    319             raise ValueError, msg 
    320         if len(self.pos_z) != length: 
    321             raise ValueError, msg 
    322         if len(self.mx) != length: 
    323             raise ValueError, msg 
    324         if len(self.my) != length: 
    325             raise ValueError, msg 
    326         if len(self.mz) != length: 
    327             raise ValueError, msg 
     315        parts = (self.pos_x, self.pos_y, self.pos_z, self.mx, self.my, self.mz) 
     316        if any(len(v) != length for v in parts): 
     317            raise ValueError("Error: Inconsistent data length.") 
    328318 
    329319    def remove_null_points(self, remove=False, recenter=False): 
     
    415405                        msg = "Error: \n" 
    416406                        msg += "We accept only m as meshunit" 
    417                         raise ValueError, msg 
     407                        raise ValueError(msg) 
    418408                if s_line[0].lower().count("xbase") > 0: 
    419409                    xbase = s_line[1].lstrip() 
     
    485475            msg = "%s is not supported: \n" % path 
    486476            msg += "We accept only Text format OMF file." 
    487             raise RuntimeError, msg 
     477            raise RuntimeError(msg) 
    488478 
    489479class PDBReader(object): 
     
    605595            return output 
    606596        except: 
    607             raise RuntimeError, "%s is not a sld file" % path 
     597            raise RuntimeError("%s is not a sld file" % path) 
    608598 
    609599    def write(self, path, data): 
     
    697687            return output 
    698688        except: 
    699             raise RuntimeError, "%s is not a sld file" % path 
     689            raise RuntimeError("%s is not a sld file" % path) 
    700690 
    701691    def write(self, path, data): 
     
    706696        """ 
    707697        if path is None: 
    708             raise ValueError, "Missing the file path." 
     698            raise ValueError("Missing the file path.") 
    709699        if data is None: 
    710             raise ValueError, "Missing the data to save." 
     700            raise ValueError("Missing the data to save.") 
    711701        x_val = data.pos_x 
    712702        y_val = data.pos_y 
Note: See TracChangeset for help on using the changeset viewer.