예제 #1
0
def trapezoidArray(f,dx):
    """
    same as trapezoidRule() but return the integral as fn of z
    (mostly in-place operations for optimized memory usage)
    """
    i = pl.add.accumulate(f)
    pl.add(i,-0.5*f,  i)
    pl.add(i,-0.5*f[0],  i)
    pl.multiply(i,dx, i)
    return i
예제 #2
0
파일: wav.py 프로젝트: antiface/dsp-2
def beep(freq_phase_amp, L):
    '''Additive synthesis of sinewaves.

    freq_phase_amp -- a numpy array with a row for each sinewave, and
    frequency, phase and amplitude in each column.
    L -- length in samples.
    '''
    res = pl.zeros(L)
    ii = pl.arange(L)
    tmp = pl.empty(L)
    for f, p, a in freq_phase_amp:
        pl.multiply(ii, f * tau / sr, tmp)
        pl.add(tmp, p, tmp)
        pl.sin(tmp, tmp)
        pl.multiply(tmp, a, tmp)
        pl.add(res, tmp, res)

    return res
예제 #3
0
파일: MRIDE.py 프로젝트: parhamaram/MRAIDE
def directsum(arg):

	#check if all matrices are square
	for i in range(arg.shape[1]):
		assert arg[0,i].shape[0]==arg[0,i].shape[1], 'Matrix '+str(arg[i])+ ' is not square.'

	#calculate the shape of the result of the directsum operation
	temp=(0,0)
	for i in range(arg.shape[1]):
		temp=pb.add(temp,arg[0,i].shape)
	dsum =pb.zeros(temp)

	dsum[:arg[0,0].shape[0],:arg[0,0].shape[1]]=arg[0,0]

	rc_Indices=0   
	for i in range(1,arg.shape[1]):
		rc_Indices+=arg[0,i-1].shape[0]
		dsum[rc_Indices:rc_Indices+arg[0,i].shape[0],rc_Indices:rc_Indices+arg[0,i].shape[1]]=arg[0,i]
	return dsum
예제 #4
0
def scatter(data,lim,tilt,include):

        tiltX = tilt[0]
        tiltY = tilt[1]

        loadData = np.loadtxt(data)
	x = loadData[:,2]
        y = loadData[:,1]

	#Center peak vales at (0,0)
        centx = np.subtract(x,float(lim))
        centy = np.subtract(y,float(lim))
        #Calculate distance of peaks from expected angle
        dist = []
        for i in xrange(len(loadData[:,1])):
	        rx = centx[i]
        	ry = centy[i]
                distance = math.sqrt(((rx - tiltX)*(rx - tiltX)) + ((ry - tiltY)*(ry - tiltY))/2)
                dist.append(distance)

        newDist = sorted(dist)

        numReadLines = round((float(include)/100)*len(loadData[:,1]))

        includeRadius = []
        for j in xrange(numReadLines):
        	includeRadius = newDist[j]
        #Create function for plotting circle
        theta = np.linspace(0,2*math.pi)

        incRadx = includeRadius*pylab.cos(theta)
        incRady = includeRadius*pylab.sin(theta)

        incRadx = pylab.add(incRadx,tiltX)
        incRady = pylab.add(incRady,tiltY)

        #Set radii for concentric circles       
        rad1 = 10
        rad2 = 20
        rad3 = 30
        rad4 = 40
        rad5 = 50
        rad6 = 60

        #Create x,y coords for concentric cricles
        cx1 = rad1*pylab.cos(theta)
        cy1 = rad1*pylab.sin(theta)
        cx2 = rad2*pylab.cos(theta)
        cy2 = rad2*pylab.sin(theta)
        cx3 = rad3*pylab.cos(theta)
        cy3 = rad3*pylab.sin(theta)
        cx4 = rad4*pylab.cos(theta)
        cy4 = rad4*pylab.sin(theta)
        cx5 = rad5*pylab.cos(theta)
        cy5 = rad5*pylab.sin(theta)
        cx6 = rad6*pylab.cos(theta)
        cy6 = rad6*pylab.sin(theta)

        #Create axes
        line1 = np.linspace(-60,60,100)

        #Create zeros array
        line2 = []
        i = 1
        while i <= 100:
                line2.append('0')
		i = i + 1
        fig = plt.figure(1)

        scatter = plt.subplot(111,aspect='equal')
        majorLocator = MultipleLocator(10)
        majorFormatter = FormatStrFormatter('%d')
        minorLocator = MultipleLocator(5)
        scatter.set_xlabel('Tilt direction (degrees)',fontsize=15)
        scatter.set_ylabel('Tilt direction (degrees)',fontsize=15)
        scatter.set_title('%d'%(include) + '% ' + 'of particles are within %d degrees of expected angle'%(round(includeRadius)))
        scatter.plot(cx1,cy1,c = 'k')
        scatter.plot(cx2,cy2,c = 'k')
        scatter.plot(cx3,cy3,c = 'k')
        scatter.plot(cx4,cy4,c = 'k')
        scatter.plot(cx5,cy5,c = 'k')
        scatter.plot(cx6,cy6,c = 'k')
        scatter.plot(cx5,cy5,c = 'k')
        scatter.plot(incRadx,incRady,c = 'r')
        scatter.plot(line2,line1,c='k')
        scatter.plot(line1,line2,c='k')
        scatter.scatter(centx,centy,marker='+',c='k',edgecolor='k',s=55)
        majorLocator = MultipleLocator(10)
        majorFormatter = FormatStrFormatter('%d')
        minorLocator = MultipleLocator(5)
        scatter.xaxis.set_major_locator(majorLocator)
        scatter.xaxis.set_major_formatter(majorFormatter)
        scatter.xaxis.set_minor_locator(minorLocator)
        scatter.yaxis.set_major_locator(majorLocator)
        scatter.yaxis.set_major_formatter(majorFormatter)
        scatter.yaxis.set_minor_locator(minorLocator)
        lim1 = -float(lim)
	plt.xlim(lim1,float(lim))
        plt.ylim(lim1,float(lim))
	outFILE = '%s.png' %(data[:-4])
        plt.savefig(outFILE,dpi=150,format='png')
