def _logticks(self, lower, upper):
     #lower,upper = map(_Numeric.log10,[lower,upper])
     #print 'logticks',lower,upper
     ticks = []
     mag = _Numeric.power(10,_Numeric.floor(lower))
     if upper-lower > 6:
         t = _Numeric.power(10,_Numeric.ceil(lower))
         base = _Numeric.power(10,_Numeric.floor((upper-lower)/6))
         def inc(t):
             return t*base-t
     else:
         t = _Numeric.ceil(_Numeric.power(10,lower)/mag)*mag
         def inc(t):
             return 10**int(_Numeric.floor(_Numeric.log10(t)+1e-16))
     majortick = int(_Numeric.log10(mag))
     while t <= pow(10,upper):
         if majortick != int(_Numeric.floor(_Numeric.log10(t)+1e-16)):
             majortick = int(_Numeric.floor(_Numeric.log10(t)+1e-16))
             ticklabel = '1e%d'%majortick
         else:
             if upper-lower < 2:
                 minortick = int(t/pow(10,majortick)+.5)
                 ticklabel = '%de%d'%(minortick,majortick)
             else:
                 ticklabel = ''
         ticks.append((_Numeric.log10(t), ticklabel))
         t += inc(t)
     if len(ticks) == 0:
         ticks = [(0,'')]
     return ticks
 def _ticks(self, lower, upper):
     ideal = (upper-lower)/7.
     log = _Numeric.log10(ideal)
     power = _Numeric.floor(log)
     fraction = log-power
     factor = 1.
     error = fraction
     for f, lf in self._multiples:
         e = _Numeric.fabs(fraction-lf)
         if e < error:
             error = e
             factor = f
     grid = factor * 10.**power
     if power > 4 or power < -4:
         format = '%+7.1e'        
     elif power >= 0:
         digits = max(1, int(power))
         format = '%' + `digits`+'.0f'
     else:
         digits = -int(power)
         format = '%'+`digits+2`+'.'+`digits`+'f'
     ticks = []
     t = -grid*_Numeric.floor(-lower/grid)
     while t <= upper:
         ticks.append( (t, format % (t,)) )
         t = t + grid
     return ticks
 def _axisInterval(self, spec, lower, upper):
     """Returns sensible axis range for given spec"""
     if spec == 'none' or spec == 'min':
         if lower == upper:
             return lower-0.5, upper+0.5
         else:
             return lower, upper
     elif spec == 'auto':
         range = upper-lower
         if range == 0.:
             return lower-0.5, upper+0.5
         log = _Numeric.log10(range)
         power = _Numeric.floor(log)
         fraction = log-power
         if fraction <= 0.05:
             power = power-1
         grid = 10.**power
         lower = lower - lower % grid
         mod = upper % grid
         if mod != 0:
             upper = upper - mod + grid
         return lower, upper
     elif type(spec) == type(()):
         lower, upper = spec
         if lower <= upper:
             return lower, upper
         else:
             return upper, lower
     else:
         raise ValueError, str(spec) + ': illegal axis specification'
Esempio n. 4
0
    def logMap(self, data, data_min, data_max, val_min, val_max,
               arr_min, arr_max, datatype):
        if arr_min < 0:
            diff = abs(arr_min)+1.0
        elif arr_min >= 0 and arr_min < 1.0:
            diff = 1.0
        elif arr_min >= 1.0:
            diff=0
        k1, c1 = self.ScaleMap( (val_min, val_max),
                                (log(arr_min+diff), log(arr_max+diff)) )

        return  (k1*Numeric.log10(data+diff)+c1).astype(datatype)
 def Draw(self, graphics, xAxis = None, yAxis = None, dc = None):
     """Wrapper around _Draw, which handles log axes"""
     
     graphics.setLogScale(self.getLogScale())
     
     # check Axis is either tuple or none
     if type(xAxis) not in [type(None),tuple]:
         raise TypeError, "xAxis should be None or (minX,maxX)"+str(type(xAxis))
     if type(yAxis) not in [type(None),tuple]:
         raise TypeError, "yAxis should be None or (minY,maxY)"+str(type(xAxis))
          
     # check case for axis = (a,b) where a==b caused by improper zooms
     if xAxis != None:
         if xAxis[0] == xAxis[1]:
             return
         if self.getLogScale()[0]:
             xAxis = _Numeric.log10(xAxis)
     if yAxis != None:
         if yAxis[0] == yAxis[1]:
             return
         if self.getLogScale()[1]:
             yAxis = _Numeric.log10(yAxis)
     self._Draw(graphics, xAxis, yAxis, dc)
