Index: src/sas/dataloader/readers/cansas_reader.py
===================================================================
--- src/sas/dataloader/readers/cansas_reader.py	(revision b3efb7dfc293a955756eccf52e0bbd30d3a2c32d)
+++ src/sas/dataloader/readers/cansas_reader.py	(revision aa720c45e269e6d96de4d797870ce95bfbe28969)
@@ -5,9 +5,9 @@
 #This software was developed by the University of Tennessee as part of the
 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
-#project funded by the US National Science Foundation. 
-#If you use DANSE applications to do scientific research that leads to 
-#publication, we ask that you acknowledge the use of the software with the 
+#project funded by the US National Science Foundation.
+#If you use DANSE applications to do scientific research that leads to
+#publication, we ask that you acknowledge the use of the software with the
 #following sentence:
-#This work benefited from DANSE software developed under NSF award DMR-0520547. 
+#This work benefited from DANSE software developed under NSF award DMR-0520547.
 #copyright 2008,2009 University of Tennessee
 #############################################################################
@@ -42,12 +42,9 @@
     HAS_CONVERTER = False
 
-CONSTANTS = CansasConstants()    
+CONSTANTS = CansasConstants()
 CANSAS_FORMAT = CONSTANTS.format
 CANSAS_NS = CONSTANTS.names
 ALLOW_ALL = True
 
-
-# minidom used in functions called by outside classes
-import xml.dom.minidom
 # DO NOT REMOVE
 # Called by outside packages:
@@ -57,13 +54,13 @@
     """
     Get the first instance of the content of a xpath location.
-    
+
     :param location: xpath location
     :param node: node to start at
-    
+
     :return: Element, or None
     """
-    nodes = node.xpath(location, 
+    nodes = node.xpath(location,
                        namespaces={'ns': CANSAS_NS.get("1.0").get("ns")})
-    
+
     if len(nodes) > 0:
         return nodes[0]
@@ -82,5 +79,5 @@
     :param value: value of the child text node
     :param attr: attribute dictionary
-    
+
     :return: True if something was appended, otherwise False
     """
@@ -95,10 +92,10 @@
         return True
     return False
-                
+
 
 class Reader(XMLreader):
     """
     Class to load cansas 1D XML files
-    
+
     :Dependencies:
         The CanSAS reader requires PyXML 0.8.4 or later.
@@ -107,8 +104,8 @@
     cansas_version = "1.0"
     base_ns = "{cansas1d/1.0}"
-    
+
     logging = []
     errors = []
-    
+
     type_name = "canSAS"
     ## Wildcards
@@ -116,19 +113,19 @@
     ## List of allowed extensions
     ext = ['.xml', '.XML', '.svs', '.SVS']
-    
+
     ## Flag to bypass extension check
     allow_all = True
-    
-    
+
+
     def __init__(self):
         ## List of errors
         self.errors = []
         self.encoding = None
-        
-        
+
+
     def is_cansas(self, ext="xml"):
         """
         Checks to see if the xml file is a CanSAS file
-        
+
         :param ext: The file extension of the data file
         """
@@ -142,42 +139,42 @@
             return True
         return False
-    
-    
+
+
     def load_file_and_schema(self, xml_file):
         """
         Loads the file and associates a schema, if a known schema exists
-        
+
         :param xml_file: The xml file path sent to Reader.read
         """
         base_name = xml_reader.__file__
-        base_name = base_name.replace("\\","/")
+        base_name = base_name.replace("\\", "/")
         base = base_name.split("/sas/")[0]
-        
+
         # Load in xml file and get the cansas version from the header
         self.set_xml_file(xml_file)
         self.cansas_version = self.xmlroot.get("version", "1.0")
-        
+
         # Generic values for the cansas file based on the version
         cansas_defaults = CANSAS_NS.get(self.cansas_version, "1.0")
         schema_path = "{0}/sas/dataloader/readers/schema/{1}".format\
                 (base, cansas_defaults.get("schema")).replace("\\", "/")
-        
+
         # Link a schema to the XML file.
         self.set_schema(schema_path)
         return cansas_defaults
-                
-    
+
+
     def read(self, xml_file):
         """
         Validate and read in an xml_file file in the canSAS format.
-        
+
         :param xml_file: A canSAS file path in proper XML format
         """
-        
+
         # output - Final list of Data1D objects
         output = []
         # ns - Namespace hierarchy for current xml_file object
         ns_list = []
-        
+
         # Check that the file exists
         if os.path.isfile(xml_file):
@@ -186,7 +183,7 @@
             # If the file type is not allowed, return nothing
             if extension in self.ext or self.allow_all:
-                # Get the file location of 
+                # Get the file location of
                 cansas_defaults = self.load_file_and_schema(xml_file)
-                
+
                 # Try to load the file, but raise an error if unable to.
                 # Check the file matches the XML schema
@@ -195,19 +192,19 @@
                         # Get each SASentry from XML file and add it to a list.
                         entry_list = self.xmlroot.xpath(
-                                '/ns:SASroot/ns:SASentry', 
-                                namespaces = {'ns': cansas_defaults.get("ns")})
+                                '/ns:SASroot/ns:SASentry',
+                                namespaces={'ns': cansas_defaults.get("ns")})
                         ns_list.append("SASentry")
