Changeset 9220e89c in sasview


Ignore:
Timestamp:
Nov 20, 2018 10:55:05 AM (6 years ago)
Author:
Jeff Krzywon <jkrzywon@…>
Branches:
master, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249
Children:
c7c8143
Parents:
c222c27
Message:

Code cleanup and py3 compatibility fixes.

Location:
src/sas
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/dataloader/readers/cansas_reader_HDF5.py

    ra165bee r9220e89c  
    1414from ..loader_exceptions import FileContentsException, DefaultReaderException 
    1515from ..file_reader_base_class import FileReader, decode 
     16 
     17try: 
     18  basestring 
     19except NameError:  # CRUFT: python 2 support 
     20  basestring = str 
    1621 
    1722 
     
    630635        :param parent_list: List of names of parent elements 
    631636        """ 
    632         if self._is2d(value): 
     637        if self._is_2d_not_multi_frame(value): 
    633638            self.current_dataset = plottable_2D() 
    634639        else: 
     
    639644 
    640645    @staticmethod 
    641     def check_is_list_or_array(iterable): 
    642         try: 
    643             iter(iterable) 
    644             if (not isinstance(iterable, np.ndarray) and not isinstance( 
    645                     iterable, list)) or (isinstance(iterable, basestring)): 
    646                 raise TypeError 
    647         except TypeError: 
    648             if isinstance(iterable, basestring): 
    649                 iterable = iterable.split(",") 
    650             else: 
    651                 iterable = [iterable] 
     646    def as_list_or_array(iterable): 
     647        """ 
     648        Return value as a list if not already a list or array. 
     649        :param iterable: 
     650        :return: 
     651        """ 
     652        if not (isinstance(iterable, np.ndarray) or isinstance(iterable, list)): 
     653            iterable = iterable.split(",") if isinstance(iterable, basestring)\ 
     654                else [iterable] 
    652655        return iterable 
    653656 
     
    671674        i_axes = attrs.get("I_axes", ["Q"]) 
    672675        q_indices = attrs.get("Q_indices", [0]) 
    673         q_indices = map(int, self.check_is_list_or_array(q_indices)) 
    674         i_axes = self.check_is_list_or_array(i_axes) 
     676        i_axes = self.as_list_or_array(i_axes) 
    675677        keys = value.keys() 
    676678        # Assign attributes to appropriate class variables 
     679        self.q_names = [i_axes[int(v)] for v in self.as_list_or_array(q_indices)] 
    677680        self.mask_name = attrs.get("mask") 
    678         for val in q_indices: 
    679             self.q_names.append(i_axes[val]) 
    680681        self.i_name = signal 
    681682        self.i_node = value.get(self.i_name) 
     
    699700                self.i_uncertainties_name = i_vals.attrs.get("uncertainty") 
    700701 
    701     def _is2d(self, value, i_base="", q_base=[]): 
     702    def _is_2d_not_multi_frame(self, value, i_base="", q_base=""): 
    702703        """ 
    703704        A private class to determine if the data set is 1d or 2d. 
     
    709710        i_basename = i_base if i_base != "" else self.i_name 
    710711        i_vals = value.get(i_basename) 
    711         q_basename = q_base if q_base != [] else self.q_names 
     712        q_basename = q_base if q_base != "" else self.q_names 
    712713        q_vals = value.get(q_basename[0]) 
    713         self.multi_frame = True if (i_vals is not None and q_vals is not None 
    714                                     and len(i_vals.shape) != 1 
    715                                     and len(q_vals.shape) == 1) else False 
    716         return (i_vals is not None and i_vals.shape is not None 
    717                 and len(i_vals.shape) != 1 and not self.multi_frame) 
     714        self.multi_frame = (i_vals is not None and q_vals is not None 
     715                            and len(i_vals.shape) != 1 
     716                            and len(q_vals.shape) == 1) 
     717        return (i_vals is not None and len(i_vals.shape) != 1 
     718                and not self.multi_frame) 
    718719 
    719720    def _create_unique_key(self, dictionary, name, numb=0): 
  • src/sas/sascalc/file_converter/nxcansas_writer.py

    r2ca5d57b r9220e89c  
    8787                    entry[names[2]].attrs['units'] = units 
    8888 
    89         valid_data = all([issubclass(d.__class__, (Data1D, Data2D)) for d in 
    90                           dataset]) 
     89        valid_data = all([isinstance(d, (Data1D, Data2D)) for d in dataset]) 
    9190        if not valid_data: 
    9291            raise ValueError("All entries of dataset must be Data1D or Data2D" 
  • src/sas/sasgui/guiframe/gui_manager.py

    r9f45f83 r9220e89c  
    25802580            # Instantiate a loader 
    25812581            loader = Loader() 
    2582             if os.path.splitext(mypath)[1].lower() == '.dat': 
     2582            ext = os.path.splitext(mypath)[1].lower() 
     2583            if ext == '.dat': 
    25832584                # Make sure the ext included in the file name 
    25842585                # especially on MAC 
    25852586                fileName = os.path.splitext(path)[0] + ext_format 
    25862587                loader.save(fileName, data, ext_format) 
    2587             elif os.path.splitext(mypath)[1].lower() == '.h5': 
     2588            elif ext == '.h5': 
    25882589                # Make sure the ext included in the file name 
    25892590                # especially on MAC 
Note: See TracChangeset for help on using the changeset viewer.