Ignore:
Timestamp:
19/01/12 21:46:58 (4 months ago)
Author:
Paul Kienzle
Message:

Refs #322: Allow root.save() to replace the underlying file; tree property now returns a string rather than printing; treestr changed to tree_with_attrs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bindings/python/nxs/tree.py

    r1803 r1804  
    99    1. To provide convenient access to existing data contained in NeXus files. 
    1010    2. To enable new NeXus data to be created and manipulated interactively. 
    11      
     11 
    1212These goals are achieved by mapping hierarchical NeXus data structures directly 
    1313into python objects, which either represent NeXus groups or NeXus fields. 
     
    7575    >>> X,Y=np.meshgrid(y,x) 
    7676    >>> z=np.sin(X)*np.sin(Y) 
    77      
    78 Then a NeXus data groups are created and the data inserted to produce a  
     77 
     78Then a NeXus data groups are created and the data inserted to produce a 
    7979NeXus-compliant structure that can be saved to a file. 
    8080 
     
    147147    * nxdata   attribute data 
    148148 
    149 There is a subclass of NXgroup for each group class defined by the NeXus standard,  
     149There is a subclass of NXgroup for each group class defined by the NeXus standard, 
    150150so it is possible to create an NXgroup of NeXus class NXsample directly using: 
    151151 
    152152    >>> sample = NXsample() 
    153153 
    154 The default group name will be the class name following the 'NX', so the above  
    155 group will have an nxname of 'sample'. However, this is overridden by the  
     154The default group name will be the class name following the 'NX', so the above 
     155group will have an nxname of 'sample'. However, this is overridden by the 
    156156attribute name when it is assigned as a group attribute, e.g., 
    157157 
     
    164164specify which one to use.  For example, 
    165165 
    166     tree.NXentry[0].NXinstrument[0].NXdetector[0].distance  
    167  
    168 references the first detector of the first instrument of the first entry.  
     166    tree.NXentry[0].NXinstrument[0].NXdetector[0].distance 
     167 
     168references the first detector of the first instrument of the first entry. 
    169169Unfortunately, there is no guarantee regarding the order of the entries, and it 
    170170may vary from call to call, so this is mainly useful in iterative searches. 
     
    225225""" 
    226226 
    227 __all__ = ['NeXusTree', 'NXobject', 'NXfield', 'NXgroup', 'NXattr',  
    228            'NX_MEMORY', 'setmemory', 'load', 'save', 'tree', 'centers',  
     227__all__ = ['NeXusTree', 'NXobject', 'NXfield', 'NXgroup', 'NXattr', 
     228           'NX_MEMORY', 'setmemory', 'load', 'save', 'tree', 'centers', 
    229229           'NXlink', 'NXlinkfield', 'NXlinkgroup', 'SDS', 'NXlinkdata'] 
    230230 
     
    288288        Read the NeXus file structure from the file and return a tree of NXobjects. 
    289289 
    290         Large datasets are not read until they are needed.   
     290        Large datasets are not read until they are needed. 
    291291        """ 
    292292        self.open() 
     
    294294        root = self._readgroup() 
    295295        self.close() 
    296         root._group = None         
     296        root._group = None 
    297297        # Resolve links (not necessary now that link is set as a property) 
    298298        #self._readlinks(root, root) 
     
    304304        Write the NeXus file structure to a file. 
    305305 
    306         The file is assumed to start empty. Updating individual objects can be  
     306        The file is assumed to start empty. Updating individual objects can be 
    307307        done using the napi interface, with nx.handle as the nexus file handle. 
    308308        """ 
     
    379379        n,name,nxclass = self.getgroupinfo() 
    380380        attrs = {} 
    381         attrs = self.getattrs()         
     381        attrs = self.getattrs() 
    382382        if 'target' in attrs and attrs['target'] != self.path: 
    383383            # This is a linked group; don't try to load it. 
     
    397397                obj._group = group 
    398398        return group 
    399      
     399 
    400400    def _readlinks(self, root, group): 
    401401        """ 
     
    413413            elif isinstance(entry, NXgroup): 
    414414                self._readlinks(root, entry) 
    415                  
     415 
    416416    def _writeattrs(self, attrs): 
    417417        """ 
    418418        Return the attributes for the currently open group/data. 
    419          
     419 
    420420        If no group or data object is open, the file attributes are returned. 
    421421        """ 
     
    446446            if shape[-1] < 100000: 
    447447                slab_dims[-1] = shape[-1] 
    448             else:  
     448            else: 
    449449                slab_dims[-1] = 100000 
    450450            self.compmakedata(data.nxname, data.dtype, shape, 'lzw', slab_dims) 
     
    493493        """ 
    494494        Create links within the NeXus file. 
    495          
     495 
    496496        THese are defined by the set of pairs returned by _writegroup. 
    497497        """ 
     
    527527    """ 
    528528    Return a list of axis names stored in the 'axes' attribute. 
    529      
     529 
    530530    The delimiter separating each axis can be white space, a comma, or a colon. 
    531531    """ 
     
    540540    A dictionary class to assign all attributes to the NXattr class. 
    541541    """ 
    542      
     542 
    543543    def __setitem__(self, key, value): 
    544544        if isinstance(value, NXattr): 
     
    552552    """ 
    553553    Class for NeXus attributes of a NXfield or NXgroup object. 
    554      
    555     This class is only used for NeXus attributes that are stored in a  
    556     NeXus file and helps to distinguish them from Python attributes.  
     554 
     555    This class is only used for NeXus attributes that are stored in a 
     556    NeXus file and helps to distinguish them from Python attributes. 
    557557    There are two Python attributes for each NeXus attribute. 
    558      
     558 
    559559    Python Attributes 
    560560    ----------------- 
     
    565565        a string attribute or the string of the corresponding Numpy data type 
    566566        for a numeric attribute. 
    567      
     567 
    568568    NeXus Attributes 
    569569    ---------------- 
    570570    NeXus attributes are stored in the 'attrs' dictionary of the parent object, 
    571571    NXfield or NXgroup, but can often be referenced or assigned using the 
    572     attribute name as if it were an object attribute.  
    573      
     572    attribute name as if it were an object attribute. 
     573 
    574574    For example, after assigning the NXfield, the following three attribute 
    575575    assignments are all equivalent:: 
     
    579579        >>> entry.sample.temperature.units = NXattr('K') 
    580580        >>> entry.sample.temperature.units = 'K' 
    581      
    582     The third version above is only allowed for NXfield attributes and is  
     581 
     582    The third version above is only allowed for NXfield attributes and is 
    583583    not allowed if the attribute has the same name as one of the following 
    584584    internally defined attributes, i.e., 
    585      
    586     ['entries', 'attrs', 'dtype','shape']  
    587      
    588     or if the attribute name begins with 'nx' or '_'. It is only possible to  
     585 
     586    ['entries', 'attrs', 'dtype','shape'] 
     587 
     588    or if the attribute name begins with 'nx' or '_'. It is only possible to 
    589589    reference attributes with one of the proscribed names using the 'attrs' 
    590590    dictionary. 
     
    606606                self._data,self._dtype = str(value), 'char' 
    607607            elif value is not None: 
    608                 if isinstance(value, NXobject):  
     608                if isinstance(value, NXobject): 
    609609                    raise NeXusError, "A data attribute cannot be a NXfield or NXgroup" 
    610610                else: 
     
    639639        """ 
    640640        return self._data 
    641      
     641 
    642642    def _getdtype(self): 
    643643        return self._dtype 
    644      
     644 
    645645    nxdata = property(_getdata,doc="The attribute values") 
    646646    dtype = property(_getdtype, "Data type of NeXus attribute") 
     
    652652    """ 
    653653    Abstract base class for elements in NeXus files. 
    654      
     654 
    655655    The object has a subclass of NXfield, NXgroup, or one of the NXgroup 
    656656    subclasses. Child nodes should be accessible directly as object attributes. 
    657657    Constructors for NXobject objects are defined by either the NXfield or 
    658658    NXgroup classes. 
    659      
     659 
    660660    Python Attributes 
    661661    ----------------- 
     
    664664        be one of the NXgroup subclasses. 
    665665    nxname : string 
    666         The name of the NXobject. Since it is possible to reference the same  
     666        The name of the NXobject. Since it is possible to reference the same 
    667667        Python object multiple times, this is not necessarily the same as the 
    668668        object name. However, if the object is part of a NeXus tree, this will 
    669         be the attribute name within the tree.  
     669        be the attribute name within the tree. 
    670670    nxgroup : NXgroup 
    671         The parent group containing this object within a NeXus tree. If the  
     671        The parent group containing this object within a NeXus tree. If the 
    672672        object is not part of any NeXus tree, it will be set to None. 
    673673    nxpath : string 
    674674        The path to this object with respect to the root of the NeXus tree. For 
    675675        NeXus data read from a file, this will be a group of class NXroot, but 
    676         if the NeXus tree was defined interactively, it can be any valid  
     676        if the NeXus tree was defined interactively, it can be any valid 
    677677        NXgroup. 
    678678    nxroot : NXgroup 
    679679        The root object of the NeXus tree containing this object. For 
    680680        NeXus data read from a file, this will be a group of class NXroot, but 
    681         if the NeXus tree was defined interactively, it can be any valid  
     681        if the NeXus tree was defined interactively, it can be any valid 
    682682        NXgroup. 
    683683    nxfile : NeXusTree 
    684         The file handle of the root object of the NeXus tree containing this  
     684        The file handle of the root object of the NeXus tree containing this 
    685685        object. 
    686686    filename : string 
     
    693693    dir(self, attrs=False, recursive=False): 
    694694        Print the group directory. 
    695          
     695 
    696696        The directory is a list of NeXus objects within this group, either NeXus 
    697697        groups or NXfield data. If 'attrs' is True, NXfield attributes are 
     
    701701    tree: 
    702702        Print the object's tree. 
    703          
    704         It invokes the 'dir' method with both 'attrs' and 'recursive'  
     703 
     704        It invokes the 'dir' method with both 'attrs' and 'recursive' 
    705705        set to True. Note that this method is defined as a property attribute and 
    706706        does not require parentheses. 
     
    709709        Save the NeXus group into a file 
    710710 
    711         The object is wrapped in an NXroot group (with name 'root') and an  
    712         NXentry group (with name 'entry'), if necessary, in order to produce  
     711        The object is wrapped in an NXroot group (with name 'root') and an 
     712        NXentry group (with name 'entry'), if necessary, in order to produce 
    713713        a valid NeXus file. 
    714714 
     
    725725    def __repr__(self): 
    726726        return "NXobject('%s','%s')"%(self.nxclass,self.nxname) 
    727          
     727 
    728728    def _setattrs(self, attrs): 
    729729        for k,v in attrs.items(): 
    730730            self._attrs[k] = v 
    731      
     731 
    732732    def _str_name(self,indent=0): 
    733733        if self.nxclass == 'NXfield': 
     
    752752        """ 
    753753        result = [self._str_name(indent=indent)] 
    754         if attrs and self.attrs:  
     754        if attrs and self.attrs: 
    755755            result.append(self._str_attrs(indent=indent+2)) 
    756756        # Print children 
     
    769769        return "\n".join(result) 
    770770 
     771    def walk(self): 
     772        print "yielding",self.nxname,self.nxclass 
     773        if False: yield 
     774 
     775 
    771776    def dir(self,attrs=False,recursive=False): 
    772777        """ 
    773778        Print the object directory. 
    774          
    775         The directory is a list of NeXus objects within this object, either  
    776         NeXus groups or NXfields. If 'attrs' is True, NXfield attributes are  
    777         displayed. If 'recursive' is True, the contents of child groups are  
     779 
     780        The directory is a list of NeXus objects within this object, either 
     781        NeXus groups or NXfields. If 'attrs' is True, NXfield attributes are 
     782        displayed. If 'recursive' is True, the contents of child groups are 
    778783        also displayed. 
    779784        """ 
     
    784789        """ 
    785790        Print the directory tree. 
    786          
    787         The tree contains all child objects of this object and their children.  
    788         It invokes the 'dir' method with both 'attrs' and 'recursive' set  
     791 
     792        The tree contains all child objects of this object and their children. 
     793        It invokes the 'dir' method with both 'attrs' and 'recursive' set 
    789794        to True. 
    790795        """ 
    791         print self._str_tree(attrs=True,recursive=True) 
    792          
    793     def treestr(self, attrs=True): 
     796        return self._str_tree(attrs=False,recursive=True) 
     797 
     798    @property 
     799    def tree_with_attrs(self, attrs=True): 
    794800        """Return directory tree string""" 
    795         return self._str_tree(attrs=attrs,recursive=True) 
    796      
     801        return self._str_tree(attrs=True,recursive=True) 
     802 
    797803    def save(self, filename=None, format='w5'): 
    798804        """ 
    799805        Save the NeXus object to a data file. 
    800          
    801         An error is raised if the object is an NXroot group from an external file  
    802         that has been opened as readonly and no file name is specified.   
    803          
    804         The object is wrapped in an NXroot group (with name 'root') and an  
    805         NXentry group (with name 'entry'), if necessary, in order to produce  
     806 
     807        An error is raised if the object is an NXroot group from an external file 
     808        that has been opened as readonly and no file name is specified. 
     809 
     810        The object is wrapped in an NXroot group (with name 'root') and an 
     811        NXentry group (with name 'entry'), if necessary, in order to produce 
    806812        a valid NeXus file. 
    807813        """ 
    808814        if self.nxclass == "NXroot": 
    809             tree = self 
     815            root = self 
    810816            if filename is None: 
    811817                if self._file: 
     
    817823        elif filename: 
    818824            if self.nxclass == "NXentry": 
    819                 tree = NXroot(self) 
     825                root = NXroot(self) 
    820826            else: 
    821                 tree = NXroot(NXentry(self)) 
     827                root = NXroot(NXentry(self)) 
    822828 
    823829        if filename is None: 
    824830            raise NeXusError, "No output file specified" 
    825831 
     832        # Preload the source tree 
     833        for node in root.walk(): 
     834            #print "node",node.nxname, node 
     835            if isinstance(node, NXfield): node.nxdata 
     836        if root._file: root._file.close() 
    826837        file = NeXusTree(filename, format) 
    827         file.writefile(tree) 
     838        file.writefile(root) 
    828839        file.close() 
    829         tree._file = file 
    830         tree._file.open() 
    831         tree._file.openpath('/') 
    832         tree._setattrs(tree._file.getattrs()) 
    833         tree._file.close() 
    834         return tree 
     840 
     841        return load(filename, 'rw') 
    835842 
    836843    def _getclass(self): 
    837844        return self._class 
    838      
     845 
    839846    def _getname(self): 
    840847        return self._name 
    841      
     848 
    842849    def _getgroup(self): 
    843850        return self._group 
    844      
     851 
    845852    def _getpath(self): 
    846853        if self.nxgroup is None: 
     
    850857        else: 
    851858            return self.nxgroup._getpath()+"/"+self.nxname 
    852      
     859 
    853860    def _getroot(self): 
    854861        if self.nxgroup is None: 
     
    858865        else: 
    859866            return self.nxgroup._getroot() 
    860      
     867 
    861868    def _getfile(self): 
    862869        return self.nxroot._file 
    863      
     870 
    864871    def _getfilename(self): 
    865872        return self.nxroot._file.filename 
    866      
     873 
    867874    def _getattrs(self): 
    868875        return self._attrs 
     
    882889    """ 
    883890    A NeXus data field. 
    884      
     891 
    885892    This is a subclass of NXobject that contains scalar, array, or string data 
    886     and associated NeXus attributes.  
    887      
    888     NXfield(value=None, name='unknown', dtype='', shape=[], attrs={}, file=None,  
     893    and associated NeXus attributes. 
     894 
     895    NXfield(value=None, name='unknown', dtype='', shape=[], attrs={}, file=None, 
    889896            path=None, group=None, **attr) 
    890897 
     
    911918    shape : list of ints 
    912919        The dimensions of the NXfield data, which is accessible as the NXfield 
    913         attribute 'shape'. This corresponds to the shape of the Numpy array.  
     920        attribute 'shape'. This corresponds to the shape of the Numpy array. 
    914921        Scalars (numeric or string) are stored as Numpy zero-rank arrays, 
    915922        for which shape=[]. 
     
    920927        The file from which the NXfield has been read. 
    921928    path : string 
    922         The path to this object with respect to the root of the NeXus tree,  
     929        The path to this object with respect to the root of the NeXus tree, 
    923930        using the convention for unix file paths. 
    924931    group : NXgroup or subclass of NXgroup 
     
    931938        The class of the NXobject. 
    932939    nxname : string 
    933         The name of the NXfield. Since it is possible to reference the same  
     940        The name of the NXfield. Since it is possible to reference the same 
    934941        Python object multiple times, this is not necessarily the same as the 
    935942        object name. However, if the field is part of a NeXus tree, this will 
    936         be the attribute name within the tree.  
     943        be the attribute name within the tree. 
    937944    nxgroup : NXgroup 
    938         The parent group containing this field within a NeXus tree. If the  
     945        The parent group containing this field within a NeXus tree. If the 
    939946        field is not part of any NeXus tree, it will be set to None. 
    940947    dtype : string or Numpy dtype 
    941948        The data type of the NXfield value. If the NXfield has been initialized 
    942949        but the data values have not been read in or defined, this is a string. 
    943         Otherwise, it is set to the equivalent Numpy dtype.  
     950        Otherwise, it is set to the equivalent Numpy dtype. 
    944951    shape : list or tuple of ints 
    945952        The dimensions of the NXfield data. If the NXfield has been initialized 
     
    949956        for which shape=(). 
    950957    attrs : dict 
    951         A dictionary of all the NeXus attributes associated with the field.  
     958        A dictionary of all the NeXus attributes associated with the field. 
    952959        These are objects with class NXattr. 
    953960    nxdata : scalar, Numpy array or string 
    954         The data value of the NXfield. This is normally initialized using the  
    955         'value' parameter (see above). If the NeXus data is contained  
    956         in a file and the size of the NXfield array is too large to be stored  
     961        The data value of the NXfield. This is normally initialized using the 
     962        'value' parameter (see above). If the NeXus data is contained 
     963        in a file and the size of the NXfield array is too large to be stored 
    957964        in memory, the value is not read in until this attribute is directly 
    958965        accessed. Even then, if there is insufficient memory, a value of None 
    959         will be returned. In this case, the NXfield array should be read as a  
    960         series of smaller slabs using 'get'.  
     966        will be returned. In this case, the NXfield array should be read as a 
     967        series of smaller slabs using 'get'. 
    961968    nxdata_as('units') : scalar value or Numpy array 
    962969        If the NXfield 'units' attribute has been set, the data values, stored 
     
    965972        The path to this object with respect to the root of the NeXus tree. For 
    966973        NeXus data read from a file, this will be a group of class NXroot, but 
    967         if the NeXus tree was defined interactively, it can be any valid  
     974        if the NeXus tree was defined interactively, it can be any valid 
    968975        NXgroup. 
    969976    nxroot : NXgroup 
    970977        The root object of the NeXus tree containing this object. For 
    971978        NeXus data read from a file, this will be a group of class NXroot, but 
    972         if the NeXus tree was defined interactively, it can be any valid  
     979        if the NeXus tree was defined interactively, it can be any valid 
    973980        NXgroup. 
    974981 
     
    983990    attributes always be referenced using the 'attrs' dictionary if there is 
    984991    any doubt. 
    985      
     992 
    986993    a) Assigning a NeXus attribute 
    987      
     994 
    988995    In the example below, after assigning the NXfield, the following three 
    989996    NeXus attribute assignments are all equivalent: 
     
    9931000        >>> entry.sample.temperature.units = NXattr('K') 
    9941001        >>> entry.sample.temperature.units = 'K' 
    995      
     1002 
    9961003    b) Referencing a NeXus attribute 
    997      
     1004 
    9981005    If the name of the NeXus attribute is not the same as any of the Python 
    999     attributes listed above, or one of the methods listed below, or any of the  
     1006    attributes listed above, or one of the methods listed below, or any of the 
    10001007    attributes defined for Numpy arrays, they can be referenced as if they were 
    10011008    a Python attribute of the NXfield. However, it is only possible to reference 
    10021009    attributes with one of the proscribed names using the 'attrs' dictionary. 
    1003      
     1010 
    10041011        >>> entry.sample.temperature.tree = 10.0 
    10051012        >>> entry.sample.temperature.tree 
     
    10191026    most Numpy operations work on NXfields, returning either another NXfield or, 
    10201027    in some cases, an ndarray that can easily be converted to an NXfield. 
    1021      
     1028 
    10221029        >>> x = NXfield((1.0,2.0,3.0,4.0)) 
    10231030        >>> print x+1 
     
    10431050 
    10441051    All these operations return valid NXfield objects containing the same 
    1045     attributes as the first NXobject in the expression. The 'reshape' and  
     1052    attributes as the first NXobject in the expression. The 'reshape' and 
    10461053    'transpose' methods also return NXfield objects. 
    1047      
     1054 
    10481055    It is possible to use the standard slice syntax. 
    10491056 
     
    10531060        >>> x[2:5] 
    10541061        NXfield([ 2.  3.  4.]) 
    1055      
     1062 
    10561063    In addition, it is possible to use floating point numbers as the slice 
    10571064    indices. If one of the indices is not integer, both indices are used to 
    10581065    extract elements in the array with values between the two index values. 
    1059      
     1066 
    10601067        >>> x=NXfield(np.linspace(0,100.,11)) 
    10611068        >>> x 
     
    10631070        >>> x[20.:50.] 
    10641071        NXfield([ 20.  30.  40.  50.]) 
    1065     
    1066     The standard Numpy ndarray attributes and methods will also work with  
     1072 
     1073    The standard Numpy ndarray attributes and methods will also work with 
    10671074    NXfields, but will return scalars or Numpy arrays. 
    1068      
     1075 
    10691076        >>> x.size 
    10701077        4 
     
    10791086        >>> x.reshape((2,2)).sum(1) 
    10801087        array([ 3.,  7.]) 
    1081      
     1088 
    10821089    Finally, NXfields are cast as ndarrays for operations that require them. 
    1083     The returned value will be the same as for the equivalent ndarray  
     1090    The returned value will be the same as for the equivalent ndarray 
    10841091    operation, e.g., 
    1085      
     1092 
    10861093    >>> np.sin(x) 
    10871094    array([ 0.84147098,  0.90929743,  0.14112001, -0.7568025 ]) 
    10881095    >>> np.sqrt(x) 
    10891096    array([ 1.        ,  1.41421356,  1.73205081,  2.        ]) 
    1090      
     1097 
    10911098    Methods 
    10921099    ------- 
    10931100    dir(self, attrs=False): 
    10941101        Print the NXfield specification. 
    1095          
    1096         This outputs the name, dimensions and data type of the NXfield.  
     1102 
     1103        This outputs the name, dimensions and data type of the NXfield. 
    10971104        If 'attrs' is True, NXfield attributes are displayed. 
    10981105 
    10991106    tree: 
    11001107        Print the NXfield's tree. 
    1101          
    1102         It invokes the 'dir' method with both 'attrs' and 'recursive'  
     1108 
     1109        It invokes the 'dir' method with both 'attrs' and 'recursive' 
    11031110        set to True. Note that this method is defined as a property attribute and 
    11041111        does not require parentheses. 
    1105          
    1106          
     1112 
     1113 
    11071114    save(self, filename, format='w5') 
    11081115        Save the NXfield into a file wrapped in a NXroot group and NXentry group 
    1109         with default names. This is equivalent to  
    1110          
     1116        with default names. This is equivalent to 
     1117 
    11111118        >>> NXroot(NXentry(NXfield(...))).save(filename) 
    11121119 
     
    11161123    >>> phi = x.nxdata_as(units='radian') 
    11171124    >>> y = NXfield(np.sin(phi)) 
    1118      
     1125 
    11191126    # Read a Ni x Nj x Nk array one vector at a time 
    11201127    >>> with root.NXentry[0].data.data as slab: 
     
    11271134    """ 
    11281135 
    1129     def __init__(self, value=None, name='unknown', dtype=None, shape=(), attrs={}, group=None,  
     1136    def __init__(self, value=None, name='unknown', dtype=None, shape=(), attrs={}, group=None, 
    11301137                 **attr): 
    11311138        if isinstance(value, list) or isinstance(value, tuple): 
     
    11661173        else: 
    11671174            return "NXfield(dtype=%s,shape=%s)" % (self.dtype,self.shape) 
    1168          
     1175 
    11691176    def __getattr__(self, name): 
    11701177        """ 
     
    11931200        """ 
    11941201        Returns a slice from the NXfield. 
    1195          
     1202 
    11961203        In most cases, the slice values are applied to the NXfield nxdata array 
    11971204        and returned within an NXfield object with the same metadata. However, 
    1198         if the array is one-dimensional and the index start and stop values  
     1205        if the array is one-dimensional and the index start and stop values 
    11991206        are real, the nxdata array is returned with values between those limits. 
    12001207        This is to allow axis arrays to be limited by their actual value. This 
     
    12291236                result = self.nxdata.__getitem__(index) 
    12301237        return NXfield(result, name=self.nxname, attrs=self.attrs) 
    1231                  
     1238 
    12321239    def __setitem__(self, index, value): 
    12331240        """ 
     
    12381245        else: 
    12391246            raise NeXusError, "NXfield dataspace not yet allocated" 
    1240                  
     1247 
    12411248    def __deepcopy__(self, memo): 
    12421249        dpcpy = self.__class__() 
     
    12541261        Return the length of the NXfield data. 
    12551262        """ 
    1256         return np.prod(self.shape)         
    1257          
     1263        return np.prod(self.shape) 
     1264 
    12581265    def index(self, value, max=False): 
    12591266        """ 
    12601267        Return the index of the NXfield nxdata array that is greater than or equal to the value. 
    1261          
     1268 
    12621269        If max, then return the index that is less than or equal to the value. 
    12631270        This should only be used on one-dimensional monotonically increasing arrays. 
     
    12731280        """ 
    12741281        return self.nxdata 
    1275                  
     1282 
    12761283    def __eq__(self, other): 
    12771284        """ 
     
    13041311        try: 
    13051312            if isinstance(other, NXfield): 
    1306                 return NXfield(value=self.nxdata+other.nxdata, name=self.nxname,  
     1313                return NXfield(value=self.nxdata+other.nxdata, name=self.nxname, 
    13071314                               attrs=self.attrs) 
    13081315            else: 
    1309                 return NXfield(value=self.nxdata+other, name=self.nxname,  
     1316                return NXfield(value=self.nxdata+other, name=self.nxname, 
    13101317                               attrs=self.attrs) 
    13111318        except TypeError, message: 
     
    13151322        """ 
    13161323        Return the sum of the NXfield and another NXfield or number. 
    1317          
     1324 
    13181325        This variant makes __add__ commutative. 
    13191326        """ 
     
    13261333        try: 
    13271334            if isinstance(other, NXfield): 
    1328                 return NXfield(value=self.nxdata-other.nxdata, name=self.nxname,  
     1335                return NXfield(value=self.nxdata-other.nxdata, name=self.nxname, 
    13291336                               attrs=self.attrs) 
    13301337            else: 
    1331                 return NXfield(value=self.nxdata-other, name=self.nxname,  
     1338                return NXfield(value=self.nxdata-other, name=self.nxname, 
    13321339                               attrs=self.attrs) 
    13331340        except TypeError, message: 
     
    13401347        try: 
    13411348            if isinstance(other, NXfield): 
    1342                 return NXfield(value=self.nxdata*other.nxdata, name=self.nxname,  
     1349                return NXfield(value=self.nxdata*other.nxdata, name=self.nxname, 
    13431350                               attrs=self.attrs) 
    13441351            else: 
    1345                 return NXfield(value=self.nxdata*other, name=self.nxname,  
     1352                return NXfield(value=self.nxdata*other, name=self.nxname, 
    13461353                               attrs=self.attrs) 
    13471354        except TypeError, message: 
     
    13511358        """ 
    13521359        Return the product of the NXfield and another NXfield or number. 
    1353          
     1360 
    13541361        This variant makes __mul__ commutative. 
    13551362        """ 
     
    13621369        try: 
    13631370            if isinstance(other, NXfield): 
    1364                 return NXfield(value=self.nxdata/other.nxdata, name=self.nxname,  
     1371                return NXfield(value=self.nxdata/other.nxdata, name=self.nxname, 
    13651372                               attrs=self.attrs) 
    13661373            else: 
    1367                 return NXfield(value=self.nxdata/other, name=self.nxname,  
     1374                return NXfield(value=self.nxdata/other, name=self.nxname, 
    13681375                               attrs=self.attrs) 
    13691376        except TypeError, message: 
     
    13761383        try: 
    13771384            if isinstance(other, NXfield): 
    1378                 return NXfield(value=other.nxdata/self.nxdata, name=self.nxname,  
     1385                return NXfield(value=other.nxdata/self.nxdata, name=self.nxname, 
    13791386                               attrs=self.attrs) 
    13801387            else: 
    1381                 return NXfield(value=other/self.nxdata, name=self.nxname,  
     1388                return NXfield(value=other/self.nxdata, name=self.nxname, 
    13821389                               attrs=self.attrs) 
    13831390        except TypeError, message: 
     
    13891396        """ 
    13901397        try: 
    1391             return NXfield(value=pow(self.nxdata,power), name=self.nxname,  
     1398            return NXfield(value=pow(self.nxdata,power), name=self.nxname, 
    13921399                           attrs=self.attrs) 
    13931400        except TypeError, message: 
     
    14041411    def transpose(self,shape=None):#added shape variable here 9/8/2010 
    14051412        """ 
    1406         Returns an NXfield containing the transpose of the data array. Equivalent  
     1413        Returns an NXfield containing the transpose of the data array. Equivalent 
    14071414        to the Numpy ndarray.transpose. 
    14081415        """ 
    14091416        # error, no shape variable in this scope 
    1410         return NXfield(value=self.nxdata.transpose(shape), name=self.nxname,  
     1417        return NXfield(value=self.nxdata.transpose(shape), name=self.nxname, 
    14111418                       attrs=self.attrs) 
    14121419 
    14131420    def centers(self): 
    14141421        """ 
    1415         Returns an NXfield with the centers of a single axis  
     1422        Returns an NXfield with the centers of a single axis 
    14161423        assuming it contains bin boundaries. 
    14171424        """ 
     
    14241431 
    14251432        Note: the results are undefined if you try accessing 
    1426         more than one slab at a time.  Don't nest your  
     1433        more than one slab at a time.  Don't nest your 
    14271434        "with data" statements! 
    14281435        """ 
     
    14501457        Offsets are 0-origin. Shape can be inferred from the data. 
    14511458        Offset and shape must each have one entry per dimension. 
    1452          
     1459 
    14531460        This operation should be performed in a "with group.data" 
    14541461        context. 
     
    14861493            self.__enter__() 
    14871494            if isinstance(data, NXfield): 
    1488                 self.nxroot._file.putslab(data.nxdata.astype(self.dtype), offset,  
     1495                self.nxroot._file.putslab(data.nxdata.astype(self.dtype), offset, 
    14891496                                        data.shape) 
    14901497            else: 
    14911498                data = np.array(data) 
    1492                 self.nxroot._file.putslab(data.astype(self.dtype), offset,  
     1499                self.nxroot._file.putslab(data.astype(self.dtype), offset, 
    14931500                                        data.shape) 
    14941501            self.__exit__() 
     
    14961503        else: 
    14971504            raise NeXusError, "No output file specified for NXputslab" 
    1498          
     1505 
    14991506    def add(self, data, offset): 
    15001507        """ 
     
    15061513        """ 
    15071514        if isinstance(data, NXfield): 
    1508             value = self.get(offset, data.shape)         
     1515            value = self.get(offset, data.shape) 
    15091516            self.put(data.nxdata.astype(self.dtype)+value, offset) 
    15101517        else: 
    15111518            value = self.get(offset, data.shape) 
    15121519            self.put(data.astype(self.dtype)+value, offset) 
    1513          
     1520 
    15141521    def refresh(self): 
    15151522        """ 
     
    15181525        Calls net to read in data again. If put has been called, then 
    15191526        nxdata is no longer synchronized with the file making a refresh 
    1520         necessary. This will only be performed if nxdata already stores the  
     1527        necessary. This will only be performed if nxdata already stores the 
    15211528        data. 
    15221529        """ 
     
    15261533            else: 
    15271534                raise NeXusError, "No file specified for reads" 
    1528          
     1535 
    15291536    def convert(self, units=""): 
    15301537        """ 
     
    15391546        else: 
    15401547            return None 
    1541      
     1548 
    15421549    def __str__(self): 
    15431550        """ 
     
    15651572        return "\n".join(v) 
    15661573 
     1574    def walk(self): 
     1575        yield self 
     1576 
    15671577    def _getaxes(self): 
    15681578        """ 
    15691579        Return a list of NXfields containing axes. 
    1570          
     1580 
    15711581        Only works if the NXfield has the 'axes' attribute 
    15721582        """ 
     
    15901600            else: 
    15911601                return None 
    1592                  
     1602 
    15931603        return self._value 
    1594      
     1604 
    15951605    def _setdata(self, value): 
    15961606        if value is not None: 
     
    16091619    def _getdtype(self): 
    16101620        return self._dtype 
    1611      
     1621 
    16121622    def _getshape(self): 
    16131623        return self._shape 
    1614      
     1624 
    16151625    def _getsize(self): 
    16161626        return len(self) 
     
    16441654        """ 
    16451655        Plot the data entry. 
    1646          
     1656 
    16471657        Raises NeXusError if the data cannot be plotted. 
    16481658        """ 
     
    16571667            over = False 
    16581668        if not over: pylab.clf() 
    1659          
     1669 
    16601670        if "log" in opts.keys(): 
    16611671            logplot = True 
     
    16651675 
    16661676        # Provide a new view of the data if there is a dimension of length 1 
    1667         if 1 in signal.shape:  
     1677        if 1 in signal.shape: 
    16681678            data, axes = _fixaxes(signal, axes) 
    16691679        else: 
     
    16811691                data = np.log10(np.clip(data,0,1e8)) 
    16821692                if errors: ebars = np.log10(errors) 
    1683             elif errors:  
     1693            elif errors: 
    16841694                ebars = errors.nxdata 
    16851695            if errors: 
     
    16951705                pylab.ylabel(label(signal)) 
    16961706                pylab.title(title) 
    1697   
     1707 
    16981708        #Two dimensional plot 
    16991709        else: 
     
    17091719            gridplot = imshow_irregular 
    17101720            if logplot: 
    1711                 gridplot(axis_data[0], axis_data[1],  
     1721                gridplot(axis_data[0], axis_data[1], 
    17121722                         np.log10(np.clip(data,0.,1e8)+1).T, **opts) 
    17131723            else: 
     
    17201730    def show(): 
    17211731        import pylab 
    1722         pylab.show()     
     1732        pylab.show() 
    17231733 
    17241734 
     
    17271737    """ 
    17281738    A NeXus group object. 
    1729      
     1739 
    17301740    This is a subclass of NXobject and is the base class for the specific 
    1731     NeXus group classes, e.g., NXentry, NXsample, NXdata.  
    1732      
     1741    NeXus group classes, e.g., NXentry, NXsample, NXdata. 
     1742 
    17331743    NXgroup(*items, **opts) 
    17341744 
    17351745    Parameters 
    17361746    ---------- 
    1737     The NXgroup parameters consist of a list of positional and/or keyword  
     1747    The NXgroup parameters consist of a list of positional and/or keyword 
    17381748    arguments. 
    1739      
    1740     Positional Arguments : These must be valid NeXus objects, either an NXfield  
    1741     or a NeXus group. These are added without modification as children of this  
    1742     group.  
    1743      
    1744     Keyword Arguments : Apart from a list of special keywords shown below,  
     1749 
     1750    Positional Arguments : These must be valid NeXus objects, either an NXfield 
     1751    or a NeXus group. These are added without modification as children of this 
     1752    group. 
     1753 
     1754    Keyword Arguments : Apart from a list of special keywords shown below, 
    17451755    keyword arguments are used to add children to the group using the keywords 
    1746     as attribute names. The values can either be valid NXfields or NXgroups,  
    1747     in which case the 'name' attribute is changed to the keyword, or they  
     1756    as attribute names. The values can either be valid NXfields or NXgroups, 
     1757    in which case the 'name' attribute is changed to the keyword, or they 
    17481758    can be numerical or string data, which are converted to NXfield objects. 
    1749      
     1759 
    17501760    Special Keyword Arguments: 
    17511761 
    17521762    name : string 
    1753         The name of the NXgroup, which is directly accessible as the NXgroup  
    1754         attribute 'name'. If the NXgroup is initialized as the attribute of  
    1755         a parent group, the name is automatically set to the name of this  
     1763        The name of the NXgroup, which is directly accessible as the NXgroup 
     1764        attribute 'name'. If the NXgroup is initialized as the attribute of 
     1765        a parent group, the name is automatically set to the name of this 
    17561766        attribute. If 'nxclass' is specified and has the usual prefix 'NX', 
    17571767        the default name is the class name without this prefix. 
    17581768    nxclass : string 
    1759         The class of the NXgroup.  
     1769        The class of the NXgroup. 
    17601770    entries : dict 
    1761         A dictionary containing a list of group entries. This is an  
    1762         alternative way of adding group entries to the use of keyword  
     1771        A dictionary containing a list of group entries. This is an 
     1772        alternative way of adding group entries to the use of keyword 
    17631773        arguments. 
    17641774    file : filename 
    17651775        The file from which the NXfield has been read. 
    17661776    path : string 
    1767         The path to this object with respect to the root of the NeXus tree,  
     1777        The path to this object with respect to the root of the NeXus tree, 
    17681778        using the convention for unix file paths. 
    17691779    group : NXobject (NXgroup or subclass of NXgroup) 
    1770         The parent NeXus group, which is accessible as the group attribute  
    1771         'group'. If the group is initialized as the attribute of  
     1780        The parent NeXus group, which is accessible as the group attribute 
     1781        'group'. If the group is initialized as the attribute of 
    17721782        a parent group, this is set to the parent group. 
    17731783 
     
    17771787        The class of the NXobject. 
    17781788    nxname : string 
    1779         The name of the NXfield.  
     1789        The name of the NXfield. 
    17801790    entries : dictionary 
    17811791        A dictionary of all the NeXus objects contained within an NXgroup. 
     
    17901800        The path to this object with respect to the root of the NeXus tree. For 
    17911801        NeXus data read from a file, this will be a group of class NXroot, but 
    1792         if the NeXus tree was defined interactively, it can be any valid  
     1802        if the NeXus tree was defined interactively, it can be any valid 
    17931803        NXgroup. 
    17941804    nxroot : NXgroup 
    17951805        The root object of the NeXus tree containing this object. For 
    17961806        NeXus data read from a file, this will be a group of class NXroot, but 
    1797         if the NeXus tree was defined interactively, it can be any valid  
     1807        if the NeXus tree was defined interactively, it can be any valid 
    17981808        NXgroup. 
    17991809 
     
    18071817    dictionary name directly as the group attribute name, as long as this name 
    18081818    is not the same as one of the Python attributes defined above or as one of 
    1809     the NXfield Python attributes.   
    1810      
     1819    the NXfield Python attributes. 
     1820 
    18111821    a) Assigning a NeXus object to a NeXus group 
    1812      
     1822 
    18131823    In the example below, after assigning the NXgroup, the following three 
    18141824    NeXus object assignments to entry.sample are all equivalent: 
     
    18201830        >>> entry.sample.temperature 
    18211831        NXfield(40.0) 
    1822          
    1823     If the assigned value is not a valid NXobject, then it is cast as an NXfield  
     1832 
     1833    If the assigned value is not a valid NXobject, then it is cast as an NXfield 
    18241834    with a type determined from the Python data type. 
    1825      
     1835 
    18261836        >>> entry.sample.temperature = 40.0 
    18271837        >>> entry.sample.temperature 
     
    18301840        >>> entry.data.data.x 
    18311841        NXfield([  0.   1.   2. ...,   8.   9.  10.]) 
    1832      
     1842 
    18331843    b) Referencing a NeXus object in a NeXus group 
    1834      
     1844 
    18351845    If the name of the NeXus object is not the same as any of the Python 
    18361846    attributes listed above, or the methods listed below, they can be referenced 
    1837     as if they were a Python attribute of the NXgroup. However, it is only possible  
    1838     to reference attributes with one of the proscribed names using the group  
     1847    as if they were a Python attribute of the NXgroup. However, it is only possible 
     1848    to reference attributes with one of the proscribed names using the group 
    18391849    dictionary, i.e., 
    18401850 
     
    18451855        >>> entry.sample['tree'] 
    18461856        NXfield(100.0) 
    1847      
     1857 
    18481858    For this reason, it is recommended to use the group dictionary to reference 
    18491859    all group objects within Python scripts. 
     
    18711881    insert(self, NXobject, name='unknown'): 
    18721882        Insert a valid NXobject (NXfield or NXgroup) into the group. 
    1873          
     1883 
    18741884        If NXobject has a 'name' attribute and the 'name' keyword is not given, 
    18751885        then the object is inserted with the NXobject name. 
    1876          
     1886 
    18771887    makelink(self, NXobject): 
    18781888        Add the NXobject to the group entries as a link (NXlink). 
     
    18801890    dir(self, attrs=False, recursive=False): 
    18811891        Print the group directory. 
    1882          
     1892 
    18831893        The directory is a list of NeXus objects within this group, either NeXus 
    18841894        groups or NXfield data. If 'attrs' is True, NXfield attributes are 
     
    18881898    tree: 
    18891899        Print the group tree. 
    1890          
    1891         It invokes the 'dir' method with both 'attrs' and 'recursive'  
     1900 
     1901        It invokes the 'dir' method with both 'attrs' and 'recursive' 
    18921902        set to True. Note that this method is defined as a property attribute and 
    18931903        does not require parentheses. 
    1894          
     1904 
    18951905    save(self, filename, format='w5') 
    18961906        Save the NeXus group into a file 
    18971907 
    1898         The object is wrapped in an NXroot group (with name 'root') and an  
    1899         NXentry group (with name 'entry'), if necessary, in order to produce  
     1908        The object is wrapped in an NXroot group (with name 'root') and an 
     1909        NXentry group (with name 'entry'), if necessary, in order to produce 
    19001910        a valid NeXus file. 
    19011911 
     
    19121922 
    19131923    Note: All the currently defined NeXus classes are defined as subclasses 
    1914           of the NXgroup class. It is recommended that these are used  
     1924          of the NXgroup class. It is recommended that these are used 
    19151925          directly, so that the above examples become: 
    19161926 
    19171927    >>> entry = NXentry(x) 
    19181928    >>> entry.sample = NXsample(temperature=NXfield(40.0,units='K')) 
    1919      
     1929 
    19201930    or 
    1921      
     1931 
    19221932    >>> entry.sample.temperature = 40.0 
    19231933    >>> entry.sample.temperature.units='K' 
    1924       
     1934 
    19251935    """ 
    19261936 
     
    19511961                self.__class__ = globals()[self.nxclass] 
    19521962            except KeyError: 
    1953                 pass              
     1963                pass 
    19541964        for item in items: 
    19551965            try: 
     
    19671977    def __repr__(self): 
    19681978        return "%s('%s')" % (self.__class__.__name__,self.nxname) 
    1969          
     1979 
    19701980    def _str_value(self,indent=0): 
    19711981        return "" 
     1982 
     1983    def walk(self): 
     1984        yield self 
     1985        for node in self.entries.values(): 
     1986            for child in node.walk(): 
     1987                yield child 
    19721988 
    19731989    def __getattr__(self, key): 
     
    19862002        """ 
    19872003        Set an attribute as an object or regular Python attribute. 
    1988          
    1989         It is assumed that attributes starting with 'nx' or '_' are regular  
     2004 
     2005        It is assumed that attributes starting with 'nx' or '_' are regular 
    19902006        Python attributes. All other attributes are converted to valid NXobjects, 
    19912007        with class NXfield, NXgroup, or a sub-class of NXgroup, depending on the 
    19922008        assigned value. 
    1993          
    1994         The internal value of the attribute name, i.e., 'name', is set to the  
    1995         attribute name used in the assignment.  The parent group of the  
     2009 
     2010        The internal value of the attribute name, i.e., 'name', is set to the 
     2011        attribute name used in the assignment.  The parent group of the 
    19962012        attribute, i.e., 'group', is set to the parent group of the attribute. 
    1997          
     2013 
    19982014        If the assigned value is a numerical (scalar or array) or string object, 
    1999         it is converted to an object of class NXfield, whose attribute, 'nxdata',  
     2015        it is converted to an object of class NXfield, whose attribute, 'nxdata', 
    20002016        is set to the assigned value. 
    20012017        """ 
     
    20052021            self._attrs[name] = value 
    20062022        else: 
    2007             self[name] = value  
     2023            self[name] = value 
    20082024 
    20092025    def __getitem__(self, index): 
    20102026        """ 
    20112027        Returns a slice from the NXgroup nxsignal attribute (if it exists) as 
    2012         a new NXdata group, if the index is a slice object.  
    2013          
     2028        a new NXdata group, if the index is a slice object. 
     2029 
    20142030        In most cases, the slice values are applied to the NXfield nxdata array 
    20152031        and returned within an NXfield object with the same metadata. However, 
    2016         if the array is one-dimensional and the index start and stop values  
     2032        if the array is one-dimensional and the index start and stop values 
    20172033        are real, the nxdata array is returned with values between the limits 
    20182034        set by those axis values. 
     
    20242040            return self._entries[index] 
    20252041 
    2026         if not self.nxsignal:  
     2042        if not self.nxsignal: 
    20272043            raise NeXusError, "No plottable signal" 
    20282044        if not hasattr(self,"nxclass"): 
     
    20372053            axes[0] = axes[0][index] 
    20382054            if isinstance(index.start, float) or isinstance(index.stop, float): 
    2039                 index = slice(self.nxaxes[0].index(index.start),  
     2055                index = slice(self.nxaxes[0].index(index.start), 
    20402056                              self.nxaxes[0].index(index.stop,max=True)+1) 
    20412057                result = NXdata(self.nxsignal[index], axes) 
     
    20742090            self._entries[key] = value 
    20752091        elif isinstance(value, NXobject): 
    2076             if value.nxgroup is not None:    
     2092            if value.nxgroup is not None: 
    20772093                memo = {} 
    20782094                value = deepcopy(value, memo) 
     
    20822098            self._entries[key] = value 
    20832099        else: 
    2084             self._entries[key] = NXfield(value=value, name=key, group=self)  
     2100            self._entries[key] = NXfield(value=value, name=key, group=self) 
    20852101 
    20862102    def __deepcopy__(self, memo): 
     
    20912107                dpcpy[k] = deepcopy(v, memo) 
    20922108            else: 
    2093                 dpcpy[k] = copy(v)                 
     2109                dpcpy[k] = copy(v) 
    20942110        for k, v in self.attrs.items(): 
    20952111            dpcpy.attrs[k] = copy(v) 
     
    21072123        """ 
    21082124        return self._entries.values() 
    2109      
     2125 
    21102126    def items(self): 
    21112127        """ 
     
    21132129        """ 
    21142130        return self._entries.items() 
    2115      
     2131 
    21162132    def has_key(self, name): 
    21172133        """ 
     
    21232139        """ 
    21242140        Adds an attribute to the group. 
    2125          
    2126         If it is not a valid NeXus object (NXfield or NXgroup), the attribute  
    2127         is converted to an NXfield.         
     2141 
     2142        If it is not a valid NeXus object (NXfield or NXgroup), the attribute 
     2143        is converted to an NXfield. 
    21282144        """ 
    21292145        if isinstance(value, NXobject): 
     
    21392155        """ 
    21402156        Creates a linked NXobject within the group. 
    2141          
     2157 
    21422158        All attributes are inherited from the parent object including the name 
    21432159        """ 
     
    21472163            raise NeXusError, "Link target must be an NXobject" 
    21482164 
    2149          
     2165 
    21502166    def sum(self, axis=None): 
    21512167        """ 
     
    21542170 
    21552171        The result contains a copy of all the metadata contained in 
    2156         the NXdata group.  
    2157         """ 
    2158         if not self.nxsignal:  
     2172        the NXdata group. 
     2173        """ 
     2174        if not self.nxsignal: 
    21592175            raise NeXusError, "No signal to sum" 
    21602176        if not hasattr(self,"nxclass"): 
     
    21782194            if self.nxtitle: 
    21792195                result.title = self.nxtitle 
    2180             return result         
     2196            return result 
    21812197 
    21822198    def moment(self, order=1): 
    21832199        """ 
    2184         Return an NXfield containing the moments of the NXdata group  
     2200        Return an NXfield containing the moments of the NXdata group 
    21852201        assuming the signal is one-dimensional. 
    2186          
    2187         Currently, only the first moment has been defined. Eventually, the  
     2202 
     2203        Currently, only the first moment has been defined. Eventually, the 
    21882204        order of the moment will be defined by the 'order' parameter. 
    21892205        """ 
    2190         if not self.nxsignal:  
     2206        if not self.nxsignal: 
    21912207            raise NeXusError, "No signal to calculate" 
    21922208        elif len(self.nxsignal.shape) > 1: 
     
    22082224        """ 
    22092225        Return a dictionary of NXfield's containing signal data. 
    2210          
     2226 
    22112227        The key is the value of the signal attribute. 
    22122228        """ 
     
    22152231            if 'signal' in obj.attrs: 
    22162232                signals[obj.nxsignal.nxdata] = obj 
    2217         return signals                 
     2233        return signals 
    22182234 
    22192235    def _signal(self): 
     
    22542270        """ 
    22552271        Return the title as a string. 
    2256          
    2257         If there is no title attribute in the string, the parent  
     2272 
     2273        If there is no title attribute in the string, the parent 
    22582274        NXentry group in the group's path is searched. 
    22592275        """ 
     
    22692285                    pass 
    22702286                obj = obj.nxgroup 
    2271             return self.nxpath         
     2287            return self.nxpath 
    22722288 
    22732289    def _getentries(self): 
     
    22782294    nxerrors = property(_errors, "Errors NXfield within group") 
    22792295    nxtitle = property(_title, "Title for group plot") 
    2280     entries = property(_getentries,doc="NeXus objects within group")     
    2281  
    2282      
     2296    entries = property(_getentries,doc="NeXus objects within group") 
     2297 
     2298 
    22832299    def plot(self, **opts): 
    22842300        """ 
    22852301        Plot data contained within the group. 
    2286          
     2302 
    22872303        Raises NeXusError if the data could not be plotted. 
    22882304        """ 
    2289          
     2305 
    22902306        group = self 
    22912307        if self.nxclass == "NXroot": 
     
    22962312            except IndexError: 
    22972313                raise NeXusError('No NXdata group found') 
    2298          
     2314 
    22992315        # Find a plottable signal 
    23002316        signal = group.nxsignal 
     
    23042320        # Find errors 
    23052321        errors= group.nxerrors 
    2306          
     2322 
    23072323        # Find the associated axes 
    23082324        axes = group.nxaxes 
    2309          
     2325 
    23102326        # Construct title 
    23112327        title = group.nxtitle 
    2312   
     2328 
    23132329        # Plot with the available plotter 
    23142330        group._plotter.plot(signal, axes, title, errors, **opts) 
     
    23192335    """ 
    23202336    Class for NeXus linked objects. 
    2321      
     2337 
    23222338    The real object will be accessible by following the link attribute. 
    23232339    """ 
     
    23802396    nxlink = property(_getlink, "Linked object") 
    23812397    attrs = property(_getattrs,doc="NeXus attributes for object") 
    2382     entries = property(_getentries,doc="NeXus objects within group")     
     2398    entries = property(_getentries,doc="NeXus objects within group") 
    23832399 
    23842400 
     
    23872403    """ 
    23882404    Class for a NeXus linked field. 
    2389      
     2405 
    23902406    The real field will be accessible by following the link attribute. 
    23912407    """ 
     
    24052421        Offsets are 0-origin.  Shape can be inferred from the data. 
    24062422        Offset and shape must each have one entry per dimension. 
    2407          
     2423 
    24082424        This operation should be performed in a "with group.data" 
    24092425        conext. 
     
    24192435        else: 
    24202436            raise NeXusError, "No input file specified for NXgetslab" 
    2421      
     2437 
    24222438NXlinkdata = NXlinkfield # For backward compatibility 
    24232439 
     
    24262442    """ 
    24272443    Class for a NeXus linked group. 
    2428      
     2444 
    24292445    The real group will be accessible by following the link attribute. 
    24302446    """ 
     
    24492465 
    24502466    Each NXdata and NXmonitor object of the same name will be added 
    2451     together, raising an NeXusError if any of the groups do not exist  
    2452     in both NXentry groups or if any of the NXdata additions fail.  
    2453     The resulting NXentry group contains a copy of all the other metadata  
    2454     contained in the first group. Note that other extensible data, such  
    2455     as the run duration, are not currently added together.  
     2467    together, raising an NeXusError if any of the groups do not exist 
     2468    in both NXentry groups or if any of the NXdata additions fail. 
     2469    The resulting NXentry group contains a copy of all the other metadata 
     2470    contained in the first group. Note that other extensible data, such 
     2471    as the run duration, are not currently added together. 
    24562472 
    24572473    See the NXgroup documentation for more details. 
     
    24642480    def __add__(self, other): 
    24652481        """ 
    2466         Add two NXentry objects        
     2482        Add two NXentry objects 
    24672483        """ 
    24682484        result = NXentry(entries=self.entries, attrs=self.attrs) 
     
    25242540    """ 
    25252541    NXdata group. This is a subclass of the NXgroup class. 
    2526      
     2542 
    25272543    The constructor assumes that the first argument contains the signal and 
    25282544    the second contains either the axis, for one-dimensional data, or a list 
    2529     of axes, for multidimensional data. These arguments can either be NXfield  
    2530     objects or Numpy arrays, which are converted to NXfield objects with default  
     2545    of axes, for multidimensional data. These arguments can either be NXfield 
     2546    objects or Numpy arrays, which are converted to NXfield objects with default 
    25312547    names. 
    2532      
    2533     Various arithmetic operations (addition, subtraction, multiplication,  
     2548 
     2549    Various arithmetic operations (addition, subtraction, multiplication, 
    25342550    and division) have been defined for combining NXdata groups with other 
    2535     NXdata groups, Numpy arrays, or constants, raising a NeXusError if the  
    2536     shapes don't match. Data errors are propagated in quadrature if  
    2537     they are defined, i.e., if the 'nexerrors' attribute is not None,  
     2551    NXdata groups, Numpy arrays, or constants, raising a NeXusError if the 
     2552    shapes don't match. Data errors are propagated in quadrature if 
     2553    they are defined, i.e., if the 'nexerrors' attribute is not None, 
    25382554 
    25392555    Attributes 
     
    25472563    plot(self, over=False, log=False, **opts) 
    25482564        Plot the NXdata group using the defined signal and axes. Valid 
    2549         Matplotlib parameters, specifying markers, colors, etc, can be  
    2550         specified using the 'opts' dictionary.     
    2551      
     2565        Matplotlib parameters, specifying markers, colors, etc, can be 
     2566        specified using the 'opts' dictionary. 
     2567 
    25522568    moment(self, order=1) 
    2553         Calculate moments of the NXdata group. This assumes that the  
    2554         signal is one-dimenional. Currently, only the first moment is  
     2569        Calculate moments of the NXdata group. This assumes that the 
     2570        signal is one-dimenional. Currently, only the first moment is 
    25552571        implemented. 
    25562572 
     
    25752591        intensity = float64(101x101) 
    25762592          @axes = axis1:axis2 
    2577           @signal = 1     
     2593          @signal = 1 
    25782594 
    25792595    See the NXgroup documentation for more details. 
     
    26082624                        self[axisname] = axis 
    26092625                        axisnames[i] = axisname 
    2610                 self[signalname].axes = ":".join(axisnames.values())                 
     2626                self[signalname].axes = ":".join(axisnames.values()) 
    26112627 
    26122628    def __add__(self, other): 
     
    26162632 
    26172633        The result contains a copy of all the metadata contained in 
    2618         the first NXdata group. The module checks that the dimensions are  
     2634        the first NXdata group. The module checks that the dimensions are 
    26192635        compatible, but does not check that the NXfield names or values are 
    26202636        identical. This is so that spelling variations or rounding errors 
    2621         do not make the operation fail. However, it is up to the user to  
     2637        do not make the operation fail. However, it is up to the user to 
    26222638        ensure that the results make sense. 
    26232639        """ 
     
    26382654            result.entries[self.nxsignal.nxname].nxname = self.nxsignal.nxname 
    26392655            return result 
    2640          
     2656 
    26412657    def __sub__(self, other): 
    26422658        """ 
    2643         Define a method for subtracting a NXdata group or a number from  
     2659        Define a method for subtracting a NXdata group or a number from 
    26442660        the NXdata group. Only the signal data is affected. 
    26452661 
    26462662        The result contains a copy of all the metadata contained in 
    2647         the first NXdata group. The module checks that the dimensions are  
     2663        the first NXdata group. The module checks that the dimensions are 
    26482664        compatible, but does not check that the NXfield names or values are 
    26492665        identical. This is so that spelling variations or rounding errors 
    2650         do not make the operation fail. However, it is up to the user to  
     2666        do not make the operation fail. However, it is up to the user to 
    26512667        ensure that the results make sense. 
    26522668        """ 
     
    26672683            result.entries[self.nxsignal.nxname].nxname = self.nxsignal.nxname 
    26682684            return result 
    2669          
     2685 
    26702686    def __mul__(self, other): 
    26712687        """ 
     
    26742690 
    26752691        The result contains a copy of all the metadata contained in 
    2676         the first NXdata group. The module checks that the dimensions are  
     2692        the first NXdata group. The module checks that the dimensions are 
    26772693        compatible, but does not check that the NXfield names or values are 
    26782694        identical. This is so that spelling variations or rounding errors 
    2679         do not make the operation fail. However, it is up to the user to  
     2695        do not make the operation fail. However, it is up to the user to 
    26802696        ensure that the results make sense. 
    26812697        """ 
     
    27102726        """ 
    27112727        return self.__mul__(other) 
    2712          
     2728 
    27132729    def __div__(self, other): 
    27142730        """ 
     
    27172733 
    27182734        The result contains a copy of all the metadata contained in 
    2719         the first NXdata group. The module checks that the dimensions are  
     2735        the first NXdata group. The module checks that the dimensions are 
    27202736        compatible, but does not check that the NXfield names or values are 
    27212737        identical. This is so that spelling variations or rounding errors 
    2722         do not make the operation fail. However, it is up to the user to  
     2738        do not make the operation fail. However, it is up to the user to 
    27232739        ensure that the results make sense. 
    27242740        """ 
     
    27322748                if self.nxerrors: 
    27332749                    if other.nxerrors: 
    2734                         result.errors = (np.sqrt(self.errors.nxdata**2 +  
     2750                        result.errors = (np.sqrt(self.errors.nxdata**2 + 
    27352751                                         (resultvalues*other.errors.nxdata)**2) 
    2736                                          / other.nxsignal)                                               
     2752                                         / other.nxsignal) 
    27372753                    else: 
    27382754                        result.errors = self.errors 
     
    27512767    """ 
    27522768    NXmonitor group. This is a subclass of the NXdata class. 
    2753      
     2769 
    27542770    See the NXdata and NXgroup documentation for more details. 
    27552771    """ 
     
    27662782    """ 
    27672783    NXlog group. This is a subclass of the NXgroup class. 
    2768      
     2784 
    27692785    Methods 
    27702786    ------- 
    27712787    plot(self, **opts) 
    27722788        Plot the logged values against the elapsed time. Valid 
    2773         Matplotlib parameters, specifying markers, colors, etc, can be  
     2789        Matplotlib parameters, specifying markers, colors, etc, can be 
    27742790        specified using the 'opts' dictionary. 
    2775      
     2791 
    27762792    See the NXgroup documentation for more details. 
    27772793    """ 
     
    27802796        self._class = "NXlog" 
    27812797        NXgroup.__init__(self, *items, **opts) 
    2782      
     2798 
    27832799    def plot(self, **opts): 
    27842800        axis = [self.time] 
     
    27942810        docstring = """ 
    27952811                    %s group. This is a subclass of the NXgroup class. 
    2796      
     2812 
    27972813                    See the NXgroup documentation for more details. 
    27982814                    """ % _class 
     
    28072823    """ 
    28082824    Return the centers of the axes. 
    2809      
     2825 
    28102826    This works regardless if the axes contain bin boundaries or centers. 
    28112827    """ 
     
    28522868    """ 
    28532869    Read a NeXus file returning a tree of objects. 
    2854      
     2870 
    28552871    This is aliased to 'read' because of potential name clashes with Numpy 
    28562872    """ 
     
    28872903def demo(argv): 
    28882904    """ 
    2889     Process a list of command line commands.   
    2890      
     2905    Process a list of command line commands. 
     2906 
    28912907    'argv' should contain program name, command, arguments, where command is one 
    28922908    of the following: 
     
    29092925        tree.plot() 
    29102926        tree._plotter.show() 
    2911              
     2927 
    29122928    else: 
    29132929        usage = """ 
     
    29182934        """%(argv[0],) 
    29192935        print usage 
    2920          
     2936 
    29212937 
    29222938if __name__ == "__main__": 
Note: See TracChangeset for help on using the changeset viewer.