-                        
+
                         # If multiple files, modify the name for each is unique
                         increment = 0
                         # Parse each SASentry item
                         for entry in entry_list:
-                            # Define a new Data1D object with zeroes for 
+                            # Define a new Data1D object with zeroes for
                             # x_vals and y_vals
-                            data1d = Data1D(numpy.empty(0), numpy.empty(0), \
+                            data1d = Data1D(numpy.empty(0), numpy.empty(0),
                                             numpy.empty(0), numpy.empty(0))
                             data1d.dxl = numpy.empty(0)
                             data1d.dxw = numpy.empty(0)
-                            
+
                             # If more than one SASentry, increment each in order
                             name = basename
@@ -215,20 +212,20 @@
                                 name += "_{0}".format(increment)
                                 increment += 1
-                            
-                            # Set the Data1D name and then parse the entry. 
+
+                            # Set the Data1D name and then parse the entry.
                             # The entry is appended to a list of entry values
                             data1d.filename = name
                             data1d.meta_data["loader"] = "CanSAS 1D"
-                            
+
                             # Get all preprocessing events and encoding
                             self.set_processing_instructions()
                             data1d.meta_data[PREPROCESS] = \
                                     self.processing_instructions
-                            
+
                             # Parse the XML file
                             return_value, extras = \
                                 self._parse_entry(entry, ns_list, data1d)
                             del extras[:]
-                            
+
                             return_value = self._final_cleanup(return_value)
                             output.append(return_value)
@@ -242,11 +239,11 @@
         # Return a list of parsed entries that dataloader can manage
         return None
-    
-    
+
+
     def _final_cleanup(self, data1d):
         """
         Final cleanup of the Data1D object to be sure it has all the
         appropriate information needed for perspectives
-        
+
         :param data1d: Data1D object that has been populated
         """
@@ -272,11 +269,10 @@
             numpy.trim_zeros(data1d.dxw)
         return data1d
-                            
-    
-    def _create_unique_key(self, dictionary, name, numb = 0):
+
+    def _create_unique_key(self, dictionary, name, numb=0):
         """
         Create a unique key value for any dictionary to prevent overwriting
         Recurses until a unique key value is found.
-        
+
         :param dictionary: A dictionary with any number of entries
         :param name: The index of the item to be added to dictionary
@@ -289,6 +285,6 @@
             name = self._create_unique_key(dictionary, name, numb)
         return name
-    
-    
+
+
     def _unit_conversion(self, node, new_current_level, data1d, \
                                                 tagname, node_value):
@@ -296,6 +292,6 @@
         A unit converter method used to convert the data included in the file
         to the default units listed in data_info
-        
-        :param new_current_level: cansas_constants level as returned by 
+
+        :param new_current_level: cansas_constants level as returned by
             iterate_namespace
         :param attr: The attributes of the node
@@ -318,5 +314,4 @@
                     if HAS_CONVERTER == True:
                         ## Check local units - bad units raise KeyError
-                        data_conv_q = Converter(local_unit)
                         value_unit = default_unit
                         i_string = "node_value = data_conv_q"
@@ -350,10 +345,10 @@
         node_value = "float({0})".format(node_value)
         return node_value, value_unit
-    
-    
+
+
     def _check_for_empty_data(self, data1d):
         """
         Creates an empty data set if no data is passed to the reader
-        
+
         :param data1d: presumably a Data1D object
         """
@@ -370,10 +365,9 @@
             data1d.dxw = dxw
         return data1d
-    
-    
+
     def _handle_special_cases(self, tagname, data1d, children):
         """
         Handle cases where the data type in Data1D is a dictionary or list
-        
+
         :param tagname: XML tagname in use
         :param data1d: The original Data1D object
@@ -404,6 +398,5 @@
             data1d = self._check_for_empty_resolution(data1d, children)
         return data1d
-    
-    
+
     def _check_for_empty_resolution(self, data1d, children):
         """
@@ -434,15 +427,14 @@
             data1d.dy = numpy.append(data1d.dy, 0.0)
         return data1d
-    
-    
-    def _restore_original_case(self, 
-                               tagname_original, 
-                               tagname, 
-                               save_data1d, 
+
+    def _restore_original_case(self,
+                               tagname_original,
+                               tagname,
+                               save_data1d,
                                data1d):
         """
         Save the special case data to the appropriate location and restore
         the original Data1D object
-        
+
         :param tagname_original: Unmodified tagname for the node
         :param tagname: modified tagname for the node
@@ -463,6 +455,5 @@
             save_data1d = data1d
         return save_data1d
-    
-    
+
     def _handle_attributes(self, node, data1d, cs_values, tagname):
         """
@@ -473,6 +464,6 @@
             for key in node.keys():
                 try:
-                    node_value, unit = self._get_node_value(node, cs_values, \
-                                                        data1d, tagname)
+                    _, unit = self._get_node_value(node, cs_values, \
+                                                   data1d, tagname)
                     cansas_attrib = \
                         cs_values.current_level.get("attributes").get(key)
@@ -486,12 +477,11 @@
                     exec store_attr
                 except AttributeError:
-                    pass    
+                    pass
         return data1d
-    
-    
+
     def _get_node_value(self, node, cs_values, data1d, tagname):
         """
         Get the value of a node and any applicable units
-        
+
         :param node: The XML node to get the value of
         :param cs_values: A CansasConstants.CurrentLevel object
@@ -507,5 +497,5 @@
         if node_value is not None:
             node_value = ' '.join(node_value.split())
-       
+
         # If the value is a float, compile with units.
         if cs_values.ns_datatype == "float":
@@ -517,5 +507,5 @@
             node_value, units = self._unit_conversion(node, \
                         cs_values.current_level, data1d, tagname, node_value)
-            
+
         # If the value is a timestamp, convert to a datetime object
         elif cs_values.ns_datatype == "timestamp":
@@ -529,6 +519,5 @@
                     node_value = None
         return node_value, units
-    
-    
+
     def _parse_entry(self, dom, names=None, data1d=None, extras=None):
         """
@@ -536,5 +525,5 @@
             the CanSAS data format. This will allow multiple data files
             and extra nodes to be read in simultaneously.
-        
+
         :param dom: dom object with a namespace base of names
         :param names: A list of element names that lead up to the dom object
@@ -543,17 +532,17 @@
             is not a Data1D object
         """
-        
+
         if extras is None:
             extras = []
         if names is None or names == []:
             names = ["SASentry"]
-        
+
         data1d = self._check_for_empty_data(data1d)
-                            
+
         self.base_ns = "{0}{1}{2}".format("{", \
                             CANSAS_NS.get(self.cansas_version).get("ns"), "}")
         tagname = ''
         tagname_original = ''
-        
+
         # Go through each child in the parent element
         for node in dom:
@@ -570,25 +559,25 @@
                     children = None
                 save_data1d = data1d
-                
+
                 # Look for special cases
                 data1d = self._handle_special_cases(tagname, data1d, children)
-                
+
                 # Get where to store content
                 cs_values = CONSTANTS.iterate_namespace(names)
                 # If the element is a child element, recurse
                 if children is not None:
-                    # Returned value is new Data1D object with all previous and 
+                    # Returned value is new Data1D object with all previous and
                     # new values in it.
-                    data1d, extras = self._parse_entry(node, 
+                    data1d, extras = self._parse_entry(node,
                                                        names, data1d, extras)
-                    
+
                 #Get the information from the node
                 node_value, _ = self._get_node_value(node, cs_values, \
                                                             data1d, tagname)
-                
+
                 # If appending to a dictionary (meta_data | run_name)
                 # make sure the key is unique
                 if cs_values.ns_variable == "{0}.meta_data[\"{2}\"] = \"{1}\"":
-                    # If we are within a Process, Detector, Collimation or 
+                    # If we are within a Process, Detector, Collimation or
                     # Aperture instance, pull out old data1d
                     tagname = self._create_unique_key(data1d.meta_data, \
@@ -602,5 +591,5 @@
                     tagname = self._create_unique_key(data1d.run_name, \
                                                       tagname, 0)
-                
+
                 # Check for Data1D object and any extra commands to save
                 if isinstance(data1d, Data1D):
@@ -618,5 +607,5 @@
                 data1d = self._handle_attributes(node, data1d, cs_values, \
                                                  tagname)
-                
+
             except TypeError:
                 pass
@@ -640,6 +629,5 @@
                     names.remove(tagname_original)
         return data1d, extras
-        
-    
+
     def _get_pi_string(self):
         """
@@ -656,6 +644,5 @@
             pi_string = ""
         return pi_string
-    
-    
+
     def _create_main_node(self):
         """
@@ -673,15 +660,13 @@
                   "version" : version}
         nsmap = {'xsi' : xsi, None: n_s}
-        
-        main_node = self.create_element("{" + n_s + "}SASroot", \
-                                               attrib = attrib, \
-                                               nsmap = nsmap)
+
+        main_node = self.create_element("{" + n_s + "}SASroot",
+                                        attrib=attrib, nsmap=nsmap)
         return main_node
-    
-    
+
     def _write_run_names(self, datainfo, entry_node):
         """
         Writes the run names to the XML file
-        
+
         :param datainfo: The Data1D object the information is coming from
         :param entry_node: lxml node ElementTree object to be appended to
@@ -696,10 +681,9 @@
                 runname = {'name': datainfo.run_name[item]}
             self.write_node(entry_node, "Run", item, runname)
-            
-    
+
     def _write_data(self, datainfo, entry_node):
         """
         Writes the I and Q data to the XML file
-        
+
         :param datainfo: The Data1D object the information is coming from
         :param entry_node: lxml node ElementTree object to be appended to
@@ -707,32 +691,30 @@
         node = self.create_element("SASdata")
         self.append(node, entry_node)
-        
+
         for i in range(len(datainfo.x)):
             point = self.create_element("Idata")
             node.append(point)
-            self.write_node(point, "Q", datainfo.x[i], \
-                             {'unit': datainfo.x_unit})
+            self.write_node(point, "Q", datainfo.x[i],
+                            {'unit': datainfo.x_unit})
             if len(datainfo.y) >= i:
                 self.write_node(point, "I", datainfo.y[i],
-                            {'unit': datainfo.y_unit})
+                                {'unit': datainfo.y_unit})
             if datainfo.dy != None and len(datainfo.dy) > i:
                 self.write_node(point, "Idev", datainfo.dy[i],
-                            {'unit': datainfo.y_unit})
+                                {'unit': datainfo.y_unit})
             if datainfo.dx != None and len(datainfo.dx) > i:
                 self.write_node(point, "Qdev", datainfo.dx[i],
-                            {'unit': datainfo.x_unit})
+                                {'unit': datainfo.x_unit})
             if datainfo.dxw != None and len(datainfo.dxw) > i:
                 self.write_node(point, "dQw", datainfo.dxw[i],
-                            {'unit': datainfo.x_unit})
+                                {'unit': datainfo.x_unit})
             if datainfo.dxl != None and len(datainfo.dxl) > i:
                 self.write_node(point, "dQl", datainfo.dxl[i],
-                            {'unit': datainfo.x_unit})
-        
-    
-    
+                                {'unit': datainfo.x_unit})
+
     def _write_trans_spectrum(self, datainfo, entry_node):
         """
         Writes the transmission spectrum data to the XML file
-        
+
         :param datainfo: The Data1D object the information is coming from
         :param entry_node: lxml node ElementTree object to be appended to
@@ -741,5 +723,5 @@
             spectrum = datainfo.trans_spectrum[i]
             node = self.create_element("SAStransmission_spectrum",
-                                              {"name" : spectrum.name})
+                                       {"name" : spectrum.name})
             self.append(node, entry_node)
             if isinstance(spectrum.timestamp, datetime.datetime):
@@ -748,19 +730,19 @@
                 point = self.create_element("Tdata")
                 node.append(point)
-                self.write_node(point, "Lambda", spectrum.wavelength[i], 
-                           {'unit': spectrum.wavelength_unit})
-                self.write_node(point, "T", spectrum.transmission[i], 
-                           {'unit': spectrum.transmission_unit})
+                self.write_node(point, "Lambda", spectrum.wavelength[i],
+                                {'unit': spectrum.wavelength_unit})
+                self.write_node(point, "T", spectrum.transmission[i],
+                                {'unit': spectrum.transmission_unit})
                 if spectrum.transmission_deviation != None \
                 and len(spectrum.transmission_deviation) >= i:
-                    self.write_node(point, "Tdev", \
-                               spectrum.transmission_deviation[i], \
-                               {'unit': spectrum.transmission_deviation_unit})
-    
-    
+                    self.write_node(point, "Tdev",
+                                    spectrum.transmission_deviation[i],
+                                    {'unit':
+                                     spectrum.transmission_deviation_unit})
+
     def _write_sample_info(self, datainfo, entry_node):
         """
         Writes the sample information to the XML file
