def calibrate_microlens(dir_test, dir_calib): # Start program print("\nAnalysis started") # Fixed parameters modes_str = ['legacy', 'single', 'variable'] # Name of AIROPA modes coo_star = 'ob150029' # Star name in the ".coo" file # Prepare the arguments args_long = '-f 1 -T 0.0 -I ' + coo_star + ' -N ' + \ path.join(dir_calib, 'photo_calib.dat') + ' -M K -c 4 ' for i_mode in modes_str: # Find input data print() print("--- AIROPA \"{0}\" mode ---".format(i_mode)) cats = glob(path.join(dir_test, 'fit', i_mode, '*_stf.lis')) cats = [path.basename(cats[i]) for i in range(len(cats))] chdir(path.join(dir_test, 'fit', i_mode)) # Calibrate for i_image in range(len(cats)): print("\rCalibrating catalog {0} / {1}...".format((i_image + 1), len(cats)), end="") args_temp = args_long + cats[i_image] args = args_temp.split() calibrate.main(argv=args) # End program print() print() print("Analysis completed\n")
def calibrateClean(self): try: # Calibrate each file os.chdir(self.dirCleanStf) print "DEBUG 2nd dec --",self.dirCleanStf # open writeable file for log _log = open('calibrate.log','w') cmdBase = 'calibrate_new %s ' % self.calFlags cmdBase += '-I %s ' % self.calCooStar cmdBase += '-N %s ' % self.calFile cmdBase += '-M %d ' % self.calColumn if (self.calStars != None) and (len(self.calStars) > 0): cmdBase += '-S ' for cc in range(len(self.calStars)): if (cc != 0): cmdBase += ',' cmdBase += self.calStars[cc] cmdBase += ' ' for file in self.cleanFiles: fitsFile = '../%s.fits' % file listFile = '%s_%3.1f_stf.lis' % (file, self.corrClean) # Get the position angle angle = float(pyfits.getval(fitsFile, 'ROTPOSN')) - 0.7 calCamera = calibrate.get_camera_type(fitsFile) cmd = cmdBase + ('-T %.1f -c %d ' % (angle, calCamera)) cmd += listFile # 2nd dec 2009 - changed "_out" "_log" _log.write(cmd + '\n') args = cmd.split()[1:] calibrate.main(args) _log.close() # clean up # Copy over the calibration list. shutil.copyfile(self.calFile, 'clean_phot_list.txt') os.chdir(self.dirStart) except: os.chdir(self.dirStart) raise
def calibrateCombo(self): try: print 'COMBO calibrate' # Get the position angle from the *.fits header # We assume that the submaps have the same PA as the main maps os.chdir(self.dirCombo) calCamera = 1 if self.type == 'ao': fitsFile = 'mag%s%s_%s.fits' % (self.epoch, self.imgSuffix, self.filt) angle = float(pyfits.getval(fitsFile, 'ROTPOSN')) - 0.7 # Check for wide camera calCamera = calibrate.get_camera_type(fitsFile) elif self.type == 'speckle': angle = 0.0 fitsFile = 'mag%s.fits' % self.epoch # CALIBRATE os.chdir(self.dirComboStf) cmd = 'calibrate_new %s' % self.calFlags cmd += '-T %.1f ' % angle cmd += '-I %s ' % self.calCooStar cmd += '-N %s ' % self.calFile cmd += '-M %d ' % self.calColumn cmd += '-c %d ' % calCamera if (self.calStars != None) and (len(self.calStars) > 0): cmd += '-S ' for cc in range(len(self.calStars)): if (cc != 0): cmd += ',' cmd += self.calStars[cc] cmd += ' ' # Calibrate Main Map if self.type == 'speckle': # This stuff is left over. fileMain = 'mag%s_%3.1f_stf.lis' % \ (self.epoch, self.corrMain) else: if self.deblend == 1: fileMain = 'mag%s%s_%s_%3.1fd_stf.lis' % \ (self.epoch, self.imgSuffix, self.filt, self.corrMain) else: fileMain = 'mag%s%s_%s_%3.1f_stf.lis' % \ (self.epoch, self.imgSuffix, self.filt, self.corrMain) print cmd + fileMain # Now call from within python... don't bother with command line anymore. argsTmp = cmd + fileMain args = argsTmp.split()[1:] calibrate.main(args) # Copy over the calibration list. shutil.copyfile(self.calFile, fileMain.replace('.lis', '_cal_phot_list.txt')) # Calibrate Sub Maps for ss in range(self.numSubMaps): if self.type == 'speckle': fileSub = 'm%s_%d_%3.1f_stf.lis' % \ (self.epoch, ss+1, self.corrSub) else: if self.deblend == 1: fileSub = 'm%s%s_%s_%d_%3.1fd_stf.lis' % \ (self.epoch, self.imgSuffix, self.filt, ss+1, self.corrSub) else: fileSub = 'm%s%s_%s_%d_%3.1f_stf.lis' % \ (self.epoch, self.imgSuffix, self.filt, ss+1, self.corrSub) print cmd + fileSub argsTmp = cmd + fileSub args = argsTmp.split()[1:] calibrate.main(args) os.chdir(self.dirStart) except: os.chdir(self.dirStart) raise