Changeset 9e2bc6c in sasview


Ignore:
Timestamp:
Apr 4, 2014 10:04:58 AM (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:
f309303
Parents:
92a8206
Message:

Fixing tickets #204 and #233.

Location:
src/sans/dataloader/readers
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/sans/dataloader/readers/cansas_constants.py

    re090c624 r9e2bc6c  
    193193                                     "timestamp" : { 
    194194                                                    "variable" : META_DATA, 
    195                                                     "storeas" : "content", 
     195                                                    "storeas" : "timestamp", 
    196196                                                    } 
    197197                                     }, 
  • src/sans/dataloader/readers/cansas_reader.py

    rea67541 r9e2bc6c  
    1717import os 
    1818import sys 
     19import datetime 
    1920from sans.dataloader.data_info import Data1D 
    2021from sans.dataloader.data_info import Collimation 
     
    428429                                cs_values.current_level, attr, data1d, \ 
    429430                                tagname, node_value, cs_values.ns_optional) 
    430                      
     431                # If the value is a timestamp, convert to a datetime object 
     432                elif cs_values.ns_datatype == "timestamp": 
     433                    if node_value is None or node_value.isspace(): 
     434                        pass 
     435                    else: 
     436                        try: 
     437                            node_value = \ 
     438                                datetime.datetime.fromtimestamp(node_value) 
     439                        except ValueError: 
     440                            node_value = None 
    431441                # If appending to a dictionary (meta_data | run_name) 
    432442                # make sure the key is unique 
     
    516526        main_node = doc.createElement("SASroot") 
    517527         
    518         doc = self.setProcessingInstructions(doc, datainfo.meta_data[PREPROCESS]) 
     528        doc = self.setProcessingInstructions(doc, \ 
     529                                        datainfo.meta_data.get(PREPROCESS, {})) 
    519530        main_node.setAttribute("version", self.cansas_version) 
    520531        main_node.setAttribute("xmlns", ns) 
     
    532543         
    533544        write_node(doc, entry_node, "Title", datainfo.title) 
     545        if datainfo.run == None or datainfo.run == []: 
     546            RUN_NAME_DEFAULT = "None" 
     547            datainfo.run.append(RUN_NAME_DEFAULT) 
     548            datainfo.run_name[RUN_NAME_DEFAULT] = RUN_NAME_DEFAULT 
    534549        for item in datainfo.run: 
    535550            runname = {} 
     
    567582            spectrum = datainfo.trans_spectrum[i] 
    568583            node = doc.createElement("SAStransmission_spectrum") 
     584            node.setAttribute("name", spectrum.name) 
     585            if isinstance(spectrum.timestamp, datetime.datetime): 
     586                node.setAttribute("timestamp", spectrum.timestamp) 
    569587            entry_node.appendChild(node) 
    570588            for i in range(len(spectrum.wavelength)): 
     
    632650            source.setAttribute("name", str(datainfo.source.name)) 
    633651        instr.appendChild(source) 
     652        if datainfo.source.radiation == None or datainfo.source.radiation == '': 
     653            datainfo.source.radiation = "neutron" 
    634654        write_node(doc, source, "radiation", datainfo.source.radiation) 
    635655         
     
    663683         
    664684        #   Collimation 
     685        if datainfo.collimation == [] or datainfo.collimation == None: 
     686            coll = Collimation() 
     687            datainfo.collimation.append(coll) 
    665688        for item in datainfo.collimation: 
    666689            coll = doc.createElement("SAScollimation") 
     
    696719 
    697720        #   Detectors 
     721        if datainfo.detector == None or datainfo.detector == []: 
     722            det = Detector() 
     723            det.name = "" 
     724            datainfo.detector.append(det) 
     725                 
    698726        for item in datainfo.detector: 
    699727            det = doc.createElement("SASdetector") 
     
    808836        return minidomObject 
    809837     
    810      
Note: See TracChangeset for help on using the changeset viewer.