-        
+
         :param datainfo: The Data1D object the information is coming from
         :param entry_node: lxml node ElementTree object to be appended to
@@ -768,52 +750,48 @@
         sample = self.create_element("SASsample")
         if datainfo.sample.name is not None:
-            self.write_attribute(sample, 
-                                        "name", 
-                                        str(datainfo.sample.name))
+            self.write_attribute(sample, "name",
+                                 str(datainfo.sample.name))
         self.append(sample, entry_node)
         self.write_node(sample, "ID", str(datainfo.sample.ID))
         self.write_node(sample, "thickness", datainfo.sample.thickness,
-                   {"unit": datainfo.sample.thickness_unit})
+                        {"unit": datainfo.sample.thickness_unit})
         self.write_node(sample, "transmission", datainfo.sample.transmission)
         self.write_node(sample, "temperature", datainfo.sample.temperature,
-                   {"unit": datainfo.sample.temperature_unit})
-        
+                        {"unit": datainfo.sample.temperature_unit})
+
         pos = self.create_element("position")
-        written = self.write_node(pos, 
-                                  "x", 
+        written = self.write_node(pos,
+                                  "x",
                                   datainfo.sample.position.x,
                                   {"unit": datainfo.sample.position_unit})
-        written = written | self.write_node(pos, 
-                                            "y", 
-                                            datainfo.sample.position.y,
-                                       {"unit": datainfo.sample.position_unit})
-        written = written | self.write_node(pos, 
-                                            "z",
-                                            datainfo.sample.position.z,
-                                       {"unit": datainfo.sample.position_unit})
+        written = written | self.write_node( \
+            pos, "y", datainfo.sample.position.y,
+            {"unit": datainfo.sample.position_unit})
+        written = written | self.write_node( \
+            pos, "z", datainfo.sample.position.z,
+            {"unit": datainfo.sample.position_unit})
         if written == True:
             self.append(pos, sample)
-        
+
         ori = self.create_element("orientation")
         written = self.write_node(ori, "roll",
                                   datainfo.sample.orientation.x,
                                   {"unit": datainfo.sample.orientation_unit})
-        written = written | self.write_node(ori, "pitch",
-                                       datainfo.sample.orientation.y,
-                                    {"unit": datainfo.sample.orientation_unit})
-        written = written | self.write_node(ori, "yaw",
-                                       datainfo.sample.orientation.z,
-                                    {"unit": datainfo.sample.orientation_unit})
+        written = written | self.write_node( \
+            ori, "pitch", datainfo.sample.orientation.y,
+            {"unit": datainfo.sample.orientation_unit})
+        written = written | self.write_node( \
+            ori, "yaw", datainfo.sample.orientation.z,
+            {"unit": datainfo.sample.orientation_unit})
         if written == True:
             self.append(ori, sample)
-        
+
         for item in datainfo.sample.details:
             self.write_node(sample, "details", item)
-    
-    
+
     def _write_instrument(self, datainfo, entry_node):
         """
         Writes the instrumental information to the XML file
-        
+
         :param datainfo: The Data1D object the information is coming from
         :param entry_node: lxml node ElementTree object to be appended to
@@ -823,10 +801,9 @@
         self.write_node(instr, "name", datainfo.instrument)
         return instr
-    
-    
+
     def _write_source(self, datainfo, instr):
         """
         Writes the source information to the XML file
-        
+
         :param datainfo: The Data1D object the information is coming from
         :param instr: instrument node  to be appended to
@@ -834,47 +811,45 @@
         source = self.create_element("SASsource")
         if datainfo.source.name is not None:
-            self.write_attribute(source,
-                                        "name",
-                                        str(datainfo.source.name))
+            self.write_attribute(source, "name",
+                                 str(datainfo.source.name))
         self.append(source, instr)
         if datainfo.source.radiation == None or datainfo.source.radiation == '':
             datainfo.source.radiation = "neutron"
         self.write_node(source, "radiation", datainfo.source.radiation)
-        
+
         size = self.create_element("beam_size")
         if datainfo.source.beam_size_name is not None:
-            self.write_attribute(size,
-                                        "name",
-                                        str(datainfo.source.beam_size_name))
-        written = self.write_node(size, "x", datainfo.source.beam_size.x,
-                             {"unit": datainfo.source.beam_size_unit})
-        written = written | self.write_node(size, "y",
-                                       datainfo.source.beam_size.y,
-                                       {"unit": datainfo.source.beam_size_unit})
-        written = written | self.write_node(size, "z",
-                                       datainfo.source.beam_size.z,
-                                       {"unit": datainfo.source.beam_size_unit})
+            self.write_attribute(size, "name",
+                                 str(datainfo.source.beam_size_name))
+        written = self.write_node( \
+            size, "x", datainfo.source.beam_size.x,
+            {"unit": datainfo.source.beam_size_unit})
+        written = written | self.write_node( \
+            size, "y", datainfo.source.beam_size.y,
+            {"unit": datainfo.source.beam_size_unit})
+        written = written | self.write_node( \
+            size, "z", datainfo.source.beam_size.z,
+            {"unit": datainfo.source.beam_size_unit})
         if written == True:
             self.append(size, source)
-            
+
         self.write_node(source, "beam_shape", datainfo.source.beam_shape)
         self.write_node(source, "wavelength",
-                   datainfo.source.wavelength,
-                   {"unit": datainfo.source.wavelength_unit})
+                        datainfo.source.wavelength,
+                        {"unit": datainfo.source.wavelength_unit})
         self.write_node(source, "wavelength_min",
-                   datainfo.source.wavelength_min,
-                   {"unit": datainfo.source.wavelength_min_unit})
+                        datainfo.source.wavelength_min,
+                        {"unit": datainfo.source.wavelength_min_unit})
         self.write_node(source, "wavelength_max",
-                   datainfo.source.wavelength_max,
-                   {"unit": datainfo.source.wavelength_max_unit})
+                        datainfo.source.wavelength_max,
+                        {"unit": datainfo.source.wavelength_max_unit})
         self.write_node(source, "wavelength_spread",
-                   datainfo.source.wavelength_spread,
-                   {"unit": datainfo.source.wavelength_spread_unit})
-    
-    
-    def _write_collimation(self, datainfo, instr):    
+                        datainfo.source.wavelength_spread,
+                        {"unit": datainfo.source.wavelength_spread_unit})
+
+    def _write_collimation(self, datainfo, instr):
         """
         Writes the collimation information to the XML file
-        
+
         :param datainfo: The Data1D object the information is coming from
         :param instr: lxml node ElementTree object to be appended to
@@ -888,8 +863,8 @@
                 self.write_attribute(coll, "name", str(item.name))
             self.append(coll, instr)
-            
+
             self.write_node(coll, "length", item.length,
-                       {"unit": item.length_unit})
-            
+                            {"unit": item.length_unit})
+
             for aperture in item.aperture:
                 apert = self.create_element("aperture")
@@ -899,27 +874,28 @@
                     self.write_attribute(apert, "type", str(aperture.type))
                 self.append(apert, coll)
-                
+
                 size = self.create_element("size")
                 if aperture.size_name is not None:
-                    self.write_attribute(size, 
-                                                "name", 
-                                                str(aperture.size_name))
+                    self.write_attribute(size, "name",
+                                         str(aperture.size_name))
                 written = self.write_node(size, "x", aperture.size.x,
-                                     {"unit": aperture.size_unit})
-                written = written | self.write_node(size, "y", aperture.size.y,
-                                               {"unit": aperture.size_unit})
-                written = written | self.write_node(size, "z", aperture.size.z,
-                                               {"unit": aperture.size_unit})
+                                          {"unit": aperture.size_unit})
+                written = written | self.write_node( \
+                    size, "y", aperture.size.y,
+                    {"unit": aperture.size_unit})
+                written = written | self.write_node( \
+                    size, "z", aperture.size.z,
+                    {"unit": aperture.size_unit})
                 if written == True:
                     self.append(size, apert)
-                
+
                 self.write_node(apert, "distance", aperture.distance,
-                           {"unit": aperture.distance_unit})
-    
-    
+                                {"unit": aperture.distance_unit})
+
+
     def _write_detectors(self, datainfo, instr):
         """
         Writes the detector information to the XML file