Esempio n. 6
0
    def __call__(self,**params):
        p=ParamOverrides(self,params)

        for template in p.plot_template:

            for sheet in topo.sim.objects(Sheet).values():
                name=template.keys().pop(0)
                plot=make_template_plot(template,sheet.sheet_views,sheet.xdensity,sheet.bounds,p.normalize,name=template[name])
                if plot:
                    bitmap=plot.bitmap
                    pylab.figure(figsize=(5,5))
                    isint=pylab.isinteractive() # Temporarily make non-interactive for plotting
                    pylab.ioff()                                         # Turn interactive mode off

                    pylab.imshow(bitmap.image,origin='lower',interpolation='nearest')
                    pylab.axis('off')

                    for (t,pref,sel,c) in p.overlay:
                        v = pylab.flipud(sheet.sheet_views[pref].view()[0])

                        if (t=='contours'):
                            pylab.contour(v,[sel,sel],colors=c,linewidths=2)

                        if (t=='arrows'):
                            s = pylab.flipud(sheet.sheet_views[sel].view()[0])
                            scale=int(pylab.ceil(log10(len(v))))
                            X=pylab.array([x for x in xrange(len(v)/scale)])
                            v_sc=pylab.zeros((len(v)/scale,len(v)/scale))
                            s_sc=pylab.zeros((len(v)/scale,len(v)/scale))
                            for i in X:
                                for j in X:
                                    v_sc[i][j]=v[scale*i][scale*j]
                                    s_sc[i][j]=s[scale*i][scale*j]
                            pylab.quiver(scale*X,scale*X,-cos(2*pi*v_sc)*s_sc,-sin(2*pi*v_sc)*s_sc,color=c,edgecolors=c,minshaft=3,linewidths=1)

                    p.title='%s overlaid with %s at time %s' %(plot.name,pref,topo.sim.timestr())
                    if isint: pylab.ion()
                    p.filename_suffix="_"+sheet.name
                    self._generate_figure(p)
