Example #1
0
 def _make_verts(self, U, V):
     uv = U+V*1j
     uv = nx.ravel(nx.ma.filled(uv, nx.nan))
     a = nx.absolute(uv)
     if self.scale is None:
         sn = max(10, math.sqrt(self.N))
         scale = 1.8 * nx.average(a) * sn # crude auto-scaling
         scale = scale/self.span
         self.scale = scale
     length = a/(self.scale*self.width)
     X, Y = self._h_arrows(length)
     xy = (X+Y*1j) * nx.exp(1j*nx.angle(uv[...,nx.newaxis]))*self.width
     xy = xy[:,:,nx.newaxis]
     XY = nx.concatenate((xy.real, xy.imag), axis=2)
     return XY
Example #2
0
fpin = NetCDFFile(infile)
tlat = fpin.variables['TLAT'][:]
tlon = fpin.variables['TLONG'][:]
temp = fpin.variables['TEMP'][:]
fillvalue = fpin.variables['TEMP'].attributes['_FillValue']
fpin.close()

# make longitudes monotonically increasing.
tlon = N.where(N.greater_equal(tlon, min(tlon[:, 0])), tlon - 360, tlon)

# create a masked array with temperature data (continents masked).
temp = MA.masked_values(temp, fillvalue)

# stack grids side-by-side (in longitiudinal direction), so
# any range of longitudes may be plotted on a world map.
tlon = N.concatenate((tlon, tlon + 360), 1)
tlat = N.concatenate((tlat, tlat), 1)
temp = MA.concatenate((temp, temp), 1)
tlon = tlon - 360.

pl.figure(figsize=(8.5, 11))
pl.subplot(2, 1, 1)
# subplot 1 just shows POP grid cells.
map = Basemap(projection='merc', lat_ts=20, llcrnrlon=-180, \
      urcrnrlon=180, llcrnrlat=-84, urcrnrlat=84, resolution='c')

map.drawcoastlines()
map.fillcontinents(color='white')

