Changeset 278ddee in sasview for src/sas/sascalc/dataloader


Ignore:
Timestamp:
Apr 11, 2017 9:51:05 AM (7 years ago)
Author:
krzywon
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.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
beba407
Parents:
7f75a3f (diff), 97c60f8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Jeff Krzywon <krzywon@…> (04/11/17 09:51:05)
git-committer:
krzywon <krzywon@…> (04/11/17 09:51:05)
Message:

Merge branch 'master' into ticket-876

# Conflicts:
# src/sas/sascalc/dataloader/readers/ascii_reader.py
# src/sas/sascalc/dataloader/readers/xml_reader.py

Location:
src/sas/sascalc/dataloader
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/dataloader/data_info.py

    r9a5097c r7432acb  
    353353    details = None 
    354354    ## SESANS zacceptance 
    355     zacceptance = None 
     355    zacceptance = (0,"") 
     356    yacceptance = (0,"") 
    356357 
    357358    def __init__(self): 
     
    805806            # create zero vector 
    806807            dy_other = other.dy 
    807             if other.dy == None or (len(other.dy) != len(other.y)): 
     808            if other.dy is None or (len(other.dy) != len(other.y)): 
    808809                dy_other = np.zeros(len(other.y)) 
    809810 
    810811        # Check that we have errors, otherwise create zero vector 
    811812        dy = self.dy 
    812         if self.dy == None or (len(self.dy) != len(self.y)): 
     813        if self.dy is None or (len(self.dy) != len(self.y)): 
    813814            dy = np.zeros(len(self.y)) 
    814815 
     
    821822        dy, dy_other = self._validity_check(other) 
    822823        result = self.clone_without_data(len(self.x)) 
    823         if self.dxw == None: 
     824        if self.dxw is None: 
    824825            result.dxw = None 
    825826        else: 
    826827            result.dxw = np.zeros(len(self.x)) 
    827         if self.dxl == None: 
     828        if self.dxl is None: 
    828829            result.dxl = None 
    829830        else: 
     
    883884        self._validity_check_union(other) 
    884885        result = self.clone_without_data(len(self.x) + len(other.x)) 
    885         if self.dy == None or other.dy is None: 
     886        if self.dy is None or other.dy is None: 
    886887            result.dy = None 
    887888        else: 
    888889            result.dy = np.zeros(len(self.x) + len(other.x)) 
    889         if self.dx == None or other.dx is None: 
     890        if self.dx is None or other.dx is None: 
    890891            result.dx = None 
    891892        else: 
    892893            result.dx = np.zeros(len(self.x) + len(other.x)) 
    893         if self.dxw == None or other.dxw is None: 
     894        if self.dxw is None or other.dxw is None: 
    894895            result.dxw = None 
    895896        else: 
    896897            result.dxw = np.zeros(len(self.x) + len(other.x)) 
    897         if self.dxl == None or other.dxl is None: 
     898        if self.dxl is None or other.dxl is None: 
    898899            result.dxl = None 
    899900        else: 
     
    906907        result.y = np.append(self.y, other.y) 
    907908        result.y = result.y[ind] 
    908         if result.dy != None: 
     909        if result.dy is not None: 
    909910            result.dy = np.append(self.dy, other.dy) 
    910911            result.dy = result.dy[ind] 
     
    10291030            # Check that the scales match 
    10301031            err_other = other.err_data 
    1031             if other.err_data == None or \ 
     1032            if other.err_data is None or \ 
    10321033                (len(other.err_data) != len(other.data)): 
    10331034                err_other = np.zeros(len(other.data)) 
     
    10351036        # Check that we have errors, otherwise create zero vector 
    10361037        err = self.err_data 
    1037         if self.err_data == None or \ 
     1038        if self.err_data is None or \ 
    10381039            (len(self.err_data) != len(self.data)): 
    10391040            err = np.zeros(len(other.data)) 
     
    10501051        dy, dy_other = self._validity_check(other) 
    10511052        result = self.clone_without_data(np.size(self.data)) 
    1052         if self.dqx_data == None or self.dqy_data == None: 
     1053        if self.dqx_data is None or self.dqy_data is None: 
    10531054            result.dqx_data = None 
    10541055            result.dqy_data = None 
     
    11241125        result.ymin = self.ymin 
    11251126        result.ymax = self.ymax 
    1126         if self.dqx_data == None or self.dqy_data == None or \ 
    1127                 other.dqx_data == None or other.dqy_data == None: 
     1127        if self.dqx_data is None or self.dqy_data is None or \ 
     1128                other.dqx_data is None or other.dqy_data is None: 
    11281129            result.dqx_data = None 
    11291130            result.dqy_data = None 
  • src/sas/sascalc/dataloader/loader.py

    r7f75a3f r278ddee  
    3434from readers import cansas_reader_HDF5 
    3535 
     36 
     37logger = logging.getLogger(__name__) 
    3638 
    3739class Registry(ExtensionRegistry): 
     
    114116            msg = "DataLoader couldn't locate DataLoader plugin folder." 
    115117            msg += """ "%s" does not exist""" % dir 
    116             logging.warning(msg) 
     118            logger.warning(msg) 
    117119            return readers_found 
    118120 
     
    132134                        msg = "Loader: Error importing " 
    133135                        msg += "%s\n  %s" % (item, sys.exc_value) 
    134                         logging.error(msg) 
     136                        logger.error(msg) 
    135137 
    136138                # Process zip files 
     
    154156                                msg = "Loader: Error importing" 
    155157                                msg += " %s\n  %s" % (mfile, sys.exc_value) 
    156                                 logging.error(msg) 
     158                                logger.error(msg) 
    157159 
    158160                    except: 
    159161                        msg = "Loader: Error importing " 
    160162                        msg += " %s\n  %s" % (item, sys.exc_value) 
    161                         logging.error(msg) 
     163                        logger.error(msg) 
    162164 
    163165        return readers_found 
     
    205207                msg = "Loader: Error accessing" 
    206208                msg += " Reader in %s\n  %s" % (module.__name__, sys.exc_value) 
    207                 logging.error(msg) 
     209                logger.error(msg) 
    208210        return reader_found 
    209211 
     
    238240            msg = "Loader: Error accessing Reader " 
    239241            msg += "in %s\n  %s" % (loader.__name__, sys.exc_value) 
    240             logging.error(msg) 
     242            logger.error(msg) 
    241243        return reader_found 
    242244 
     
    283285                msg = "Loader: Error accessing Reader" 
    284286                msg += " in %s\n  %s" % (module.__name__, sys.exc_value) 
    285                 logging.error(msg) 
     287                logger.error(msg) 
    286288        return reader_found 
    287289 
  • src/sas/sascalc/dataloader/manipulations.py

    rdd11014 r7432acb  
    210210            y[i_q] += frac * data[npts] 
    211211 
    212             if err_data == None or err_data[npts] == 0.0: 
     212            if err_data is None or err_data[npts] == 0.0: 
    213213                if data[npts] < 0: 
    214214                    data[npts] = -data[npts] 
     
    333333                continue 
    334334            y += frac * data[npts] 
    335             if err_data == None or err_data[npts] == 0.0: 
     335            if err_data is None or err_data[npts] == 0.0: 
    336336                if data[npts] < 0: 
    337337                    data[npts] = -data[npts] 
     
    422422 
    423423        # Get the dq for resolution averaging 
    424         if data2D.dqx_data != None and data2D.dqy_data != None: 
     424        if data2D.dqx_data is not None and data2D.dqy_data is not None: 
    425425            # The pinholes and det. pix contribution present 
    426426            # in both direction of the 2D which must be subtracted when 
     
    462462 
    463463        #q_data_max = numpy.max(q_data) 
    464         if len(data2D.q_data) == None: 
     464        if len(data2D.q_data) is None: 
    465465            msg = "Circular averaging: invalid q_data: %g" % data2D.q_data 
    466466            raise RuntimeError, msg 
     
    502502            # Take dqs from data to get the q_average 
    503503            x[i_q] += frac * q_value 
    504             if err_data == None or err_data[npt] == 0.0: 
     504            if err_data is None or err_data[npt] == 0.0: 
    505505                if data_n < 0: 
    506506                    data_n = -data_n 
     
    508508            else: 
    509509                err_y[i_q] += frac * frac * err_data[npt] * err_data[npt] 
    510             if dq_data != None: 
     510            if dq_data is not None: 
    511511                # To be consistent with dq calculation in 1d reduction, 
    512512                # we need just the averages (not quadratures) because 
     
    523523                err_y[n] = -err_y[n] 
    524524            err_y[n] = math.sqrt(err_y[n]) 
    525             #if err_x != None: 
     525            #if err_x is not None: 
    526526            #    err_x[n] = math.sqrt(err_x[n]) 
    527527 
     
    532532        idx = (numpy.isfinite(y)) & (numpy.isfinite(x)) 
    533533 
    534         if err_x != None: 
     534        if err_x is not None: 
    535535            d_x = err_x[idx] / y_counts[idx] 
    536536        else: 
     
    623623            phi_bins[i_phi] += frac * data[npt] 
    624624 
    625             if err_data == None or err_data[npt] == 0.0: 
     625            if err_data is None or err_data[npt] == 0.0: 
    626626                if data_n < 0: 
    627627                    data_n = -data_n 
     
    777777 
    778778        # Get the dq for resolution averaging 
    779         if data2D.dqx_data != None and data2D.dqy_data != None: 
     779        if data2D.dqx_data is not None and data2D.dqy_data is not None: 
    780780            # The pinholes and det. pix contribution present 
    781781            # in both direction of the 2D which must be subtracted when 
     
    888888            y[i_bin] += frac * data_n 
    889889            x[i_bin] += frac * q_value 
    890             if err_data[n] == None or err_data[n] == 0.0: 
     890            if err_data[n] is None or err_data[n] == 0.0: 
    891891                if data_n < 0: 
    892892                    data_n = -data_n 
     
    895895                y_err[i_bin] += frac * frac * err_data[n] * err_data[n] 
    896896 
    897             if dq_data != None: 
     897            if dq_data is not None: 
    898898                # To be consistent with dq calculation in 1d reduction, 
    899899                # we need just the averages (not quadratures) because 
     
    925925        y_err[y_err == 0] = numpy.average(y_err) 
    926926        idx = (numpy.isfinite(y) & numpy.isfinite(y_err)) 
    927         if x_err != None: 
     927        if x_err is not None: 
    928928            d_x = x_err[idx] / y_counts[idx] 
    929929        else: 
  • src/sas/sascalc/dataloader/readers/ascii_reader.py

    r7f75a3f r235f514  
    1717import os 
    1818from sas.sascalc.dataloader.data_info import Data1D 
    19 from sas.sascalc.dataloader.loader_exceptions import FileContentsException 
    2019 
    2120# Check whether we have a converter available 
     
    129128                        if new_lentoks > 2: 
    130129                            _dy = float(toks[2]) 
    131                         has_error_dy = False if _dy == None else True 
     130                        has_error_dy = False if _dy is None else True 
    132131 
    133132                        # If a 4th row is present, consider it dx 
    134133                        if new_lentoks > 3: 
    135134                            _dx = float(toks[3]) 
    136                         has_error_dx = False if _dx == None else True 
     135                        has_error_dx = False if _dx is None else True 
    137136 
    138137                        # Delete the previously stored lines of data candidates if 
     
    174173                if not is_data: 
    175174                    msg = "ascii_reader: x has no data" 
    176                     raise FileContentsException, msg 
     175                    raise RuntimeError, msg 
    177176                # Sanity check 
    178177                if has_error_dy == True and not len(ty) == len(tdy): 
    179178                    msg = "ascii_reader: y and dy have different length" 
    180                     raise FileContentsException, msg 
     179                    raise RuntimeError, msg 
    181180                if has_error_dx == True and not len(tx) == len(tdx): 
    182181                    msg = "ascii_reader: y and dy have different length" 
    183                     raise FileContentsException, msg 
     182                    raise RuntimeError, msg 
    184183                # If the data length is zero, consider this as 
    185184                # though we were not able to read the file. 
    186185                if len(tx) == 0: 
    187                     raise FileContentsException, "ascii_reader: could not load file" 
     186                    raise RuntimeError, "ascii_reader: could not load file" 
    188187 
    189188                #Let's re-order the data to make cal. 
  • src/sas/sascalc/dataloader/readers/associations.py

    re5c09cf r959eb01  
    1818import logging 
    1919import json 
     20 
     21logger = logging.getLogger(__name__) 
    2022 
    2123FILE_NAME = 'defaults.json' 
     
    6769                    msg = "read_associations: skipping association" 
    6870                    msg += " for %s\n  %s" % (ext.lower(), sys.exc_value) 
    69                     logging.error(msg) 
     71                    logger.error(msg) 
    7072    else: 
    7173        print "Could not find reader association settings\n  %s [%s]" % (__file__, os.getcwd()) 
     
    8183    :param registry_function: function to be called to register each reader 
    8284    """ 
    83     logging.info("register_readers is now obsolete: use read_associations()") 
     85    logger.info("register_readers is now obsolete: use read_associations()") 
    8486    import abs_reader 
    8587    import ascii_reader 
  • src/sas/sascalc/dataloader/readers/cansas_constants.py

    rad4632c r63d773c  
    135135                             "Sesans": {"storeas": "content"}, 
    136136                             "zacceptance": {"storeas": "float"}, 
     137                             "yacceptance": {"storeas": "float"}, 
    137138                             "<any>" : ANY 
    138139                            } 
  • src/sas/sascalc/dataloader/readers/cansas_reader.py

    r7f75a3f r278ddee  
    3434import xml.dom.minidom 
    3535from xml.dom.minidom import parseString 
     36 
     37logger = logging.getLogger(__name__) 
    3638 
    3739PREPROCESS = "xmlpreprocess" 
     
    291293                elif tagname == 'Sesans': 
    292294                    self.current_datainfo.isSesans = bool(data_point) 
     295                elif tagname == 'yacceptance': 
     296                    self.current_datainfo.sample.yacceptance = (data_point, unit) 
    293297                elif tagname == 'zacceptance': 
    294298                    self.current_datainfo.sample.zacceptance = (data_point, unit) 
     
    809813        :param data1d: presumably a Data1D object 
    810814        """ 
    811         if self.current_dataset == None: 
     815        if self.current_dataset is None: 
    812816            x_vals = np.empty(0) 
    813817            y_vals = np.empty(0) 
     
    897901        # Write the file 
    898902        file_ref = open(filename, 'w') 
    899         if self.encoding == None: 
     903        if self.encoding is None: 
    900904            self.encoding = "UTF-8" 
    901905        doc.write(file_ref, encoding=self.encoding, 
     
    10171021        :param entry_node: lxml node ElementTree object to be appended to 
    10181022        """ 
    1019         if datainfo.run == None or datainfo.run == []: 
     1023        if datainfo.run is None or datainfo.run == []: 
    10201024            datainfo.run.append(RUN_NAME_DEFAULT) 
    10211025            datainfo.run_name[RUN_NAME_DEFAULT] = RUN_NAME_DEFAULT 
     
    10611065            sesans.text = str(datainfo.isSesans) 
    10621066            node.append(sesans) 
     1067            self.write_node(node, "yacceptance", datainfo.sample.yacceptance[0], 
     1068                             {'unit': datainfo.sample.yacceptance[1]}) 
    10631069            self.write_node(node, "zacceptance", datainfo.sample.zacceptance[0], 
    10641070                             {'unit': datainfo.sample.zacceptance[1]}) 
     
    11331139                self.write_node(point, "T", spectrum.transmission[i], 
    11341140                                {'unit': spectrum.transmission_unit}) 
    1135                 if spectrum.transmission_deviation != None \ 
     1141                if spectrum.transmission_deviation is not None \ 
    11361142                and len(spectrum.transmission_deviation) >= i: 
    11371143                    self.write_node(point, "Tdev", 
     
    12131219                                 str(datainfo.source.name)) 
    12141220        self.append(source, instr) 
    1215         if datainfo.source.radiation == None or datainfo.source.radiation == '': 
     1221        if datainfo.source.radiation is None or datainfo.source.radiation == '': 
    12161222            datainfo.source.radiation = "neutron" 
    12171223        self.write_node(source, "radiation", datainfo.source.radiation) 
     
    12541260        :param instr: lxml node ElementTree object to be appended to 
    12551261        """ 
    1256         if datainfo.collimation == [] or datainfo.collimation == None: 
     1262        if datainfo.collimation == [] or datainfo.collimation is None: 
    12571263            coll = Collimation() 
    12581264            datainfo.collimation.append(coll) 
     
    12991305        :param inst: lxml instrument node to be appended to 
    13001306        """ 
    1301         if datainfo.detector == None or datainfo.detector == []: 
     1307        if datainfo.detector is None or datainfo.detector == []: 
    13021308            det = Detector() 
    13031309            det.name = "" 
     
    14641470                local_unit = None 
    14651471                exec "local_unit = storage.%s_unit" % toks[0] 
    1466                 if local_unit != None and units.lower() != local_unit.lower(): 
     1472                if local_unit is not None and units.lower() != local_unit.lower(): 
    14671473                    if HAS_CONVERTER == True: 
    14681474                        try: 
     
    14771483                            self.errors.add(err_mess) 
    14781484                            if optional: 
    1479                                 logging.info(err_mess) 
     1485                                logger.info(err_mess) 
    14801486                            else: 
    14811487                                raise ValueError, err_mess 
     
    14861492                        self.errors.add(err_mess) 
    14871493                        if optional: 
    1488                             logging.info(err_mess) 
     1494                            logger.info(err_mess) 
    14891495                        else: 
    14901496                            raise ValueError, err_mess 
  • src/sas/sascalc/dataloader/readers/danse_reader.py

    r9a5097c r235f514  
    1919from sas.sascalc.dataloader.data_info import Data2D, Detector 
    2020from sas.sascalc.dataloader.manipulations import reader2D_converter 
     21 
     22logger = logging.getLogger(__name__) 
    2123 
    2224# Look for unit converter 
     
    142144                            error.append(err) 
    143145                        except: 
    144                             logging.info("Skipping line:%s,%s" %(data_str, 
     146                            logger.info("Skipping line:%s,%s" %(data_str, 
    145147                                                                sys.exc_value)) 
    146148             
     
    164166                 
    165167                x_vals.append(qx) 
    166                 if xmin == None or qx < xmin: 
     168                if xmin is None or qx < xmin: 
    167169                    xmin = qx 
    168                 if xmax == None or qx > xmax: 
     170                if xmax is None or qx > xmax: 
    169171                    xmax = qx 
    170172             
     
    179181                 
    180182                y_vals.append(qy) 
    181                 if ymin == None or qy < ymin: 
     183                if ymin is None or qy < ymin: 
    182184                    ymin = qy 
    183                 if ymax == None or qy > ymax: 
     185                if ymax is None or qy > ymax: 
    184186                    ymax = qy 
    185187             
     
    196198                    msg = "Skipping entry (v1.0):%s,%s" % (str(data[i_pt]), 
    197199                                                           sys.exc_value) 
    198                     logging.info(msg) 
     200                    logger.info(msg) 
    199201                 
    200202                # Get bin number 
     
    271273                raise ValueError, msg 
    272274            else: 
    273                 logging.info("Danse_reader Reading %s \n" % filename) 
     275                logger.info("Danse_reader Reading %s \n" % filename) 
    274276             
    275277            # Store loading process information 
  • src/sas/sascalc/dataloader/readers/tiff_reader.py

    r9a5097c r959eb01  
    1616from sas.sascalc.dataloader.data_info import Data2D 
    1717from sas.sascalc.dataloader.manipulations import reader2D_converter 
    18      
     18 
     19logger = logging.getLogger(__name__) 
     20 
    1921class Reader: 
    2022    """ 
     
    7678                value = float(val) 
    7779            except: 
    78                 logging.error("tiff_reader: had to skip a non-float point") 
     80                logger.error("tiff_reader: had to skip a non-float point") 
    7981                continue 
    8082             
  • src/sas/sascalc/dataloader/readers/xml_reader.py

    r7f75a3f r235f514  
    1818from lxml import etree 
    1919from lxml.builder import E 
     20 
     21logger = logging.getLogger(__name__) 
    2022 
    2123PARSER = etree.ETCompatXMLParser(remove_comments=True, remove_pis=False) 
     
    7072            self.xmldoc = etree.parse(self.xml, parser=PARSER) 
    7173            self.xmlroot = self.xmldoc.getroot() 
    72         except etree.XMLSyntaxError: 
    73             raise 
     74        except etree.XMLSyntaxError as xml_error: 
     75            logger.info(xml_error) 
    7476        except Exception: 
    7577            self.xml = None 
     
    8890            self.xmlroot = etree.fromstring(tag_soup) 
    8991        except etree.XMLSyntaxError as xml_error: 
    90             logging.info(xml_error) 
     92            logger.info(xml_error) 
    9193        except Exception: 
    9294            self.xml = None 
     
    102104            self.schemadoc = etree.parse(self.schema, parser=PARSER) 
    103105        except etree.XMLSyntaxError as xml_error: 
    104             logging.info(xml_error) 
     106            logger.info(xml_error) 
    105107        except Exception: 
    106108            self.schema = None 
     
    238240        :param name: The name of the element to be created 
    239241        """ 
    240         if attrib == None: 
     242        if attrib is None: 
    241243            attrib = {} 
    242244        return etree.Element(name, attrib, nsmap) 
     
    297299        """ 
    298300        text = str(text) 
    299         if attrib == None: 
     301        if attrib is None: 
    300302            attrib = {} 
    301303        elem = E(elementname, attrib, text) 
  • src/sas/sascalc/dataloader/readers/cansas_reader_HDF5.py

    rc94280c r7f75a3f  
    1313    TransmissionSpectrum, Detector 
    1414from sas.sascalc.dataloader.data_info import combine_data_info_with_plottable 
     15from sas.sascalc.dataloader.loader_exceptions import FileContentsException 
    1516 
    1617 
     
    7576            if extension in self.ext or self.allow_all: 
    7677                # Load the data file 
    77                 self.raw_data = h5py.File(filename, 'r') 
     78                try: 
     79                    self.raw_data = h5py.File(filename, 'r') 
     80                except Exception as e: 
     81                    raise FileContentsException, e 
    7882                # Read in all child elements of top level SASroot 
    7983                self.read_children(self.raw_data, []) 
Note: See TracChangeset for help on using the changeset viewer.