docs: 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