Exemplo n.º 1
0
def FSM_full_test(model=False, AT='AT4'):
    """
    """
    directory = '/Volumes/DATA500/PRIMA/COMM16/'
    ### AT4
    if AT=='AT4' or AT==4:
        AT = 'AT4'; DT = .6/(24*3600)
        #a = prima.drs(directory+'2011-08-29/PACMAN_OBJ_ASTRO_242_0014.fits')
        #p = prima.pssRecorder(directory+'PSSRECORDER/pssguiRecorder_lat4vcm_2011-08-30_09-09-54.dat')
        #f = open(directory+'PIEZOSCAN/pscsosfPiezoScan2_lat4fsm_2011-08-30T09_10_46.txt')
        a = prima.drs(directory+'2011-08-29/PACMAN_OBJ_ASTRO_242_0018.fits')
        p = prima.pssRecorder(directory+'PSSRECORDER/pssguiRecorder_lat4vcm_2011-08-30_09-49-23.dat')
        f = open(directory+'PIEZOSCAN/pscsosfPiezoScan2_lat4fsm_2011-08-30T09_50_11.txt')
        #a = prima.drs(directory+'2011-08-29/PACMAN_OBJ_ASTRO_242_0021.fits')
        #p = prima.pssRecorder(directory+'PSSRECORDER/pssguiRecorder_lat4vcm_2011-08-30_10-24-43.dat')
        #f = open(directory+'PIEZOSCAN/pscsosfPiezoScan2_lat4fsm_2011-08-30T10_25_14.txt')
        #a = prima.drs(directory+'2011-08-29/PACMAN_OBJ_ASTRO_242_0023.fits')
        #p = prima.pssRecorder(directory+'PSSRECORDER/pssguiRecorder_lat4vcm_2011-08-30_10-35-52.dat')
        #f = open(directory+'PIEZOSCAN/pscsosfPiezoScan2_lat4fsm_2011-08-30T10_36_31.txt')
    else:
        ### AT3
        AT = 'AT3'; DT=0.75/(24.*3600)
        #a = prima.drs(directory+'2011-08-29/PACMAN_OBJ_ASTRO_242_0016.fits')
        #p = prima.pssRecorder(directory+'PSSRECORDER/pssguiRecorder_lat3vcm_2011-08-30_09-27-37.dat')
        #f = open(directory+'PIEZOSCAN/pscsosfPiezoScan2_lat3fsm_2011-08-30T09_28_22.txt')
        #a = prima.drs(directory+'2011-08-29/PACMAN_OBJ_ASTRO_242_0020.fits')
        #p = prima.pssRecorder(directory+'PSSRECORDER/pssguiRecorder_lat3vcm_2011-08-30_10-09-40.dat')
        #f = open(directory+'PIEZOSCAN/pscsosfPiezoScan2_lat3fsm_2011-08-30T10_10_09.txt')
        #a = prima.drs(directory+'2011-08-29/PACMAN_OBJ_ASTRO_242_0024.fits')
        #p = prima.pssRecorder(directory+'PSSRECORDER/pssguiRecorder_lat3vcm_2011-08-30_10-41-53.dat')
        #f = open(directory+'PIEZOSCAN/pscsosfPiezoScan2_lat3fsm_2011-08-30T10_43_04.txt')
        #a = prima.drs(directory+'2011-08-29/PACMAN_OBJ_ASTRO_242_0026.fits')
        #p = prima.pssRecorder(directory+'PSSRECORDER/pssguiRecorder_lat3vcm_2011-08-30_10-53-32.dat')
        #f = open(directory+'PIEZOSCAN/pscsosfPiezoScan2_lat3fsm_2011-08-30T10_54_20.txt')
        a = prima.drs(directory+'2011-08-29/PACMAN_OBJ_ASTRO_242_0027.fits')
        p = prima.pssRecorder(directory+'PSSRECORDER/pssguiRecorder_lat3vcm_2011-08-30_11-00-29.dat')
        f = open(directory+'PIEZOSCAN/pscsosfPiezoScan2_lat3fsm_2011-08-30T11_00_58.txt')

    lines = f.readlines()
    f.close()
    lines = filter(lambda x: not '#' in x and len(x)>10, lines)
    mjd =  [astro.tag2mjd('2011-08-30T'+x.split()[1])+DT for x in lines]
    xmjd = np.linspace(min(mjd), max(mjd), 200)

    FSM1X = [float(x.split()[2]) for x in lines]
    FSM1Y = [float(x.split()[3]) for x in lines]
    FSM2X = [float(x.split()[4]) for x in lines]
    FSM2Y = [float(x.split()[5]) for x in lines]

    print 'PCR START:', a.raw[0].header['ESO PCR ACQ START']
    print 'PCR END  :', a.raw[0].header['ESO PCR ACQ END']

    min_mjd = min(mjd)
    max_mjd = max(mjd)
    if model:
        param = np.array([0,0,.1,.1,.1,.1])
        mjd_primet =  1e-6*a.raw['METROLOGY_DATA'].data.field('TIME')/\
                   (24*3600)+astro.tag2mjd(a.raw[0].header['ESO PCR ACQ START'])
        primet =  (a.raw['METROLOGY_DATA'].data.field('DELTAL')-
                   a.raw['METROLOGY_DATA'].data.field('DELTAL').mean())*1e6
        print 'w_fit:'
        w_fit = np.where((mjd_primet>min_mjd)*(mjd_primet<max_mjd))
        #w_fit = np.where((mjd_primet>min_mjd))
        w_fit = (w_fit[0][::200],)
        print 'x_fit:'
        X_fit = [mjd_primet[w_fit]-mjd_primet[w_fit].mean(),
                 interpByStep(mjd_primet[w_fit], mjd, np.array(FSM1X)-FSM1X[0]),
                 interpByStep(mjd_primet[w_fit], mjd, np.array(FSM1Y)-FSM1Y[0]),
                 interpByStep(mjd_primet[w_fit], mjd, np.array(FSM2X)-FSM2X[0]),
                 interpByStep(mjd_primet[w_fit], mjd, np.array(FSM2Y)-FSM2Y[0])]
        Y_fit = primet[w_fit]
        print 'fit:'
        fit = myfit.fit(primetFsmBias, X_fit, param, Y_fit)
        fit.leastsqfit()
        print 'dOPD_um/(FSM1X_um - %5.3f) = %6.4f' %\
              (FSM1X[0], fit.leastsq_best_param[2])
        print 'dOPD_um/(FSM1Y_um - %5.3f) = %6.4f' %\
              (FSM1Y[0], fit.leastsq_best_param[3])
        print 'dOPD_um/(FSM2X_um - %5.3f) = %6.4f' %\
              (FSM2X[0], fit.leastsq_best_param[4])
        print 'dOPD_um/(FSM2Y_um - %5.3f) = %6.4f' %\
              (FSM2Y[0], fit.leastsq_best_param[5])

        pylab.figure(4, figsize=(17,3))
        pylab.clf()
        pylab.subplots_adjust(left=0.06, bottom=0.15, right=0.96, top=0.85,
                              wspace=0.15, hspace=0.01)
        pylab.title(AT+' FSM test:'+a.filename)
        pylab.plot(mjd_primet,  primet, 'b-', label='PRIMET A-B')
        pylab.plot(mjd_primet[w_fit[0]],
                   primetFsmBias(X_fit,fit.leastsq_best_param),
                   'r-', alpha=0.5, linewidth=3, label='linear model FSM')
        pylab.plot(mjd_primet[w_fit[0]],
                   Y_fit-primetFsmBias(X_fit,fit.leastsq_best_param),
                   '-', color='g', alpha=0.5, linewidth=3, label='residuals')
        pylab.hlines([0], min(mjd), max(mjd), color='k', linestyle='dashed',
                     linewidth=2)
        pylab.legend(ncol=3, loc=('upper left' if AT=='AT4' else 'upper right'))
        pylab.xlim(min_mjd, max_mjd)
        pylab.ylabel('PRIMET A-B ($\mu$m)')

    pylab.figure(3, figsize=(17,9))
    pylab.subplots_adjust(left=0.06, bottom=0.07, right=0.96, top=0.96,
                          wspace=0.15, hspace=0.01)
    pylab.clf()

    ax1 = pylab.subplot(5,2,1)
    pylab.title(AT+' FSM test:'+a.filename)
    pylab.plot(1e-6*a.raw['METROLOGY_DATA'].data.field('TIME')/(24*3600)+
               astro.tag2mjd(a.raw[0].header['ESO PCR ACQ START']),
               (a.raw['METROLOGY_DATA'].data.field('DELTAL')-
                a.raw['METROLOGY_DATA'].data.field('DELTAL').mean())*1e6,
               'b-')
    pylab.ylabel('PRIMET A-B ($\mu$m)')

    pylab.subplot(5,2,3, sharex=ax1)
    #pylab.plot(mjd, FSM1X, '-k', markersize=8, linestyle='steps')
    pylab.plot(xmjd, interpByStep(xmjd, mjd, FSM1X), 'k-')
    pylab.ylabel('FSM1 X ($\mu$m)')

    pylab.subplot(5,2,5, sharex=ax1)
    #pylab.plot(mjd, FSM1Y, '-k', markersize=8, linestyle='steps')
    pylab.plot(xmjd, interpByStep(xmjd, mjd, FSM1Y), 'k-')
    pylab.ylabel('FSM1 Y ($\mu$m)')

    pylab.subplot(5,2,7, sharex=ax1)
    #pylab.plot(mjd, FSM2X, '-k', markersize=8, linestyle='steps')
    pylab.plot(xmjd, interpByStep(xmjd, mjd, FSM2X), 'k-')
    pylab.ylabel('FSM2 X ($\mu$m)')

    pylab.subplot(5,2,9, sharex=ax1)
    #pylab.plot(mjd, FSM2Y, '-k', markersize=8, linestyle='steps')
    pylab.plot(xmjd, interpByStep(xmjd, mjd, FSM2Y), 'k-')
    pylab.ylabel('FSM2 Y ($\mu$m)')
    pylab.xlabel('MJD')

    pylab.subplot(5,2,2, sharex = ax1, sharey= ax1)
    pylab.title(AT+' FSM test:'+a.filename)
    pylab.plot(1e-6*a.raw['METROLOGY_DATA'].data.field('TIME')/(24*3600)+
               astro.tag2mjd(a.raw[0].header['ESO PCR ACQ START']),
               (a.raw['METROLOGY_DATA'].data.field('DELTAL')-
                a.raw['METROLOGY_DATA'].data.field('DELTAL').mean())*1e6,
               'b-')

    pylab.subplot(5,2,4, sharex=ax1)
    pylab.plot(p.mjd, p.data['VCM1X[um]'], '-k')
    pylab.ylabel('VCM1 X ($\mu$m)')

    pylab.subplot(5,2,6, sharex=ax1)
    pylab.plot(p.mjd, p.data['VCM1Y[um]'], '-k')
    pylab.ylabel('VCM1 Y ($\mu$m)')

    pylab.subplot(5,2,8, sharex=ax1)
    pylab.plot(p.mjd, p.data['VCM2X[um]'], '-k')
    pylab.ylabel('VCM2 X ($\mu$m)')

    pylab.subplot(5,2,10, sharex=ax1)
    pylab.plot(p.mjd, p.data['VCM2Y[um]'], '-k')
    pylab.ylabel('VCM2 Y ($\mu$m)')
    pylab.xlim(min_mjd, max_mjd)
    del a

    return