Esempio n. 7
0
            self.logfile.write("Photometric ZeroPoint of " +
                               os.path.basename(fitsfile) + ": " + str(zpoint))

            #---------------- Temporary zero point correction --------------------#
            ## Commented 24-Sep-2002 as per Bugzilla bug #1800
            ##
            ## zpointCor=fUtil.zeroPointCorrection(imfilter)
            ## zpoint+= zpointCor
            ## self.logfile.write("ZeroPoint %s corrected by %.2f mag" % (imfilter,zpointCor))
            ## print "ZeroPoint %s corrected by %.2f mag" % (imfilter,zpointCor)
            ##
            #---------------- End temporary zero point correction ----------------#

            flux[i, :] = Numeric.clip(flux[i, :], 1e-100, 1e100)
            m[i, :] = Numeric.where(
                detected, -2.5 * Numeric.log10(abs(flux[i, :])) + zpoint,
                m[i, :])
            m[i, :] = Numeric.where(nondetected, 99.0, m[i, :])
            m[i, :] = Numeric.where(nonobserved, -99.0, m[i, :])
            # the filter specific extinction correction is applied.
            m_corr[i, :] = Numeric.where(nondetected, 99.0,
                                         m[i, :] - filterXCorr)
            m_corr[i, :] = Numeric.where(nonobserved, -99, m_corr[i, :])

            m_bpz[i, :] = Numeric.where(nondetected, 99.0,
                                        m_corr[i, :] + ap_corr[i, :])
            m_bpz[i, :] = Numeric.where(nonobserved, -99, m_bpz[i, :])

            # clip values from being too small or large, i.e. 0 or inf.
            fluxerr[i, :] = Numeric.clip(fluxerr[i, :], 1e-100, 1e100)
            em[i, :] = Numeric.where(
Esempio n. 8
0
            pardict["Zeropoint_Error"] = zpoint_err
            self.logfile.write("Photometric ZeroPoint of "+
                                   os.path.basename(fitsfile)+": "+str(zpoint))

            #---------------- Temporary zero point correction --------------------#
            ## Commented 24-Sep-2002 as per Bugzilla bug #1800
            ##
            ## zpointCor=fUtil.zeroPointCorrection(imfilter)
            ## zpoint+= zpointCor
            ## self.logfile.write("ZeroPoint %s corrected by %.2f mag" % (imfilter,zpointCor))
            ## print "ZeroPoint %s corrected by %.2f mag" % (imfilter,zpointCor)
            ##
            #---------------- End temporary zero point correction ----------------#                   
            
            flux[i,:]=Numeric.clip(flux[i,:],1e-100,1e100)
            m[i,:]  = Numeric.where(detected,-2.5*Numeric.log10(abs(flux[i,:]))+zpoint,m[i,:])
            m[i,:]  = Numeric.where(nondetected,99.0,m[i,:])
            m[i,:]  = Numeric.where(nonobserved,-99.0,m[i,:])
            # the filter specific extinction correction is applied.
            m_corr[i,:] = Numeric.where(nondetected,99.0,m[i,:]-filterXCorr)
            m_corr[i,:] = Numeric.where(nonobserved,-99,m_corr[i,:])

            m_bpz[i,:] = Numeric.where(nondetected,99.0,m_corr[i,:] + ap_corr[i,:])
            m_bpz[i,:] = Numeric.where(nonobserved,-99,m_bpz[i,:])

            # clip values from being too small or large, i.e. 0 or inf.
            fluxerr[i,:]=Numeric.clip(fluxerr[i,:],1e-100,1e100)
            em[i,:]  = Numeric.where(detected,2.5*Numeric.log10(1.0+abs(fluxerr[i,:]/flux[i,:])),em[i,:])
            em[i,:]  = Numeric.where(nondetected,2.5*Numeric.log10(abs(fluxerr[i,:]))-zpoint,em[i,:])
            em[i,:]  = Numeric.where(nonobserved,0.0,em[i,:])
            # will need to determine how the mag error changes with the app of the extinction
 def inc(t):
     return 10**int(_Numeric.floor(_Numeric.log10(t)+1e-16))
Esempio n. 10
0
    def __call__(self, data, data_min=None, data_max=None,
                 val_min=None, val_max=None, map_type='linear', powerOf2=0):
        """ (data, data_min=None, data_max=None, val_min=None, val_max=None,
             map_type = 'linear', powerOf2=0)
        Maps an array of floats to integer values.
        data -- 3D numeric array;
        data_min, data_max -- min and max data values(other than actual
        array minimum/maximum) to map to integer values -
        val_min and val_max - in range (0 ... int_limit);
        map_type -- can be 'linear' or 'log';
        powerOf2 -- if set to 1, then if the data array dimensions are not
                    power of 2 - the returned array will be padded with zeros
                    so that its dims are power of 2.
        """
        # if data_min/max and val_min/max specified then the mapping
        # will proceed as follows:
        # [arr_min, data_min] is mapped to [int_min, val_min],
        # [data_min, data_max] is maped to [val_min, val_max],
        # [data_max, arr_max] is mapped to [val_max, int_limit].
        int_limit = self.int_limit
        int_min = self.int_min
        shape = data.shape
        assert len(shape)==3
        nx, ny, nz = shape
        arrsize = nx*ny*nz
        #arr_max = Numeric.maximum.reduce(data.ravel())
        #arr_min = Numeric.minimum.reduce(data.ravel())
        maxif = Numeric.maximum.reduce 
        arr_max = maxif(maxif(maxif(data)))
        minif = Numeric.minimum.reduce
        arr_min = minif(minif(minif(data)))
        #print "min(arr)=%f" % arr_min
        #print "max(arr)=%f" % arr_max
        if val_min != None:
            assert val_min >= 0 and val_min < int_limit
        else:
            val_min = int_min
        if val_max != None:
            assert val_max <= int_limit and val_max > 0
        else:
            val_max = int_limit
        if data_min != None:
            if data_min < arr_min: data_min = arr_min
        else:
            data_min = arr_min
        if data_max != None:
            if data_max > arr_max: data_max = arr_max
        else:
            data_max = arr_max
        print "mapping data_min %4f to val_min %d, data_max %4f to val_max %d"\
              % (data_min, val_min, data_max, val_max)
        if map_type == 'linear':
            k2,c2 = self.ScaleMap((val_min, val_max), (data_min, data_max))
            n_intervals = 3
            if abs(data_min-arr_min) < 0.00001: # data_min==arr_min
                k1,c1 = k2, c2
                n_intervals = n_intervals-1
            else :
                k1, c1 = self.ScaleMap((int_min, val_min),
                                       (arr_min, data_min)) 
            if abs(data_max-arr_max) < 0.00001: # data_max == arr_max
                k3, c3 = k2, c2
                n_intervals = n_intervals-1
            else:
                k3, c3 = self.ScaleMap((val_max, int_limit),
                                       (data_max, arr_max))

            t1 = time()
            #print "n_intervals = ", n_intervals
            if n_intervals == 2:
                if data_max == arr_max:
                    #print "data_max == arr_max"
                    new_arr = Numeric.where(Numeric.less(data, data_min),
                                            k1*data+c1, k2*data+c2 )
                elif data_min == arr_min:
                    #print "data_min == arr_min"
                    new_arr = Numeric.where(Numeric.greater_equal(data,
                              data_max), k3*data+c3, k2*data+c2)
            elif n_intervals == 3:
                new_arr1 = Numeric.where(Numeric.less(data, data_min),
                                        k1*data+c1, k2*data+c2)
                new_arr = Numeric.where(Numeric.greater_equal(data, data_max),
                                        k3*data+c3, new_arr1)
                del(new_arr1)
            else :
                new_arr = k2*data+c2
            arr = Numeric.transpose(new_arr).astype(self.int_type)
            del(new_arr)
            t2 = time()
            print "time to map : ", t2-t1
        elif map_type == 'log':
            if arr_min < 0:
                diff = abs(arr_min)+1.0
            elif arr_min >= 0 and arr_min < 1.0:
                diff = 1.0
            elif arr_min >= 1.0:
                diff=0
            k1, c1 = self.ScaleMap( (int_min, int_limit),
                           (log(arr_min+diff), log(arr_max+diff)) )
            arr=Numeric.transpose(k1*Numeric.log10(data+diff)+c1).astype(self.int_type)
        self.data_min = data_min
        self.data_max = data_max
        self.val_min = val_min
        self.val_max = val_max    
        if powerOf2:
            nx1, ny1, nz1 = nx, ny, nz
            res, power = isPowerOf2(nx)
            if not res:
                nx1 = 2**power
            res, power = isPowerOf2(ny)
            if not res:
                ny1 = 2**power
            res, power = isPowerOf2(nz)
            if not res:
                nz1 = 2**power
            dx, dy, dz = 0, 0, 0
            if nx1 != nx or ny1 != ny or nz1 != nz:
                #print "new data size: ", nx1,ny1,nz1
                dx = (nx1-nx)/2. ; dy = (ny1-ny)/2. ; dz = (nz1-nz)/2.
                #narr = Numeric.zeros((nx1,ny1,nz1), self.int_type)
                #narr[:nx,:ny,:nz] = arr[:,:,:]
                narr = Numeric.zeros((nz1,ny1,nx1), self.int_type)
                narr[:nz,:ny,:nx] = arr[:,:,:]
                self.arr = narr
                #arr = Numeric.zeros((nx1,ny1,nz1), self.int_type)
                #arr[:nx,:ny,:nz] = new_arr[:,:,:]
                #arr = Numeric.transpose(arr).astype(self.int_type)
                #self.arr = arr
                return narr
        self.arr = arr
        return arr