x, y = map(tlon, tlat)
im = map.pcolor(x,y,MA.masked_array(N.zeros(temp.shape,'f'), temp.mask),\
Example #3
0
fpin      = NetCDFFile(infile)
tlat      = fpin.variables['TLAT'][:]
tlon      = fpin.variables['TLONG'][:]
temp      = fpin.variables['TEMP'][:]
fillvalue = fpin.variables['TEMP'].attributes['_FillValue']
fpin.close()

# make longitudes monotonically increasing.
tlon = N.where(N.greater_equal(tlon,min(tlon[:,0])),tlon-360,tlon)

# create a masked array with temperature data (continents masked).
temp = MA.masked_values(temp,fillvalue)

# stack grids side-by-side (in longitiudinal direction), so
# any range of longitudes may be plotted on a world map.
tlon = N.concatenate((tlon,tlon+360),1)
tlat = N.concatenate((tlat,tlat),1)
temp = MA.concatenate((temp,temp),1)
tlon = tlon-360.

pl.figure(figsize=(8.5,11))
pl.subplot(2,1,1)
# subplot 1 just shows POP grid cells.
map = Basemap(projection='merc', lat_ts=20, llcrnrlon=-180, \
      urcrnrlon=180, llcrnrlat=-84, urcrnrlat=84, resolution='c')

map.drawcoastlines()
map.fillcontinents(color='white')

x, y = map(tlon,tlat)
im = map.pcolor(x,y,MA.masked_array(N.zeros(temp.shape,'f'), temp.mask),\
Example #4
0
	def __init__(self, start_ls, end_ls, y=0, width=0.001, x_offset=0, is_arrow=True, length_includes_head=True, \
		head_width=None, head_length=None, shape='full', overhang=0, \
		head_starts_at_zero=False,**kwargs):
		"""2008-02-02 an artist for gene. block-like. based on matplotlib.patches.FancyArrow
		
		Returns a new Arrow.
		
		x_offset: is the value of how far start_ls and end_ls should all be pushed
		
		is_arrow: True if it's an arrow. False if it's just a rectangle
		
		length_includes_head: True if head is counted in calculating the length.

		shape: ['full', 'left', 'right']

		overhang: ratio of the head_length that the arrow is swept back (0 overhang means
		triangular shape).

		head_starts_at_zero: if True, the head starts being drawn at coordinate
		0 instead of ending at coordinate 0.

		Valid kwargs are:
		%(Patch)s

		"""
		if head_width is None:
			head_width = 2 * width
		if head_length is None:
			head_length = 1/(2.0 * abs(end_ls[0]-start_ls[0]))

		distance = abs(end_ls[-1]-start_ls[0])
		if length_includes_head:
			length=distance
		else:
			length=distance+head_length
		
		no_of_blocks = len(start_ls)
		if not distance:
			verts = [] #display nothing if empty
		else:
			"""
			start by drawing horizontal arrow, point (tip of the arrow) at (0,0). the whole arrow sticks on the x-axis (<=0 part)
			Notice: the XY -coordination is not the usual math coordination system. it's canvas coordination. (0,0) is top left. horizontal is y-axis. vertical is x-axis.
			start from the last block, reversely to the 1st block
			"""
			inc_block_length = abs(end_ls[-1]-start_ls[-1])
			hw, hl = head_width, head_length
			if is_arrow:
				left_half_arrow_ls = [
    				[0.0,0.0],				  #tip
    				[-hl, -hw/2.0],			 #leftmost
    				[-hl*(1-overhang), -width/2.0], #meets stem
    				[-inc_block_length, -width/2.0]		 #bottom left
    			]
			else:	#this is just a rectangle
				left_half_arrow_ls = [
    				[0.0,0.0],				  #tip
    				[0.0, -width/2.0],		#left to the tip
    				[-inc_block_length, -width/2.0]		 #bottom left
    			]
			if no_of_blocks==1:	#only one block, seal it
				left_half_arrow_ls.append([-inc_block_length, 0])
			elif no_of_blocks>1:	#more than one block
				left_half_arrow_ls.append([-inc_block_length, -width/6.0])   #leave if open
				for i in range(1, no_of_blocks):
					block_index = -i-1	#backwards
					gap = abs(start_ls[block_index+1]-end_ls[block_index])
					inc_block_start = inc_block_length + gap
					this_block_length = abs(end_ls[block_index]-start_ls[block_index])
					inc_block_length = inc_block_length + gap + this_block_length
					if i!=no_of_blocks-1:	#don't seal it
						left_half_arrow_ls.append([-inc_block_start, -width/6.0])
						left_half_arrow_ls.append([-inc_block_start, -width/2.0])
						left_half_arrow_ls.append([-inc_block_length, -width/2.0])
						left_half_arrow_ls.append([-inc_block_length, -width/6.0])
					else:	#seal it
						left_half_arrow_ls.append([-inc_block_start, -width/6.0])
						left_half_arrow_ls.append([-inc_block_start, -width/2.0])
						left_half_arrow_ls.append([-inc_block_length, -width/2.0])
						left_half_arrow_ls.append([-inc_block_length, 0])
			left_half_arrow = array(left_half_arrow_ls)
			#if we're not including the head, shift up by head length
			if not length_includes_head:
				left_half_arrow += [head_length, 0]
			#if the head starts at 0, shift up by another head length
			if head_starts_at_zero:
				left_half_arrow += [head_length/2.0, 0]
			#figure out the shape, and complete accordingly
			if shape == 'left':
				coords = left_half_arrow
			else:
				right_half_arrow = left_half_arrow*[1,-1]
				if shape == 'right':
					coords = right_half_arrow
				elif shape == 'full':
					coords=concatenate([left_half_arrow,right_half_arrow[::-1]])
				else:
					raise ValueError, "Got unknown shape: %s" % shape
			dx = end_ls[-1]-start_ls[0]
			x = start_ls[0] + x_offset
			dy = 0
			cx = float(dx)/distance
			sx = float(dy)/distance
			M = array([[cx, sx],[-sx,cx]])
			verts = matrixmultiply(coords, M) + (x+dx, y+dy)

		Polygon.__init__(self, map(tuple, verts), **kwargs)