-        
+
         :param datainfo: The Data1D object the information is coming from
         :param inst: lxml instrument node to be appended to
@@ -929,73 +905,71 @@
             det.name = ""
             datainfo.detector.append(det)
-                
+
         for item in datainfo.detector:
             det = self.create_element("SASdetector")
             written = self.write_node(det, "name", item.name)
             written = written | self.write_node(det, "SDD", item.distance,
-                                           {"unit": item.distance_unit})
+                                                {"unit": item.distance_unit})
             if written == True:
                 self.append(det, instr)
-            
+
             off = self.create_element("offset")
             written = self.write_node(off, "x", item.offset.x,
-                                 {"unit": item.offset_unit})
+                                      {"unit": item.offset_unit})
             written = written | self.write_node(off, "y", item.offset.y,
-                                           {"unit": item.offset_unit})
+                                                {"unit": item.offset_unit})
             written = written | self.write_node(off, "z", item.offset.z,
-                                           {"unit": item.offset_unit})
+                                                {"unit": item.offset_unit})
             if written == True:
                 self.append(off, det)
-                
+
             ori = self.create_element("orientation")
             written = self.write_node(ori, "roll", item.orientation.x,
-                                 {"unit": item.orientation_unit})
+                                      {"unit": item.orientation_unit})
             written = written | self.write_node(ori, "pitch",
-                                           item.orientation.y,
-                                           {"unit": item.orientation_unit})
+                                                item.orientation.y,
+                                                {"unit": item.orientation_unit})
             written = written | self.write_node(ori, "yaw",
-                                           item.orientation.z,
-                                           {"unit": item.orientation_unit})
+                                                item.orientation.z,
+                                                {"unit": item.orientation_unit})
             if written == True:
                 self.append(ori, det)
