Changeset 9220e89c in sasview for src/sas/sascalc/dataloader/readers
- Timestamp:
- Nov 20, 2018 10:55:05 AM (6 years ago)
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/readers/cansas_reader_HDF5.py
ra165bee r9220e89c 14 14 from ..loader_exceptions import FileContentsException, DefaultReaderException 15 15 from ..file_reader_base_class import FileReader, decode 16 17 try: 18 basestring 19 except NameError: # CRUFT: python 2 support 20 basestring = str 16 21 17 22 … … 630 635 :param parent_list: List of names of parent elements 631 636 """ 632 if self._is 2d(value):637 if self._is_2d_not_multi_frame(value): 633 638 self.current_dataset = plottable_2D() 634 639 else: … … 639 644 640 645 @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] 652 655 return iterable 653 656 … … 671 674 i_axes = attrs.get("I_axes", ["Q"]) 672 675 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) 675 677 keys = value.keys() 676 678 # Assign attributes to appropriate class variables 679 self.q_names = [i_axes[int(v)] for v in self.as_list_or_array(q_indices)] 677 680 self.mask_name = attrs.get("mask") 678 for val in q_indices:679 self.q_names.append(i_axes[val])680 681 self.i_name = signal 681 682 self.i_node = value.get(self.i_name) … … 699 700 self.i_uncertainties_name = i_vals.attrs.get("uncertainty") 700 701 701 def _is 2d(self, value, i_base="", q_base=[]):702 def _is_2d_not_multi_frame(self, value, i_base="", q_base=""): 702 703 """ 703 704 A private class to determine if the data set is 1d or 2d. … … 709 710 i_basename = i_base if i_base != "" else self.i_name 710 711 i_vals = value.get(i_basename) 711 q_basename = q_base if q_base != []else self.q_names712 q_basename = q_base if q_base != "" else self.q_names 712 713 q_vals = value.get(q_basename[0]) 713 self.multi_frame = True if(i_vals is not None and q_vals is not None714 715 and len(q_vals.shape) == 1) else False716 return (i_vals is not None and i_vals.shape is not None717 and len(i_vals.shape) != 1 andnot 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) 718 719 719 720 def _create_unique_key(self, dictionary, name, numb=0):
Note: See TracChangeset
for help on using the changeset viewer.