コード例 #1
0
ファイル: laser.py プロジェクト: yan-kuan/ART
 def shoot2(self, x, y, datum_point_x=7, datum_point_y=7, debug=False):
     # calculate the rotate angles
     quadrant = getQuadrant(x, y, datum_point_x, datum_point_y)
     print 'quadrant : %d' % quadrant
     xcoef = 1 if quadrant == 3 or quadrant == 4 else -1
     ycoef = 1 if quadrant == 2 or quadrant == 4 else -1
     base = abs(abs(x-datum_point_x) * self.gridLength - (xcoef * (self.gridLength / 2)))
     height = abs(abs(y-datum_point_y) * self.gridLength - (ycoef * (self.gridLength / 2)))
     laser2target = math.sqrt(pylab.square(base) + pylab.square(height) + pylab.square(self.laser2wall))
     print "base : %f \t height : %f" % (base, height)
     print laser2target
     yaw = math.asin(base / laser2target)
     pitch = math.asin(height / laser2target)
     print "yaw : %f \t pitch : %f" % (yaw, pitch)
     units2yaw = yaw / anglePerStep
     units2pitch = pitch / anglePerStep
     
     if quadrant == 1 or quadrant == 3:
         units2yaw = -units2yaw 
     if quadrant == 3 or quadrant == 4:
         units2pitch = -units2pitch
     print 'steps to yaw %f \t steps to pitch %f' % (units2yaw, units2pitch)
     self.move(units2yaw, units2pitch, 1, 3000)
     time.sleep(5)
     # return to the datum point
     self.move(-units2yaw, -units2pitch, 1, 0)
コード例 #2
0
ファイル: 2012-2.py プロジェクト: fukuta0614/procon
def calc_a(x_point, y_point):
    A = pylab.sum(pylab.square(x_point)) * 30
    B = pylab.square(pylab.sum(x_point))
    C = pylab.sum(x_point * y_point) * 30
    D = pylab.sum(x_point) * pylab.sum(y_point)
    a = (C - D) / (A - B)
    print(a)
コード例 #3
0
ファイル: ps5.py プロジェクト: vwozhaoxin/mit-6.0002
def r_squared(y, estimated):
    """
    Calculate the R-squared error term.
    
    Args:
        y: 1-d pylab array with length N, representing the y-coordinates of the
            N sample points
        estimated: an 1-d pylab array of values estimated by the regression
            model

    Returns:
        a float for the R-squared error term
    """
    # TODO
    #    pass
    mean = pylab.mean(y)
    result = 1 - pylab.sum(pylab.square(y - estimated)) / pylab.sum(
        pylab.square(y - mean))
    return result
コード例 #4
0
ファイル: ps5.py プロジェクト: vwozhaoxin/mit-6.0002
def rmse(y, estimated):
    """
    Calculate the root mean square error term.

    Args:
        y: an 1-d pylab array with length N, representing the y-coordinates of
            the N sample points
        estimated: an 1-d pylab array of values estimated by the regression
            model

    Returns:
        a float for the root mean square error term
    """
    # TODO
    return pylab.sqrt(pylab.sum(pylab.square(y - estimated)) / y.shape[0])
コード例 #5
0
ファイル: hinton.py プロジェクト: jameshensman/pyvb
def hinton(W):
	"""Draw a hinton diagram of the matrix W on the current pylab axis"""
	M,N = W.shape
	square_x,square_y = pylab.array([-.5,.5,.5,-.5]),pylab.array([-.5,-.5,.5,.5])
	pylab.fill([-.5,N-.5,N-.5,-.5],[-.5,-.5,M-.5,M-.5],'grey')
	Wmax = pylab.sqrt(pylab.square(W)).max() #pylab. has no abs!
	for m,Wrow in enumerate(W):
		for n,w in enumerate(Wrow):
			c = pylab.signbit(w) and 'k' or 'w'#love python :)
			pylab.fill(square_x*w/Wmax+n,square_y*w/Wmax+m,c,edgecolor=c)
	pylab.axis('equal')
	pylab.ylim(M-0.5,-0.5)
				
				
			
			
