def changeUnit(self, unit): #save old unit oldunit = self.unit() #use parent class's changeUnit, but please remember: if self.__isslice: msg = "This axis %r is a slice. cannot change unit." % self.name() raise RuntimeError, msg #there is a problem with mapper!!!! Dataset.changeUnit(self, unit) #mapper need to be reset self._mapper = createMapper( self._storage.asList(), self._mapper.__class__ ) #!!! need to remove cache!!! self._cache = {} #also need to update centers if necssary if self._centers is not None: self._centers = N.array(self._centers) * (oldunit/self.unit()) return
def __getitem__(self, s): '''axis[ SlicingInfo( a,b ) ] --> a slice of the original axis axis[ index ] --> binboundaries[index] * unit ''' if not isSlicingInfo(s): return Dataset.__getitem__(self, s) slicingInfo = s indexStart, indexEnd = self.slicingInfo2IndexSlice( slicingInfo ) s = slice(indexStart, indexEnd + 1 ) #inclusive stor = self.storage()[s] ret = self._copy( storage = stor ) ret.__isslice = True return ret
def __init__( self, name='', unit='1', attributes = None, length = 0, storage = None, mapper = None, centers = None): """HistogramAxis( attributes={}, length=0, storage=None) Inputs: attributes: additional user defined attributes length: number of cells in axis (int >= 1) storage: raw array/vector etc. holding BIN BOUNDARIES Output: new HistogramAxis object Exceptions: None Notes: Meant to hold histogram bin boundaries """ if length == 0 and storage is not None: length = storage.size()-1 elif length !=0 and storage is not None: if int(length) != int(storage.size()-1) : raise "incompatible inputs: length = %s, storage.shape = %s" % ( length, storage.shape()) pass shape = [length+1] Dataset.__init__( self, name, unit, attributes, shape, storage) self._mapper = mapper if isinstance( mapper, DiscreteAxisMapper ): self._isDiscrete = True else: self._isDiscrete = False self._cache = {} if centers is not None: centers = N.array(centers) self._centers = centers self.__isslice = False return