Exemple #1
0
    def fillcontinents(self,ax,color=0.8):
        """
 Fill continents.

 ax - current axis instance.
 color - color to fill continents (default gray).
        """
        # define corners of map domain.
        p1 = (self.llcrnrx,self.llcrnry); p2 = (self.urcrnrx,self.urcrnry)
        p3 = (self.llcrnrx,self.urcrnry); p4 = (self.urcrnrx,self.llcrnry)
        for x,y in self.coastpolygons:
            xa = N.array(x,'f')
            ya = N.array(y,'f')
        # clip to map domain.
            xa = N.clip(xa, self.xmin, self.xmax)
            ya = N.clip(ya, self.ymin, self.ymax)
        # check to see if all four corners of domain in polygon (if so,
        # don't draw since it will just fill in the whole map).
            test1 = N.fabs(xa-self.xmax) < 10.
            test2 = N.fabs(xa-self.xmin) < 10.
            test3 = N.fabs(ya-self.ymax) < 10.
            test4 = N.fabs(ya-self.ymin) < 10.
            hasp1 = sum(test1*test3)
            hasp2 = sum(test2*test3)
            hasp4 = sum(test2*test4)
            hasp3 = sum(test1*test4)
            if not hasp1 or not hasp2 or not hasp3 or not hasp4:
                xy = zip(xa.tolist(),ya.tolist())
                poly = Polygon(xy,facecolor=color,edgecolor=color,linewidth=0)
                ax.add_patch(poly)
Exemple #2
0
    def fillcontinents(self, ax, color=0.8):
        """
 Fill continents.

 ax - current axis instance.
 color - color to fill continents (default gray).
        """
        # define corners of map domain.
        p1 = (self.llcrnrx, self.llcrnry)
        p2 = (self.urcrnrx, self.urcrnry)
        p3 = (self.llcrnrx, self.urcrnry)
        p4 = (self.urcrnrx, self.llcrnry)
        for x, y in self.coastpolygons:
            xa = N.array(x, 'f')
            ya = N.array(y, 'f')
            # clip to map domain.
            xa = N.clip(xa, self.xmin, self.xmax)
            ya = N.clip(ya, self.ymin, self.ymax)
            # check to see if all four corners of domain in polygon (if so,
            # don't draw since it will just fill in the whole map).
            test1 = N.fabs(xa - self.xmax) < 10.
            test2 = N.fabs(xa - self.xmin) < 10.
            test3 = N.fabs(ya - self.ymax) < 10.
            test4 = N.fabs(ya - self.ymin) < 10.
            hasp1 = sum(test1 * test3)
            hasp2 = sum(test2 * test3)
            hasp4 = sum(test2 * test4)
            hasp3 = sum(test1 * test4)
            if not hasp1 or not hasp2 or not hasp3 or not hasp4:
                xy = zip(xa.tolist(), ya.tolist())
                poly = Polygon(xy,
                               facecolor=color,
                               edgecolor=color,
                               linewidth=0)
                ax.add_patch(poly)
Exemple #3
0
def lessthan(matrix,a):
	import numarray
	copymatrix = numarray.array(matrix)
	ones = numarray.ones([len(matrix),len(matrix[0])]) 
	matrix = matrix - (a) * ones 
	matrix = numarray.clip(matrix,-1*1e20,0)
	matrix = matrix * -1 
	matrix = numarray.clip(matrix,-1*1e20,10e-10)
	matrix = matrix * 1e9
	copymatrix = matrix * copymatrix 
	return copymatrix
Exemple #4
0
def exceptreplace(matrix,a):
	print a
	import numarray
	copymatrix = numarray.array(matrix)
	ones = numarray.ones([len(matrix),len(matrix[0])]) 
	matrix = matrix - (a-1) * ones 
	matrix = numarray.clip(matrix,0,2)
	matrix2 = copymatrix - (a+1) * ones 
        matrix2 = numarray.clip(matrix2,-2,0)
	##print matrix, matrix2
	matrix = copymatrix * matrix * matrix2 * (-1 * ones) / (ones * a)
	#print matrix
	return matrix
Exemple #5
0
def zscale(data,contrast,min=100,max=60000):
	"""Scale the data cube into the range 0-255"""

	## pic 100 random elements along each dimension
	## use zscale (see the IRAF display man page or
	## http://iraf.net/article.php/20051205162333315


	import random
	x=[]
	for i in random.sample(xrange(data.shape[0]),50):
	    for j in random.sample(xrange(data.shape[1]),50):
	 	x.append(data[i,j])
	
	yl=numarray.sort(numarray.clip(x,min,max))
	n=len(yl)
        ym=sum(yl)/float(n)

        xl=numarray.array(range(n))
 	xm=sum(xl)/float(n)	


	ss_xx=sum((xl-xm)*(xl-xm))
	ss_yy=sum((yl-ym)*(yl-ym))
        ss_xy=sum((xl-xm)*(yl-ym))
	b=ss_xy/ss_xx
	a=ym-b*xm

	z1=yl[n/2] + (b/contrast)*(1-n/2)
	z2=yl[n/2] + (b/contrast)*(n-n/2)

	## Now put the data inbetween Z1 and Z2
	high=data-z1
	z2=z2-z1
	high=numarray.clip(high,0,z2)

	## and change that to 0-255
	high= 256-256*high/z2

	### send back the scalled data
	return high