コード例 #6
0
ファイル: almapolhelpers.py プロジェクト: schiebel/casa
def qufromgain(caltable, badspw=[], paoffset=0.0):

    mytb = taskinit.tbtool()
    myme = taskinit.metool()

    mytb.open(caltable + '/ANTENNA')
    pos = mytb.getcol('POSITION')
    meanpos = pl.mean(pos, 1)
    frame = mytb.getcolkeyword('POSITION', 'MEASINFO')['Ref']
    units = mytb.getcolkeyword('POSITION', 'QuantumUnits')
    mpos = myme.position(frame,
                         str(meanpos[0]) + units[0],
                         str(meanpos[1]) + units[1],
                         str(meanpos[2]) + units[2])
    myme.doframe(mpos)

    # _geodetic_ latitude
    latr = myme.measure(mpos, 'WGS84')['m1']['value']

    print 'Latitude = ', latr * 180 / pi

    mytb.open(caltable + '/FIELD')
    nfld = mytb.nrows()
    dirs = mytb.getcol('DELAY_DIR')[:, 0, :]
    mytb.close()
    print 'Found as many as ' + str(nfld) + ' fields.'

    mytb.open(caltable + '/SPECTRAL_WINDOW')
    nspw = mytb.nrows()
    bandnames = [x.split('#')[0].split('_')[-1] for x in mytb.getcol('NAME')]
    mytb.close()
    print 'Found as many as ' + str(nspw) + ' spws.'

    R = pl.zeros((nspw, nfld))
    Q = pl.zeros((nspw, nfld))
    U = pl.zeros((nspw, nfld))
    mask = pl.ones((nspw, nfld), dtype=bool)

    if (len(badspw) > 0):
        mask[badspw, :] = False

    QU = {}
    mytb.open(caltable)
    for ifld in range(nfld):
        for ispw in range(nspw):
            st = mytb.query('FIELD_ID==' + str(ifld) +
                            ' && SPECTRAL_WINDOW_ID==' + str(ispw))
            nrows = st.nrows()
            if nrows > 0:

                rah = dirs[0, ifld] * 12.0 / pi
                decr = dirs[1, ifld]
                times = st.getcol('TIME')
                gains = st.getcol('CPARAM')
                ants = st.getcol('ANTENNA1')

                nants = ants.max() + 1

                # times
                time0 = 86400.0 * floor(times[0] / 86400.0)
                rtimes = times - time0

                # amplitude ratio
                amps = pl.absolute(gains)
                amps[amps == 0.0] = 1.0
                ratio = amps[0, 0, :] / amps[1, 0, :]

                ratio.resize(nrows / nants, nants)

                # parang
                parang = pl.zeros(len(times))

                for itim in range(len(times)):
                    tm = myme.epoch('UTC', str(times[itim]) + 's')
                    last = myme.measure(tm, 'LAST')['m0']['value']
                    last -= floor(last)  # days
                    last *= 24.0  # hours
                    ha = last - rah  # hours
                    har = ha * 2.0 * pi / 24.0

                    parang[itim] = atan2((cos(latr) * sin(har)),
                                         (sin(latr) * cos(decr) -
                                          cos(latr) * sin(decr) * cos(har)))

                parang.resize(nrows / nants, nants)
                parang += bandpa(bandnames[ispw])  # feed pos ang offset
                parang += (paoffset * pi / 180.)  # manual feed pa offset
                parangd = parang * (180.0 / pi)

                A = pl.ones((nrows / nants, 3))
                A[:, 1] = pl.cos(2 * parang[:, 0])
                A[:, 2] = pl.sin(2 * parang[:, 0])

                fit = pl.lstsq(A, pl.square(ratio))

                ants0 = range(nants)
                rsum = pl.sum(ratio[:, ants0], 1)
                rsum /= len(ants0)

                fit = pl.lstsq(A, pl.square(rsum))
                R[ispw, ifld] = fit[0][0]
                Q[ispw, ifld] = fit[0][1] / R[ispw, ifld] / 2.0
                U[ispw, ifld] = fit[0][2] / R[ispw, ifld] / 2.0
                P = sqrt(Q[ispw, ifld]**2 + U[ispw, ifld]**2)
                X = 0.5 * atan2(U[ispw, ifld], Q[ispw, ifld]) * 180 / pi

                print 'Fld=', ifld, 'Spw=', ispw, '(B=' + str(
                    bandnames[ispw]) + ', PA offset=' + str(
                        bandpa(bandnames[ispw]) * 180. /
                        pi) + 'deg)', 'Gx/Gy=', R[ispw, ifld], 'Q=', Q[
                            ispw, ifld], 'U=', U[ispw, ifld], 'P=', P, 'X=', X

            else:
                mask[ispw, ifld] = False

            st.close()

        if sum(mask[:, ifld]) > 0:
            print 'For field id = ', ifld, ' there are ', sum(
                mask[:, ifld]), 'good spws.'

            Qm = pl.mean(Q[mask[:, ifld], ifld])
            Um = pl.mean(U[mask[:, ifld], ifld])
            QU[ifld] = (Qm, Um)
            Qe = pl.std(Q[mask[:, ifld], ifld])
            Ue = pl.std(U[mask[:, ifld], ifld])
            Pm = sqrt(Qm**2 + Um**2)
            Xm = 0.5 * atan2(Um, Qm) * 180 / pi
            print 'Spw mean: Fld=', ifld, 'Q=', Qm, 'U=', Um, '(rms=', Qe, Ue, ')', 'P=', Pm, 'X=', Xm

    mytb.close()

    return QU