예제 #5
0
    def scatter(self, data, lim, tilt, include):

        tiltX = tilt[0]
        tiltY = tilt[1]

        loadData = np.loadtxt(data)
        x = loadData[:, 2]
        y = loadData[:, 1]

        #Center peak vales at (0,0)
        centx = np.subtract(x, lim)
        centy = np.subtract(y, lim)

        #Calculate distance of peaks from expected angle
        dist = []
        for i in xrange(len(loadData[:, 1])):
            rx = centx[i]
            ry = centy[i]

            distance = math.sqrt(((rx - tiltX) * (rx - tiltX)) +
                                 ((ry - tiltY) * (ry - tiltY)) / 2)
            dist.append(distance)

        newDist = sorted(dist)

        numReadLines = round((float(include) / 100) * len(loadData[:, 1]))

        includeRadius = []
        for j in xrange(numReadLines):
            includeRadius = newDist[j]
        #Create function for plotting circle
        theta = np.linspace(0, 2 * math.pi)

        incRadx = includeRadius * pylab.cos(theta)
        incRady = includeRadius * pylab.sin(theta)

        incRadx = pylab.add(incRadx, tiltX)
        incRady = pylab.add(incRady, tiltY)

        #Set radii for concentric circles
        rad1 = 10
        rad2 = 20
        rad3 = 30
        rad4 = 40
        rad5 = 50
        rad6 = 60

        #Create x,y coords for concentric cricles
        cx1 = rad1 * pylab.cos(theta)
        cy1 = rad1 * pylab.sin(theta)
        cx2 = rad2 * pylab.cos(theta)
        cy2 = rad2 * pylab.sin(theta)
        cx3 = rad3 * pylab.cos(theta)
        cy3 = rad3 * pylab.sin(theta)
        cx4 = rad4 * pylab.cos(theta)
        cy4 = rad4 * pylab.sin(theta)
        cx5 = rad5 * pylab.cos(theta)
        cy5 = rad5 * pylab.sin(theta)
        cx6 = rad6 * pylab.cos(theta)
        cy6 = rad6 * pylab.sin(theta)

        #Create axes
        line1 = np.linspace(-60, 60, 100)

        #Create zeros array
        line2 = []
        i = 1
        while i <= 100:
            line2.append('0')
            i = i + 1
        fig = plt.figure(1)

        scatter = plt.subplot(111, aspect='equal')
        majorLocator = MultipleLocator(10)
        majorFormatter = FormatStrFormatter('%d')
        minorLocator = MultipleLocator(5)
        scatter.set_xlabel('Tilt direction (degrees)', fontsize=15)
        scatter.set_ylabel('Tilt direction (degrees)', fontsize=15)
        scatter.set_title(
            '%d' % (include) + '% ' +
            'of particles are within %d degrees of expected angle' %
            (round(includeRadius)))
        scatter.plot(cx1, cy1, c='k')
        scatter.plot(cx2, cy2, c='k')
        scatter.plot(cx3, cy3, c='k')
        scatter.plot(cx4, cy4, c='k')
        scatter.plot(cx5, cy5, c='k')
        scatter.plot(cx6, cy6, c='k')
        scatter.plot(cx5, cy5, c='k')
        scatter.plot(incRadx, incRady, c='r')
        scatter.plot(line2, line1, c='k')
        scatter.plot(line1, line2, c='k')
        scatter.scatter(centx, centy, marker='+', c='k', edgecolor='k', s=55)
        majorLocator = MultipleLocator(10)
        majorFormatter = FormatStrFormatter('%d')
        minorLocator = MultipleLocator(5)
        scatter.xaxis.set_major_locator(majorLocator)
        scatter.xaxis.set_major_formatter(majorFormatter)
        scatter.xaxis.set_minor_locator(minorLocator)
        scatter.yaxis.set_major_locator(majorLocator)
        scatter.yaxis.set_major_formatter(majorFormatter)
        scatter.yaxis.set_minor_locator(minorLocator)
        plt.xlim(-lim, lim)
        plt.ylim(-lim, lim)
        outFILE = '%s.png' % (data[:-4])
        plt.savefig(outFILE, dpi=150, format='png')