Ejemplo n.º 1
0
def doit_numarray(L):
    import numarray
    L = numarray.array(L)
    t0 = time.clock()
    numarray.sort(L)
    t1 = time.clock()
    print "%6.2f" % (t1-t0),
    fl()
Ejemplo n.º 2
0
def cumulative(input):
    #print "max x = ",max(input)
    x = N.sort(input)
    #print "max x = ",max(x)
    n = len(input)
    y = N.arange(0., 1., (1. / float(n)))
    return x, y
Ejemplo n.º 3
0
def mad(xdata, xmed):
    # The XMAD subroutine calculates the Median Absolute Deviation from
    #    the sample median. The median, M , is subtracted from each
    #    ORDERED statistic and then the absolute value is taken. This new
    #    set of of statistics is then resorted so that they are ORDERED
    #    statistics. The MAD is then defined to be the median of this
    #    new set of statistics and is returned as XMADM. The MAD can
    #    be defined:
    #
    #                   XMADM = median{ abs(x[i] - M) }
    #
    #    where the x[i] are the values passed in the array XDATA, and
    #    the median, M, is passed in the array XLETTER. The set of stats
    #    in the brackets is assumed to be resorted. For more information
    #    see page 408 in UREDA.
    n = len(xdata)
    dhalf, n1, n2 = (0.5, 1, 2)
    xdata2 = N.absolute(xdata - xmed)
    xdata2 = N.sort(xdata2,0)
    if (float(n)/float(n2) - int(n/n2) == 0):
        i1 = n/n2
        i2 = n/n2 - n1
        xmadm = dhalf*(xdata2[i1] + xdata2[i2])
    else:
        i1 = n/n2
        xmadm = xdata2[i1]
    return xmadm
Ejemplo n.º 4
0
def median(x, sorted=0):
    if not sorted: x = N.sort(x,axis=0)
    n = len(x)
    n2 = n/2
    if 2*n2 == n:
        xmed = 0.5*(x[n2-1]+x[n2])
    else:
        xmed = x[n2]
    return xmed
Ejemplo n.º 5
0
def quartiles(x, sorted=0):
    if not sorted: x = N.sort(x)
    n = len(x)
    n2 = n/2
    n4 = n/4
    if 2*n2 == n:
        xlq = 0.75*x[n4] + 0.25*x[n4+1]
        xhq = 0.25*x[3*n4] + 0.75*x[3*n4+1]
    else:
        xlq = x[n4]
        xhq = x[3*n4]
    return (xlq, xhq)
Ejemplo n.º 6
0
def kuiper_test(x, y):
    x = N.sort(x)
    y = N.sort(y)
    nx = len(x)
    ny = len(y)
    jx = jy = 0
    fnx = fny = 0.0
    fnx_arr = N.zeros(nx, N.Float32)
    fny_arr = N.zeros(ny, N.Float32)
    binx = N.zeros(nx, N.Float32)
    biny = N.zeros(ny, N.Float32)
    d1 = d2 = 0.0
    while (jx < nx or jy < ny):
        if jx < nx:
            dx = x[jx]
        else:
            dx = x[-1]
        if jy < ny:
            dy = y[jy]
        else:
            dy = y[-1]
        if (dx <= dy or jy >= ny-1) and jx < nx:
            fnx = (jx+1)/float(nx)
            binx[jx] = dx
            fnx_arr[jx] = fnx
            jx += 1
        if (dy <= dx or jx >= nx-1) and jy < ny:
            fny = (jy+1)/float(ny)
            biny[jy] = dy
            fny_arr[jy] = fny
            jy += 1
        dt1 = (fny-fnx)
        dt2 = (fnx-fny)
	d1 = max(d1, dt1)
	d2 = max(d2, dt2)
    v = d1 + d2
    n = sqrt(nx*ny/(nx+ny))
    prob = probkuiper((n+0.155+0.24/n)*v)
    return v, prob, [binx, fnx_arr], [biny, fny_arr]
Ejemplo n.º 7
0
def ks_test(x, y):
    x = N.sort(x)
    y = N.sort(y)
    nx = len(x)
    ny = len(y)
    jx = jy = 0
    fnx = fny = 0.0
    fnx_arr = N.zeros(nx, N.Float32)
    fny_arr = N.zeros(ny, N.Float32)
    binx = N.zeros(nx, N.Float32)
    biny = N.zeros(ny, N.Float32)
    d = 0.0
    while (jx < nx or jy < ny):
        if jx < nx:
            dx = x[jx]
        else:
            dx = x[-1]
        if jy < ny:
            dy = y[jy]
        else:
            dy = y[-1]
        if (dx <= dy or jy >= ny-1) and jx < nx:
            fnx = (jx+1)/float(nx)
            binx[jx] = dx
            fnx_arr[jx] = fnx
            jx += 1
        if (dy <= dx or jx >= nx-1) and jy < ny:
            fny = (jy+1)/float(ny)
            biny[jy] = dy
            fny_arr[jy] = fny
            jy += 1
        dt = abs(fny-fnx)
        if dt > d:
            d = dt
        #print '%5.3f  %5.3f  %5.3f  %5.3f  %5.3f  %5.3f'%(dx, dy, fnx, fny, dt, d)
    n = sqrt(nx*ny/(nx+ny))
    prob = probks((n+0.12+0.11/n)*d)
    return d, prob, [binx, fnx_arr], [biny, fny_arr]
Ejemplo n.º 8
0
Archivo: display.py Proyecto: OSSOS/MOP
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
Ejemplo n.º 9
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
Ejemplo n.º 10
0
def median(x):
    x = N.sort(x)
    n = float(len(x))
    nmed = int(n / 2.)
    return x[nmed]
Ejemplo n.º 11
0
def cumulative(input):
    x = N.sort(input)
    n = len(input)
    y = N.arange(0, 1, (1. / n))
    return x, y