コード例 #7
0
ファイル: almapolhelpers.py プロジェクト: schiebel/casa
def qufromgain(caltable,badspw=[],paoffset=0.0):

    mytb=taskinit.tbtool()
    myme=taskinit.metool()

    mytb.open(caltable+'/ANTENNA')
    pos=mytb.getcol('POSITION')
    meanpos=pl.mean(pos,1)
    frame=mytb.getcolkeyword('POSITION','MEASINFO')['Ref']
    units=mytb.getcolkeyword('POSITION','QuantumUnits')
    mpos=myme.position(frame,
                     str(meanpos[0])+units[0],
                     str(meanpos[1])+units[1],
                     str(meanpos[2])+units[2])
    myme.doframe(mpos)

    # _geodetic_ latitude
    latr=myme.measure(mpos,'WGS84')['m1']['value']

    print 'Latitude = ',latr*180/pi

    mytb.open(caltable+'/FIELD')
    nfld=mytb.nrows()
    dirs=mytb.getcol('DELAY_DIR')[:,0,:]
    mytb.close()
    print 'Found as many as '+str(nfld)+' fields.'

    mytb.open(caltable+'/SPECTRAL_WINDOW')
    nspw=mytb.nrows()
    bandnames=[x.split('#')[0].split('_')[-1] for x in mytb.getcol('NAME')]
    mytb.close()
    print 'Found as many as '+str(nspw)+' spws.'

    R=pl.zeros((nspw,nfld))
    Q=pl.zeros((nspw,nfld))
    U=pl.zeros((nspw,nfld))
    mask=pl.ones((nspw,nfld),dtype=bool)

    if (len(badspw)>0):
        mask[badspw,:]=False

    QU={}
    mytb.open(caltable)
    for ifld in range(nfld):
        for ispw in range(nspw):
            st=mytb.query('FIELD_ID=='+str(ifld)+' && SPECTRAL_WINDOW_ID=='+str(ispw))
            nrows=st.nrows()
            if nrows > 0:


                rah=dirs[0,ifld]*12.0/pi
                decr=dirs[1,ifld]
                times=st.getcol('TIME')
                gains=st.getcol('CPARAM')
                ants=st.getcol('ANTENNA1')

                nants=ants.max()+1
                    
                # times
                time0=86400.0*floor(times[0]/86400.0)
                rtimes=times-time0

                # amplitude ratio
                amps=pl.absolute(gains)
                amps[amps==0.0]=1.0
                ratio=amps[0,0,:]/amps[1,0,:]
                
                ratio.resize(nrows/nants,nants)
                
                # parang
                parang=pl.zeros(len(times))
                
                for itim in range(len(times)):
                    tm=myme.epoch('UTC',str(times[itim])+'s')
                    last=myme.measure(tm,'LAST')['m0']['value']
                    last-=floor(last)  # days
                    last*=24.0  # hours
                    ha=last-rah  # hours
                    har=ha*2.0*pi/24.0
                    
                    parang[itim]=atan2( (cos(latr)*sin(har)),
                                        (sin(latr)*cos(decr)-cos(latr)*sin(decr)*cos(har)) )

                parang.resize(nrows/nants,nants)
                parang+=bandpa(bandnames[ispw])  # feed pos ang offset
                parang+=(paoffset*pi/180.)       # manual feed pa offset
                parangd=parang*(180.0/pi)

                A=pl.ones((nrows/nants,3))
                A[:,1]=pl.cos(2*parang[:,0])
                A[:,2]=pl.sin(2*parang[:,0])

                fit=pl.lstsq(A,pl.square(ratio))

                ants0=range(nants)
                rsum=pl.sum(ratio[:,ants0],1)
                rsum/=len(ants0)
                
                fit=pl.lstsq(A,pl.square(rsum))
                R[ispw,ifld]=fit[0][0]
                Q[ispw,ifld]=fit[0][1]/R[ispw,ifld]/2.0
                U[ispw,ifld]=fit[0][2]/R[ispw,ifld]/2.0
                P=sqrt(Q[ispw,ifld]**2+U[ispw,ifld]**2)
                X=0.5*atan2(U[ispw,ifld],Q[ispw,ifld])*180/pi

                print 'Fld=',ifld,'Spw=',ispw,'(B='+str(bandnames[ispw])+', PA offset='+str(bandpa(bandnames[ispw])*180./pi)+'deg)','Gx/Gy=',R[ispw,ifld],'Q=',Q[ispw,ifld],'U=',U[ispw,ifld],'P=',P,'X=',X
                
            else:
                mask[ispw,ifld]=False

            st.close()

        if sum(mask[:,ifld])>0:
            print 'For field id = ',ifld,' there are ',sum(mask[:,ifld]),'good spws.'

            Qm=pl.mean(Q[mask[:,ifld],ifld])
            Um=pl.mean(U[mask[:,ifld],ifld])
            QU[ifld]=(Qm,Um)
            Qe=pl.std(Q[mask[:,ifld],ifld])
            Ue=pl.std(U[mask[:,ifld],ifld])
            Pm=sqrt(Qm**2+Um**2)
            Xm=0.5*atan2(Um,Qm)*180/pi
            print 'Spw mean: Fld=', ifld,'Q=',Qm,'U=',Um,'(rms=',Qe,Ue,')','P=',Pm,'X=',Xm

    mytb.close()

    return QU
