Changeset 76cd1ae in sasview


Ignore:
Timestamp:
Jan 14, 2014 1:53:36 PM (10 years ago)
Author:
Jeff Krzywon <jeffery.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:
16bd5ca
Parents:
083e993
Message:

Fix for the datainfo window not loading and bug fixes for the cansas data reader.

Fixes/changes:
(1) datainfo window is now loading for every data file I can test
(2) transmission spectrum information (but not data) is listed in datainfo window
(3) more than one transmission spectra can be loaded for each Data1D object
(4) fixed a bug in the cansas reader that allowed any file to be loaded as data if and only if another data file was already loaded
(5) fixed the cansas writer to include transmission spectrum data and output data in strict canSAS format
(6) increased the pylint score of cansas_constants.py to above 7
(7) increased the pylint score for all files I have modified

Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • src/sans/dataloader/data_info.py

    rbe577e7 r76cd1ae  
    425425    def __str__(self): 
    426426        _str  = "Transmission Spectrum:\n" 
    427         _str += "   Name:       {0}".format(self.name) 
    428         _str += "   Timestamp:  {1}".format(self.timestamp) 
    429         _str += "   Wavelength [{0}] | Transmission [{1}] | Trans Dev [{2}]\n".format(self.wavelength_unit, self.transmission_unit, self.transmission_deviation_unit) 
    430         for i in range(len(self.wavelength)): 
    431             _str += "   {0}, {1}".format(self.wavelength[i], self.transmission[i]) 
    432             if len(self.transmission_deviation > i): 
    433                 _str += ", {0}".format(self.transmission_deviation[i]) 
    434             _str += "\n" 
     427        _str += "   Name:             \t{0}\n".format(self.name) 
     428        _str += "   Timestamp:        \t{0}\n".format(self.timestamp) 
     429        _str += "   Wavelength unit:  \t{0}\n".format(self.wavelength_unit) 
     430        _str += "   Transmission unit:\t{0}\n".format(self.transmission_unit) 
     431        _str += "   Trans. Dev. unit:  \t{0}\n".format(\ 
     432                                            self.transmission_deviation_unit) 
     433        length_list = [len(self.wavelength), len(self.transmission), \ 
     434                len(self.transmission_deviation)] 
     435        _str += "   Number of Pts:    \t{0}\n".format(max(length_list)) 
    435436        return _str 
    436437     
     
    498499        self.collimation = [] 
    499500        ## Transmission Spectrum 
    500         self.trans_spectrum = TransmissionSpectrum() 
     501        self.trans_spectrum = [] 
    501502        ## Additional meta-data 
    502503        self.meta_data  = {} 
     
    533534        for item in self.notes: 
    534535            _str += "%s\n" % str(item) 
    535  
     536        for item in self.trans_spectrum: 
     537            _str += "%s\n" % str(item) 
    536538        return _str 
    537539             
     
    757759            clone = Data1D(x, y, dx=dx, dy=dy) 
    758760         
    759         clone.title       = self.title 
    760         clone.run         = self.run 
    761         clone.filename    = self.filename 
    762         clone.instrument  = self.instrument 
    763         clone.notes       = deepcopy(self.notes) 
    764         clone.process     = deepcopy(self.process) 
    765         clone.detector    = deepcopy(self.detector) 
    766         clone.sample      = deepcopy(self.sample) 
    767         clone.source      = deepcopy(self.source) 
    768         clone.collimation = deepcopy(self.collimation) 
    769         clone.meta_data   = deepcopy(self.meta_data) 
    770         clone.errors      = deepcopy(self.errors) 
     761        clone.title          = self.title 
     762        clone.run            = self.run 
     763        clone.filename       = self.filename 
     764        clone.instrument     = self.instrument 
     765        clone.notes          = deepcopy(self.notes) 
     766        clone.process        = deepcopy(self.process) 
     767        clone.detector       = deepcopy(self.detector) 
     768        clone.sample         = deepcopy(self.sample) 
     769        clone.source         = deepcopy(self.source) 
     770        clone.collimation    = deepcopy(self.collimation) 
     771        clone.trans_spectrum = deepcopy(self.trans_spectrum) 
     772        clone.meta_data      = deepcopy(self.meta_data) 
     773        clone.errors         = deepcopy(self.errors) 
    771774         
    772775        return clone 
  • src/sans/dataloader/readers/cansas_constants.py

    r75eeb425 r76cd1ae  
    1 ## Left off at SASInstrument, line 178 
    2  
     1""" 
     2Information relating to the CanSAS data format. These constants are used in 
     3the cansas_reader.py file to read in any version of the cansas format. 
     4""" 
    35class cansasConstants: 
     6     
     7    ns = '' 
     8    format = '' 
     9     
     10    def __init__(self): 
     11        self.ns = self.CANSAS_NS 
     12        self.format = self.CANSAS_FORMAT 
     13    """ 
     14    CANSAS_NS holds the base namespace and the default schema file information 
     15    """ 
    416    CANSAS_NS = { 
    517                 "1.0" : { 
     
    1224                          } 
    1325                 } 
     26     
     27    """ 
     28    The constants below hold information on where to store the CanSAS data when 
     29    loaded in using sasview 
     30    """ 
     31    META_DATA = "{0}.meta_data[\"{2}\"] = \"{1}\"" 
     32    ANY = { 
     33           "variable" : "{0}.meta_data[\"{2}\"] = \'{1}\'", 
     34           "storeas" : "content", 
     35           } 
     36    TITLE = {"variable" : "{0}.title = \"{1}\""} 
     37    SASNOTE = {"variable" : "{0}.notes.append(\'{1}\')"} 
     38    SASPROCESS_TERM = { 
     39                       "variable" : None, 
     40                       "attributes" : { 
     41                                       "unit" : {"variable" : None}, 
     42                                       "name" : {"variable" : None} 
     43                                       } 
     44                       } 
     45    SASPROCESS_SASPROCESSNOTE = { 
     46                                 "variable" : None, 
     47                                 "children" : {"<any>" : ANY} 
     48                                 } 
     49    SASPROCESS = { 
     50                  "variable" : None, 
     51                  "children" : { 
     52                                "name" : {"variable" : "{0}.name = \'{1}\'"}, 
     53                               "date" : {"variable" : "{0}.date = \'{1}\'"}, 
     54                               "description" : {"variable" : \ 
     55                                                "{0}.description = \'{1}\'"}, 
     56                               "term" : SASPROCESS_TERM, 
     57                               "SASprocessnote" : SASPROCESS_SASPROCESSNOTE, 
     58                               "<any>" : ANY 
     59                               }, 
     60                 } 
     61    RUN = { 
     62           "variable" : "{0}.run.append(\"{1}\")", 
     63           "attributes" : {"name" : {"variable" : \ 
     64                                     "{0}.run_name[node_value] = \"{1}\""}} 
     65           } 
     66    SASDATA_IDATA_Q = { 
     67                       "variable" : "{0}.x = numpy.append({0}.x, {1})", 
     68                       "unit" : "x_unit", 
     69                       "attributes" : { 
     70                                       "unit" : { 
     71                                                 "variable" : \ 
     72                                                    "{0}._xunit = \"{1}\"", 
     73                                                    "storeas" : "content" 
     74                                                    } 
     75                                       } 
     76                       } 
     77    SASDATA_IDATA_I = { 
     78                       "variable" : "{0}.y = numpy.append({0}.y, {1})", 
     79                       "unit" : "y_unit", 
     80                       "attributes" : { 
     81                                       "unit" : { 
     82                                                 "variable" : \ 
     83                                                    "{0}._yunit = \"{1}\"", 
     84                                                    "storeas" : "content" 
     85                                                } 
     86                                       } 
     87                       } 
     88    SASDATA_IDATA_IDEV = { 
     89                          "variable" : \ 
     90                          "{0}.dy = numpy.append({0}.dy, {1})", 
     91                          "unit" : "y_unit", 
     92                          "attributes" : { 
     93                                          "unit" : { 
     94                                                    "variable" : META_DATA, 
     95                                                    "storeas" : "content" 
     96                                                    } 
     97                                          }, 
     98                          } 
     99    SASDATA_IDATA_QDEV = { 
     100                          "variable" : \ 
     101                          "{0}.dx = numpy.append({0}.dx, {1})", 
     102                          "unit" : "x_unit", 
     103                          "attributes" : { 
     104                                          "unit" : { 
     105                                                    "variable" : META_DATA, 
     106                                                    "storeas" : "content" 
     107                                                    } 
     108                                          }, 
     109                          } 
     110    SASDATA_IDATA_DQL = { 
     111                         "variable" : \ 
     112                         "{0}.dxl = numpy.append({0}.dxl, {1})", 
     113                         "unit" : "x_unit", 
     114                         "attributes" : { 
     115                                         "unit" : { 
     116                                                   "variable" : META_DATA, 
     117                                                "storeas" : "content" 
     118                                                } 
     119                                         }, 
     120                         } 
     121    SASDATA_IDATA_DQW = { 
     122                         "variable" : \ 
     123                         "{0}.dxw = numpy.append({0}.dxw, {1})", 
     124                         "unit" : "x_unit", 
     125                         "attributes" : { 
     126                                         "unit" : { 
     127                                                   "variable" : META_DATA, 
     128                                                   "storeas" : "content" 
     129                                                   } 
     130                                         }, 
     131                         } 
     132    SASDATA_IDATA_QMEAN = { 
     133                           "storeas" : "content", 
     134                           "unit" : "x_unit", 
     135                           "variable" : META_DATA, 
     136                           "attributes" : {"unit" : {"variable" : META_DATA}}, 
     137                           } 
     138    SASDATA_IDATA_SHADOWFACTOR = { 
     139                                  "variable" : META_DATA, 
     140                                  "storeas" : "content", 
     141                                  } 
     142    SASDATA_IDATA = { 
     143                     "storeas" : "float", 
     144                     "units_optional" : False, 
     145                     "variable" : None, 
     146                     "attributes" : { 
     147                                     "name" : { 
     148                                               "variable" : META_DATA, 
     149                                               "storeas" : "content", 
     150                                               }, 
     151                                     "timestamp" : { 
     152                                                    "variable" : META_DATA, 
     153                                                    "storeas" : "content", 
     154                                                    } 
     155                                     }, 
     156                     "children" : { 
     157                                   "Q" : SASDATA_IDATA_Q, 
     158                                   "I" : SASDATA_IDATA_I, 
     159                                   "Idev" : SASDATA_IDATA_IDEV, 
     160                                   "Qdev" : SASDATA_IDATA_QDEV, 
     161                                   "dQw" : SASDATA_IDATA_DQW, 
     162                                   "dQl" : SASDATA_IDATA_DQL, 
     163                                   "Qmean" : SASDATA_IDATA_QMEAN, 
     164                                   "Shadowfactor" : SASDATA_IDATA_SHADOWFACTOR, 
     165                                   "<any>" : ANY 
     166                                   } 
     167                   } 
     168    SASDATA = { 
     169               "attributes" : {"name" : {"variable" : META_DATA,}}, 
     170               "variable" : None, 
     171               "children" : { 
     172                             "Idata" : SASDATA_IDATA, 
     173                             "<any>" : ANY 
     174                             } 
     175               } 
     176    SASTRANSSPEC_TDATA_LAMDBA = { 
     177                                 "variable" : "{0}.wavelength.append({1})", 
     178                                 "unit" : "wavelength_unit", 
     179                                 "attributes" : { 
     180                                                 "unit" : { 
     181                                                            "variable" : "{0}.wavelength_unit = \"{1}\"", 
     182                                                            "storeas" : "content" 
     183                                                            } 
     184                                                 } 
     185                                 } 
     186    SASTRANSSPEC_TDATA_T = { 
     187                            "variable" : "{0}.transmission.append({1})", 
     188                            "unit" : "transmission_unit", 
     189                            "attributes" : { 
     190                                            "unit" : { 
     191                                                      "variable" : "{0}.transmission_unit = \"{1}\"", 
     192                                                      "storeas" : "content" 
     193                                                      } 
     194                                            } 
     195                            } 
     196    SASTRANSSPEC_TDATA_TDEV = { 
     197                               "variable" : \ 
     198                                    "{0}.transmission_deviation.append({1})", 
     199                               "unit" : "transmission_deviation_unit", 
     200                                "attributes" : { 
     201                                                "unit" : { 
     202                                                          "variable" : "{0}.transmission_deviation_unit = \"{1}\"", 
     203                                                          "storeas" : "content" 
     204                                                          } 
     205                                                } 
     206                               } 
     207    SASTRANSSPEC_TDATA = { 
     208                          "storeas" : "float", 
     209                          "variable" : None, 
     210                          "children" : { 
     211                                        "Lambda" : SASTRANSSPEC_TDATA_LAMDBA, 
     212                                        "T" : SASTRANSSPEC_TDATA_T, 
     213                                        "Tdev" : SASTRANSSPEC_TDATA_TDEV, 
     214                                        "<any>" : ANY, 
     215                                        } 
     216                          } 
     217    SASTRANSSPEC = { 
     218                    "variable" : None, 
     219                    "children" : { 
     220                                  "Tdata" : SASTRANSSPEC_TDATA, 
     221                                  "<any>" : ANY, 
     222                                  }, 
     223                    "attributes" : {"name" : {"variable" : \ 
     224                                              "{0}.name = \"{1}\""}, 
     225                                    "timestamp" : {"variable" : \ 
     226                                                   "{0}.timestamp = \"{1}\""}, 
     227                                    } 
     228                    } 
     229    SASSAMPLE_THICK = { 
     230                       "variable" : "{0}.sample.thickness = {1}", 
     231                       "unit" : "sample.thickness_unit", 
     232                       "storeas" : "float", 
     233                       "attributes" : { 
     234                                       "units" : { 
     235                                                  "variable" : "{0}.sample.thickness_unit = \"{1}\"", 
     236                                                  "storeas" : "content" 
     237                                                  } 
     238                                       }, 
     239                       } 
     240    SASSAMPLE_TRANS = { 
     241                       "variable" : "{0}.sample.transmission = {1}", 
     242                       "storeas" : "float", 
     243                       } 
     244    SASSAMPLE_TEMP = { 
     245                      "variable" : "{0}.sample.temperature = {1}", 
     246                      "unit" : "sample.temperature_unit", 
     247                      "storeas" : "float", 
     248                      "attributes" : { 
     249                                      "units" : { 
     250                                                 "variable" : "{0}.sample.temperature_unit = \"{1}\"", 
     251                                                 "storeas" : "content" 
     252                                                 } 
     253                                      }, 
     254                      } 
     255    SASSAMPLE_POS_ATTR = { 
     256                          "units" : { 
     257                                     "variable" : \ 
     258                                        "{0}.sample.position_unit = \"{1}\"", 
     259                                     "storeas" : "content" 
     260                                     } 
     261                          } 
     262    SASSAMPLE_POS_X = { 
     263                       "variable" : "{0}.sample.position.x = {1}", 
     264                       "unit" : "sample.position_unit", 
     265                       "storeas" : "float", 
     266                       "attributes" : SASSAMPLE_POS_ATTR 
     267                       } 
     268    SASSAMPLE_POS_Y = { 
     269                       "variable" : "{0}.sample.position.y = {1}", 
     270                       "unit" : "sample.position_unit", 
     271                       "storeas" : "float", 
     272                       "attributes" : SASSAMPLE_POS_ATTR 
     273                       } 
     274    SASSAMPLE_POS_Z = { 
     275                       "variable" : "{0}.sample.position.z = {1}", 
     276                       "unit" : "sample.position_unit", 
     277                       "storeas" : "float", 
     278                       "attributes" : SASSAMPLE_POS_ATTR 
     279                       } 
     280    SASSAMPLE_POS = { 
     281                     "children" : { 
     282                                   "variable" : None, 
     283                                   "x" : SASSAMPLE_POS_X, 
     284                                   "y" : SASSAMPLE_POS_Y, 
     285                                   "z" : SASSAMPLE_POS_Z, 
     286                                   }, 
     287                     } 
     288    SASSAMPLE_ORIENT_ATTR = { 
     289                             "units" : { 
     290                                        "variable" : "{0}.sample.orientation_unit = \"{1}\"", 
     291                                        "storeas" : "content" 
     292                                        } 
     293                             } 
     294    SASSAMPLE_ORIENT_ROLL = { 
     295                             "variable" : "{0}.sample.orientation.x = {1}", 
     296                             "unit" : "sample.orientation_unit", 
     297                             "storeas" : "float", 
     298                             "attributes" : SASSAMPLE_ORIENT_ATTR 
     299                             } 
     300    SASSAMPLE_ORIENT_PITCH = { 
     301                             "variable" : "{0}.sample.orientation.y = {1}", 
     302                             "unit" : "sample.orientation_unit", 
     303                             "storeas" : "float", 
     304                             "attributes" : SASSAMPLE_ORIENT_ATTR 
     305                             } 
     306    SASSAMPLE_ORIENT_YAW = { 
     307                             "variable" : "{0}.sample.orientation.z = {1}", 
     308                             "unit" : "sample.orientation_unit", 
     309                             "storeas" : "float", 
     310                             "attributes" : SASSAMPLE_ORIENT_ATTR 
     311                             } 
     312    SASSAMPLE_ORIENT = { 
     313                        "variable" : None, 
     314                        "children" : { 
     315                                      "roll" : SASSAMPLE_ORIENT_ROLL, 
     316                                      "pitch" : SASSAMPLE_ORIENT_PITCH, 
     317                                      "yaw" : SASSAMPLE_ORIENT_YAW, 
     318                                      }, 
     319                        } 
     320    SASSAMPLE = { 
     321                 "attributes" : {"name" : {\ 
     322                                    "variable" : "{0}.sample.name = \"{1}\""},}, 
     323                 "variable" : None, 
     324                 "children" : { 
     325                               "ID" : {"variable" : "{0}.sample.ID = \"{1}\""}, 
     326                               "thickness" : SASSAMPLE_THICK, 
     327                               "transmission" : SASSAMPLE_TRANS,  
     328                               "temperature" : SASSAMPLE_TEMP,  
     329                               "position" : SASSAMPLE_POS, 
     330                               "orientation" : SASSAMPLE_ORIENT, 
     331                               "details" : {"variable" : \ 
     332                                        "{0}.sample.details.append(\"{1}\")"}, 
     333                               "<any>" : ANY 
     334                               }, 
     335                 } 
     336    SASINSTR_SRC_BEAMSIZE_ATTR = { 
     337                                  "unit" : \ 
     338                                    "{0}.source.beam_size_unit = \"{1}\"", 
     339                                  "storeas" : "content" 
     340                                  } 
     341    SASINSTR_SRC_BEAMSIZE_X = { 
     342                               "variable" : "{0}.source.beam_size.x = {1}", 
     343                               "unit" : "source.beam_size_unit", 
     344                               "storeas" : "float", 
     345                               "attributes" : SASINSTR_SRC_BEAMSIZE_ATTR 
     346                               } 
     347    SASINSTR_SRC_BEAMSIZE_Y = { 
     348                               "variable" : "{0}.source.beam_size.y = {1}", 
     349                               "unit" : "source.beam_size_unit", 
     350                               "storeas" : "float", 
     351                               "attributes" : SASINSTR_SRC_BEAMSIZE_ATTR 
     352                               } 
     353    SASINSTR_SRC_BEAMSIZE_Z = { 
     354                               "variable" : "{0}.source.beam_size.z = {1}", 
     355                               "unit" : "source.beam_size_unit", 
     356                               "storeas" : "float", 
     357                               "attributes" : SASINSTR_SRC_BEAMSIZE_ATTR 
     358                               } 
     359    SASINSTR_SRC_BEAMSIZE = { 
     360                             "attributes" : {"name" : {"variable" : \ 
     361                                        "{0}.source.beam_size_name = \"{1}\""}}, 
     362                             "variable" : None, 
     363                             "children" : { 
     364                                           "x" : SASINSTR_SRC_BEAMSIZE_X, 
     365                                           "y" : SASINSTR_SRC_BEAMSIZE_Y, 
     366                                           "z" : SASINSTR_SRC_BEAMSIZE_Z, 
     367                                           } 
     368                             } 
     369    SASINSTR_SRC_WL = { 
     370                       "variable" : "{0}.source.wavelength = {1}", 
     371                       "unit" : "source.wavelength_unit", 
     372                       "storeas" : "float", 
     373                       "attributes" : { 
     374                                       "unit" : { 
     375                                                 "variable" : "{0}.source.wavelength_unit = \"{1}\"", 
     376                                                 "storeas" : "content" 
     377                                                 }, 
     378                                       } 
     379                       } 
     380    SASINSTR_SRC_WL_MIN = { 
     381                           "variable" : "{0}.source.wavelength_min = {1}", 
     382                           "unit" : "source.wavelength_min_unit", 
     383                           "storeas" : "float", 
     384                           "attributes" : { 
     385                                           "unit" : { 
     386                                                     "variable" : "{0}.source.wavelength_min_unit = \"{1}\"",   
     387                                                     "storeas" : "content" 
     388                                                     }, 
     389                                           } 
     390                           } 
     391    SASINSTR_SRC_WL_MAX = { 
     392                           "variable" : "{0}.source.wavelength_max = {1}", 
     393                           "unit" : "source.wavelength_max_unit", 
     394                           "storeas" : "float", 
     395                           "attributes" : { 
     396                                           "unit" : { 
     397                                                     "variable" : "{0}.source.wavelength_max_unit = \"{1}\"",   
     398                                                     "storeas" : "content" 
     399                                                     }, 
     400                                           } 
     401                           } 
     402    SASINSTR_SRC_WL_SPR = { 
     403                           "variable" : "{0}.source.wavelength_spread = {1}", 
     404                           "unit" : "source.wavelength_spread_unit", 
     405                           "storeas" : "float", 
     406                           "attributes" : { 
     407                                           "unit" : { 
     408                                                     "variable" : "{0}.source.wavelength_spread_unit = \"{1}\"",   
     409                                                     "storeas" : "content" 
     410                                                     }, 
     411                                           } 
     412                           } 
     413    SASINSTR_SRC = { 
     414                    "attributes" : {"name" : {"variable" : "{0}.source.name = \"{1}\""}}, 
     415                    "variable" : None, 
     416                    "children" : { 
     417                                  "radiation" : {"variable" : "{0}.source.radiation = \"{1}\""}, 
     418                                  "beam_size" : SASINSTR_SRC_BEAMSIZE, 
     419                                  "beam_shape" : {"variable" : \ 
     420                                            "{0}.source.beam_shape = \"{1}\""}, 
     421                                  "wavelength" : SASINSTR_SRC_WL, 
     422                                  "wavelength_min" : SASINSTR_SRC_WL_MIN, 
     423                                  "wavelength_max" : SASINSTR_SRC_WL_MAX, 
     424                                  "wavelength_spread" : SASINSTR_SRC_WL_SPR, 
     425                                  }, 
     426                    } 
     427    SASINSTR_COLL_APER_ATTR = { 
     428                               "unit" : { 
     429                                         "variable" : "{0}.size_unit = \"{1}\"", 
     430                                         "storeas" : "content" 
     431                                         },                                     
     432                               } 
     433    SASINSTR_COLL_APER_X = { 
     434                            "variable" : "{0}.size.x = {1}", 
     435                            "unit" : "size_unit", 
     436                            "storeas" : "float", 
     437                            "attributes" : SASINSTR_COLL_APER_ATTR 
     438                            } 
     439    SASINSTR_COLL_APER_Y = { 
     440                            "variable" : "{0}.size.y = {1}", 
     441                            "unit" : "size_unit", 
     442                            "storeas" : "float", 
     443                            "attributes" : SASINSTR_COLL_APER_ATTR 
     444                            } 
     445    SASINSTR_COLL_APER_Z = { 
     446                            "variable" : "{0}.size.z = {1}", 
     447                            "unit" : "size_unit", 
     448                            "storeas" : "float", 
     449                            "attributes" : SASINSTR_COLL_APER_ATTR 
     450                            } 
     451    SASINSTR_COLL_APER_SIZE = { 
     452                               "attributes" : {"unit" : {"variable" : \ 
     453                                                    "{0}.size_unit = \"{1}\""}}, 
     454                               "children" : { 
     455                                             "storeas" : "float", 
     456                                            "x" : SASINSTR_COLL_APER_X, 
     457                                            "y" : SASINSTR_COLL_APER_Y, 
     458                                            "z" : SASINSTR_COLL_APER_Z, 
     459                                            } 
     460                               } 
     461    SASINSTR_COLL_APER_DIST = { 
     462                               "storeas" : "float", 
     463                               "attributes" : { 
     464                                               "storeas" : "content", 
     465                                               "unit" : {"variable" : \ 
     466                                                "{0}.distance_unit = \"{1}\""}}, 
     467                               "variable" : "{0}.distance = {1}", 
     468                               "unit" : "distance_unit", 
     469                               } 
     470    SASINSTR_COLL_APER = { 
     471                          "variable" : None, 
     472                          "attributes" : { 
     473                                          "name" : {"variable" : \ 
     474                                                    "{0}.name = \"{1}\""}, 
     475                                          "type" : {"variable" : \ 
     476                                                    "{0}.type = \"{1}\""}, 
     477                                          }, 
     478                          "children" : { 
     479                                        "size" : SASINSTR_COLL_APER_SIZE, 
     480                                        "distance" : SASINSTR_COLL_APER_DIST 
     481                                        } 
     482                          } 
     483    SASINSTR_COLL = { 
     484                     "attributes" : {"name" : {"variable" : \ 
     485                                               "{0}.name = \"{1}\""}}, 
     486                     "variable" : None, 
     487                     "children" : { 
     488                                   "length" : { 
     489                                            "variable" : "{0}.length = {1}", 
     490                                            "unit" : "length_unit", 
     491                                            "storeas" : "float", 
     492                                            "attributes" : { 
     493                                                            "storeas" : \ 
     494                                                                "content", 
     495                                                            "unit" : {"variable" : "{0}.length_unit = \"{1}\""} 
     496                                                            }, 
     497                                            }, 
     498                                   "aperture" : SASINSTR_COLL_APER, 
     499                                   }, 
     500                     } 
     501    SASINSTR_DET_SDD = { 
     502                        "variable" : "{0}.distance = {1}", 
     503                        "unit" : "distance_unit", 
     504                        "attributes" : { 
     505                                        "unit" : { 
     506                                                  "variable" : \ 
     507                                                  "{0}.distance_unit = \"{1}\"", 
     508                                                  "storeas" : "content" 
     509                                                  } 
     510                                        }, 
     511                        } 
     512    SASINSTR_DET_OFF_ATTR = { 
     513                            "unit" : { 
     514                                      "variable" : "{0}.offset_unit = \"{1}\"", 
     515                                      "storeas" : "content" 
     516                                      }, 
     517                            } 
     518    SASINSTR_DET_OFF_X = { 
     519                         "variable" : "{0}.offset.x = {1}", 
     520                         "unit" : "offset_unit", 
     521                         "attributes" : SASINSTR_DET_OFF_ATTR 
     522                         } 
     523    SASINSTR_DET_OFF_Y = { 
     524                         "variable" : "{0}.offset.y = {1}", 
     525                         "unit" : "offset_unit", 
     526                         "attributes" : SASINSTR_DET_OFF_ATTR 
     527                         } 
     528    SASINSTR_DET_OFF_Z = { 
     529                         "variable" : "{0}.offset.z = {1}", 
     530                         "unit" : "offset_unit", 
     531                         "attributes" : SASINSTR_DET_OFF_ATTR 
     532                         } 
     533    SASINSTR_DET_OFF = { 
     534                        "variable" : None, 
     535                        "children" : { 
     536                                      "x" : SASINSTR_DET_OFF_X, 
     537                                      "y" : SASINSTR_DET_OFF_Y, 
     538                                      "z" : SASINSTR_DET_OFF_Z, 
     539                                      } 
     540                        } 
     541    SASINSTR_DET_OR_ATTR = { 
     542                            "unit" : "{0}.orientation_unit = \"{1}\"", 
     543                            "storeas" : "content" 
     544                            } 
     545    SASINSTR_DET_OR_ROLL = { 
     546                            "variable" : "{0}.orientation.x = {1}", 
     547                            "unit" : "orientation_unit", 
     548                            "attributes" : SASINSTR_DET_OR_ATTR 
     549                            } 
     550    SASINSTR_DET_OR_PITCH = { 
     551                             "variable" : "{0}.orientation.y = {1}", 
     552                             "unit" : "orientation_unit", 
     553                             "attributes" : SASINSTR_DET_OR_ATTR 
     554                             } 
     555    SASINSTR_DET_OR_YAW = { 
     556                           "variable" : "{0}.orientation.z = {1}", 
     557                           "unit" : "orientation_unit", 
     558                           "attributes" : SASINSTR_DET_OR_ATTR 
     559                           } 
     560    SASINSTR_DET_OR = { 
     561                       "variable" : None, 
     562                       "children" : { 
     563                                     "roll" : SASINSTR_DET_OR_ROLL, 
     564                                     "pitch" : SASINSTR_DET_OR_PITCH, 
     565                                     "yaw" : SASINSTR_DET_OR_YAW, 
     566                                     } 
     567                       } 
     568    SASINSTR_DET_BC_X = { 
     569                         "variable" : "{0}.beam_center.x = {1}", 
     570                         "unit" : "beam_center_unit", 
     571                         "attributes" : { 
     572                                         "unit" : \ 
     573                                            "{0}.beam_center_unit = \"{1}\"", 
     574                                         "storeas" : "content" 
     575                                         } 
     576                         } 
     577    SASINSTR_DET_BC_Y = { 
     578                         "variable" : "{0}.beam_center.y = {1}", 
     579                         "unit" : "beam_center_unit", 
     580                         "attributes" : { 
     581                                         "unit" : \ 
     582                                            "{0}.beam_center_unit = \"{1}\"", 
     583                                         "storeas" : "content" 
     584                                         } 
     585                         } 
     586    SASINSTR_DET_BC_Z = { 
     587                         "variable" : "{0}.beam_center.z = {1}", 
     588                         "unit" : "beam_center_unit", 
     589                         "attributes" : { 
     590                                         "unit" : \ 
     591                                            "{0}.beam_center_unit = \"{1}\"", 
     592                                         "storeas" : "content" 
     593                                         } 
     594                         } 
     595    SASINSTR_DET_BC = { 
     596                       "variable" : None, 
     597                       "children" : { 
     598                                    "x" : SASINSTR_DET_BC_X, 
     599                                    "y" : SASINSTR_DET_BC_Y, 
     600                                    "z" : SASINSTR_DET_BC_Z, 
     601                                    } 
     602                      } 
     603    SASINSTR_DET_PIXEL_X = { 
     604                        "variable" : "{0}.pixel_size.x = {1}", 
     605                        "unit" : "pixel_size_unit", 
     606                        "attributes" : { 
     607                                        "unit" : "{0}.pixel_size_unit = \"{1}\"", 
     608                                        "storeas" : "content" 
     609                                        } 
     610                        } 
     611    SASINSTR_DET_PIXEL_Y = { 
     612                        "variable" : "{0}.pixel_size.y = {1}", 
     613                        "unit" : "pixel_size_unit", 
     614                        "attributes" : { 
     615                                        "unit" : "{0}.pixel_size_unit = \"{1}\"", 
     616                                        "storeas" : "content" 
     617                                        } 
     618                        } 
     619    SASINSTR_DET_PIXEL_Z = { 
     620                        "variable" : "{0}.pixel_size.z = {1}", 
     621                        "unit" : "pixel_size_unit", 
     622                        "attributes" : { 
     623                                        "unit" : "{0}.pixel_size_unit = \"{1}\"", 
     624                                        "storeas" : "content" 
     625                                        } 
     626                        } 
     627    SASINSTR_DET_PIXEL = { 
     628                      "variable" : None, 
     629                      "children" : { 
     630                                    "x" : SASINSTR_DET_PIXEL_X, 
     631                                    "y" : SASINSTR_DET_PIXEL_Y, 
     632                                    "z" : SASINSTR_DET_PIXEL_Z, 
     633                                    } 
     634                      } 
     635    SASINSTR_DET_SLIT = { 
     636                         "variable" : "{0}.slit_length = {1}", 
     637                         "unit" : "slit_length_unit", 
     638                         "attributes" : { 
     639                                         "unit" : { 
     640                                                   "variable" : "{0}.slit_length_unit = \"{1}\"", 
     641                                                   "storeas" : "content" 
     642                                                   } 
     643                                         } 
     644                         } 
     645    SASINSTR_DET = { 
     646                    "storeas" : "float", 
     647                    "variable" : None, 
     648                    "attributes" : { 
     649                                    "name" : { 
     650                                              "storeas" : "content", 
     651                                              "variable" : "{0}.name = \"{1}\"", 
     652                                              } 
     653                                    }, 
     654                    "children" : { 
     655                                  "name" : { 
     656                                            "storeas" : "content", 
     657                                            "variable" : "{0}.name = \"{1}\"", 
     658                                            }, 
     659                                  "SDD" : SASINSTR_DET_SDD, 
     660                                  "offset" : SASINSTR_DET_OFF, 
     661                                  "orientation" : SASINSTR_DET_OR, 
     662                                  "beam_center" : SASINSTR_DET_BC, 
     663                                  "pixel_size" : SASINSTR_DET_PIXEL, 
     664                                  "slit_length" : SASINSTR_DET_SLIT, 
     665                                  } 
     666                    } 
     667    SASINSTR = { 
     668                "variable" : None, 
     669                "children" : { 
     670                              "variable" : None, 
     671                              "name" : {"variable" : \ 
     672                                            "{0}.instrument = \"{1}\""}, 
     673                              "SASsource" : SASINSTR_SRC, 
     674                              "SAScollimation" : SASINSTR_COLL, 
     675                              "SASdetector" : SASINSTR_DET, 
     676                              }, 
     677                } 
    14678    CANSAS_FORMAT = { 
    15679                     "SASentry" : { 
     
    17681                                   "variable" : None, 
    18682                                   "storeas" : "content", 
    19                                    "attributes" : {"name" : {"variable" : "{0}.run_name[node_value] = \"{1}\""}}, 
     683                                   "attributes" : {"name" : {"variable" : \ 
     684                                        "{0}.run_name[node_value] = \"{1}\""}}, 
    20685                                   "children" : { 
    21                                                  "Title" : {"variable" : "{0}.title = \"{1}\""}, 
    22                                                  "Run" : { 
    23                                                           "variable" : "{0}.run.append(\"{1}\")", 
    24                                                           "attributes" : {"name" : {"variable" : "{0}.run_name[node_value] = \"{1}\""}} 
    25                                                           }, 
    26                                                  "SASdata" : { 
    27                                                               "attributes" : {"name" : {"variable" : "{0}.meta_data[\"{2}\"] = \"{1}\"",}}, 
    28                                                               "variable" : None, 
    29                                                               "children" : {"Idata" : { 
    30                                                                                        "storeas" : "float", 
    31                                                                                        "units_optional" : False, 
    32                                                                                        "variable" : None, 
    33                                                                                        "attributes" : { 
    34                                                                                                        "name" : { 
    35                                                                                                                  "variable" : "{0}.meta_data[\"{2}\"] = \"{1}\"", 
    36                                                                                                                  "storeas" : "content", 
    37                                                                                                                  }, 
    38                                                                                                        "timestamp" : { 
    39                                                                                                                       "variable" : "{0}.meta_data[\"{2}\"] = \"{1}\"", 
    40                                                                                                                       "storeas" : "content", 
    41                                                                                                                       } 
    42                                                                                                         }, 
    43                                                                                        "children" : { 
    44                                                                                                      "Q" : { 
    45                                                                                                             "variable" : "{0}.x = numpy.append({0}.x, {1})", 
    46                                                                                                             "unit" : "x_unit", 
    47                                                                                                             "attributes" : { 
    48                                                                                                                             "unit" : { 
    49                                                                                                                                       "variable" : "{0}._xunit = \"{1}\"", 
    50                                                                                                                                       "storeas" : "content" 
    51                                                                                                                                       } 
    52                                                                                                                             } 
    53                                                                                                             }, 
    54                                                                                                      "I" : { 
    55                                                                                                             "variable" : "{0}.y = numpy.append({0}.y, {1})", 
    56                                                                                                             "unit" : "y_unit", 
    57                                                                                                             "attributes" : { 
    58                                                                                                                             "unit" : { 
    59                                                                                                                                       "variable" : "{0}._yunit = \"{1}\"", 
    60                                                                                                                                       "storeas" : "content" 
    61                                                                                                                                       } 
    62                                                                                                                             } 
    63                                                                                                             }, 
    64                                                                                                      "Idev" : { 
    65                                                                                                                "variable" : "{0}.dy = numpy.append({0}.dy, {1})", 
    66                                                                                                                "unit" : "y_unit", 
    67                                                                                                                "attributes" : { 
    68                                                                                                                                "unit" : { 
    69                                                                                                                                          "variable" : "{0}.meta_data[\"{2}\"] = \"{1}\"", 
    70                                                                                                                                          "storeas" : "content" 
    71                                                                                                                                          } 
    72                                                                                                                                }, 
    73                                                                                                                }, 
    74                                                                                                      "Qdev" : { 
    75                                                                                                                "variable" : "{0}.dx = numpy.append({0}.dx, {1})", 
    76                                                                                                                "unit" : "x_unit", 
    77                                                                                                                "attributes" : { 
    78                                                                                                                                "unit" : { 
    79                                                                                                                                          "variable" : "{0}.meta_data[\"{2}\"] = \"{1}\"", 
    80                                                                                                                                          "storeas" : "content" 
    81                                                                                                                                          } 
    82                                                                                                                                }, 
    83                                                                                                                }, 
    84                                                                                                      "dQw" : { 
    85                                                                                                               "variable" : "{0}.dxw = numpy.append({0}.dxw, {1})", 
    86                                                                                                               "unit" : "x_unit", 
    87                                                                                                               "attributes" : { 
    88                                                                                                                               "unit" : { 
    89                                                                                                                                         "variable" : "{0}.meta_data[\"{2}\"] = \"{1}\"", 
    90                                                                                                                                         "storeas" : "content" 
    91                                                                                                                                         } 
    92                                                                                                                               }, 
    93                                                                                                               }, 
    94                                                                                                      "dQl" : { 
    95                                                                                                               "variable" : "{0}.dxl = numpy.append({0}.dxl, {1})", 
    96                                                                                                               "unit" : "x_unit", 
    97                                                                                                               "attributes" : { 
    98                                                                                                                               "unit" : { 
    99                                                                                                                                         "variable" : "{0}.meta_data[\"{2}\"] = \"{1}\"", 
    100                                                                                                                                         "storeas" : "content" 
    101                                                                                                                                         } 
    102                                                                                                                               }, 
    103                                                                                                               }, 
    104                                                                                                      "Qmean" : { 
    105                                                                                                                 "storeas" : "content", 
    106                                                                                                                 "unit" : "x_unit", 
    107                                                                                                                 "variable" : "{0}.meta_data[\"{2}\"] = {1}", 
    108                                                                                                                 "attributes" : {"unit" : {"variable" : "{0}.meta_data[\"{2}\"] = \"{1}\""}}, 
    109                                                                                                                 }, 
    110                                                                                                      "Shadowfactor" : { 
    111                                                                                                                        "variable" : "{0}.meta_data[\"{2}\"] = \"{1}\"", 
    112                                                                                                                        "storeas" : "content", 
    113                                                                                                                        }, 
    114                                                                                                      "<any>" : { 
    115                                                                                                                 "variable" : "{0}.meta_data[\"{2}\"] = \"{1}\"", 
    116                                                                                                                 "storeas" : "content", 
    117                                                                                                                 } 
    118                                                                                                      } 
    119                                                                                        }, 
    120                                                                             "<any>" : {"variable" : "{0}.meta_data[\"{2}\"] = \"{1}\"",} 
    121                                                                             } 
    122                                                               }, 
    123                                                  "SAStransmission_spectrum" : { 
    124                                                                                "variable" : None, 
    125                                                                                "children" : { 
    126                                                                                              "Tdata" : { 
    127                                                                                                         "storeas" : "float", 
    128                                                                                                         "variable" : None, 
    129                                                                                                         "children" : { 
    130                                                                                                                       "Lambda" : { 
    131                                                                                                                                   "variable" : "{0}.trans_spectrum.wavelength.append({1})", 
    132                                                                                                                                   "unit" : "trans_spectrum.wavelength_unit", 
    133                                                                                                                                   "attributes" : { 
    134                                                                                                                                                   "unit" : { 
    135                                                                                                                                                             "variable" : "{0}.trans_spectrum.wavelength_unit = \"{1}\"", 
    136                                                                                                                                                             "storeas" : "content" 
    137                                                                                                                                                             } 
    138                                                                                                                                                   } 
    139                                                                                                                                   }, 
    140                                                                                                                       "T" : { 
    141                                                                                                                              "variable" : "{0}.trans_spectrum.transmission.append({1})", 
    142                                                                                                                              "unit" : "trans_spectrum.transmission_unit", 
    143                                                                                                                              "attributes" : { 
    144                                                                                                                                              "unit" : { 
    145                                                                                                                                                        "variable" : "{0}.trans_spectrum.transmission_unit = \"{1}\"", 
    146                                                                                                                                                        "storeas" : "content" 
    147                                                                                                                                                        } 
    148                                                                                                                                              } 
    149                                                                                                                              }, 
    150                                                                                                                       "Tdev" : { 
    151                                                                                                                                 "variable" : "{0}.trans_spectrum.transmission_deviation.append({1})", 
    152                                                                                                                                 "unit" : "trans_spectrum.transmission_deviation_unit", 
    153                                                                                                                                 "attributes" : { 
    154                                                                                                                                              "unit" : { 
    155                                                                                                                                                        "variable" : "{0}.trans_spectrum.transmission_deviation_unit = \"{1}\"", 
    156                                                                                                                                                        "storeas" : "content" 
    157                                                                                                                                                        } 
    158                                                                                                                                              } 
    159                                                                                                                                 }, 
    160                                                                                                                       "<any>" : {"variable" : "{0}.meta_data[\"{2}\"] = \"{1}\""}, 
    161                                                                                                                       } 
    162                                                                                                         }, 
    163                                                                                              "<any>" : {"variable" : "{0}.meta_data[\"{2}\"] = \"{1}\""}, 
    164                                                                                              }, 
    165                                                                                "attributes" : {"name" : {"variable" : "{0}.trans_spectrum.name = \"{1}\""}, 
    166                                                                                                "timestamp" : {"variable" : "{0}.trans_spectrum.timestamp = \"{1}\""},} 
    167                                                                                }, 
    168                                                  "SASsample" : { 
    169                                                                 "attributes" : {"name" : {"variable" : "{0}.sample.name = \"{1}\""},}, 
    170                                                                 "variable" : None, 
    171                                                                 "children" : { 
    172                                                                               "ID" : {"variable" : "{0}.sample.ID = \"{1}\""}, 
    173                                                                               "thickness" : { 
    174                                                                                              "variable" : "{0}.sample.thickness = {1}", 
    175                                                                                              "unit" : "sample.thickness_unit", 
    176                                                                                              "storeas" : "float", 
    177                                                                                              "attributes" : { 
    178                                                                                                              "units" : { 
    179                                                                                                                         "variable" : "{0}.sample.thickness_unit = \"{1}\"", 
    180                                                                                                                         "storeas" : "content" 
    181                                                                                                                         } 
    182                                                                                                              }, 
    183                                                                                              }, 
    184                                                                               "transmission" : { 
    185                                                                                                 "variable" : "{0}.sample.transmission = {1}", 
    186                                                                                                 "storeas" : "float", 
    187                                                                                                 },  
    188                                                                               "temperature" : { 
    189                                                                                                "variable" : "{0}.sample.temperature = {1}", 
    190                                                                                                "unit" : "sample.temperature_unit", 
    191                                                                                                "storeas" : "float", 
    192                                                                                                "attributes" : { 
    193                                                                                                                "units" : { 
    194                                                                                                                           "variable" : "{0}.sample.temperature_unit = \"{1}\"", 
    195                                                                                                                           "storeas" : "content" 
    196                                                                                                                           } 
    197                                                                                                                }, 
    198                                                                                                },  
    199                                                                               "position" : { 
    200                                                                                             "children" : { 
    201                                                                                                           "variable" : None, 
    202                                                                                                           "x" : { 
    203                                                                                                                  "variable" : "{0}.sample.position.x = {1}", 
    204                                                                                                                  "unit" : "sample.position_unit", 
    205                                                                                                                  "storeas" : "float", 
    206                                                                                                                  "attributes" : { 
    207                                                                                                                                  "units" : { 
    208                                                                                                                                             "variable" : "{0}.sample.position_unit = \"{1}\"", 
    209                                                                                                                                             "storeas" : "content" 
    210                                                                                                                                             } 
    211                                                                                                                                  } 
    212                                                                                                                  }, 
    213                                                                                                           "y" : { 
    214                                                                                                                  "variable" : "{0}.sample.position.y = {1}", 
    215                                                                                                                  "unit" : "sample.position_unit", 
    216                                                                                                                  "attributes" : { 
    217                                                                                                                                  "units" : { 
    218                                                                                                                                             "variable" : "{0}.sample.position_unit = \"{1}\"", 
    219                                                                                                                                             "storeas" : "content" 
    220                                                                                                                                             } 
    221                                                                                                                                  } 
    222                                                                                                                  }, 
    223                                                                                                           "z" : { 
    224                                                                                                                  "variable" : "{0}.sample.position.z = {1}", 
    225                                                                                                                  "unit" : "sample.position_unit", 
    226                                                                                                                  "attributes" : { 
    227                                                                                                                                  "units" : { 
    228                                                                                                                                             "variable" : "{0}.sample.position_unit = \"{1}\"", 
    229                                                                                                                                             "storeas" : "content" 
    230                                                                                                                                             } 
    231                                                                                                                                  } 
    232                                                                                                                  }, 
    233                                                                                                           }, 
    234                                                                                             }, 
    235                                                                               "orientation" : { 
    236                                                                                                "variable" : None, 
    237                                                                                                "children" : { 
    238                                                                                                              "roll" : { 
    239                                                                                                                        "variable" : "{0}.sample.orientation.x = {1}", 
    240                                                                                                                        "unit" : "sample.orientation_unit", 
    241                                                                                                                        "storeas" : "float", 
    242                                                                                                                        "attributes" : { 
    243                                                                                                                                        "units" : { 
    244                                                                                                                                                   "variable" : "{0}.sample.orientation_unit = \"{1}\"", 
    245                                                                                                                                                   "storeas" : "content" 
    246                                                                                                                                                   } 
    247                                                                                                                                        } 
    248                                                                                                                        }, 
    249                                                                                                              "pitch" : { 
    250                                                                                                                        "variable" : "{0}.sample.orientation.y = {1}", 
    251                                                                                                                        "unit" : "sample.orientation_unit", 
    252                                                                                                                        "storeas" : "float", 
    253                                                                                                                        "attributes" : { 
    254                                                                                                                                        "units" : { 
    255                                                                                                                                                   "variable" : "{0}.sample.orientation_unit = \"{1}\"", 
    256                                                                                                                                                   "storeas" : "content" 
    257                                                                                                                                                   } 
    258                                                                                                                                        } 
    259                                                                                                                        }, 
    260                                                                                                              "yaw" : { 
    261                                                                                                                        "variable" : "{0}.sample.orientation.z = {1}", 
    262                                                                                                                        "unit" : "sample.orientation_unit", 
    263                                                                                                                        "storeas" : "float", 
    264                                                                                                                        "attributes" : { 
    265                                                                                                                                        "units" : { 
    266                                                                                                                                                   "variable" : "{0}.sample.orientation_unit = \"{1}\"", 
    267                                                                                                                                                   "storeas" : "content" 
    268                                                                                                                                                   } 
    269                                                                                                                                        } 
    270                                                                                                                        }, 
    271                                                                                                              }, 
    272                                                                                                }, 
    273                                                                               "details" : {"variable" : "{0}.sample.details.append(\"{1}\")"}, 
    274                                                                               "<any>" : {"variable" : "{0}.meta_data[\"{2}\"] = \"{1}\""} 
    275                                                                               }, 
    276                                                                 }, 
    277                                                  "SASinstrument" : { 
    278                                                                     "variable" : None, 
    279                                                                     "children" : { 
    280                                                                                   "variable" : None, 
    281                                                                                   "name" : {"variable" : "{0}.instrument = \"{1}\""}, 
    282                                                                                   "SASsource" : { 
    283                                                                                                  "attributes" : {"name" : {"variable" : "{0}.source.name = \"{1}\""}}, 
    284                                                                                                  "variable" : None, 
    285                                                                                                  "children" : { 
    286                                                                                                                "radiation" : {"variable" : "{0}.source.radiation = \"{1}\""}, 
    287                                                                                                                "beam_size" : { 
    288                                                                                                                               "attributes" : {"name" : {"variable" : "{0}.source.beam_size_name = \"{1}\""}}, 
    289                                                                                                                               "variable" : None, 
    290                                                                                                                               "children" : { 
    291                                                                                                                                             "x" : { 
    292                                                                                                                                                    "variable" : "{0}.source.beam_size.x = {1}", 
    293                                                                                                                                                    "unit" : "source.beam_size_unit", 
    294                                                                                                                                                    "storeas" : "float", 
    295                                                                                                                                                    "attributes" : { 
    296                                                                                                                                                                    "unit" : "{0}.source.beam_size_unit = \"{1}\"", 
    297                                                                                                                                                                    "storeas" : "content" 
    298                                                                                                                                                                    } 
    299                                                                                                                                                    }, 
    300                                                                                                                                             "y" : { 
    301                                                                                                                                                    "variable" : "{0}.source.beam_size.y = {1}", 
    302                                                                                                                                                    "unit" : "source.beam_size_unit", 
    303                                                                                                                                                    "storeas" : "float", 
    304                                                                                                                                                    "attributes" : { 
    305                                                                                                                                                                    "unit" : "{0}.source.beam_size_unit = \"{1}\"", 
    306                                                                                                                                                                    "storeas" : "content" 
    307                                                                                                                                                                    } 
    308                                                                                                                                                    }, 
    309                                                                                                                                             "z" : { 
    310                                                                                                                                                    "variable" : "{0}.source.beam_size.z = {1}", 
    311                                                                                                                                                    "unit" : "source.beam_size_unit", 
    312                                                                                                                                                    "storeas" : "float", 
    313                                                                                                                                                    "attributes" : { 
    314                                                                                                                                                                    "unit" : "{0}.source.beam_size_unit = \"{1}\"", 
    315                                                                                                                                                                    "storeas" : "content" 
    316                                                                                                                                                                    } 
    317                                                                                                                                                    }, 
    318                                                                                                                                             } 
    319                                                                                                                               }, 
    320                                                                                                                "beam_shape" : {"variable" : "{0}.source.beam_shape = \"{1}\""}, 
    321                                                                                                                "wavelength" : { 
    322                                                                                                                                "variable" : "{0}.source.wavelength = {1}", 
    323                                                                                                                                "unit" : "source.wavelength_unit", 
    324                                                                                                                                "storeas" : "float", 
    325                                                                                                                                "attributes" : { 
    326                                                                                                                                                "unit" : { 
    327                                                                                                                                                          "variable" : "{0}.source.wavelength_unit = \"{1}\"", 
    328                                                                                                                                                          "storeas" : "content" 
    329                                                                                                                                                          }, 
    330                                                                                                                                                } 
    331                                                                                                                                }, 
    332                                                                                                                "wavelength_min" : { 
    333                                                                                                                                   "variable" : "{0}.source.wavelength_min = {1}", 
    334                                                                                                                                   "unit" : "source.wavelength_min_unit", 
    335                                                                                                                                   "storeas" : "float", 
    336                                                                                                                                   "attributes" : { 
    337                                                                                                                                                   "unit" : { 
    338                                                                                                                                                             "variable" : "{0}.source.wavelength_min_unit = \"{1}\"",   
    339                                                                                                                                                             "storeas" : "content" 
    340                                                                                                                                                             }, 
    341                                                                                                                                                   } 
    342                                                                                                                                   }, 
    343                                                                                                                "wavelength_max" : { 
    344                                                                                                                                    "variable" : "{0}.source.wavelength_max = {1}", 
    345                                                                                                                                    "unit" : "source.wavelength_max_unit", 
    346                                                                                                                                    "storeas" : "float", 
    347                                                                                                                                    "attributes" : { 
    348                                                                                                                                                    "unit" : { 
    349                                                                                                                                                              "variable" : "{0}.source.wavelength_max_unit = \"{1}\"", 
    350                                                                                                                                                              "storeas" : "content" 
    351                                                                                                                                                              }, 
    352                                                                                                                                                    } 
    353                                                                                                                                    }, 
    354                                                                                                                "wavelength_spread" : { 
    355                                                                                                                                       "variable" : "{0}.source.wavelength_spread = {1}", 
    356                                                                                                                                       "unit" : "source.wavelength_spread_unit", 
    357                                                                                                                                       "storeas" : "float", 
    358                                                                                                                                       "attributes" : { 
    359                                                                                                                                                       "unit" : {"variable" : "{0}.source.wavelength_spread_unit = \"{1}\""}, 
    360                                                                                                                                                       "storeas" : "content" 
    361                                                                                                                                                       } 
    362                                                                                                                                       }, 
    363                                                                                                                }, 
    364                                                                                                  }, 
    365                                                                                   "SAScollimation" : { 
    366                                                                                                       "attributes" : {"name" : {"variable" : "{0}.name = \"{1}\""}}, 
    367                                                                                                       "variable" : None, 
    368                                                                                                       "children" : { 
    369                                                                                                                     "length" : { 
    370                                                                                                                                 "variable" : "{0}.length = {1}", 
    371                                                                                                                                 "unit" : "length_unit", 
    372                                                                                                                                 "storeas" : "float", 
    373                                                                                                                                 "attributes" : { 
    374                                                                                                                                                 "storeas" : "content", 
    375                                                                                                                                                 "unit" : {"variable" : "{0}.length_unit = \"{1}\""} 
    376                                                                                                                                                 }, 
    377                                                                                                                                 }, 
    378                                                                                                                     "aperture" : { 
    379                                                                                                                                   "variable" : None, 
    380                                                                                                                                   "attributes" : { 
    381                                                                                                                                                   "name" : {"variable" : "{0}.name = \"{1}\""}, 
    382                                                                                                                                                   "type" : {"variable" : "{0}.type = \"{1}\""}, 
    383                                                                                                                                                   }, 
    384                                                                                                                                   "children" : { 
    385                                                                                                                                                 "size" : { 
    386                                                                                                                                                           "attributes" : {"unit" : {"variable" : "{0}.size_unit = \"{1}\""}}, 
    387                                                                                                                                                           "children" : { 
    388                                                                                                                                                                         "storeas" : "float", 
    389                                                                                                                                                                         "x" : { 
    390                                                                                                                                                                                "variable" : "{0}.size.x = {1}", 
    391                                                                                                                                                                                "unit" : "size_unit", 
    392                                                                                                                                                                                "storeas" : "float", 
    393                                                                                                                                                                                "attributes" : { 
    394                                                                                                                                                                                                "unit" : { 
    395                                                                                                                                                                                                          "variable" : "{0}.size_unit = \"{1}\"", 
    396                                                                                                                                                                                                          "storeas" : "content" 
    397                                                                                                                                                                                                          },                                    } 
    398                                                                                                                                                                                }, 
    399                                                                                                                                                                         "y" : { 
    400                                                                                                                                                                                "variable" : "{0}.size.y = {1}", 
    401                                                                                                                                                                                "unit" : "size_unit", 
    402                                                                                                                                                                                "storeas" : "float", 
    403                                                                                                                                                                                "attributes" : { 
    404                                                                                                                                                                                                "unit" : { 
    405                                                                                                                                                                                                          "variable" : "{0}.size_unit = \"{1}\"", 
    406                                                                                                                                                                                                          "storeas" : "content" 
    407                                                                                                                                                                                                          }, 
    408                                                                                                                                                                                                } 
    409                                                                                                                                                                                }, 
    410                                                                                                                                                                         "z" : { 
    411                                                                                                                                                                                "variable" : "{0}.size.z = {1}", 
    412                                                                                                                                                                                "unit" : "size_unit", 
    413                                                                                                                                                                                "storeas" : "float", 
    414                                                                                                                                                                                "attributes" : { 
    415                                                                                                                                                                                                "unit" : { 
    416                                                                                                                                                                                                          "variable" : "{0}.size_unit = \"{1}\"", 
    417                                                                                                                                                                                                          "storeas" : "content" 
    418                                                                                                                                                                                                          }, 
    419                                                                                                                                                                                               } 
    420                                                                                                                                                                                }, 
    421                                                                                                                                                                         } 
    422                                                                                                                                                           }, 
    423                                                                                                                                                 "distance" : { 
    424                                                                                                                                                               "storeas" : "float", 
    425                                                                                                                                                               "attributes" : { 
    426                                                                                                                                                                               "storeas" : "content", 
    427                                                                                                                                                                               "unit" : {"variable" : "{0}.distance_unit = \"{1}\""}}, 
    428                                                                                                                                                               "variable" : "{0}.distance = {1}", 
    429                                                                                                                                                               "unit" : "distance_unit", 
    430                                                                                                                                                               } 
    431                                                                                                                                                 } 
    432                                                                                                                                   }, 
    433                                                                                                                     }, 
    434                                                                                                       }, 
    435                                                                                   "SASdetector" : { 
    436                                                                                                    "storeas" : "float", 
    437                                                                                                    "variable" : None, 
    438                                                                                                    "attributes" : { 
    439                                                                                                                    "name" : { 
    440                                                                                                                              "storeas" : "content", 
    441                                                                                                                              "variable" : "{0}.name = \"{1}\"", 
    442                                                                                                                              } 
    443                                                                                                                    }, 
    444                                                                                                    "children" : { 
    445                                                                                                                  "name" : { 
    446                                                                                                                            "storeas" : "content", 
    447                                                                                                                            "variable" : "{0}.name = \"{1}\"", 
    448                                                                                                                            }, 
    449                                                                                                                  "SDD" : { 
    450                                                                                                                           "variable" : "{0}.distance = {1}", 
    451                                                                                                                           "unit" : "distance_unit", 
    452                                                                                                                           "attributes" : { 
    453                                                                                                                                           "unit" : { 
    454                                                                                                                                                     "variable" : "{0}.distance_unit = \"{1}\"", 
    455                                                                                                                                                     "storeas" : "content" 
    456                                                                                                                                                     } 
    457                                                                                                                                           }, 
    458                                                                                                                           }, 
    459                                                                                                                  "offset" : { 
    460                                                                                                                              "variable" : None, 
    461                                                                                                                              "children" : { 
    462                                                                                                                                            "x" : { 
    463                                                                                                                                                   "variable" : "{0}.offset.x = {1}", 
    464                                                                                                                                                   "unit" : "offset_unit", 
    465                                                                                                                                                   "attributes" : { 
    466                                                                                                                                                                   "unit" : { 
    467                                                                                                                                                                             "variable" : "{0}.offset_unit = \"{1}\"", 
    468                                                                                                                                                                             "storeas" : "content" 
    469                                                                                                                                                                             }, 
    470                                                                                                                                                                   } 
    471                                                                                                                                                   }, 
    472                                                                                                                                            "y" : { 
    473                                                                                                                                                   "variable" : "{0}.offset.y = {1}", 
    474                                                                                                                                                   "unit" : "offset_unit", 
    475                                                                                                                                                   "attributes" : { 
    476                                                                                                                                                                   "unit" : { 
    477                                                                                                                                                                             "variable" : "{0}.offset_unit = \"{1}\"", 
    478                                                                                                                                                                             "storeas" : "content" 
    479                                                                                                                                                                             }, 
    480                                                                                                                                                                   } 
    481                                                                                                                                                   }, 
    482                                                                                                                                            "z" : { 
    483                                                                                                                                                   "variable" : "{0}.offset.z = {1}", 
    484                                                                                                                                                   "unit" : "offset_unit", 
    485                                                                                                                                                   "attributes" : { 
    486                                                                                                                                                                   "unit" : { 
    487                                                                                                                                                                             "variable" : "{0}.offset_unit = \"{1}\"", 
    488                                                                                                                                                                             "storeas" : "content" 
    489                                                                                                                                                                             }, 
    490                                                                                                                                                                   } 
    491                                                                                                                                                   }, 
    492                                                                                                                                            } 
    493                                                                                                                              }, 
    494                                                                                                                  "orientation" : { 
    495                                                                                                                                   "variable" : None, 
    496                                                                                                                                   "children" : { 
    497                                                                                                                                                 "roll" : { 
    498                                                                                                                                                           "variable" : "{0}.orientation.x = {1}", 
    499                                                                                                                                                           "unit" : "orientation_unit", 
    500                                                                                                                                                           "attributes" : { 
    501                                                                                                                                                                           "unit" : "{0}.orientation_unit = \"{1}\"", 
    502                                                                                                                                                                           "storeas" : "content" 
    503                                                                                                                                                                           } 
    504                                                                                                                                                           }, 
    505                                                                                                                                                 "pitch" : { 
    506                                                                                                                                                            "variable" : "{0}.orientation.y = {1}", 
    507                                                                                                                                                            "unit" : "orientation_unit", 
    508                                                                                                                                                            "attributes" : { 
    509                                                                                                                                                                            "unit" : "{0}.orientation_unit = \"{1}\"", 
    510                                                                                                                                                                            "storeas" : "content" 
    511                                                                                                                                                                            } 
    512                                                                                                                                                            }, 
    513                                                                                                                                                 "yaw" : { 
    514                                                                                                                                                          "variable" : "{0}.orientation.z = {1}", 
    515                                                                                                                                                          "unit" : "orientation_unit", 
    516                                                                                                                                                          "attributes" : { 
    517                                                                                                                                                                          "unit" : "{0}.orientation_unit = \"{1}\"", 
    518                                                                                                                                                                          "storeas" : "content" 
    519                                                                                                                                                                          } 
    520                                                                                                                                                          }, 
    521                                                                                                                                                 } 
    522                                                                                                                                   }, 
    523                                                                                                                  "beam_center" : { 
    524                                                                                                                                   "variable" : None, 
    525                                                                                                                                   "children" : { 
    526                                                                                                                                                 "x" : { 
    527                                                                                                                                                        "variable" : "{0}.beam_center.x = {1}", 
    528                                                                                                                                                        "unit" : "beam_center_unit", 
    529                                                                                                                                                        "attributes" : { 
    530                                                                                                                                                                        "unit" : "{0}.beam_center_unit = \"{1}\"", 
    531                                                                                                                                                                        "storeas" : "content" 
    532                                                                                                                                                                        } 
    533                                                                                                                                                   }, 
    534                                                                                                                                                 "y" : { 
    535                                                                                                                                                        "variable" : "{0}.beam_center.y = {1}", 
    536                                                                                                                                                        "unit" : "beam_center_unit", 
    537                                                                                                                                                        "attributes" : { 
    538                                                                                                                                                                        "unit" : "{0}.beam_center_unit = \"{1}\"", 
    539                                                                                                                                                                        "storeas" : "content" 
    540                                                                                                                                                                        } 
    541                                                                                                                                                        }, 
    542                                                                                                                                                 "z" : { 
    543                                                                                                                                                        "variable" : "{0}.beam_center.z = {1}", 
    544                                                                                                                                                        "unit" : "beam_center_unit", 
    545                                                                                                                                                        "attributes" : { 
    546                                                                                                                                                                        "unit" : "{0}.beam_center_unit = \"{1}\"", 
    547                                                                                                                                                                        "storeas" : "content" 
    548                                                                                                                                                                        } 
    549                                                                                                                                                        }, 
    550                                                                                                                                                 } 
    551                                                                                                                                   }, 
    552                                                                                                                  "pixel_size" : { 
    553                                                                                                                                  "variable" : None, 
    554                                                                                                                                  "children" : { 
    555                                                                                                                                                "x" : { 
    556                                                                                                                                                       "variable" : "{0}.pixel_size.x = {1}", 
    557                                                                                                                                                       "unit" : "pixel_size_unit", 
    558                                                                                                                                                       "attributes" : { 
    559                                                                                                                                                                       "unit" : "{0}.pixel_size_unit = \"{1}\"", 
    560                                                                                                                                                                       "storeas" : "content" 
    561                                                                                                                                                                       } 
    562                                                                                                                                                       }, 
    563                                                                                                                                                 "y" : { 
    564                                                                                                                                                        "variable" : "{0}.pixel_size.y = {1}", 
    565                                                                                                                                                        "unit" : "pixel_size_unit", 
    566                                                                                                                                                       "attributes" : { 
    567                                                                                                                                                                        "unit" : "{0}.pixel_size_unit = \"{1}\"", 
    568                                                                                                                                                                        "storeas" : "content" 
    569                                                                                                                                                                        } 
    570                                                                                                                                                        }, 
    571                                                                                                                                                 "z" : { 
    572                                                                                                                                                        "variable" : "{0}.pixel_size.z = {1}", 
    573                                                                                                                                                        "unit" : "pixel_size_unit", 
    574                                                                                                                                                       "attributes" : { 
    575                                                                                                                                                                        "unit" : "{0}.pixel_size_unit = \"{1}\"", 
    576                                                                                                                                                                        "storeas" : "content" 
    577                                                                                                                                                                        } 
    578                                                                                                                                                        }, 
    579                                                                                                                                                 } 
    580                                                                                                                                   }, 
    581                                                                                                                  "slit_length" : { 
    582                                                                                                                                   "variable" : "{0}.slit_length = {1}", 
    583                                                                                                                                   "unit" : "slit_length_unit", 
    584                                                                                                                                   "attributes" : { 
    585                                                                                                                                                   "unit" : { 
    586                                                                                                                                                             "variable" : "{0}.slit_length_unit = \"{1}\"", 
    587                                                                                                                                                             "storeas" : "content" 
    588                                                                                                                                                             } 
    589                                                                                                                                                   } 
    590                                                                                                                                   } 
    591                                                                                                                   }, 
    592                                                                                                    }, 
    593                                                                                    }, 
    594                                                                     }, 
    595                                                  "SASprocess" : { 
    596                                                                  "variable" : None, 
    597                                                                  "children" : { 
    598                                                                                "name" : {"variable" : "{0}.name = \'{1}\'"}, 
    599                                                                                "date" : {"variable" : "{0}.date = \'{1}\'"}, 
    600                                                                                "description" : {"variable" : "{0}.description = \'{1}\'"}, 
    601                                                                                "term" : { 
    602                                                                                          "variable" : None, 
    603                                                                                          "attributes" : { 
    604                                                                                                          "unit" : {"variable" : None}, 
    605                                                                                                          "name" : {"variable" : None} 
    606                                                                                                          } 
    607                                                                                          }, 
    608                                                                                "SASprocessnote" : { 
    609                                                                                                    "variable" : None, 
    610                                                                                                    "children" : {"<any>" : {"variable" : "{0}.notes.append(\'2}: {1}\')"}}}, 
    611                                                                                "<any>" : {"variable" : "{0}.notes.append(\'{2}: {1}\')",} 
    612                                                                                }, 
    613                                                                  }, 
    614                                                  "SASnote" : {"variable" : "{0}.notes.append(\'{1}\')"}, 
    615                                                  "<any>" : {"variable" : "{0}.meta_data[\"{2}\"] = \'{1}\'"}, 
     686                                                 "Title" : TITLE, 
     687                                                 "Run" : RUN, 
     688                                                 "SASdata" : SASDATA, 
     689                                                 "SAStransmission_spectrum" : \ 
     690                                                    SASTRANSSPEC, 
     691                                                 "SASsample" : SASSAMPLE, 
     692                                                 "SASinstrument" : SASINSTR, 
     693                                                 "SASprocess" : SASPROCESS, 
     694                                                 "SASnote" : SASNOTE, 
     695                                                 "<any>" : ANY, 
    616696                                                 } 
    617697                                   } 
    618698                     } 
     699     
  • src/sans/dataloader/readers/cansas_reader.py

    r1ce36f37 r76cd1ae  
    11""" 
    2     CanSAS data reader - new recursive cansasVersion. 
     2    CanSAS data reader - new recursive cansas_version. 
    33""" 
    44############################################################################ 
     
    1919from sans.dataloader.data_info import Data1D 
    2020from sans.dataloader.data_info import Collimation 
     21from sans.dataloader.data_info import TransmissionSpectrum 
    2122from sans.dataloader.data_info import Detector 
    2223from sans.dataloader.data_info import Process 
    2324from sans.dataloader.data_info import Aperture 
    24 import xml_reader 
     25import sans.dataloader.readers.xml_reader as xml_reader 
    2526import xml.dom.minidom 
    26 from cansas_constants import cansasConstants 
     27from sans.dataloader.readers.cansas_constants import cansasConstants 
    2728 
    2829_ZERO = 1e-16 
     
    3233except: 
    3334    HAS_CONVERTER = False 
    34      
    35 CANSAS_FORMAT = cansasConstants.CANSAS_FORMAT 
    36 CANSAS_NS = cansasConstants.CANSAS_NS 
     35 
     36constants = cansasConstants()     
     37CANSAS_FORMAT = constants.format 
     38CANSAS_NS = constants.ns 
    3739ALLOW_ALL = True 
    3840 
     
    118120    """ 
    119121    ##CanSAS version - defaults to version 1.0 
    120     cansasVersion = "1.0" 
     122    cansas_version = "1.0" 
    121123    ##Data reader 
    122124    reader = xml_reader.XMLreader() 
     
    137139        self.errors = [] 
    138140         
    139     def isCansas(self): 
     141    def is_cansas(self): 
    140142        """ 
    141143        Checks to see if the xml file is a CanSAS file 
     
    143145        if self.reader.validateXML(): 
    144146            xmlns = self.reader.xmlroot.keys() 
    145             if (CANSAS_NS.get(self.cansasVersion).get("ns") == self.reader.xmlroot.get(xmlns[1]).rsplit(" ")[0]): 
     147            if (CANSAS_NS.get(self.cansas_version).get("ns") == \ 
     148                    self.reader.xmlroot.get(xmlns[1]).rsplit(" ")[0]): 
    146149                return True 
    147150        return False 
     
    176179                base = base_name.split("/sans/")[0] 
    177180                 
    178                 # Load in the xml file and get the cansas version from the header 
     181                # Load in xml file and get the cansas version from the header 
    179182                self.reader.setXMLFile(xml) 
    180183                root = self.reader.xmlroot 
    181184                if root is None: 
    182185                    root = {} 
    183                 self.cansasVersion = root.get("version", "1.0") 
     186                self.cansas_version = root.get("version", "1.0") 
    184187                 
    185188                # Generic values for the cansas file based on the version 
    186                 cansas_defaults = CANSAS_NS.get(self.cansasVersion, "1.0") 
    187                 schema_path = "{0}/sans/dataloader/readers/schema/{1}".format(base, cansas_defaults.get("schema")).replace("\\", "/") 
     189                cansas_defaults = CANSAS_NS.get(self.cansas_version, "1.0") 
     190                schema_path = "{0}/sans/dataloader/readers/schema/{1}".format\ 
     191                        (base, cansas_defaults.get("schema")).replace("\\", "/") 
    188192                 
    189193                # Link a schema to the XML file. 
     
    193197                # Check the file matches the XML schema 
    194198                try: 
    195                     if self.isCansas(): 
    196                         # Get each SASentry from the XML file and add it to a list. 
     199                    if self.is_cansas(): 
     200                        # Get each SASentry from XML file and add it to a list. 
    197201                        entry_list = root.xpath('/ns:SASroot/ns:SASentry', 
    198                                                      namespaces={'ns': cansas_defaults.get("ns")}) 
     202                                namespaces={'ns': cansas_defaults.get("ns")}) 
    199203                        ns.append("SASentry") 
    200204                         
    201                         # If there are multiple files, modify the name for each is unique 
    202                         multipleFiles = len(entry_list) - 1 
    203                         n = 0 
     205                        # If multiple files, modify the name for each is unique 
     206                        multiple_files = len(entry_list) - 1 
     207                        increment = 0 
    204208                        name = basename 
    205209                        # Parse each SASentry item 
    206210                        for entry in entry_list: 
     211                            # Define a new Data1D object with zeroes for x and y 
     212                            data1d = Data1D(x,y,dx,dy) 
     213                            data1d.dxl = dxl 
     214                            data1d.dxw = dxw 
    207215                             
    208                             # Define a new Data1D object with zeroes for x and y 
    209                             data1D = Data1D(x,y,dx,dy) 
    210                             data1D.dxl = dxl 
    211                             data1D.dxw = dxw 
     216                            # If more than one SASentry, increment each in order 
     217                            if multiple_files: 
     218                                name += "_{0}".format(increment) 
     219                                increment += 1 
    212220                             
    213                             # If more than one SASentry, number each in order 
    214                             if multipleFiles: 
    215                                 name += "_{0}".format(n) 
    216                                 n += 1 
    217                              
    218                             # Set the Data1D name and then parse the entry. The entry is appended to a list of entry values 
    219                             data1D.filename = name 
    220                             data1D.meta_data["loader"] = "CanSAS 1D" 
    221                             return_value, extras = self._parse_entry(entry, ns, data1D) 
     221                            # Set the Data1D name and then parse the entry.  
     222                            # The entry is appended to a list of entry values 
     223                            data1d.filename = name 
     224                            data1d.meta_data["loader"] = "CanSAS 1D" 
     225                            return_value, extras = \ 
     226                                self._parse_entry(entry, ns, data1d) 
    222227                            del extras[:] 
    223228                             
    224                             #Final cleanup - Remove empty nodes, verify array sizes are correct 
     229                            # Final cleanup 
     230                            # Remove empty nodes, verify array sizes are correct 
    225231                            for error in self.errors: 
    226232                                return_value.errors.append(error) 
     
    241247                                numpy.trim_zeros(return_value.dxl) 
    242248                                numpy.trim_zeros(return_value.dxw) 
    243                              
    244249                            output.append(return_value) 
    245250                    else: 
     
    248253                except: 
    249254                    # If the file does not match the schema, raise this error 
    250                     raise RuntimeError, "%s cannot be read \n" % xml 
     255                    raise RuntimeError, "%s cannot be read \increment" % xml 
    251256                return output 
    252257        # Return a list of parsed entries that dataloader can manage 
     
    254259     
    255260    def _create_unique_key(self, dictionary, name, i): 
     261        """ 
     262        Create a unique key value for any dictionary to prevent overwriting 
     263         
     264         
     265        :param dictionary: A dictionary with any number of entries 
     266        :param name: The index of the item to be added to dictionary 
     267        :param i: The number to be appended to the name 
     268        """ 
    256269        if dictionary.get(name) is not None: 
    257270            i += 1 
     
    261274        return name 
    262275     
    263     def _iterate_namespace(self, ns): 
     276    def _iterate_namespace(self, namespace): 
     277        """ 
     278        Method to iterate through a cansas constants tree based on a list of 
     279        names 
     280         
     281        :param namespace: A list of names that match the tree structure of 
     282            cansas_constants 
     283        """ 
    264284        # The current level to look through in cansas_constants. 
    265285        current_level = CANSAS_FORMAT.get("SASentry") 
     
    268288        ns_datatype = "content" 
    269289        ns_optional = True 
    270         for name in ns: 
     290        for name in namespace: 
    271291            if name != "SASentry": 
    272292                current_level = current_level.get("children").get(name, "") 
     
    277297                cl_units_optional = current_level.get("units_required", "") 
    278298                # Where are how to store the variable for the given namespace 
    279                 # The CANSAS_CONSTANTS tree is hierarchical, so is no value, inherit 
     299                # CANSAS_CONSTANTS tree is hierarchical, so is no value, inherit 
    280300                ns_variable = cl_variable if cl_variable != "" else ns_variable 
    281301                ns_datatype = cl_datatype if cl_datatype != "" else ns_datatype 
    282                 ns_optional = cl_units_optional if cl_units_optional != ns_optional else ns_optional 
     302                ns_optional = cl_units_optional if cl_units_optional != \ 
     303                                    ns_optional else ns_optional 
    283304        return current_level, ns_variable, ns_datatype, ns_optional 
    284305     
    285     def _unit_conversion(self, new_current_level, attr, data1D, node_value, optional = True): 
     306     
     307    def _unit_conversion(self, new_current_level, attr, data1d, \ 
     308                                    node_value, optional = True): 
     309        """ 
     310        A unit converter method used to convert the data included in the file 
     311        to the default units listed in data_info 
     312         
     313        :param new_current_level: cansas_constants level as returned by  
     314            _iterate_namespace 
     315        :param attr: The attributes of the node 
     316        :param data1d: Where the values will be saved 
     317        :param node_value: The value of the current dom node 
     318        :param optional: Boolean that says if the units are required 
     319        """ 
    286320        value_unit = '' 
    287321        if 'unit' in attr and new_current_level.get('unit') is not None: 
     
    291325                default_unit = None 
    292326                unitname = new_current_level.get("unit") 
    293                 exec "default_unit = data1D.{0}".format(unitname) 
     327                exec "default_unit = data1d.{0}".format(unitname) 
    294328                local_unit = attr['unit'] 
    295                 if local_unit.lower() != default_unit.lower() and local_unit is not None\ 
    296                     and local_unit.lower() != "none" and default_unit is not None: 
     329                if local_unit.lower() != default_unit.lower() and \ 
     330                    local_unit is not None and local_unit.lower() != "none" and\ 
     331                     default_unit is not None: 
    297332                    if HAS_CONVERTER == True: 
    298333                        try: 
    299334                            data_conv_q = Converter(attr['unit']) 
    300335                            value_unit = default_unit 
    301                             exec "node_value = data_conv_q(node_value, units=data1D.{0})".format(unitname) 
     336                            exec "node_value = data_conv_q(node_value, units=data1d.{0})".format(unitname) 
    302337                        except: 
    303338                            err_msg = "CanSAS reader: could not convert " 
    304339                            err_msg += "Q unit {0}; ".format(local_unit) 
    305                             intermediate = "err_msg += \"expecting [{1}]  {2}\".format(data1D.{0}, sys.exc_info()[1])".format(unitname, "{0}", "{1}") 
     340                            intermediate = "err_msg += \"expecting [{1}]  {2}\".format(data1d.{0}, sys.exc_info()[1])".format(unitname, "{0}", "{1}") 
    306341                            exec intermediate 
    307342                            self.errors.append(err_msg) 
     
    325360                err_msg = "CanSAS reader: could not convert " 
    326361                err_msg += "Q unit [%s]; " % attr['unit'], 
    327                 exec "err_msg += \"expecting [%s]\n  %s\" % (data1D.{0}, sys.exc_info()[1])".format(unitname) 
     362                exec "err_msg += \"expecting [%s]\n  %s\" % (data1d.{0}, sys.exc_info()[1])".format(unitname) 
    328363                self.errors.append(err_msg) 
    329364                if optional: 
     
    336371        return node_value, value_unit 
    337372     
    338     def _parse_entry(self, dom, ns, data1D, extras = []): 
     373    def _parse_entry(self, dom, ns, data1d, extras = []): 
    339374        """ 
    340375        Parse a SASEntry - new recursive method for parsing the dom of 
     
    344379        :param dom: dom object with a namespace base of ns 
    345380        :param ns: A list of element names that lead up to the dom object 
    346         :param data1D: The data1D object that will be modified 
     381        :param data1d: The data1d object that will be modified 
     382        :param extras: Any values that should go into meta_data when data1d 
     383            is not a Data1D object 
    347384        """ 
    348385          
    349386        # A portion of every namespace entry 
    350         base_ns = "{0}{1}{2}".format("{", CANSAS_NS.get(self.cansasVersion).get("ns"), "}") 
     387        base_ns = "{0}{1}{2}".format("{", \ 
     388                            CANSAS_NS.get(self.cansas_version).get("ns"), "}") 
    351389        unit = '' 
    352390         
     
    361399                 
    362400                # Look for special cases 
    363                 save_data1D = data1D 
     401                save_data1d = data1d 
    364402                if tagname == "SASdetector": 
    365                     data1D = Detector() 
     403                    data1d = Detector() 
    366404                elif tagname == "SAScollimation": 
    367                     data1D = Collimation() 
     405                    data1d = Collimation() 
     406                elif tagname == "SAStransmission_spectrum": 
     407                    data1d = TransmissionSpectrum() 
    368408                elif tagname == "SASprocess": 
    369                     data1D = Process() 
     409                    data1d = Process() 
    370410                    for child in node: 
    371411                        if child.tag.replace(base_ns, "") == "term": 
    372412                            term_attr = {} 
    373413                            for attr in child.keys(): 
    374                                 term_attr[attr] = ' '.join(child.get(attr).split()) 
     414                                term_attr[attr] = \ 
     415                                    ' '.join(child.get(attr).split()) 
    375416                            if child.text is not None: 
    376                                 term_attr['value'] = ' '.join(child.text.split()) 
    377                             data1D.term.append(term_attr) 
     417                                term_attr['value'] = \ 
     418                                    ' '.join(child.text.split()) 
     419                            data1d.term.append(term_attr) 
    378420                elif tagname == "aperture": 
    379                     data1D = Aperture() 
     421                    data1d = Aperture() 
    380422                 
    381423                # Get where to store content 
    382                 new_current_level, ns_variable, ns_datatype, optional = self._iterate_namespace(ns) 
     424                new_current_level, ns_var, ns_datatype, \ 
     425                                    optional = self._iterate_namespace(ns) 
    383426                # If the element is a child element, recurse 
    384427                if node.getchildren() is not None: 
    385428                    # Returned value is new Data1D object with all previous and new values in it. 
    386                     data1D, extras = self._parse_entry(node, ns, data1D, extras) 
     429                    data1d, extras = self._parse_entry(node, ns, data1d, extras) 
    387430                     
    388431                #Get the information from the node 
     
    396439                if ns_datatype == "float": 
    397440                    # If an empty value is given, store as zero. 
    398                     if node_value is None or node_value.isspace() or node_value.lower() == "nan": 
     441                    if node_value is None or node_value.isspace() \ 
     442                                            or node_value.lower() == "nan": 
    399443                        node_value = "0.0" 
    400                     node_value, unit = self._unit_conversion(new_current_level, attr, data1D, node_value, optional) 
     444                    node_value, unit = self._unit_conversion(new_current_level,\ 
     445                                             attr, data1d, node_value, optional) 
    401446                     
    402447                # If appending to a dictionary (meta_data | run_name), name sure the key is unique 
    403                 if ns_variable == "{0}.meta_data[\"{2}\"] = \"{1}\"": 
    404                     # If we are within a Process, Detector, Collimation or Aperture instance, pull out old data1D 
    405                     tagname = self._create_unique_key(data1D.meta_data, tagname, 0) 
    406                     if isinstance(data1D, Data1D) == False: 
    407                         store_me = ns_variable.format("data1D", node_value, tagname) 
     448                if ns_var == "{0}.meta_data[\"{2}\"] = \"{1}\"": 
     449                    # If we are within a Process, Detector, Collimation or Aperture instance, pull out old data1d 
     450                    tagname = self._create_unique_key(data1d.meta_data, tagname, 0) 
     451                    if isinstance(data1d, Data1D) == False: 
     452                        store_me = ns_var.format("data1d", node_value, tagname) 
    408453                        extras.append(store_me) 
    409                         ns_variable = None 
    410                 if ns_variable == "{0}.run_name[\"{2}\"] = \"{1}\"": 
    411                     tagname = self._create_unique_key(data1D.run_name, tagname, 0) 
     454                        ns_var = None 
     455                if ns_var == "{0}.run_name[\"{2}\"] = \"{1}\"": 
     456                    tagname = self._create_unique_key(data1d.run_name, tagname, 0) 
    412457                 
    413458                # Check for Data1D object and any extra commands to save 
    414                 if isinstance(data1D, Data1D): 
     459                if isinstance(data1d, Data1D): 
    415460                    for item in extras: 
    416461                        exec item 
    417462                # Don't bother saving empty information unless it is a float 
    418                 if ns_variable is not None and node_value is not None and node_value.isspace() == False: 
     463                if ns_var is not None and node_value is not None and \ 
     464                            node_value.isspace() == False: 
    419465                    # Format a string and then execute it. 
    420                     store_me = ns_variable.format("data1D", node_value, tagname) 
     466                    store_me = ns_var.format("data1d", node_value, tagname) 
    421467                    exec store_me 
    422468                # Get attributes and process them 
     
    430476                            else: 
    431477                                attrib_value = node.attrib[key] 
    432                             store_attr = attrib_variable.format("data1D", attrib_value, key) 
     478                            store_attr = attrib_variable.format("data1d", \ 
     479                                                            attrib_value, key) 
    433480                            exec store_attr 
    434481                        except AttributeError as e: 
     
    441488                print(e, exc_type, fname, exc_tb.tb_lineno, tagname, exc_obj) 
    442489            finally: 
    443                 # Save special cases in original data1D object and then restore the data1D 
     490                # Save special cases in original data1d object 
     491                # then restore the data1d 
    444492                if tagname_original == "SASdetector": 
    445                     save_data1D.detector.append(data1D) 
     493                    save_data1d.detector.append(data1d) 
    446494                elif tagname_original == "SAScollimation": 
    447                     save_data1D.collimation.append(data1D) 
     495                    save_data1d.collimation.append(data1d) 
     496                elif tagname == "SAStransmission_spectrum": 
     497                    save_data1d.trans_spectrum.append(data1d) 
    448498                elif tagname_original == "SASprocess": 
    449                     save_data1D.process.append(data1D) 
     499                    save_data1d.process.append(data1d) 
    450500                elif tagname_original == "aperture": 
    451                     save_data1D.aperture.append(data1D) 
     501                    save_data1d.aperture.append(data1d) 
    452502                else: 
    453                     save_data1D = data1D 
    454                 data1D = save_data1D 
     503                    save_data1d = data1d 
     504                data1d = save_data1d 
    455505                # Remove tagname from ns to restore original base 
    456506                ns.remove(tagname_original) 
    457507         
    458         return data1D, extras 
     508        return data1d, extras 
    459509         
    460510    def _to_xml_doc(self, datainfo): 
     
    468518            raise RuntimeError, "The cansas writer expects a Data1D instance" 
    469519         
    470         ns = CANSAS_NS.get(self.cansasVersion).get("ns") 
     520        ns = CANSAS_NS.get(self.cansas_version).get("ns") 
    471521        doc = xml.dom.minidom.Document() 
    472522        main_node = doc.createElement("SASroot") 
    473         main_node.setAttribute("version", self.cansasVersion) 
     523        main_node.setAttribute("version", self.cansas_version) 
    474524        main_node.setAttribute("xmlns", ns) 
    475525        main_node.setAttribute("xmlns:xsi", 
     
    502552                write_node(doc, pt, "I", datainfo.y[i], 
    503553                            {'unit': datainfo.y_unit}) 
    504             if datainfo.dy != None and len(datainfo.dy) >= i: 
     554            if datainfo.dy != None and len(datainfo.dy) > i: 
    505555                write_node(doc, pt, "Idev", datainfo.dy[i], 
    506556                            {'unit': datainfo.y_unit}) 
    507             if datainfo.dx != None and len(datainfo.dx) >= i: 
     557            if datainfo.dx != None and len(datainfo.dx) > i: 
    508558                write_node(doc, pt, "Qdev", datainfo.dx[i], 
    509559                            {'unit': datainfo.x_unit}) 
    510             if datainfo.dxw != None and len(datainfo.dxw) >= i: 
     560            if datainfo.dxw != None and len(datainfo.dxw) > i: 
    511561                write_node(doc, pt, "dQw", datainfo.dxw[i], 
    512562                            {'unit': datainfo.x_unit}) 
    513             if datainfo.dxl != None and len(datainfo.dxl) >= i: 
     563            if datainfo.dxl != None and len(datainfo.dxl) > i: 
    514564                write_node(doc, pt, "dQl", datainfo.dxl[i], 
    515565                            {'unit': datainfo.x_unit}) 
    516566 
    517567        # Transmission Spectrum Info 
    518         if len(datainfo.trans_spectrum.wavelength) > 0: 
     568        for i in range(len(datainfo.trans_spectrum)): 
     569            spectrum = datainfo.trans_spectrum[i] 
    519570            node = doc.createElement("SAStransmission_spectrum") 
    520571            entry_node.appendChild(node) 
    521             for i in range(len(datainfo.trans_spectrum.wavelength)): 
     572            for i in range(len(spectrum.wavelength)): 
    522573                pt = doc.createElement("Tdata") 
    523574                node.appendChild(pt) 
    524                 write_node(doc, pt, "Lambda", datainfo.trans_spectrum.wavelength[i],  
    525                            {'unit': datainfo.trans_spectrum.wavelength_unit}) 
    526                 write_node(doc, pt, "T", datainfo.trans_spectrum.transmission[i],  
    527                            {'unit': datainfo.trans_spectrum.transmission_unit}) 
    528                 if datainfo.trans_spectrum.transmission_deviation != None \ 
    529                 and len(datainfo.trans_spectrum.transmission_deviation) >= i: 
    530                     write_node(doc, pt, "Tdev", datainfo.trans_spectrum.transmission_deviation[i],  
    531                                {'unit': datainfo.trans_spectrum.transmission_deviation_unit}) 
     575                write_node(doc, pt, "Lambda", spectrum.wavelength[i],  
     576                           {'unit': spectrum.wavelength_unit}) 
     577                write_node(doc, pt, "T", spectrum.transmission[i],  
     578                           {'unit': spectrum.transmission_unit}) 
     579                if spectrum.transmission_deviation != None \ 
     580                and len(spectrum.transmission_deviation) >= i: 
     581                    write_node(doc, pt, "Tdev", \ 
     582                               spectrum.transmission_deviation[i], \ 
     583                               {'unit': spectrum.transmission_deviation_unit}) 
    532584 
    533585        # Sample info 
  • src/sans/dataloader/readers/xml_reader.py

    r17a25d4 r76cd1ae  
    1717 
    1818class XMLreader(): 
     19     
     20    xml = None 
     21    xmldoc = None 
     22    xmlroot = None 
     23    schema = None 
     24    schemadoc = None 
    1925     
    2026    def __init__(self, xml = None, schema = None, root = None): 
     
    4753            self.xmlroot = self.xmldoc.getroot() 
    4854        except Exception: 
    49             ##!TODO: raise exception if no xml is passed to this function 
    50             print "No xml file was found!" 
     55            self.xml = None 
     56            self.xmldoc = None 
     57            self.xmlroot = None 
    5158     
    5259    def setSchema(self, schema): 
     
    5562            self.schemadoc = etree.parse(self.schema, parser = parser) 
    5663        except Exception: 
    57             ##!TODO: raise exception if no schema is passed to this function 
    58             print "No schema file was found!" 
     64            self.schema = None 
     65            self.schemadoc = None 
    5966     
    6067    def validateXML(self): 
  • src/sans/guiframe/gui_manager.py

    r1c1b037 r76cd1ae  
    24852485                                       info="error")) 
    24862486            raise ValueError, msg 
    2487         text = data.__str__()  
     2487        ## text = str(data) 
     2488        text = data.__str__() 
    24882489        text += 'Data Min Max:\n' 
    24892490        text += 'X_min = %s:  X_max = %s\n'% (xmin, max(data.x)) 
     
    24942495        x_st = "X" 
    24952496        for index in range(len(data.x)): 
    2496             if data.dy != None: 
     2497            if data.dy != None and len(data.dy) > index: 
    24972498                dy_val = data.dy[index] 
    24982499            else: 
    24992500                dy_val = 0.0 
    2500             if data.dx != None: 
     2501            if data.dx != None and len(data.dx) > index: 
    25012502                dx_val = data.dx[index] 
    25022503            else: 
    25032504                dx_val = 0.0 
    2504             if data.dxl != None: 
     2505            if data.dxl != None and len(data.dxl) > index: 
    25052506                if index == 0:  
    25062507                    x_st = "Xl" 
    25072508                dx_val = data.dxl[index] 
    2508             elif data.dxw != None: 
     2509            elif data.dxw != None and len(data.dxw) > index: 
    25092510                if index == 0:  
    25102511                    x_st = "Xw" 
  • test/sansdataloader/test/utest_cansas.py

    r3f484b0 r76cd1ae  
    3838        self.isis_1_1 = "ISIS_1_1.xml" 
    3939        self.isis_1_1_notrans = "ISIS_1_1_notrans.xml" 
     40        self.isis_1_1_doubletrans = "ISIS_1_1_doubletrans.xml" 
    4041        self.schema_1_0 = "cansas1d_v1_0.xsd" 
    4142        self.schema_1_1 = "cansas1d_v1_1.xsd" 
     
    7778            self.assertFalse(valid) 
    7879             
     80             
     81    def _check_data(self, data): 
     82        self.assertTrue(data.title == "TK49 c10_SANS") 
     83        self.assertTrue(data.x.size == 138) 
     84        self.assertTrue(len(data.meta_data) == 2) 
     85        self.assertTrue(data.detector[0].distance_unit == "mm") 
     86        self.assertTrue(data.detector[1].distance_unit == "mm") 
     87        self.assertTrue(data.detector[0].name == "HAB") 
     88        self.assertTrue(data.detector[1].name == "main-detector-bank") 
     89        self.assertTrue(data.detector[0].distance == 575.0) 
     90        self.assertTrue(data.detector[1].distance == 4145.02) 
     91        spectrum = data.trans_spectrum[0] 
     92        self.assertTrue(len(spectrum.wavelength) == 138) 
     93        self.assertTrue(data.process[0].name == "Mantid generated CanSAS1D XML") 
     94         
    7995         
    8096    def test_cansas_xml(self): 
     
    8399        valid = xmlreader.validateXML() 
    84100        self.assertTrue(valid) 
    85         reader = Reader() 
    86         dataloader = reader.read(self.isis_1_1) 
    87         for data in dataloader: 
    88             self.assertTrue(data.title == "TK49 c10_SANS") 
    89             self.assertTrue(data.x.size == 138) 
    90             self.assertTrue(len(data.meta_data) == 2) 
    91             self.assertTrue(data.detector[0].distance_unit == "mm") 
    92             reader.write(filename, data) 
     101        reader_generic = Loader() 
     102        dataloader = reader_generic.load(self.isis_1_1) 
     103        reader_cansas = Reader() 
     104        cansasreader = reader_cansas.read(self.isis_1_1) 
     105        for i in range(len(dataloader)): 
     106            self._check_data(dataloader[i]) 
     107            self._check_data(cansasreader[i]) 
     108            reader_generic.save(filename, dataloader[i], None) 
    93109            reader2 = Reader() 
    94110            return_data = reader2.read(filename) 
    95111            data_new = return_data 
    96             self.data = return_data[0] 
    97             self.assertTrue(self.data.x.size == 138) 
    98             self.assertTrue(len(self.data.meta_data) == 2) 
    99             self.assertTrue(self.data.detector[0].distance_unit == "mm") 
    100             self.assertTrue(self.data.title == "TK49 c10_SANS") 
     112            written_data = return_data[0] 
     113            self._check_data(written_data) 
     114             
     115     
     116    def test_double_trans_spectra(self): 
     117        xmlreader = XMLreader(self.isis_1_1_doubletrans, self.schema_1_1) 
     118        self.assertTrue(xmlreader.validateXML()) 
     119        reader = Loader() 
     120        data = reader.load(self.isis_1_1_doubletrans) 
     121        for item in data: 
     122            self._check_data(item) 
     123     
    101124                     
    102125    def test_entry_name_recurse(self): 
Note: See TracChangeset for help on using the changeset viewer.