Changeset d398285 in sasview


Ignore:
Timestamp:
Jul 13, 2016 6:52:08 AM (8 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.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
0f1e140
Parents:
dd5bf63
Message:

#237: Modified the CanSAS HDF5 reader to read the latest version output from Mantid. Fixed the CanSAS XML reader so the axis titles and units are displayed properly.

Files:
2 added
3 edited

Legend:

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

    rb699768 rd398285  
    106106                       "unit" : "x_unit", 
    107107                       "attributes" : {"unit" : 
    108                                        {"variable" : "{0}._xunit = \"{1}\"", 
     108                                       {"variable" : "{0}.xaxis(\"Q\", \'{1}\')", 
    109109                                        "storeas" : "content" 
    110110                                       } 
     
    114114                       "unit" : "y_unit", 
    115115                       "attributes" : {"unit" : 
    116                                        {"variable" : "{0}._yunit = \"{1}\"", 
     116                                       {"variable" : "{0}.yaxis(\"Intensity\", \'{1}\')", 
    117117                                        "storeas" : "content" 
    118118                                       } 
  • src/sas/sascalc/dataloader/readers/cansas_reader.py

    raf09f48 rd398285  
    1212#copyright 2008,2009 University of Tennessee 
    1313############################################################################# 
    14  
     14##TODO: Replace 1/A with 1/\AA for Angstorm 
     15##TODO: Put in x-axis and y-axis information 
    1516import logging 
    1617import numpy 
     
    456457                    attrib_variable = cansas_attrib.get("variable") 
    457458                    if key == 'unit' and unit != '': 
     459                        if unit == "1/A": 
     460                            unit = "A^{-1}" 
     461                        elif unit == "1/cm": 
     462                            unit = "cm^{-1}" 
    458463                        attrib_value = unit 
    459464                    else: 
  • src/sas/sascalc/dataloader/readers/cansas_reader_HDF5.py

    rad52d31 rd398285  
    109109            attr_keys = value.attrs.keys() 
    110110            attr_values = value.attrs.values() 
    111             class_name = value.attrs.get(u'NX_class') 
     111            if value.attrs.get(u'canSAS_class') is not None: 
     112                class_name = value.attrs.get(u'canSAS_class') 
     113            else: 
     114                class_name = value.attrs.get(u'NX_class') 
    112115            if class_name is not None: 
    113116                class_prog = re.compile(class_name) 
     
    131134                for data_point in data_set: 
    132135                    ## Top Level Meta Data 
     136                    unit = self._get_unit(value) 
    133137                    if key == u'definition': 
    134138                        self.current_dataset.meta_data['reader'] = data_point 
     
    142146                    ## I and Q Data 
    143147                    elif key == u'I': 
    144                         i_unit = value.attrs.get(u'unit') 
    145148                        if type(self.current_dataset) is Data2D: 
    146149                            self.current_dataset.data = np.append(self.current_dataset.data, data_point) 
    147                             self.current_dataset.zaxis("Intensity (%s)" % (i_unit), i_unit) 
     150                            self.current_dataset.zaxis("Intensity", unit) 
    148151                        else: 
    149152                            self.current_dataset.y = np.append(self.current_dataset.y, data_point) 
    150                             self.current_dataset.yaxis("Intensity (%s)" % (i_unit), i_unit) 
     153                            self.current_dataset.yaxis("Intensity", unit) 
    151154                    elif key == u'Idev': 
    152155                        if type(self.current_dataset) is Data2D: 
     
    155158                            self.current_dataset.dy = np.append(self.current_dataset.dy, data_point) 
    156159                    elif key == u'Q': 
    157                         q_unit = value.attrs.get(u'unit') 
    158                         self.current_dataset.xaxis("Q (%s)" % (q_unit), q_unit) 
     160                        self.current_dataset.xaxis("Q", unit) 
    159161                        if type(self.current_dataset) is Data2D: 
    160162                            self.current_dataset.q = np.append(self.current_dataset.q, data_point) 
     
    162164                            self.current_dataset.x = np.append(self.current_dataset.x, data_point) 
    163165                    elif key == u'Qy': 
    164                         q_unit = value.attrs.get(u'unit') 
    165                         self.current_dataset.yaxis("Q (%s)" % (q_unit), q_unit) 
     166                        self.current_dataset.yaxis("Q_y", unit) 
    166167                        self.current_dataset.qy_data = np.append(self.current_dataset.qy_data, data_point) 
    167168                    elif key == u'Qydev': 
    168169                        self.current_dataset.dqy_data = np.append(self.current_dataset.dqy_data, data_point) 
    169170                    elif key == u'Qx': 
    170                         q_unit = value.attrs.get(u'unit') 
    171                         self.current_dataset.xaxis("Q (%s)" % (q_unit), q_unit) 
     171                        self.current_dataset.xaxis("Q_x", unit) 
    172172                        self.current_dataset.qx_data = np.append(self.current_dataset.qx_data, data_point) 
    173173                    elif key == u'Qxdev': 
     
    191191                    elif key == u'SDD' and parent == u'SASdetector': 
    192192                        self.detector.distance = data_point 
    193                         self.detector.distance_unit = value.attrs.get(u'unit') 
     193                        self.detector.distance_unit = unit 
    194194                    elif key == u'SSD' and parent == u'SAScollimation': 
    195195                        self.collimation.length = data_point 
    196                         self.collimation.length_unit = value.attrs.get(u'unit') 
     196                        self.collimation.length_unit = unit 
    197197                    elif key == u'name' and parent == u'SAScollimation': 
    198198                        self.collimation.name = data_point 
     
    221221                    elif key == u'wavelength' and parent == u'SASdata': 
    222222                        self.source.wavelength = data_point 
    223                         self.source.wavelength.unit = value.attrs.get(u'unit') 
     223                        self.source.wavelength.unit = unit 
    224224                    elif key == u'radiation' and parent == u'SASsource': 
    225225                        self.source.radiation = data_point 
     
    426426            name = self._create_unique_key(dictionary, name, numb) 
    427427        return name 
     428 
     429    def _get_unit(self, value): 
     430        """ 
     431        Find the unit for a particular value within the h5py dictionary 
     432 
     433        :param value: attribute dictionary for a particular value set 
     434        :return: 
     435        """ 
     436        unit = value.attrs.get(u'units') 
     437        if unit == None: 
     438            unit = value.attrs.get(u'unit') 
     439 
     440        ## Convert the unit formats 
     441        if unit == "1/A": 
     442            unit = "A^{-1}" 
     443        elif unit == "1/cm": 
     444            unit = "cm^{-1}" 
     445 
     446        return unit 
Note: See TracChangeset for help on using the changeset viewer.