Exemple #6
0
def zscale(data,contrast,min=100,max=60000):
	"""Scale the data cube into the range 0-255"""

	## pic 100 random elements along each dimension
	## use zscale (see the IRAF display man page or
	## http://iraf.net/article.php/20051205162333315


	import random
	x=[]
	for i in random.sample(xrange(data.shape[0]),50):
	    for j in random.sample(xrange(data.shape[1]),50):
	 	x.append(data[i,j])
	
	yl=numarray.sort(numarray.clip(x,min,max))
	n=len(yl)
        ym=sum(yl)/float(n)

        xl=numarray.array(range(n))
 	xm=sum(xl)/float(n)	


	ss_xx=sum((xl-xm)*(xl-xm))
	ss_yy=sum((yl-ym)*(yl-ym))
        ss_xy=sum((xl-xm)*(yl-ym))
	b=ss_xy/ss_xx
	a=ym-b*xm

	z1=yl[n/2] + (b/contrast)*(1-n/2)
	z2=yl[n/2] + (b/contrast)*(n-n/2)

	## Now put the data inbetween Z1 and Z2
	high=data-z1
	z2=z2-z1
	high=numarray.clip(high,0,z2)

	## and change that to 0-255
	high= 256-256*high/z2

	### send back the scalled data
	return high
Exemple #7
0
    def _createLineSet(  self, center = [0,0,0]):
        
        # Line indices
        cnnVel = []
        for i in range(0, 512, 2):
            cnnVel.append(i)
            cnnVel.append(i + 1)
            cnnVel.append(SO_END_LINE_INDEX)

        # Create packed RGBA
        R = (numarray.clip( self.cMapColors[:,0], 0, 1 ) * 255).astype('i')
        G = (numarray.clip( self.cMapColors[:,1], 0, 1 ) * 255).astype('i')
        B = (numarray.clip( self.cMapColors[:,2], 0, 1 ) * 255).astype('i')                   
        self.cmapRGBA = (R << 24) + (G << 16) + (B <<8) + 255        

        # Create data structures
        self.colormapSep = SoSeparator()

	self.style = SoDrawStyle()
        self.style.lineWidth.setValue(5)
        self.colormapSep.addChild(self.style)
        
        self.transform = SoTransform()
        self.transform.translation.setValue( [self.xP, self.yP, 0] )
        self.colormapSep.addChild( self.transform )

        self.vertexPropertyObj    = SoVertexProperty()
        self.vertexPropertyObj.materialBinding.setValue( SoMaterialBinding.PER_VERTEX_INDEXED )
        
        self.contourLineSet = SoIndexedLineSet()          
        self.contourLineSet.vertexProperty.setValue( self.vertexPropertyObj )
        self.contourLineSet.coordIndex.setValues( 0, cnnVel )

        self.colormapSep.addChild( self.contourLineSet )        
        self.addChild( self.colormapSep )
               
        self._updateVertexPosition() 
Exemple #8
0
    def _updateVertexPosition( self ):
        # Draw Colormap Line set
        self.vertexPositions  = numarray.concatenate( ( self.vertexPositions[0:256],
                                                        self.vertexPositions[256:512]),
                                                        axis = 1 ).copy()            
        self.vertexPositions.setshape( 512, 3 )       
       
        scalar      = self.vertexPositions[:,1]
        sclrMinVal  = scalar.max()
        sclrMaxVal  = scalar.min()

        fct = (len(self.cMapColors)-1) / (sclrMaxVal - sclrMinVal)
        sclrIdx	 = fct * (scalar - sclrMinVal) + 0.5
        sclrIdx	 = numarray.clip( sclrIdx, 0, len(self.cMapColors)-1 )
        colorIdx = self.cmapRGBA[sclrIdx]
        colorIdx = colorIdx.tolist()
        colorIdx.reverse()       
     
        self.vertexPropertyObj.vertex.setValues( 0, self.vertexPositions )        
        self.vertexPropertyObj.orderedRGBA.setValues( 0, colorIdx )         
Exemple #9
0
 def transformImage(self):
     datamin = self.datamin
     datamax = self.datamax
     data2d = numarray.clip(self.data2d, min(datamin, datamax),
                            max(datamin, datamax))
     return data2d
Exemple #10
0
 def clipToInt(R,G,B):
     writeBands(clip(R,0,2047).astype('w'),
                clip(G,0,2047).astype('w'),
                clip(B,0,2047).astype('w'))
Exemple #11
0
 def clipAndScale(R,G,B):
     writeBands(clip(R*0.124573,0,255).astype('b'),
                clip(G*0.124573,0,255).astype('b'),
                clip(B*0.124573,0,255).astype('b'))
Exemple #12
0
 def clipToByte(R,G,B):
     writeBands(clip(R,0,255).astype('b'),
                clip(G,0,255).astype('b'),
                clip(B,0,255).astype('b'))
Exemple #13
0
 def clipToInt(R, G, B):
     writeBands(
         clip(R, 0, 2047).astype('w'),
         clip(G, 0, 2047).astype('w'),
         clip(B, 0, 2047).astype('w'))
Exemple #14
0
 def clipAndScale(R, G, B):
     writeBands(
         clip(R * 0.124573, 0, 255).astype('b'),
         clip(G * 0.124573, 0, 255).astype('b'),
         clip(B * 0.124573, 0, 255).astype('b'))
Exemple #15
0
 def clipToByte(R, G, B):
     writeBands(
         clip(R, 0, 255).astype('b'),
         clip(G, 0, 255).astype('b'),
         clip(B, 0, 255).astype('b'))