Changeset 579ba85 in sasview


Ignore:
Timestamp:
Aug 29, 2008 3:56:50 PM (16 years ago)
Author:
Mathieu Doucet <doucetm@…>
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:
442f42f
Parents:
4c00964
Message:

CanSAS format reader/writer completed/tested.

Location:
DataLoader
Files:
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • DataLoader/data_info.py

    r4c00964 r579ba85  
    2424 
    2525#TODO: Keep track of data manipulation in the 'process' data structure. 
    26  
    27 from sans.guitools.plottables import Data1D as plottable_1D 
     26#TODO: This module should be independent of plottables. We should write 
     27#        an adapter class for plottables when needed. 
     28 
     29#from sans.guitools.plottables import Data1D as plottable_1D 
    2830from data_util.uncertainty import Uncertainty 
    2931import numpy 
    3032import math 
    3133 
     34class plottable_1D: 
     35    """ 
     36        Data1D is a place holder for 1D plottables. 
     37    """ 
     38    x = None 
     39    y = None 
     40    dx = None 
     41    dy = None 
     42     
     43    # Units 
     44    _xaxis = '' 
     45    _xunit = '' 
     46    _yaxis = '' 
     47    _yunit = '' 
     48     
     49    def __init__(self,x,y,dx=None,dy=None): 
     50        self.x = x 
     51        self.y = y 
     52        self.dx = dx 
     53        self.dy = dy 
     54 
     55    def xaxis(self, label, unit): 
     56        self._xaxis = label 
     57        self._xunit = unit 
     58         
     59    def yaxis(self, label, unit): 
     60        self._yaxis = label 
     61        self._yunit = unit 
     62 
    3263class plottable_2D: 
    3364    """ 
    34         Data2D is a place holder for 2D plottables, which are  
    35         not yet implemented. 
     65        Data2D is a place holder for 2D plottables. 
    3666    """ 
    3767    xmin = None 
     
    148178class Aperture: 
    149179    ## Name 
    150     name = '' 
     180    name = None 
    151181    ## Type 
    152     type = '' 
     182    type = None 
     183    ## Size name 
     184    size_name = None 
    153185    ## Aperture size [Vector] 
    154186    size = None 
     
    192224    """   
    193225    ## Name 
    194     name = '' 
     226    name = None 
    195227    ## Radiation type [string] 
    196     radiation = '' 
     228    radiation = None 
     229    ## Beam size name 
     230    beam_size_name = None 
    197231    ## Beam size [Vector] [mm] 
    198232    beam_size = None 
    199233    beam_size_unit = 'mm' 
    200234    ## Beam shape [string] 
    201     beam_shape = '' 
     235    beam_shape = None 
    202236    ## Wavelength [float] [Angstrom] 
    203237    wavelength = None 
     
    246280        Class to hold the sample description 
    247281    """ 
     282    ## Short name for sample 
     283    name = '' 
    248284    ## ID 
    249285    ID = '' 
     
    327363    ## Run number 
    328364    run        = None 
     365    ## Run name 
     366    run_name   = None 
    329367    ## File name 
    330368    filename   = '' 
     
    355393        self.title      = '' 
    356394        ## Run number 
    357         self.run        = None 
     395        self.run        = [] 
     396        self.run_name   = {} 
    358397        ## File name 
    359398        self.filename   = '' 
  • DataLoader/loader.py

    r77c1c29d r579ba85  
    7171            self.readers = {} 
    7272            #Load all readers in plugins 
    73             self.__setitem__() 
     73             
     74            #TODO: misuse of __setitem__ 
     75            #TODO: this bad call is done twice: here, and in Loader.__init__ 
     76            #self.__setitem__() 
    7477             
    7578             
     
    9497            if dir==None: 
    9598                dir = 'readers' 
     99                 
     100            #TODO Probably name the new path something else... 
     101             
     102            #TODO: The whole concept of plug-ins was missed here. 
     103            # First we want to always load the reader we have (in 'readers') 
     104            # and THEN we want to add any additional readers found in 
     105            # a pre-defined plug-in path (that path should be a variable). 
    96106            dir=os.path.join(os.path.dirname(os.path.abspath(__file__)),dir) 
    97107             
     
    100110                if os.path.isdir(dir): 
    101111                    plugReader=_findReaders(dir)# import all module in plugins 
     112                 
     113                #TODO The following just doesn't make sense 
     114                # ../C:\Python25\lib... ???? 
    102115                if os.path.isdir('../'+dir): 
    103116                    plugReader=_findReaders('../'+dir) 
     
    107120                    list=[] 
    108121                    for preader in plugReader:# for each modules takes list of extensions 
     122                        #TODO should use hasattr rather than a try/except block 
    109123                        try: 
    110124                            list=preader.ext 
  • DataLoader/readers/cansas_reader.py

    r4c00964 r579ba85  
    88copyright 2008, University of Tennessee 
    99""" 
    10  
    11 #TODO: Unit conversion 
    12 #TODO: missing aperture type: go through all entries and check for additional attributes 
     10# Known issue: reader not compatible with multiple SASdata entries 
     11# within a single SASentry. Will raise a runtime error. 
     12 
    1313#TODO: check that all vectors are written only if they have at least one non-empty value 
    14 #TODO: multiple SASEntrys 
     14#TODO: Writing only allows one SASentry per file. Would be best to allow multiple entries. 
    1515#TODO: Store error list 
    16 #TODO: convert from pixel to mm for beam center... 
    1716#TODO: Allow for additional meta data for each section 
    1817#TODO: Notes need to be implemented. They can be any XML structure in version 1.0 
     
    258257        # Look up title 
    259258        _store_content('Title', dom, 'title', data_info) 
    260         # Look up run number                     
    261         _store_content('Run', dom, 'run', data_info)                     
     259        # Look up run number    
     260        nodes = xpath.Evaluate('Run', dom) 
     261        for item in nodes:     
     262            value, attr = get_node_text(item) 
     263            if value is not None: 
     264                data_info.run.append(value) 
     265                if attr.has_key('name'): 
     266                    data_info.run_name[value] = attr['name']          
     267                            
    262268        # Look up instrument name               
    263         value, attr = get_content('SASinstrument', dom) 
    264         if attr.has_key('name'): 
    265             data_info.instrument = attr['name'] 
     269        _store_content('SASinstrument/name', dom, 'instrument', data_info) 
     270        #value, attr = get_content('SASinstrument', dom) 
     271        #if attr.has_key('name'): 
     272        #    data_info.instrument = attr['name'] 
    266273 
    267274        note_list = xpath.Evaluate('SASnote', dom) 
     
    276283         
    277284        # Sample info ################### 
     285        value, attr = get_content('SASsample', dom) 
     286        if attr.has_key('name'): 
     287            data_info.sample.name = attr['name'] 
     288             
    278289        _store_content('SASsample/ID',  
    279290                     dom, 'ID', data_info.sample)                     
     
    327338                     dom, 'wavelength_spread', data_info.source)     
    328339         
    329         # Beam size (as a vector)       
     340        # Beam size (as a vector)    
     341        value, attr = get_content('SASinstrument/SASsource/beam_size', dom) 
     342        if attr.has_key('name'): 
     343            data_info.source.beam_size_name = attr['name'] 
     344             
    330345        _store_float('SASinstrument/SASsource/beam_size/x',  
    331346                     dom, 'beam_size.x', data_info.source)     
     
    350365                 
    351366                # Get the name and type of the aperture 
    352                 ap_value, ap_attr = get_node_text(item) 
     367                ap_value, ap_attr = get_node_text(apert) 
    353368                if ap_attr.has_key('name'): 
    354369                    aperture.name = ap_attr['name'] 
     
    357372                     
    358373                _store_float('distance', apert, 'distance', aperture)     
     374                 
     375                value, attr = get_content('size', apert) 
     376                if attr.has_key('name'): 
     377                    aperture.size_name = attr['name'] 
     378                 
    359379                _store_float('size/x', apert, 'size.x', aperture)     
    360380                _store_float('size/y', apert, 'size.y', aperture)     
     
    380400             
    381401            # Detector orientation (as a vector) 
    382             _store_float('orientation/pitch', item, 'orientation.x', detector)     
    383             _store_float('orientation/yaw',  item, 'orientation.y', detector)     
    384             _store_float('orientation/roll',  item, 'orientation.z', detector)     
     402            _store_float('orientation/roll', item, 'orientation.x', detector)     
     403            _store_float('orientation/pitch', item, 'orientation.y', detector)     
     404            _store_float('orientation/yaw',   item, 'orientation.z', detector)     
    385405             
    386406            # Beam center (as a vector) 
     
    430450             
    431451        # Data info ###################### 
     452        nodes = xpath.Evaluate('SASdata', dom) 
     453        if len(nodes)>1: 
     454            raise RuntimeError, "CanSAS reader is not compatible with multiple SASdata entries" 
     455         
    432456        nodes = xpath.Evaluate('SASdata/Idata', dom) 
    433457        x  = numpy.zeros(0) 
     
    455479            if _x is not None and _y is not None: 
    456480                x  = numpy.append(x, _x) 
    457                 y  = numpy.append(x, _y) 
    458                 dx = numpy.append(x, _dx) 
    459                 dy = numpy.append(x, _dy) 
     481                y  = numpy.append(y, _y) 
     482                dx = numpy.append(dx, _dx) 
     483                dy = numpy.append(dy, _dy) 
    460484             
    461485        data_info.x = x 
     
    508532        main_node.appendChild(entry_node) 
    509533         
    510         write_node(doc, entry_node, "title", datainfo.title) 
    511         write_node(doc, entry_node, "run", datainfo.run) 
     534        write_node(doc, entry_node, "Title", datainfo.title) 
     535         
     536        for item in datainfo.run: 
     537            runname = {} 
     538            if datainfo.run_name.has_key(item) and len(str(datainfo.run_name[item]))>1: 
     539                runname = {'name': datainfo.run_name[item] } 
     540            write_node(doc, entry_node, "Run", item, runname) 
    512541         
    513542        # Data info 
     
    515544        entry_node.appendChild(node) 
    516545         
     546        for i in range(len(datainfo.x)): 
     547            pt = doc.createElement("Idata") 
     548            node.appendChild(pt) 
     549            write_node(doc, pt, "Q", datainfo.x[i], {'unit':datainfo.x_unit}) 
     550            if len(datainfo.y)>=i: 
     551                write_node(doc, pt, "I", datainfo.y[i], {'unit':datainfo.y_unit}) 
     552            if len(datainfo.dx)>=i: 
     553                write_node(doc, pt, "Qdev", datainfo.dx[i], {'unit':datainfo.x_unit}) 
     554            if len(datainfo.dy)>=i: 
     555                write_node(doc, pt, "Idev", datainfo.dy[i], {'unit':datainfo.y_unit}) 
     556 
     557         
    517558        # Sample info 
    518559        sample = doc.createElement("SASsample") 
     560        if datainfo.sample.name is not None: 
     561            sample.setAttribute("name", str(datainfo.sample.name)) 
    519562        entry_node.appendChild(sample) 
    520         write_node(doc, sample, "ID", datainfo.sample.ID) 
     563        write_node(doc, sample, "ID", str(datainfo.sample.ID)) 
    521564        write_node(doc, sample, "thickness", datainfo.sample.thickness, {"unit":datainfo.sample.thickness_unit}) 
    522565        write_node(doc, sample, "transmission", datainfo.sample.transmission) 
     
    527570         
    528571        pos = doc.createElement("position") 
    529         written = False 
    530         written = written or write_node(doc, pos, "x", datainfo.sample.position.x, {"unit":datainfo.sample.position_unit}) 
    531         written = written or write_node(doc, pos, "y", datainfo.sample.position.y, {"unit":datainfo.sample.position_unit}) 
    532         written = written or write_node(doc, pos, "z", datainfo.sample.position.z, {"unit":datainfo.sample.position_unit}) 
     572        written = write_node(doc, pos, "x", datainfo.sample.position.x, {"unit":datainfo.sample.position_unit}) 
     573        written = written | write_node(doc, pos, "y", datainfo.sample.position.y, {"unit":datainfo.sample.position_unit}) 
     574        written = written | write_node(doc, pos, "z", datainfo.sample.position.z, {"unit":datainfo.sample.position_unit}) 
    533575        if written == True: 
    534576            sample.appendChild(pos) 
    535577         
    536578        ori = doc.createElement("orientation") 
    537         written = False 
    538         written = written or write_node(doc, ori, "roll",  datainfo.sample.orientation.x, {"unit":datainfo.sample.orientation_unit}) 
    539         written = written or write_node(doc, ori, "pitch", datainfo.sample.orientation.y, {"unit":datainfo.sample.orientation_unit}) 
    540         written = written or write_node(doc, ori, "yaw",   datainfo.sample.orientation.z, {"unit":datainfo.sample.orientation_unit}) 
     579        written = write_node(doc, ori, "roll",  datainfo.sample.orientation.x, {"unit":datainfo.sample.orientation_unit}) 
     580        written = written | write_node(doc, ori, "pitch", datainfo.sample.orientation.y, {"unit":datainfo.sample.orientation_unit}) 
     581        written = written | write_node(doc, ori, "yaw",   datainfo.sample.orientation.z, {"unit":datainfo.sample.orientation_unit}) 
    541582        if written == True: 
    542583            sample.appendChild(ori) 
     
    550591        #   Source 
    551592        source = doc.createElement("SASsource") 
    552         source.setAttribute("name", str(datainfo.source.name)) 
     593        if datainfo.source.name is not None: 
     594            source.setAttribute("name", str(datainfo.source.name)) 
    553595        instr.appendChild(source) 
    554596         
    555597        write_node(doc, source, "radiation", datainfo.source.radiation) 
    556598        write_node(doc, source, "beam_shape", datainfo.source.beam_shape) 
     599        size = doc.createElement("beam_size") 
     600        if datainfo.source.beam_size_name is not None: 
     601            size.setAttribute("name", str(datainfo.source.beam_size_name)) 
     602        written = write_node(doc, size, "x", datainfo.source.beam_size.x, {"unit":datainfo.source.beam_size_unit}) 
     603        written = written | write_node(doc, size, "y", datainfo.source.beam_size.y, {"unit":datainfo.source.beam_size_unit}) 
     604        written = written | write_node(doc, size, "z", datainfo.source.beam_size.z, {"unit":datainfo.source.beam_size_unit}) 
     605        if written == True: 
     606            source.appendChild(size) 
     607             
    557608        write_node(doc, source, "wavelength", datainfo.source.wavelength, {"unit":datainfo.source.wavelength_unit}) 
    558609        write_node(doc, source, "wavelength_min", datainfo.source.wavelength_min, {"unit":datainfo.source.wavelength_min_unit}) 
     
    563614        for item in datainfo.collimation: 
    564615            coll = doc.createElement("SAScollimation") 
    565             coll.setAttribute("name", item.name) 
     616            if item.name is not None: 
     617                coll.setAttribute("name", str(item.name)) 
    566618            instr.appendChild(coll) 
    567619             
     
    569621             
    570622            for apert in item.aperture: 
    571                 ap = doc.createElement("SAScollimation") 
    572                 ap.setAttribute("name", apert.name) 
    573                 ap.setAttribute("type", apert.type) 
    574                 instr.appendChild(ap) 
     623                ap = doc.createElement("aperture") 
     624                if apert.name is not None: 
     625                    ap.setAttribute("name", str(apert.name)) 
     626                if apert.type is not None: 
     627                    ap.setAttribute("type", str(apert.type)) 
     628                coll.appendChild(ap) 
    575629                 
    576630                write_node(doc, ap, "distance", apert.distance, {"unit":apert.distance_unit}) 
    577631                 
    578632                size = doc.createElement("size") 
    579                 ap.appendChild(size) 
    580                 write_node(doc, size, "x", apert.size.x, {"unit":apert.size_unit}) 
    581                 write_node(doc, size, "y", apert.size.y, {"unit":apert.size_unit}) 
    582                 write_node(doc, size, "z", apert.size.z, {"unit":apert.size_unit}) 
    583                  
     633                if apert.size_name is not None: 
     634                    size.setAttribute("name", str(apert.size_name)) 
     635                written = write_node(doc, size, "x", apert.size.x, {"unit":apert.size_unit}) 
     636                written = written | write_node(doc, size, "y", apert.size.y, {"unit":apert.size_unit}) 
     637                written = written | write_node(doc, size, "z", apert.size.z, {"unit":apert.size_unit}) 
     638                if written == True: 
     639                    ap.appendChild(size) 
    584640 
    585641        #   Detectors 
    586642        for item in datainfo.detector: 
    587643            det = doc.createElement("SASdetector") 
    588             instr.appendChild(det) 
    589              
    590             write_node(doc, det, "name", item.name) 
    591             write_node(doc, det, "SDD", item.distance, {"unit":item.distance_unit}) 
    592             write_node(doc, det, "slit_length", item.slit_length, {"unit":item.slit_length_unit}) 
     644            written = write_node(doc, det, "name", item.name) 
     645            written = written | write_node(doc, det, "SDD", item.distance, {"unit":item.distance_unit}) 
     646            written = written | write_node(doc, det, "slit_length", item.slit_length, {"unit":item.slit_length_unit}) 
     647            if written == True: 
     648                instr.appendChild(det) 
    593649             
    594650            off = doc.createElement("offset") 
    595             det.appendChild(off) 
    596             write_node(doc, off, "x", item.offset.x, {"unit":item.offset_unit}) 
    597             write_node(doc, off, "y", item.offset.y, {"unit":item.offset_unit}) 
    598             write_node(doc, off, "z", item.offset.z, {"unit":item.offset_unit}) 
    599              
     651            written = write_node(doc, off, "x", item.offset.x, {"unit":item.offset_unit}) 
     652            written = written | write_node(doc, off, "y", item.offset.y, {"unit":item.offset_unit}) 
     653            written = written | write_node(doc, off, "z", item.offset.z, {"unit":item.offset_unit}) 
     654            if written == True: 
     655                det.appendChild(off) 
    600656             
    601657            center = doc.createElement("beam_center") 
    602             det.appendChild(center) 
    603             write_node(doc, center, "x", item.beam_center.x, {"unit":item.beam_center_unit}) 
    604             write_node(doc, center, "y", item.beam_center.y, {"unit":item.beam_center_unit}) 
    605             write_node(doc, center, "z", item.beam_center.z, {"unit":item.beam_center_unit}) 
    606              
     658            written = write_node(doc, center, "x", item.beam_center.x, {"unit":item.beam_center_unit}) 
     659            written = written | write_node(doc, center, "y", item.beam_center.y, {"unit":item.beam_center_unit}) 
     660            written = written | write_node(doc, center, "z", item.beam_center.z, {"unit":item.beam_center_unit}) 
     661            if written == True: 
     662                det.appendChild(center) 
     663                 
    607664            pix = doc.createElement("pixel_size") 
    608             det.appendChild(pix) 
    609             write_node(doc, pix, "x", item.pixel_size.x, {"unit":item.pixel_size_unit}) 
    610             write_node(doc, pix, "y", item.pixel_size.y, {"unit":item.pixel_size_unit}) 
    611             write_node(doc, pix, "z", item.pixel_size.z, {"unit":item.pixel_size_unit}) 
    612              
    613          
    614         # Sample info 
     665            written = write_node(doc, pix, "x", item.pixel_size.x, {"unit":item.pixel_size_unit}) 
     666            written = written | write_node(doc, pix, "y", item.pixel_size.y, {"unit":item.pixel_size_unit}) 
     667            written = written | write_node(doc, pix, "z", item.pixel_size.z, {"unit":item.pixel_size_unit}) 
     668            if written == True: 
     669                det.appendChild(pix) 
     670                 
     671            ori = doc.createElement("orientation") 
     672            written = write_node(doc, ori, "roll",  item.orientation.x, {"unit":item.orientation_unit}) 
     673            written = written | write_node(doc, ori, "pitch", item.orientation.y, {"unit":item.orientation_unit}) 
     674            written = written | write_node(doc, ori, "yaw",   item.orientation.z, {"unit":item.orientation_unit}) 
     675            if written == True: 
     676                det.appendChild(ori) 
     677                 
     678         
     679        # Processes info 
    615680        for item in datainfo.process: 
    616681            node = doc.createElement("SASprocess") 
    617682            entry_node.appendChild(node) 
    618683 
    619             write_node(doc, entry_node, "run", item.name) 
     684            write_node(doc, node, "name", item.name) 
     685            write_node(doc, node, "date", item.date) 
     686            write_node(doc, node, "description", item.description) 
     687            for term in item.term: 
     688                value = term['value'] 
     689                del term['value'] 
     690                write_node(doc, node, "term", value, term) 
     691            for note in item.notes: 
     692                write_node(doc, node, "SASprocessnote", note) 
    620693             
    621694         
  • DataLoader/release_notes.txt

    r4c00964 r579ba85  
    44Package name: DataLoader 0.2 
    55 
    6 1-      Version 0.1 
     61-      Version 0.2 
    77        - Release date: ? 
     8        - First version of CanSAS reader/writer 
     9        - 1D data manipulations available 
     10         
     11        Version 0.1 
    812        - First version of SANS data loader 
    913        - Formats: IGOR 1D, IGOR 2D, CanSAS 1D, 2- or 3-column ascii 
     
    2529 
    2630        3.1- All systems: 
    27                 - None 
     31                - CanSAS format only allows a single SASdata section per SASentry. 
     32                - CanSAS format only allows one SASentry per file, for a single DataInfo object. 
    2833 
    2934        3.2- Windows: 
  • DataLoader/test/cansas1d.xml

    r4c00964 r579ba85  
    88        <SASentry> 
    99                <Title>Test title</Title> 
    10                 <Run>1234</Run> 
     10                <Run name='run name'>1234</Run> 
    1111                <SASdata> 
    1212                        <Idata> 
     
    1919                        </Idata> 
    2020                        <Idata> 
    21                                 <Q unit="1/A">0.02</Q> 
    22                                 <I unit="1/cm">1000</I> 
    23                                 <Idev unit="1/cm">3</Idev> 
    24                                 <Qdev unit="1/A">0.01</Qdev> 
     21                                <Q unit="1/A">0.03</Q> 
     22                                <I unit="1/cm">1001</I> 
     23                                <Idev unit="1/cm">4</Idev> 
     24                                <Qdev unit="1/A">0.02</Qdev> 
    2525                                <Qmean unit="1/A"><!-- Qmean is optional --></Qmean> 
    2626                                <Shadowfactor><!-- Shadowfactor is optional --></Shadowfactor> 
    2727                        </Idata> 
    2828                </SASdata> 
    29                 <SASsample> 
     29                <SASsample name='my sample'> 
    3030                        <ID>SI600-new-long</ID> 
    3131                        <thickness unit="mm">1.03</thickness> 
     
    5353                        <SASsource name="source name"> 
    5454                                <radiation>neutron</radiation> 
    55                                 <beam_size> 
     55                                <beam_size name='bm'> 
    5656                                        <x unit="mm">12.00</x> 
    57                                         <y unit="mm">12.00</y> 
     57                                        <y unit="mm">13.00</y> 
    5858                                </beam_size> 
    5959                                <beam_shape>disc</beam_shape> 
     
    7474                                </aperture> 
    7575                                <aperture name="sample" type="radius"> 
    76                                         <size> 
     76                                        <size name='size name'> 
    7777                                                <x unit="mm">1</x> 
    7878                                        </size> 
  • DataLoader/test/utest_abs_reader.py

    r4c00964 r579ba85  
    135135  
    136136    def test_checkdata(self): 
     137        self.assertEqual(self.data.filename, "cansas1d.xml") 
     138        self._checkdata() 
     139         
     140    def _checkdata(self): 
    137141        """ 
    138142            Check the data content to see whether  
     
    142146            tests won't pass 
    143147        """ 
    144         self.assertEqual(self.data.filename, "cansas1d.xml") 
    145         self.assertEqual(self.data.run, "1234") 
     148         
     149        self.assertEqual(self.data.run[0], "1234") 
     150         
     151        # Data 
     152        self.assertEqual(len(self.data.x), 2) 
     153        self.assertEqual(self.data.x_unit, '1/A') 
     154        self.assertEqual(self.data.y_unit, '1/cm') 
     155        self.assertEqual(self.data.x[0], 0.02) 
     156        self.assertEqual(self.data.y[0], 1000) 
     157        self.assertEqual(self.data.dx[0], 0.01) 
     158        self.assertEqual(self.data.dy[0], 3) 
     159        self.assertEqual(self.data.x[1], 0.03) 
     160        self.assertEqual(self.data.y[1], 1001) 
     161        self.assertEqual(self.data.dx[1], 0.02) 
     162        self.assertEqual(self.data.dy[1], 4) 
     163        self.assertEqual(self.data.run_name['1234'], 'run name') 
     164        self.assertEqual(self.data.title, "Test title") 
    146165         
    147166        # Sample info 
    148167        self.assertEqual(self.data.sample.ID, "SI600-new-long") 
     168        self.assertEqual(self.data.sample.name, "my sample") 
    149169        self.assertEqual(self.data.sample.thickness_unit, 'mm') 
    150170        self.assertEqual(self.data.sample.thickness, 1.03) 
     
    167187         
    168188        # Instrument info 
    169         self.assertEqual(self.data.instrument, "TEST instrument") 
     189        self.assertEqual(self.data.instrument, "canSAS instrument") 
    170190         
    171191        # Source 
     
    173193         
    174194        self.assertEqual(self.data.source.beam_size_unit, "mm") 
     195        self.assertEqual(self.data.source.beam_size_name, "bm") 
    175196        self.assertEqual(self.data.source.beam_size.x, 12) 
    176         self.assertEqual(self.data.source.beam_size.y, 12) 
     197        self.assertEqual(self.data.source.beam_size.y, 13) 
    177198         
    178199        self.assertEqual(self.data.source.beam_shape, "disc") 
     
    192213        _found2 = False 
    193214        self.assertEqual(self.data.collimation[0].length, 123.) 
     215        self.assertEqual(self.data.collimation[0].name, 'test coll name') 
    194216         
    195217        for item in self.data.collimation[0].aperture: 
     
    198220             
    199221            if item.size.x==50 \ 
    200                 and item.distance==11000.: 
     222                and item.distance==11000.0 \ 
     223                and item.name=='source' \ 
     224                and item.type=='radius': 
    201225                _found1 = True 
    202             elif item.size.x==1.0: 
     226            elif item.size.x==1.0 \ 
     227                and item.name=='sample' \ 
     228                and item.type=='radius': 
    203229                _found2 = True 
    204230                 
     
    209235        # Detector 
    210236        self.assertEqual(self.data.detector[0].name, "fictional hybrid") 
    211         self.assertEqual(self.data.detector[0].distance_unit, "m") 
    212         self.assertEqual(self.data.detector[0].distance, 4.150) 
     237        self.assertEqual(self.data.detector[0].distance_unit, "mm") 
     238        self.assertEqual(self.data.detector[0].distance, 4150) 
    213239         
    214240        self.assertEqual(self.data.detector[0].orientation_unit, "degree") 
     
    218244         
    219245        self.assertEqual(self.data.detector[0].offset_unit, "m") 
    220         self.assertEqual(self.data.detector[0].offset.x, .01) 
    221         self.assertEqual(self.data.detector[0].offset.y, .02) 
     246        self.assertEqual(self.data.detector[0].offset.x, .001) 
     247        self.assertEqual(self.data.detector[0].offset.y, .002) 
    222248        self.assertEqual(self.data.detector[0].offset.z, None) 
    223249         
     
    233259         
    234260        # Process 
     261        _found_term1 = False 
     262        _found_term2 = False 
     263        for item in self.data.process: 
     264            self.assertTrue(item.name in ['NCNR-IGOR', 'spol']) 
     265            self.assertTrue(item.date in ['04-Sep-2007 18:35:02', 
     266                                          '03-SEP-2006 11:42:47']) 
     267            for t in item.term: 
     268                if t['name']=="ABS:DSTAND" \ 
     269                    and t['unit']=='mm' \ 
     270                    and float(t['value'])==1.0: 
     271                    _found_term2 = True 
     272                elif t['name']=="radialstep" \ 
     273                    and t['unit']=='mm' \ 
     274                    and float(t['value'])==10.0: 
     275                    _found_term1 = True 
     276                     
     277        if _found_term1==False or _found_term2==False: 
     278            raise RuntimeError, "Could not find all process terms %s %s" % (_found_term1, _found_term2)  
     279             
    235280         
    236281         
     
    243288        dy = numpy.ones(5) 
    244289         
    245         d = Loader().load("jan08002.ABS") 
    246         #d = Data1D(x, y, dy) 
    247         r.write("write_test.xml", d) 
     290        filename = "write_test.xml" 
     291        r.write(filename, self.data) 
     292        self.data = Loader().load(filename) 
     293        self.assertEqual(self.data.filename, filename) 
     294        self._checkdata() 
     295         
    248296         
    249297         
Note: See TracChangeset for help on using the changeset viewer.