-            
+
             center = self.create_element("beam_center")
             written = self.write_node(center, "x", item.beam_center.x,
-                                 {"unit": item.beam_center_unit})
+                                      {"unit": item.beam_center_unit})
             written = written | self.write_node(center, "y",
-                                           item.beam_center.y,
-                                           {"unit": item.beam_center_unit})
+                                                item.beam_center.y,
+                                                {"unit": item.beam_center_unit})
             written = written | self.write_node(center, "z",
-                                           item.beam_center.z,
-                                           {"unit": item.beam_center_unit})
+                                                item.beam_center.z,
+                                                {"unit": item.beam_center_unit})
             if written == True:
                 self.append(center, det)
-                
+
             pix = self.create_element("pixel_size")
             written = self.write_node(pix, "x", item.pixel_size.x,
-                                 {"unit": item.pixel_size_unit})
+                                      {"unit": item.pixel_size_unit})
             written = written | self.write_node(pix, "y", item.pixel_size.y,
-                                           {"unit": item.pixel_size_unit})
+                                                {"unit": item.pixel_size_unit})
             written = written | self.write_node(pix, "z", item.pixel_size.z,
-                                           {"unit": item.pixel_size_unit})
+                                                {"unit": item.pixel_size_unit})
             written = written | self.write_node(det, "slit_length",
-                                           item.slit_length,
-                                           {"unit": item.slit_length_unit})
+                                                item.slit_length,
+                                                {"unit": item.slit_length_unit})
             if written == True:
                 self.append(pix, det)
