Ignore:
Timestamp:
21/10/10 16:35:38 (19 months ago)
Author:
Peter Chang
Message:

Refs #255, python tidy up

  • Correct bugs in napi that were noted and fixed by NeXpy
  • Fix an indentation mix up
  • Rename unused variables to dummy (to pass pylint/pydev)
  • Remove tree's unused imports
  • Remove tree's _readattrs method as it is same as napi's getattrs
Location:
trunk/bindings/python/nxs
Files:
2 edited

Legend:

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

    r1474 r1571  
    256256        except: 
    257257            raise OSError, \ 
    258                 "NeXus library %s could not be loaded: %s"%(file,sys.exc_info()[0]) 
     258                "NeXus library %s could not be loaded: %s"%(file,sys.exc_info()) 
    259259    raise OSError, "Set NEXUSLIB or move NeXus to one of: %s"%(", ".join(files)) 
    260260 
     
    505505                #print "target and current differ at",name 
    506506                up = self._path[i:] 
    507                 down = target[i:] 
     507                down = target[i:] 
    508508                break 
    509509        else: 
     
    725725        n,_,_ = self.getgroupinfo() 
    726726        L = [] 
    727         for i in range(n): 
     727        for dummy in range(n): 
    728728            name,nxclass = self.getnextentry() 
    729729            if nxclass not in H4SKIP: 
     
    925925        # TODO: consider accepting preallocated data so we don't thrash memory 
    926926        shape,dtype = self.getinfo() 
    927         data,pdata,size,datafn = self._poutput(dtype,shape) 
     927        dummy_data,pdata,dummy_size,datafn = self._poutput(dtype,shape) 
    928928        status = nxlib.nxigetdata_(self.handle,pdata) 
    929929        if status == ERROR: 
     
    946946        """ 
    947947        # TODO: consider accepting preallocated data so we don't thrash memory 
    948         shape,dtype = self.getrawinfo() 
    949         data,pdata,size,datafn = self._poutput(dtype,slab_shape) 
     948        dummy_shape,dtype = self.getrawinfo() 
     949        dummy_data,pdata,dummy_size,datafn = self._poutput(dtype,slab_shape) 
    950950        slab_offset = numpy.array(slab_offset,'i') 
    951951        slab_shape = numpy.array(slab_shape,'i') 
     
    988988        Corresponds to NXputslab(handle,data,offset,shape) 
    989989        """ 
    990         shape,dtype = self.getrawinfo() 
     990        dummy_shape,dtype = self.getrawinfo() 
    991991        data,pdata = self._pinput(data,dtype,slab_shape) 
    992992        slab_offset = numpy.array(slab_offset,'i') 
     
    10801080        """ 
    10811081        if dtype is 'char': length += 1  # HDF4 needs zero-terminator 
    1082         data,pdata,size,datafn = self._poutput(str(dtype),[length]) 
     1082        dummy_data,pdata,size,datafn = self._poutput(str(dtype),[length]) 
    10831083        storage = c_int(_nxtype_code[str(dtype)]) 
    10841084        #print "getattr",self._loc(),name,length,size,dtype 
     
    11661166        self.initattrdir() 
    11671167        n = self.getattrinfo() 
    1168         for i in range(n): 
     1168        for dummy in range(n): 
    11691169            name,length,dtype = self.getnextattr() 
    11701170            value = self.getattr(name,length,dtype) 
     
    12771277        n = self.getattrinfo() 
    12781278        self.initattrdir() 
    1279         for i in range(n): 
     1279        for dummy in range(n): 
    12801280            name,length,dtype = self.getnextattr() 
    12811281            if name == "target": 
     
    13651365        on the data type and shape of the data group. 
    13661366        """ 
     1367        if isinstance(shape, int): 
     1368            shape = [shape] 
    13671369        if len(shape) == 1 and dtype == 'char': 
    13681370            # string - use ctypes allocator 
     
    13951397        as you need pdata to keep the memory from being released to the heap. 
    13961398        """ 
     1399        if isinstance(shape, int): 
     1400            shape = [shape] 
    13971401        if dtype == "char": 
    13981402            data = numpy.asarray(data, dtype='S%d'%(shape[-1])) 
     
    14091413                    or (input_shape != target_shape).any(): 
    14101414                raise ValueError,\ 
    1411                     "Shape mismatch %s!=%s: %s"%(data_shape,shape,self._loc()) 
     1415                    "Shape mismatch %s!=%s: %s"%(data.shape,shape,self._loc()) 
    14121416            # Check data type 
    14131417            if str(data.dtype) != dtype: 
  • trunk/bindings/python/nxs/tree.py

    r1547 r1571  
    130130 
    131131 
    132 from copy import copy, deepcopy 
    133  
    134 import os, numpy as np 
     132from copy import copy 
     133 
     134import numpy as np 
    135135import napi 
    136136import unit 
     
    220220            return None 
    221221 
    222     def _readattrs(self): 
    223         """ 
    224         Return the attributes for the currently open group/data or for 
    225         the file if no group or data object is open. 
    226         """ 
    227         attrs = dict() 
    228         for i in range(self.getattrinfo()): 
    229             name,length,nxtype = self.getnextattr() 
    230             value = self.getattr(name, length, nxtype) 
    231             pair = self.NXattr(value,nxtype) 
    232             attrs[name] = pair 
    233             #print "read attr",name,pair.nxdata, pair.nxtype 
    234         return attrs 
    235  
    236222    def _readdata(self, name): 
    237223        """ 
     
    242228        # Instead record the location, type and size 
    243229        self.opendata(name) 
    244         attrs = self._readattrs() 
     230        attrs = self.getattrs() 
    245231        if 'target' in attrs and attrs['target'].nxdata != self.path: 
    246232            # This is a linked dataset; don't try to load it. 
     
    268254    def _readchildren(self,n): 
    269255        children = {} 
    270         for i in range(n): 
     256        for dummy in range(n): 
    271257            name,nxclass = self.getnextentry() 
    272258            #print "name,class,path",name,nxclass,self.path 
     
    294280        # in and skip those of different classes? 
    295281        n,name,nxclass = self.getgroupinfo() 
    296         attrs = self._readattrs() 
     282        attrs = self.getattrs() 
    297283        if 'target' in attrs and attrs['target'].nxdata != self.path: 
    298284            # This is a linked group; don't try to load it. 
     
    654640 
    655641    def _str_attrs(self,indent=0): 
    656         result = "" 
    657642        attrs = self.nxattrs 
    658643        names = attrs.keys() 
     
    12411226     
    12421227    def nxdata_set(self, value): 
    1243         nxtype, nxdims = _gettype(value) 
     1228        dummy_nxtype, nxdims = _gettype(value) 
    12441229        if nxdims == self.nxdims: 
    12451230            self._value = _settype(value, self.nxtype) 
     
    13091294            else: 
    13101295                slab = [slice(None), slice(None)] 
    1311                 for dim in signal.nxdims[2:]: 
     1296                for dummy in signal.nxdims[2:]: 
    13121297                    slab.append(0) 
    13131298                data = signal[slab].nxreshape(signal.nxdims[:2]).nxdata 
     
    16611646        Find all child nodes that have a particular class. 
    16621647        """ 
    1663         return [E for name,E in self.nxentries.items() if E.nxclass==nxclass] 
     1648        return [E for dummy_name,E in self.nxentries.items() if E.nxclass==nxclass] 
    16641649 
    16651650    def nxsignals(self): 
     
    26262611def imshow_irregular(x,y,z): 
    26272612    import pylab 
    2628     from matplotlib.ticker import FormatStrFormatter 
     2613    #from matplotlib.ticker import FormatStrFormatter 
    26292614    ax = pylab.gca() 
    26302615    im = pylab.mpl.image.NonUniformImage(ax, extent=(x[0],x[-1],y[0],y[-1]), origin=None) 
Note: See TracChangeset for help on using the changeset viewer.