コード例 #8
0
ファイル: blox.py プロジェクト: foxmouldy/blib
def Fn(na=0.78, nc=1., D=13.5, Trx=20, L=1):
    A = pl.pi*pl.square(D/2.);
    numer = pl.sqrt(2)*k*Trx;
    denom = na*nc*A*pl.sqrt(L)
    dI = numer/denom;
    return dI;
コード例 #9
0
 def sum_of_squares(self, parms):
     model = mp.func(self.cut_xpsd, *parms)
     return sum(p.square(model / self.cut_ypsd - self.cut_ypsd / model))
コード例 #10
0
def qufromgain(caltable,badspw=[],badant=[],fieldids=[],paoffset=None):

    mytb=taskinit.tbtool()
    myme=taskinit.metool()

    pos=myme.observatory('atca')
    myme.doframe(pos)

    # _geodetic_ latitude
    latr=myme.measure(pos,'WGS84')['m1']['value']
    #print 'latitude: ',latr*180/pi

    mytb.open(caltable+'/FIELD')
    nfld=mytb.nrows()
    dirs=mytb.getcol('DELAY_DIR')[:,0,:]
    mytb.close()
    print 'Found '+str(nfld)+' fields.'

    mytb.open(caltable+'/SPECTRAL_WINDOW')
    freq=mytb.getcol('REF_FREQUENCY')
    nspw=mytb.nrows()
    mytb.close()
    print 'Found '+str(nspw)+' spws.'

    #sort out pa offset to apply
    paoff=pl.zeros(nspw)
    if paoffset==None:
        # use defaults for ATCA
        # (should get these from Feed subtable, but cal table doesn't have one)
        for ispw in range(nspw):
            if freq[ispw]<30e9 or freq[ispw]>50e9:
                paoff[ispw]=45.
            else:
                paoff[ispw]=135.
    else:
        paoff=paoffset
    
    R=pl.zeros((nspw,nfld))
    Q=pl.zeros((nspw,nfld))
    U=pl.zeros((nspw,nfld))
    mask=pl.ones((nspw,nfld),dtype=bool)

    if (len(badspw)>0):
        mask[badspw,:]=False

    if (len(fieldids)==0):
        fieldids=range(nfld)

    QU={}
    mytb.open(caltable)
    for ifld in fieldids:
        for ispw in range(nspw):
            if not mask[ispw,ifld]:
                continue
            st=mytb.query('FIELD_ID=='+str(ifld)+' && SPECTRAL_WINDOW_ID=='+str(ispw))
            nrows=st.nrows()
            if nrows > 0:
                rah=dirs[0,ifld]*12.0/pi
                decr=dirs[1,ifld]
                times=st.getcol('TIME')
                gains=st.getcol('CPARAM')
                ants=st.getcol('ANTENNA1')

                ntimes=len(pl.unique(times))
                nants=ants.max()+1

                #print nrows, ntimes, nants

                # times
                time0=86400.0*floor(times[0]/86400.0)
                rtimes=times-time0

                # amplitude ratio
                amps=pl.absolute(gains)
                amps[amps==0.0]=1.0
                ratio=amps[0,0,:]/amps[1,0,:]
                
                
                # parang
                parang=pl.zeros(len(times))
                
                for itim in range(len(times)):
                    tm=myme.epoch('UTC',str(times[itim])+'s')
                    last=myme.measure(tm,'LAST')['m0']['value']
                    last-=floor(last)  # days
                    last*=24.0  # hours
                    ha=last-rah  # hours
                    har=ha*2.0*pi/24.0
                    
                    parang[itim]=atan2( (cos(latr)*sin(har)),
                                        (sin(latr)*cos(decr)-cos(latr)*sin(decr)*cos(har)) )

                ratio.resize(nrows/nants,nants)
                parang.resize(nrows/nants,nants)
                parang+=paoff[ispw]*pi/180.
                parangd=parang*(180.0/pi)

                A=pl.ones((nrows/nants,3))
                A[:,1]=pl.cos(2*parang[:,0])
                A[:,2]=pl.sin(2*parang[:,0])

                fit=pl.lstsq(A,pl.square(ratio))
               
                amask=pl.ones(nants,dtype=bool)
                if len(badant)>0:
                    amask[badant]=False
                rsum=pl.sum(ratio[:,amask],1)
                rsum/=pl.sum(amask)
                
                fit=pl.lstsq(A,pl.square(rsum))

                R[ispw,ifld]=fit[0][0]
                Q[ispw,ifld]=fit[0][1]/R[ispw,ifld]/2.0
                U[ispw,ifld]=fit[0][2]/R[ispw,ifld]/2.0
                P=sqrt(Q[ispw,ifld]**2+U[ispw,ifld]**2)
                X=0.5*atan2(U[ispw,ifld],Q[ispw,ifld])*180/pi

                print 'Fld=%i, Spw=%i, PA Offset=%5.1f, Gx/Gy=%5.3f, Q=%5.3f, U=%5.3f, P=%5.3f, X=%5.1f' % (ifld,ispw,paoff[ispw],R[ispw,ifld],Q[ispw,ifld],U[ispw,ifld],P,X)

            else:
                mask[ispw,ifld]=False

            st.close()

        if (sum(mask[:,ifld]))>0:
            print 'For field id = ',ifld,' there are ',sum(mask[:,ifld]),'good spws.'

            Qm=pl.mean(Q[mask[:,ifld],ifld])
            Um=pl.mean(U[mask[:,ifld],ifld])
            QU[ifld]=(Qm,Um)
            Qe=pl.std(Q[mask[:,ifld],ifld])
            Ue=pl.std(U[mask[:,ifld],ifld])
            Pm=sqrt(Qm**2+Um**2)
            Xm=0.5*atan2(Um,Qm)*180/pi
            print 'Spw mean: Fld=%i Fractional: Q=%5.3f, U=%5.3f, (rms= %5.3f,%5.3f), P=%5.3f, X=%5.1f' % (ifld,Qm,Um,Qe,Ue,Pm,Xm)
    mytb.close()

    return QU