# pm3d=[4,4,4] means x**2 in each channel
# pm3d=[7,7,7] means x**0.5 in each channel
graymap = pyxgraph.ColMapper.ColorMapper("pm3d", exponent=1.0, invert=0, pm3d=[7,7,7])
# mycolmap = pyxgraph.ColMapper.ColorMapper("pm3d", exponent=1.0, brightness=0.2)
# mycolmap = pyxgraph.ColMapper.ColorMapper("white-yellow-red-black", exponent=0.6, brightness=0.4)
mycolmap = graymap

# g.pyxplotarray(data['pp'], colmap=graymap,
imagedata = N.log10(data['dd']/(1.3*1.67262158e-24)) # log10 number density
# imagemin, imagemax = N.log10(3.0), N.log10(300.0)
imagemin, imagemax = N.log10(N.floor(10**imagedata.min())), N.log10(100*N.ceil(10**imagedata.max()/100))
gright.pyxplotarray(imagedata[::-1,:], colmap=mycolmap, minvalue=imagemin, maxvalue=imagemax,
	       xpos=0.0, ypos=0.0, width=worldwidth, height=worldheight, graphcoords=True)

cb = pyxgraph.pyxcolorbar(lut=mycolmap.generate_lut(), frame=gright, pos=(1.1,0.0),
			  orientation="vertical2",
			  minlabel="$n = %.0f$" % 10**imagemin,
			  maxlabel="$n = %.0f$" % 10**imagemax)
gright.insert(cb)


# Plot vectors of B-field
# B = N.sqrt(data['bx']**2 + data['by']**2) # magnitude of B-field
# theta = N.arctan2(data['by'], data['bx']) # angle of B with x-axis

# Subtract off mean velocity of neutral gas
vmean = (data['vx']*data['dd']*data['xn']).sum() / (data['dd']*data['xn']).sum()
data['vx'] -= vmean
print "Mean x-velocity of neutral gas: %i km/s" % (vmean/1.e5)


# Plot contours of vector potential
		      ylimits=(0, worldheight),
		      width=figwidth, height=figheight, 
		      key=None,
		      title=plottitle,
		      xlabel='$x$ (pc)',
		      ylabel='$y$ (pc)',
		      )
# image of the pressure
imagedata = N.log10(data['dd']/(1.3*1.67262158e-24)) # log10 number density
imagemin = 1.0
imagemax = 5.0
g.pyxplotarray(imagedata[::-1,:], colmap=imagecolmap,
	       xpos=0.0, ypos=0.0, width=worldwidth, height=worldheight, graphcoords=True)
cb = pyxgraph.pyxcolorbar(lut=imagecolmap.generate_lut(), frame=g, pos=(1.03,0.0),
			  orientation="vertical2",
			  width=12*pyx.unit.x_pt,
			  minlabel="$n = 10^{%.1f}$" % imagemin, 
			  maxlabel="$n = 10^{%.1f}$" % imagemax,
			  textattrs=[pyx.trafo.scale(0.7)])
g.insert(cb)


# Plot vectors of velocity
v = N.sqrt(data['vx']**2 + data['vy']**2)/vnorm # normalized magnitude of velocity
theta = N.arctan2(data['vy'], data['vx']) # angle of v with x-axis
mx, my = 64, 64*ny/nx			# fixed grid of arrows, independent of resolution 
skip = nx/mx

# we abuse a parametric function below, so we express everything in
# terms of a parameter k
import random
x = lambda k: random.randint(skip/4,3*skip/4) + skip*(int(k)/my)