-    
-    
+
     def _write_process_notes(self, datainfo, entry_node):
         """
         Writes the process notes to the XML file
-        
+
         :param datainfo: The Data1D object the information is coming from
         :param entry_node: lxml node ElementTree object to be appended to
-        
+
         """
         for item in datainfo.process:
             node = self.create_element("SASprocess")
             self.append(node, entry_node)
-
             self.write_node(node, "name", item.name)
             self.write_node(node, "date", item.date)
@@ -1009,14 +983,13 @@
             if len(item.notes) == 0:
                 self.write_node(node, "SASprocessnote", "")
-    
-    
+
     def _write_notes(self, datainfo, entry_node):
         """
         Writes the notes to the XML file and creates an empty note if none
         exist
-        
+
         :param datainfo: The Data1D object the information is coming from
         :param entry_node: lxml node ElementTree object to be appended to
-        
+
         """
         if len(datainfo.notes) == 0:
@@ -1028,6 +1001,5 @@
                 self.write_text(node, item)
                 self.append(node, entry_node)
-    
-    
+
     def _check_origin(self, entry_node, doc):
         """
@@ -1036,5 +1008,5 @@
         If the calling function was not the cansas reader, return a minidom
         object rather than an lxml object.
-        
+
         :param entry_node: lxml node ElementTree object to be appended to
         :param doc: entire xml tree
@@ -1052,52 +1024,51 @@
             entry_node = node_list.item(0)
         return entry_node
-    
-    
+
     def _to_xml_doc(self, datainfo):
         """
         Create an XML document to contain the content of a Data1D
