def __init__(self, filename, debug=False): he = 'HIERARCH ESO ' self.data = pyfits.open(filename) self.date_obs = self.data[0].header['DATE-OBS'] self.targname = self.data[0].header['HIERARCH ESO OBS TARG NAME'] self.PS_ID = self.data[0].header['HIERARCH ESO OCS PS ID'] self.SS_ID = self.data[0].header['HIERARCH ESO OCS SS ID'] self.mjd_obs = self.data[0].header['MJD-OBS'] self.lst_obs = self.data[0].header['LST']/3600. self.mjd= self.data['ASTROMETRY_BINNED'].data.field('MJD') # simple linear interpolation self.lst = self.lst_obs + (self.mjd - self.mjd_obs)*(23.+56/60.+4/3600.) self.d_al= self.data['ASTROMETRY_BINNED'].data.field('D_AL') self.d_al_err= self.data['ASTROMETRY_BINNED'].data.field('D_AL_err') try: self.rot1= self.data['ASTROMETRY_BINNED'].data.field('ROT1') self.rot2= self.data['ASTROMETRY_BINNED'].data.field('ROT2') except: self.rot1= np.zeros(len(self.d_al)) self.rot2= np.zeros(len(self.d_al)) self.mjd_PCR_start = astro.tag2mjd(self.data[0].header[he+'PCR ACQ START']) self.mjd_PCR_end = astro.tag2mjd(self.data[0].header[he+'PCR ACQ END']) self.lst_PCR_start = astro.tag2lst(self.data[0].header['ESO PCR ACQ START'], longitude=self.data[0].header['ESO ISS GEOLON']) self.A1L = self.data[0].header[he+'ISS CONF A1L'] self.A2L = self.data[0].header[he+'ISS CONF A2L'] try: self.insmode = self.data[0].header[he+'ISS PRI STS3 GUIDE_MODE'] except: self.insmode = self.data[0].header[he+'INS MODE'] cP = self.data[0].header[he+'ISS PRI MET C'] # in m/s dnuP = self.data[0].header[he+'ISS PRI MET F_SHIFT']*1e6 # in Hz nuP = self.data[0].header[he+'ISS PRI MET LASER_F'] #self.jump = (cP * dnuP/2/(nuP**2) ) * ( 2**24-1 ) # PRIMET jump in m, COMM14 self.jump = (cP * dnuP/2/(nuP**2) ) * ( 2**31-1 ) # PRIMET jump in m, COMM15 if 'SWAP' in self.insmode: # legacy: was SWAP at some point, now is SWAPPED self.swapped = np.ones(len(self.mjd)) else: astro.tag2lst(self.data[0].header['ESO PCR ACQ START'], longitude=self.data[0].header['ESO ISS GEOLON']) self.swapped = np.zeros(len(self.mjd)) # dictionnary of variables(mjd) START names = ['base', 'PA', 'OPL1', 'OPL2', 'airmass', 'tau0','seeing', 'parang'] keyw = ['ISS PBL12', 'ISS PBLA12', 'DEL DLT1 OPL', 'DEL DLT2 OPL', 'ISS AIRM', 'ISS AMBI TAU0', 'ISS AMBI FWHM', 'ISS PARANG'] self.var_start_end = {} for k in range(len(names)): self.var_start_end[names[k]] =(self.data[0].header[he+keyw[k]+' START'], self.data[0].header[he+keyw[k]+' END']) self.var_mjd={} # linear interpolation for k in self.var_start_end.keys(): if k != 'base' and k != 'PA': self.var_mjd[k] = self.var_start_end[k][0]+\ (self.mjd - self.mjd_PCR_start)/\ (self.mjd_PCR_end - self.mjd_PCR_start)*\ (self.var_start_end[k][1]- self.var_start_end[k][0]) else: # compute baselines self.baseXYZ = [self.data[0].header[he+'ISS CONF T1X']- self.data[0].header[he+'ISS CONF T2X'], self.data[0].header[he+'ISS CONF T1Y']- self.data[0].header[he+'ISS CONF T2Y'], self.data[0].header[he+'ISS CONF T1Z']- self.data[0].header[he+'ISS CONF T2Z'], self.data[0].header[he+'ISS CONF A1L']- self.data[0].header[he+'ISS CONF A2L']] # coordinates, corrected for proper motion self.radec = [astro.ESOcoord2decimal(self.data[0].header['ESO OCS TARG1 ALPHAPMC']), astro.ESOcoord2decimal(self.data[0].header['ESO OCS TARG2 DELTAPMC'])] self.radec = [self.data[0].header['RA']/15., self.data[0].header['DEC']] bb = prima.projBaseline(self.baseXYZ, self.radec, self.lst) if k == 'base': self.var_mjd[k] = bb['B'] if debug: print 'DEBUG: PBL12 START: computed', self.var_mjd[k][0],\ 'in header:', self.data[0].header[he+'ISS PBL12 START'], \ 'DELTA=', self.var_mjd[k][0]-self.data[0].header[he+'ISS PBL12 START'] print 'DEBUG: PBL12 END : computed', self.var_mjd[k][-1],\ 'in header:', self.data[0].header[he+'ISS PBL12 END'], \ 'DELTA=', self.var_mjd[k][-1]-self.data[0].header[he+'ISS PBL12 END'] if k == 'PA': self.var_mjd[k] = bb['PA'] if debug: print 'DEBUG: PBLA12 START: computed', self.var_mjd[k][0],\ 'in header:', self.data[0].header[he+'ISS PBLA12 START'],\ 'DELTA=', self.var_mjd[k][0]-self.data[0].header[he+'ISS PBLA12 START'] print 'DEBUG: PBLA12 END : computed', self.var_mjd[k][-1],\ 'in header:', self.data[0].header[he+'ISS PBLA12 END'],\ 'DELTA=', self.var_mjd[k][-1]-self.data[0].header[he+'ISS PBLA12 END'] self.data.close() return
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
def __init__(self, filename, debug=False): he = "HIERARCH ESO " self.data = pyfits.open(filename) self.filename = filename self.date_obs = self.data[0].header["DATE-OBS"] self.targname = self.data[0].header["HIERARCH ESO OBS TARG NAME"] self.PS_ID = self.data[0].header["HIERARCH ESO OCS PS ID"] self.SS_ID = self.data[0].header["HIERARCH ESO OCS SS ID"] self.mjd_obs = self.data[0].header["MJD-OBS"] self.lst_obs = self.data[0].header["LST"] / 3600.0 self.mjd = self.data["ASTROMETRY_BINNED"].data.field("MJD") try: self.lst = self.data["ASTROMETRY_BINNED"].data.field("LST") except: print "WARNING: USING BAD LST!" self.lst = self.lst_obs + (self.mjd - self.mjd_obs) * (23.0 + 56 / 60.0 + 4 / 3600.0) self.d_al = self.data["ASTROMETRY_BINNED"].data.field("D_AL") if self.PS_ID == "HD129926" and self.mjd_obs < 56005.0: # problem with these observations print "WARNING: KLUDGING D_AL -> -DA_L!!!" self.d_al *= -1 self.d_al_err = self.data["ASTROMETRY_BINNED"].data.field("D_AL_err") try: self.rot3 = self.data["ASTROMETRY_BINNED"].data.field("ROT3") self.rot4 = self.data["ASTROMETRY_BINNED"].data.field("ROT4") self.az3 = self.data["ASTROMETRY_BINNED"].data.field("AZ3") self.az4 = self.data["ASTROMETRY_BINNED"].data.field("AZ4") self.alt3 = self.data["ASTROMETRY_BINNED"].data.field("ALT3") self.alt4 = self.data["ASTROMETRY_BINNED"].data.field("ALT4") except: self.rot3 = np.zeros(len(self.d_al)) self.rot4 = np.zeros(len(self.d_al)) self.az3 = np.zeros(len(self.d_al)) self.az4 = np.zeros(len(self.d_al)) self.alt3 = np.zeros(len(self.d_al)) self.alt4 = np.zeros(len(self.d_al)) self.mjd_PCR_start = astro.tag2mjd(self.data[0].header[he + "PCR ACQ START"]) self.mjd_PCR_end = astro.tag2mjd(self.data[0].header[he + "PCR ACQ END"]) self.lst_PCR_start = astro.tag2lst( self.data[0].header["ESO PCR ACQ START"], longitude=self.data[0].header["ESO ISS GEOLON"] ) self.A1L = self.data[0].header[he + "ISS CONF A1L"] self.A2L = self.data[0].header[he + "ISS CONF A2L"] try: self.insmode = self.data[0].header[he + "ISS PRI STS3 GUIDE_MODE"] except: self.insmode = self.data[0].header[he + "INS MODE"] if not self.insmode in ["NORMAL", "SWAPPED"]: # print 'WARNING: unknown INSMODE=', self.insmode pass if self.insmode == "INCONSISTENT": # -- try to guess if self.data[0].header[he + "DEL FT SENSOR"] == "FSUB": self.insmode = "NORMAL" elif self.data[0].header[he + "DEL FT SENSOR"] == "FSUA": self.insmode = "SWAPPED" # print ' -> guessing: INSMODE=', self.insmode cP = self.data[0].header[he + "ISS PRI MET C"] # in m/s dnuP = self.data[0].header[he + "ISS PRI MET F_SHIFT"] * 1e6 # in Hz nuP = self.data[0].header[he + "ISS PRI MET LASER_F"] # self.jump = (cP*dnuP/2/(nuP**2))*(2**24-1) # PRIMET jump in m, COMM14 self.jump = (cP * dnuP / 2 / (nuP ** 2)) * (2 ** 31 - 1) # PRIMET jump in m, COMM15 if "SWAP" in self.insmode: # legacy: was SWAP at some point self.swapped = np.ones(len(self.mjd)) else: astro.tag2lst(self.data[0].header["ESO PCR ACQ START"], longitude=self.data[0].header["ESO ISS GEOLON"]) self.swapped = np.zeros(len(self.mjd)) # dictionnary of variables(mjd) START names = ["base", "PA", "OPL1", "OPL2", "airmass", "tau0", "seeing", "parang"] keyw = [ "ISS PBL12", "ISS PBLA12", "DEL DLT1 OPL", "DEL DLT2 OPL", "ISS AIRM", "ISS AMBI TAU0", "ISS AMBI FWHM", "ISS PARANG", ] self.var_start_end = {} for k in range(len(names)): self.var_start_end[names[k]] = ( self.data[0].header[he + keyw[k] + " START"], self.data[0].header[he + keyw[k] + " END"], ) self.var_mjd = {} # linear interpolation for k in self.var_start_end.keys(): if k != "base" and k != "PA": self.var_mjd[k] = self.var_start_end[k][0] + (self.mjd - self.mjd_PCR_start) / ( self.mjd_PCR_end - self.mjd_PCR_start ) * (self.var_start_end[k][1] - self.var_start_end[k][0]) else: # compute baselines self.baseXYZ = [ self.data[0].header[he + "ISS CONF T1X"] - self.data[0].header[he + "ISS CONF T2X"], self.data[0].header[he + "ISS CONF T1Y"] - self.data[0].header[he + "ISS CONF T2Y"], self.data[0].header[he + "ISS CONF T1Z"] - self.data[0].header[he + "ISS CONF T2Z"], self.data[0].header[he + "ISS CONF A1L"] - self.data[0].header[he + "ISS CONF A2L"], ] # coordinates, corrected for proper motion try: self.radec = [ astro.ESOcoord2decimal(self.data[0].header["ESO OCS TARG1 ALPHAPMC"]), astro.ESOcoord2decimal(self.data[0].header["ESO OCS TARG1 DELTAPMC"]), ] except: print "WARNING: could not find precessed coordinates in header!" self.radec = [ astro.ESOcoord2decimal(self.data[0].header["ESO ISS REF RA"]), astro.ESOcoord2decimal(self.data[0].header["ESO ISS REF DEC"]), ] self.radec = [self.data[0].header["RA"] / 15.0, self.data[0].header["DEC"]] bb = prima.projBaseline(self.baseXYZ, self.radec, self.lst) if k == "base": self.var_mjd[k] = bb["B"] if debug: print "DEBUG: PBL12 START: computed", self.var_mjd[k][0], "in header:", self.data[0].header[ he + "ISS PBL12 START" ], "DELTA=", self.var_mjd[k][0] - self.data[0].header[he + "ISS PBL12 START"] print "DEBUG: PBL12 END : computed", self.var_mjd[k][-1], "in header:", self.data[0].header[ he + "ISS PBL12 END" ], "DELTA=", self.var_mjd[k][-1] - self.data[0].header[he + "ISS PBL12 END"] if k == "PA": self.var_mjd[k] = bb["PA"] if debug: print "DEBUG: PBLA12 START: computed", self.var_mjd[k][0], "in header:", self.data[0].header[ he + "ISS PBLA12 START" ], "DELTA=", self.var_mjd[k][0] - self.data[0].header[he + "ISS PBLA12 START"] print "DEBUG: PBLA12 END : computed", self.var_mjd[k][-1], "in header:", self.data[0].header[ he + "ISS PBLA12 END" ], "DELTA=", self.var_mjd[k][-1] - self.data[0].header[he + "ISS PBLA12 END"] self.data.close() return