Exemplo n.º 2
0
def HD10360():
    """
    """
    NACO_sep = 11448.3 # Damien
    #NACO_sep *=0.999
    NACO_PA  = 187.0 # Damien
    NACO_PA +=0.9
    data = [{'DEC_mas': -11327.459991981585,
             'MJD': 55799.38788483571, 'PCA': ([-0.78351315847945402,
             -0.62137519301107402],
                     [-0.78351315847945402, -0.62137519301107402]),
             'RA_mas': -1586.2834801192896, 'errs_uas': (784.90506323494469,
             56.755250740679948), 'NOTE':'ACOMM2'},
            {'DEC_mas': -11328.434517473423,
             'MJD': 55886.23025809787, 'PCA': ([-0.47704928581135631,
             -0.87887654360943956],
                     [-0.47704928581135631, -0.87887654360943956]),
             'RA_mas': -1573.9752919650998, 'errs_uas': (636.66710179387803,
             97.443812507475542) , 'NOTE':'ACOMM3'},
            {'DEC_mas': -11325.155618568057,
             'MJD': 55889.144962967606, 'PCA': ([-0.5851692703101341,
             -0.81091116966330268],
                     [-0.5851692703101341, -0.81091116966330268]),
             'RA_mas': -1572.8284251763607, 'errs_uas': (1128.5886751363144,
             95.502764113947521), 'NOTE':'ACOMM3'},
            #{'DEC_mas':NACO_sep*np.cos(NACO_PA*np.pi/180),
            # 'RA_mas':NACO_sep*np.sin(NACO_PA*np.pi/180),
            # 'MJD': 55886.2, 'errs_uas':(1000,1000),
            #    'PCA':([1,0],[0,1]), 'NOTE':'NACO'},
            #{'DEC_mas': -11321.057996449183,
            {'DEC_mas': -11322.677253993401,
             'MJD': 55891.11655027233,
             'PCA': ([-0.78812707963177309, -0.61551255580296094],
                 [-0.78812707963177309, -0.61551255580296094]),
                 'RA_mas': -1571.7671378904256,
             'errs_uas': (582.6031352344354, 38.92080197079315),'NOTE':'ACOMM3'},
                {'DEC_mas': -11325.519043937573,
                'MJD': 55891.22297829576,
                'PCA': ([-0.36045943416341675, -0.93277489048676132],
         [-0.36045943416341675, -0.93277489048676132]),
 'RA_mas': -1571.9855632046058,
 'errs_uas': (152.81098660659865, 28.057280342744438),
                    'NOTE':'ACOMM3'}    
            ]
    cork = [55800, -1586.0, -11327,-1, 1, 12, 1., 1, 1, 1]
    fit =  np.array([0,      1,    1,   1,     1,      0, 1, 1, 1,1])
    obs = [(x['MJD'], x['RA_mas'], x['DEC_mas']) for x in data]
    p_fit = np.array(cork)[np.where(np.array(fit))]
    p_fixed = np.array(cork)[np.where(1-np.array(fit))]
    
    plsq = leastsq(leastsqCorkScrew, p_fit, args=(fit,p_fixed,obs,False), epsfcn=1e-3)
    corkF = np.array(cork)
    corkF[np.where(fit)] = plsq[0]
    print corkF
    t=np.linspace(55795, 55900, 2000)
    model = leastsqCorkScrew(plsq[0], fit, p_fixed,
                             [(tau,0,0) for tau in t], model=True)
    
    # linear fit to displacement:
    f = myfit.fit(myfit.PolyN,
               [d['MJD']-55800 for d in data], [0.,1.],
               [d['RA_mas'] for d in data],
               err=[d['errs_uas'][1] for d in data])
    f.leastsqfit()
    cRA = f.leastsq_best_param
    f = myfit.fit(myfit.PolyN,
               [d['MJD']-55800 for d in data], [0.,1.],
               [d['DEC_mas'] for d in data],
               err=[d['errs_uas'][1] for d in data])
    f.leastsqfit()
    cDEC = f.leastsq_best_param
    
    pyplot.figure(10, figsize=(10,5))
    pyplot.clf()
    pyplot.axes().set_aspect('equal', 'datalim')
    th = np.linspace(0, 2*np.pi, 100)
    colors=['r', 'g', 'b', 'y', 'm', 'c']
    for k,d in enumerate(data):
        ### observation:
        pyplot.plot(d['RA_mas']/1000., d['DEC_mas']/1000., 'o'+colors[k],
                    label='MJD:%8.2f (%s)'%(d['MJD'], d['NOTE']), markersize=8)
        ### error to linear fit:
        pyplot.plot([d['RA_mas']/1000, myfit.PolyN(d['MJD']-55800, cRA)/1000],
            [d['DEC_mas']/1000, myfit.PolyN(d['MJD']-55800, cDEC)/1000],
            color=colors[k], linewidth=2, alpha=0.5, linestyle='dotted')
        ### error to corkScrew:
        #pyplot.plot([d['RA_mas']/1000, leastsqCorkScrew(plsq[0],fit,p_fixed,
        #                                                [(d['MJD'],0,0)],
        #                                                model=True)[0][0]/1000],
        #    [d['DEC_mas']/1000, leastsqCorkScrew(plsq[0],fit,p_fixed,
        #                                         [(d['MJD'],0,0)],
        #                                         model=True)[0][1]/1000],    
        #    color=colors[k], linewidth=2)
        ### error ellipse:
        pyplot.plot(d['RA_mas']/1000.+
                    d['errs_uas'][0]*d['PCA'][0][1]*np.cos(th)/1e6+
                    d['errs_uas'][1]*d['PCA'][0][0]*np.sin(th)/1e6,
                    d['DEC_mas']/1000.+
                    -d['errs_uas'][1]*d['PCA'][0][1]*np.sin(th)/1e6+
                    d['errs_uas'][0]*d['PCA'][0][0]*np.cos(th)/1e6,
                    color=colors[k], linewidth=3, alpha=0.5)
    
    #pyplot.plot([m[0]/1000. for m in model], [m[1]/1000 for m in model], '-',
    #    linewidth=3, alpha=0.5, color='0.5')
    
    pyplot.plot(myfit.PolyN(t-55800, cRA)/1000.,
                myfit.PolyN(t-55800, cDEC)/1000., 'k-',
                label='linear fit', alpha=0.3, linewidth=2, markersize=10)
    
    print 'computed linear movement: %6.2f uas/day' %\
            (np.sqrt(cRA[1]**2+cDEC[1]**2)*1000)
    
    # some best obtained astrometric results:
    #pyplot.errorbar(-1.578, -11.326, xerr=0.001, marker='o',
    #                alpha=0.5, color='0.6',
    #                label='GLAO perfo:$\pm$1.0mas\n(Meyer et al. 2011)')
    #pyplot.errorbar(-1.578, -11.3265, xerr=0.0005, marker='o',
    #                alpha=0.5, color='0.4',
    #                label='HST perfo:$\pm$0.5mas\n(McLaughlin et al. 2009)')
    
    pyplot.xlabel('$\Delta$ in E direction (arcsec)')
    pyplot.ylabel('$\Delta$ in N direction (arcsec)')
    pyplot.xlim(pyplot.xlim()[1], pyplot.xlim()[0])
    pyplot.title('HD10360 - HD10360J')
    pyplot.legend(numpoints=1, prop={'size':8})

    return