-        
+
         :param datainfo: Data1D object
         """
         if not issubclass(datainfo.__class__, Data1D):
             raise RuntimeError, "The cansas writer expects a Data1D instance"
-        
+
         # Get PIs and create root element
         pi_string = self._get_pi_string()
-        
+
         # Define namespaces and create SASroot object
         main_node = self._create_main_node()
-        
+
         # Create ElementTree, append SASroot and apply processing instructions
         base_string = pi_string + self.to_string(main_node)
         base_element = self.create_element_from_string(base_string)
         doc = self.create_tree(base_element)
-        
+
         # Create SASentry Element
         entry_node = self.create_element("SASentry")
         root = doc.getroot()
         root.append(entry_node)
-        
+
         # Add Title to SASentry
         self.write_node(entry_node, "Title", datainfo.title)
-        
+
         # Add Run to SASentry
         self._write_run_names(datainfo, entry_node)
-        
+
         # Add Data info to SASEntry
         self._write_data(datainfo, entry_node)
-        
+
         # Transmission Spectrum Info
         self._write_trans_spectrum(datainfo, entry_node)
-        
+
         # Sample info
         self._write_sample_info(datainfo, entry_node)
-        
+
         # Instrument info
         instr = self._write_instrument(datainfo, entry_node)
-        
+
         #   Source
         self._write_source(datainfo, instr)
-        
+
         #   Collimation
         self._write_collimation(datainfo, instr)
@@ -1105,20 +1076,19 @@
         #   Detectors
         self._write_detectors(datainfo, instr)
-            
+
         # Processes info
         self._write_process_notes(datainfo, entry_node)
-                
+
         # Note info
-        self._write_notes(datainfo, entry_node) 
-        
+        self._write_notes(datainfo, entry_node)
+
         # Return the document, and the SASentry node associated with
         #      the data we just wrote
         # If the calling function was not the cansas reader, return a minidom
-        #      object rather than an lxml object.        
+        #      object rather than an lxml object.
         entry_node = self._check_origin(entry_node, doc)
-        
+
         return doc, entry_node
-    
-    
+
     def write_node(self, parent, name, value, attr=None):
         """
