Changeset afbd172 in sasview for src/sas/sascalc/file_converter


Ignore:
Timestamp:
Aug 18, 2016 10:19:09 AM (8 years ago)
Author:
lewis
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.1.1, release-4.1.2, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
7bd6860a
Parents:
eb98f24
git-author:
Lewis O'Driscoll <lewis.o'driscoll@…> (08/18/16 10:18:22)
git-committer:
Lewis O'Driscoll <lewis.o'driscoll@…> (08/18/16 10:19:09)
Message:

Pass 2D data dimesnsions to NXcanSASWriter to allow saving of non-sqaure data sets

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/file_converter/nxcansas_writer.py

    reb98f24 rafbd172  
    2222    """ 
    2323 
    24     def write(self, dataset, filename): 
     24    def write(self, dataset, filename, dimensions=[]): 
    2525        """ 
    2626        Write an array of Data1d or Data2D objects to an NXcanSAS file, as 
     
    7979                self._write_1d_data(data_obj, data_entry) 
    8080            elif isinstance(data_obj, Data2D): 
    81                 self._write_2d_data(data_obj, data_entry) 
     81                self._write_2d_data(data_obj, data_entry, dimensions) 
    8282            i += 1 
    8383 
     
    137137 
    138138        # TODO: implement writing SASnote 
    139         i = 0 
     139        i = 1 
    140140        note_entry = sasentry.create_group('sasnote{0:0=2d}'.format(i)) 
    141141        note_entry.attrs['canSAS_class'] = 'SASnote' 
     
    158158        data_entry.create_dataset('Idev', data=data_obj.dy) 
    159159 
    160     def _write_2d_data(self, data, data_entry): 
     160    def _write_2d_data(self, data, data_entry, dimensions): 
    161161        """ 
    162162        Writes the contents of a Data2D object to a SASdata h5py Group 
     
    170170        data_entry.attrs['Q_indicies'] = [0,1] 
    171171 
    172         # Calculate rows and columns, assuming detector is square 
    173         # Same logic as used in PlotPanel.py _get_bins 
    174         n_cols = int(np.floor(np.sqrt(len(data.qy_data)))) 
    175         n_rows = int(np.floor(len(data.qy_data) / n_cols)) 
     172        (n_rows, n_cols) = (None, None) 
     173        try: 
     174            (n_rows, n_cols) = dimensions.pop(0) 
     175        except: 
     176            pass 
    176177 
    177         if n_rows * n_cols != len(data.qy_data): 
    178             raise ValueError("Unable to calculate dimensions of data") 
     178        if n_rows == None and n_cols == None: 
     179            # Calculate rows and columns, assuming detector is square 
     180            # Same logic as used in PlotPanel.py _get_bins 
     181            n_cols = int(np.floor(np.sqrt(len(data.qy_data)))) 
     182            n_rows = int(np.floor(len(data.qy_data) / n_cols)) 
     183 
     184            if n_rows * n_cols != len(data.qy_data): 
     185                raise ValueError("Unable to calculate dimensions of 2D data") 
    179186 
    180187        I = np.reshape(data.data, (n_rows, n_cols)) 
    181         dI = np.reshape(data.err_data, (n_rows, n_cols)) 
     188        dI = np.zeros((n_rows, n_cols)) 
     189        if not all(data.err_data == [None]): 
     190            dI = np.reshape(data.err_data, (n_rows, n_cols)) 
    182191        qx =  np.reshape(data.qx_data, (n_rows, n_cols)) 
    183192        qy = np.reshape(data.qy_data, (n_rows, n_cols)) 
Note: See TracChangeset for help on using the changeset viewer.