Changeset b204004 in sasview for src/sas/sascalc


Ignore:
Timestamp:
Oct 17, 2018 4:20:16 PM (6 years ago)
Author:
krzywon
Branches:
master, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, unittest-saveload
Children:
845144e
Parents:
b1ec23d
Message:

Remove unneeded shape check, give better error when saving fails, and data info cleanup.

File:
1 edited

Legend:

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

    r926ece5 rb204004  
    104104        self.errors = set() 
    105105        self.logging = [] 
    106         self.q_name = [] 
     106        self.q_names = [] 
    107107        self.mask_name = u'' 
    108108        self.i_name = u'' 
    109109        self.i_node = u'' 
    110         self.q_uncertainties = None 
    111         self.q_resolutions = None 
    112         self.i_uncertainties = u'' 
     110        self.i_uncertainties_name = u'' 
     111        self.q_uncertainty_names = [] 
     112        self.q_resolution_names = [] 
    113113        self.parent_class = u'' 
    114114        self.detector = Detector() 
     
    240240            self.current_dataset.y = data_set.flatten() 
    241241            self.current_dataset.yaxis("Intensity", unit) 
    242         elif key == self.i_uncertainties: 
     242        elif key == self.i_uncertainties_name: 
    243243            self.current_dataset.dy = data_set.flatten() 
    244         elif key in self.q_name: 
     244        elif key in self.q_names: 
    245245            self.current_dataset.xaxis("Q", unit) 
    246246            self.current_dataset.x = data_set.flatten() 
    247         elif key in self.q_uncertainties or key in self.q_resolutions: 
    248             if (len(self.q_resolutions) > 1 
    249                     and np.where(self.q_resolutions == key)[0] == 0): 
     247        elif key in self.q_resolution_names: 
     248            if (len(self.q_resolution_names) > 1 
     249                    and np.where(self.q_resolution_names == key)[0] == 0): 
    250250                self.current_dataset.dxw = data_set.flatten() 
    251             elif (len(self.q_resolutions) > 1 
    252                   and np.where(self.q_resolutions == key)[0] == 1): 
     251            elif (len(self.q_resolution_names) > 1 
     252                  and np.where(self.q_resolution_names == key)[0] == 1): 
     253                self.current_dataset.dxl = data_set.flatten() 
     254            else: 
     255                self.current_dataset.dx = data_set.flatten() 
     256        elif key in self.q_uncertainty_names: 
     257            if (len(self.q_uncertainty_names) > 1 
     258                    and np.where(self.q_uncertainty_names == key)[0] == 0): 
     259                self.current_dataset.dxw = data_set.flatten() 
     260            elif (len(self.q_uncertainty_names) > 1 
     261                  and np.where(self.q_uncertainty_names == key)[0] == 1): 
    253262                self.current_dataset.dxl = data_set.flatten() 
    254263            else: 
     
    264273            self.current_dataset.data = data_set 
    265274            self.current_dataset.zaxis("Intensity", unit) 
    266         elif key == self.i_uncertainties: 
     275        elif key == self.i_uncertainties_name: 
    267276            self.current_dataset.err_data = data_set.flatten() 
    268         elif key in self.q_name: 
     277        elif key in self.q_names: 
    269278            self.current_dataset.xaxis("Q_x", unit) 
    270279            self.current_dataset.yaxis("Q_y", unit) 
    271             if self.q_name[0] == self.q_name[1]: 
     280            if self.q_names[0] == self.q_names[1]: 
    272281                # All q data in a single array 
    273282                self.current_dataset.qx_data = data_set[0] 
    274283                self.current_dataset.qy_data = data_set[1] 
    275             elif self.q_name.index(key) == 0: 
     284            elif self.q_names.index(key) == 0: 
    276285                self.current_dataset.qx_data = data_set 
    277             elif self.q_name.index(key) == 1: 
     286            elif self.q_names.index(key) == 1: 
    278287                self.current_dataset.qy_data = data_set 
    279         elif key in self.q_uncertainties or key in self.q_resolutions: 
    280             if ((self.q_uncertainties[0] == self.q_uncertainties[1]) or 
    281                     (self.q_resolutions[0] == self.q_resolutions[1])): 
     288        elif key in self.q_uncertainty_names or key in self.q_resolution_names: 
     289            if ((self.q_uncertainty_names[0] == self.q_uncertainty_names[1]) or 
     290                    (self.q_resolution_names[0] == self.q_resolution_names[1])): 
    282291                # All q data in a single array 
    283292                self.current_dataset.dqx_data = data_set[0].flatten() 
    284293                self.current_dataset.dqy_data = data_set[1].flatten() 
    285             elif (self.q_uncertainties.index(key) == 0 or 
    286                   self.q_resolutions.index(key) == 0): 
     294            elif (self.q_uncertainty_names.index(key) == 0 or 
     295                  self.q_resolution_names.index(key) == 0): 
    287296                self.current_dataset.dqx_data = data_set.flatten() 
    288             elif (self.q_uncertainties.index(key) == 1 or 
    289                   self.q_resolutions.index(key) == 1): 
     297            elif (self.q_uncertainty_names.index(key) == 1 or 
     298                  self.q_resolution_names.index(key) == 1): 
    290299                self.current_dataset.dqy_data = data_set.flatten() 
    291300                self.current_dataset.yaxis("Q_y", unit) 
     
    541550                (n_rows, n_cols) = dataset.data.shape 
    542551                flat_qy = dataset.qy_data[0::n_cols].flatten() 
     552                # For 2D arrays of Qx and Qy, the Q value should be constant 
     553                # along each row -OR- each column. The direction is not 
     554                # specified in the NXcanSAS standard. 
    543555                if flat_qy[0] == flat_qy[1]: 
    544556                    flat_qy = np.transpose(dataset.qy_data)[0::n_cols].flatten() 
    545557                dataset.y_bins = np.unique(flat_qy) 
    546558                flat_qx = dataset.qx_data[0::n_rows].flatten() 
     559                # For 2D arrays of Qx and Qy, the Q value should be constant 
     560                # along each row -OR- each column. The direction is not 
     561                # specified in the NXcanSAS standard. 
    547562                if flat_qx[0] == flat_qx[1]: 
    548563                    flat_qx = np.transpose(dataset.qx_data)[0::n_rows].flatten() 
     
    588603            self.current_dataset = plottable_1D(x, y) 
    589604        self.current_datainfo.filename = self.raw_data.filename 
    590         self.mask_name = "" 
    591         self.i_name = "" 
    592         self.i_node = "" 
    593         self.q_name = [] 
    594         self.q_uncertainties = [] 
    595         self.q_resolutions = [] 
    596         self.i_uncertainties = "" 
     605        self.mask_name = u'' 
     606        self.i_name = u'' 
     607        self.i_node = u'' 
     608        self.i_uncertainties_name = u'' 
     609        self.q_names = [] 
     610        self.q_uncertainty_names = [] 
     611        self.q_resolution_names = [] 
    597612 
    598613    @staticmethod 
     
    622637        self.mask_name = attrs.get("mask") 
    623638        for val in q_indices: 
    624             self.q_name.append(i_axes[val]) 
     639            self.q_names.append(i_axes[val]) 
    625640        self.i_name = signal 
    626641        self.i_node = value.get(self.i_name) 
    627         for item in self.q_name: 
     642        for item in self.q_names: 
    628643            if item in keys: 
    629644                q_vals = value.get(item) 
    630645                if q_vals.attrs.get("uncertainties") is not None: 
    631                     self.q_uncertainties = q_vals.attrs.get("uncertainties") 
     646                    self.q_uncertainty_names = q_vals.attrs.get("uncertainties") 
    632647                elif q_vals.attrs.get("uncertainty") is not None: 
    633                     self.q_uncertainties = q_vals.attrs.get("uncertainty") 
    634                 if isinstance(self.q_uncertainties, basestring): 
    635                     self.q_uncertainties = self.q_uncertainties.split(",") 
     648                    self.q_uncertainty_names = q_vals.attrs.get("uncertainty") 
     649                if isinstance(self.q_uncertainty_names, basestring): 
     650                    self.q_uncertainty_names = self.q_uncertainty_names.split(",") 
    636651                if q_vals.attrs.get("resolutions") is not None: 
    637                     self.q_resolutions = q_vals.attrs.get("resolutions") 
    638                 if isinstance(self.q_resolutions, basestring): 
    639                     self.q_resolutions = self.q_resolutions.split(",") 
     652                    self.q_resolution_names = q_vals.attrs.get("resolutions") 
     653                if isinstance(self.q_resolution_names, basestring): 
     654                    self.q_resolution_names = self.q_resolution_names.split(",") 
    640655        if self.i_name in keys: 
    641656            i_vals = value.get(self.i_name) 
    642             self.i_uncertainties = i_vals.attrs.get("uncertainties") 
    643             if self.i_uncertainties is None: 
    644                 self.i_uncertainties = i_vals.attrs.get("uncertainty") 
     657            self.i_uncertainties_name = i_vals.attrs.get("uncertainties") 
     658            if self.i_uncertainties_name is None: 
     659                self.i_uncertainties_name = i_vals.attrs.get("uncertainty") 
    645660 
    646661    def _is2d(self, value, basename="I"): 
Note: See TracChangeset for help on using the changeset viewer.