@@ -1128,5 +1098,5 @@
         :param value: value of the child text node
         :param attr: attribute dictionary
-        
+
         :return: True if something was appended, otherwise False
         """
@@ -1135,10 +1105,9 @@
             return True
         return False
-    
-            
+
     def write(self, filename, datainfo):
         """
         Write the content of a Data1D as a CanSAS XML file
-        
+
         :param filename: name of the file to write
         :param datainfo: Data1D object
@@ -1153,6 +1122,5 @@
                   pretty_print=True, xml_declaration=True)
         file_ref.close()
-    
-    
+
     # DO NOT REMOVE - used in saving and loading panel states.
     def _store_float(self, location, node, variable, storage, optional=True):
@@ -1162,8 +1130,8 @@
         with the destination. The value is expected to
         be a float.
-        
+
         The xpath location might or might not exist.
         If it does not exist, nothing is done
-       
+
         :param location: xpath location to fetch
         :param node: node to read the data from
@@ -1180,5 +1148,5 @@
         except:
             value = None
-            
+
         if value is not None:
             # If the entry has units, check to see that they are
@@ -1193,6 +1161,6 @@
                         try:
                             conv = Converter(units)
-                            exec "storage.%s = %g" % (variable,
-                                           conv(value, units=local_unit))
+                            exec "storage.%s = %g" % \
+                                (variable, conv(value, units=local_unit))
                         except:
                             _, exc_value, _ = sys.exc_info()
@@ -1218,6 +1186,5 @@
             else:
                 exec "storage.%s = value" % variable
-                
-    
+
     # DO NOT REMOVE - used in saving and loading panel states.
     def _store_content(self, location, node, variable, storage):
@@ -1225,13 +1192,13 @@
         Get the content of a xpath location and store
         the result. The value is treated as a string.
-        
+
         The xpath location might or might not exist.
         If it does not exist, nothing is done
-        
+
         :param location: xpath location to fetch
         :param node: node to read the data from
         :param variable: name of the data member to store it in [string]
         :param storage: data object that has the 'variable' data member
-        
+
         :return: return a list of errors
         """
