def main(file_path): darklist = functions.find_objname(file_path,functions.read_config_file("BIAS_HEADER")) master_dark = average_darks(darklist) try: functions.save_fits(master_dark,file_path+"temp/master_dark.fits") except IOError: os.system("mkdir "+file_path+"temp/") functions.save_fits(master_dark,file_path+"temp/master_dark.fits")
def run(): print "**** REMEMBER - ENTER OBJECT COORDS INTO OBJECT_COORDS.TXT ****" ### Reduce and create photometry main(functions.read_config_file("FILE_PATH")) os.system("cp config_file "+functions.read_config_file("FILE_PATH")) ### create light curve from reduced photometry os.system("python create_lightcurves.py") ### Generating guiding offset os.system("python guiding_offset.py") ### Plot the light curves os.system("python plot_lightcurves.py") ### Plot external parameters os.system("python extern_param.py")
def main(): file_path = functions.read_config_file("FILE_PATH") + "reduced/lc/" lc = genfromtxt(file_path + "0.rawlc", invalid_raise=False) plt.figure(figsize=(12, 6)) plt.subplots_adjust(left=0.07, right=0.98, wspace=0.3) plot_extern(lc) plt.savefig(file_path + "extern_param.png") # plt.show() plt.close() os.system("open " + file_path + "extern_param.png")
def main(file_path): darklist = functions.find_objname(file_path,functions.read_config_file("FLAT_HEADER")) if len(darklist) == 0: print "Error: no flats found" raise IOError master_dark = average_darks(darklist,file_path+"temp/master_dark.fits") try: functions.save_fits(master_dark,file_path+"temp/master_flat.fits") except IOError: os.system("mkdir "+file_path+"temp/") functions.save_fits(master_dark,file_path+"temp/master_flat.fits")
############################# ### Set file_path file_path = sys.argv[1] file_path_temp = file_path + "temp/" file_path_reduced = file_path + "reduced/" file_name = sys.argv[2] hdulist = pyfits.open(file_path + file_name) object_name = hdulist[0].header["OBJECT"] hdulist.close() print "This script applies bias subtraction to the image " + file_name camera = functions.read_config_file("CAMERA") if camera == "red": trimsec_value = functions.read_param_file("RED_TRIMSEC") biassec_value = functions.read_param_file("RED_BIASSEC") region1 = functions.read_param_file("RED_REGION1") region2 = functions.read_param_file("RED_REGION2") use_regions = functions.read_param_file("RED_USEREGIONS") reflect = functions.read_param_file("RED_REFLECT") if camera == "blue": trimsec_value = functions.read_param_file("BLUE_TRIMSEC") biassec_value = functions.read_param_file("BLUE_BIASSEC") region1 = functions.read_param_file("BLUE_REGION1") region2 = functions.read_param_file("BLUE_REGION2") use_regions = functions.read_param_file("BLUE_USEREGIONS") reflect = functions.read_param_file("BLUE_REFLECT")
def inflate_errors(x0,free_param_names,free_param_vals,fixed_param_names,fixed_param_vals,lc,cadence): ### Calculate stellar parameters global period_i,t0_i,rsum_i,rratio_i,i_0_i,ld1_i,ld2_i,tdiff_i,edepth_i ### Give dummy values to avoid error [period_i,t0_i,rsum_i,rratio_i,i_0_i,ld1_i,ld2_i,tdiff_i,edepth_i] = [1,1,1,1,1,1,1,1,1] temp_params = x0*free_param_vals+free_param_vals ### Set parameter names ld1_coeff = [] ld2_coeff = [] ### Set parameter names for i in range(len(free_param_names)): globals()[free_param_names[i]+"_i"] = temp_params[i] if free_param_names[i] == "lc_ld1": ld1_coeff.append(temp_params[i]) if free_param_names[i] == "lc_ld2": ld2_coeff.append(temp_params[i]) for i in range(len(fixed_param_names)): globals()[fixed_param_names[i]+"_i"] = fixed_param_vals[i] if fixed_param_names[i] == "lc_ld1": ld1_coeff.append(fixed_param_vals[i]) if fixed_param_names[i] == "lc_ld2": ld2_coeff.append(fixed_param_vals[i]) t0_global = floor(eval(functions.read_config_file("T0"))) t0_i = t0_i + t0_global if cadence == "short": t0_i = t0_i + tdiff_i #### Calculate error inflation hjd_i,flux_i,fluxerr_i = lc[:,0],lc[:,1],lc[:,2] model_input = array([edepth_i,rsum_i,rratio_i,ld1_coeff[0],0,i_0_i,ecosw_i,esinw_i,0,0,0,0,0,0,0,0,0,1,period_i,t0_i,ld2_coeff[0],0]) model = transitmodel(model_input,hjd_i,1,0,cadence) ### Apply offset z0 = [median(flux_i)] def minfunc(z0): flux_ii = flux_i + z0[0] chisq_i = sum(((flux_ii-model)/fluxerr_i)**2) return chisq_i z0 = optimize.fmin(minfunc,z0,disp=0) flux_i = flux_i + z0[0] df = float(len(flux_i)) def chisq(y,dy,f,df): return sum(((f-y)/dy)**2)/df def minfunc(factor,y,dy,f,df): if factor > 0: x2 = chisq(y,dy*factor,f,df) x2 = abs(x2-1) return x2 else: return NaN s0 = 1. s0 = optimize.fmin(minfunc,s0,args=(flux_i,fluxerr_i,model,df)) s0 = s0[0] print "inflating errors by factor of ",s0 fluxerr_i = fluxerr_i*s0 lc[:,2] = fluxerr_i return lc
### Compile shared transit library os.system("rm jktebop_lib.so") os.system("gfortran jktebop_lib.f -ffree-form -fpic -shared -o jktebop_lib.so") jktebop = cdll.LoadLibrary("./jktebop_lib.so") ### Global constants au = 1.496*10**11 msun = 1.988435*10**30 rsun = 6.955*10**8 mjup = 1.8988*10**27 rjup = 6.9173*10**7 day = 60.*60.*24. gconst = 6.67*10**(-11) free_t0 = functions.read_config_file("FREE_T0") mstar_master = eval(functions.read_config_file("MSTAR"))*msun mstar_err = eval(functions.read_config_file("MSTAR_ERR"))*msun rhostar_master = eval(functions.read_config_file("RHOSTAR")) rhostar_err = eval(functions.read_config_file("RHOSTAR_ERR")) def calculate_rstar(mstar,rhostar): rstar = (mstar/(rhostar*(4./3.)*pi))**(1./3.) return rstar rstar_master = calculate_rstar(mstar_master,rhostar_master) def obliquity(t,t0,beta,fratio,theta,phi,Protot,b,a,P,Rs,Ms):
### Usage: python combine_apertures.py file_path file_name ######################## ### Start of program ### ######################## ### Set file_path file_path = sys.argv[1] file_path_temp = file_path + "temp/" file_path_reduced = file_path + "reduced/" file_name = sys.argv[2] image_slices = functions.read_ascii(file_path_temp + "stellar_apertures.txt") camera = functions.read_config_file("CAMERA") grating = functions.read_config_file("GRATING") dichroic = functions.read_config_file("DICHROIC") spectrum_w1 = functions.read_param_file(grating+"_"+dichroic+"_w1") spectrum_w2 = functions.read_param_file(grating+"_"+dichroic+"_w2") sample_w1 = functions.read_param_file("FLUX_NORMALISE_w1") sample_w2 = functions.read_param_file("FLUX_NORMALISE_w2") sample_region = "a"+sample_w1+"-"+sample_w2 combine_apertures = functions.read_config_file("COMBINE_APERTURES") program_dir = os.getcwd() + "/" #Save the current working directory os.chdir(file_path_temp) #Change to ../temp/ dir
import os import sys import string import functions ### This is a program meant for testing! ### usage: python run_spectype_all.py file_path = functions.read_config_file("FILE_PATH") program_dir = os.getcwd() + "/" os.chdir(file_path + "/reduced/") os.system("ls fluxcal_*.fits > file_list") file_list = functions.read_ascii("file_list") os.system("rm file_list") os.chdir(program_dir) for file_name in file_list: file_name = string.split(file_name,"_") file_name = file_name[1] print "******" print file_name os.system("python spectype_main.py " + file_path + " " + file_name) os.system("python update_spectype.py " + file_path + " " + file_name)
### Flux per pixel is conserved. ### Usage: python correct_distortions.py file_path file_name ######################## ### Start of program ### ######################## ### Set file_path file_path = sys.argv[1] file_path_temp = file_path + "temp/" file_path_reduced = file_path + "reduced/" file_name = sys.argv[2] camera = functions.read_config_file("CAMERA") grating = functions.read_config_file("GRATING") dichroic = functions.read_config_file("DICHROIC") ### Get slice numbers and arc images to use arc_list = functions.read_ascii(file_path_temp + "arcs_to_use.txt") #image_slices = functions.read_ascii(file_path_temp + "stellar_apertures.txt") image_slices = loadtxt(file_path_temp+"image_slice_table.txt") image_slices = arange(len(image_slices)) ### Define linelist to use linelist = grating + "_linelist.dat" ### Define template to use template = grating +"_"+dichroic+ "_template.fits"
### Get free parameters: ### Read from config file ### Load initial parameters and lightcurve temp_param_names = [] temp_param_vals = [] temp_param_range = [] #lc = functions.read_config_file("INPUT_LC") #lc = loadtxt(lc) lc_ld1 = eval(functions.read_config_file("LC_LD1")) lc_ld1_err = eval(functions.read_config_file("LC_LD1_ERR")) lc_ld2 = eval(functions.read_config_file("LC_LD2")) lc_ld2_err = eval(functions.read_config_file("LC_LD2_ERR")) for i in range(len(lc_ld1)): temp_param_names.append("lc_ld1") temp_param_vals.append(lc_ld1[i]) temp_param_range.append(lc_ld1_err[i]) temp_param_names.append("lc_ld2") temp_param_vals.append(lc_ld2[i]) temp_param_range.append(lc_ld2_err[i]) temp_param_names.append("period") temp_param_vals.append(float(functions.read_config_file("PERIOD"))) temp_param_range.append(float(functions.read_config_file("PERIOD_ERR")))
master_flat = transpose(master_flat) ### Find the median value across the column median_values = [] for i in range(len(master_flat)): median_values.append(median(master_flat[i])) ### Find the start and end of each image slice initial_value = median_values[0] threshold = mean(median_values)/2. region_table = [] for i in range(1,len(median_values)): if median_values[i] > threshold and median_values[i-1] < threshold: region_table.append([i+1,i+38]) #region_table.append([i+5,i+33]) ### Write the table into a text file image_slice_table = open(file_path_temp + "image_slice_table.txt","w") functions.write_table(region_table,image_slice_table) image_slice_table.close() ### If no master flat exists, use default table else: print "Using default image slice positions" camera = functions.read_config_file("CAMERA") if camera == "red": os.system("cp image_slice_table_red.txt " + file_path_temp + "image_slice_table.txt") if camera == "blue": os.system("cp image_slice_table_blue.txt " + file_path_temp + "image_slice_table.txt")
######################## ### Start of program ### ######################## ### Set file_path file_path = sys.argv[1] file_path_temp = file_path + "temp/" file_path_reduced = file_path + "reduced/" file_name = sys.argv[2] hdulist = pyfits.open(file_path + file_name) object_mjd = hdulist[0].header['MJD-OBS'] hdulist.close() camera = functions.read_config_file("CAMERA") grating = functions.read_config_file("GRATING") dichroic = functions.read_config_file("DICHROIC") combine_aps = functions.read_config_file("COMBINE_APERTURES") print "This script applies NeAr arc image to calibrate the object spectrum " +file_name ### Get slice numbers and arc images to use arc_list = functions.read_ascii(file_path_temp + "arcs_to_use.txt") image_slices = functions.read_ascii(file_path_temp + "stellar_apertures.txt") ### Calculate the fractional weight of each arc arc_weight = [] for arc_name in arc_list: hdulist = pyfits.open(file_path + arc_name) arc_mjd = hdulist[0].header['MJD-OBS']
### Read from param and config files model_path_flux = functions.read_param_file("MODEL_PATH_FLUX") model_path_norm = functions.read_param_file("MODEL_PATH_NORM") ### Find the region within which to flux normalise flux_normalise_w1 = eval(functions.read_param_file("NORM_REGION_w1")) flux_normalise_w2 = eval(functions.read_param_file("NORM_REGION_w2")) ### Find initial estimate of properties hdulist = pyfits.open(file_path + file_name) object_name = hdulist[0].header["OBJECT"] hdulist.close() print "Analysing ",object_name hsmso_connect = functions.read_config_file("HSMSO_CONNECT") hscand_connect = functions.read_config_file("HSCAND_CONNECT") default_teff = float(functions.read_config_file("TEFF_ESTIMATE")) default_logg = float(functions.read_config_file("LOGG_ESTIMATE")) teff_ini,logg_ini = functions.estimate_teff_logg(object_name,hsmso_connect,hscand_connect,default_teff,default_logg) feh_ini = 0.0 ini_template_spectrum = "template_" + str(teff_ini) + "_" + str(logg_ini) + "_" + str(feh_ini) print "Initial estimate of teff, logg: ",str(teff_ini),str(logg_ini) ################# ### Make axes ### ################# teff_space = [] logg_space = []
for entry in candidates_txt: print entry[0] if entry[0] == object_name_query: print "Using candidates.txt for candidate parameters" object_found = True cand_params = [entry[5],entry[6],entry[7]] #break if not object_found: print "Using default candidate parameters" RV_points = transpose(RV_points) HJD_points = RV_points[0] cand_params = [min(HJD_points),max(HJD_points)-min(HJD_points),0.1] ### Plot the rv phase curve os.system("cp rv_plot.sh " + plots_folder) program_dir = os.getcwd() + "/" #Save the current working directory os.chdir(plots_folder) #print cand_params print "t0,period,q",cand_params[0],cand_params[1],cand_params[2] #cand_params[0] = cand_params[0] + cand_params[1]*0.5 #cand_params[1] = cand_params[1]*2 os.system("./rv_plot.sh "+object_name+" "+str(cand_params[0])+" "+str(cand_params[1])+" "+str(cand_params[2])) os.chdir(program_dir) if functions.read_config_file("OPEN_RESULT_PDFS") == "true": os.system("evince "+plots_folder + object_name + ".pdf &")
import os,sys,functions from numpy import * import matplotlib.pyplot as plt frame_scale = eval(functions.read_config_file("FRAME_SCALE")) guider_scale = eval(functions.read_config_file("GUIDER_SCALE")) def find_median_offset(data,original_x,original_y): return median(data[:,1])-original_x,median(data[:,2])-original_y def read_xy(file_path): current_dir = os.getcwd() os.chdir(file_path) lc = loadtxt("0.rawlc") hjd = lc[:,0] xcoord = lc[:,1] ycoord = lc[:,2] data = transpose(array([hjd,xcoord,ycoord])) # ### Find initial position # ### find if already calculated # if os.path.exists("init_pos"): # init_pos = loadtxt("init_pos")
os.system("make all") os.chdir("..") sys.path.append("oblateTransit") import oblateness_func ### Global constants au = 1.496*10**11 msun = 1.988435*10**30 rsun = 6.955*10**8 mjup = 1.8988*10**27 rjup = 6.9173*10**7 day = 60.*60.*24. gconst = 6.67*10**(-11) free_t0 = functions.read_config_file("FREE_T0") kipping_ld = functions.read_config_file("KIPPING_LD") grav_dark_form = functions.read_config_file("GRAV_DARK_FORM") mstar_master = eval(functions.read_config_file("MSTAR"))*msun mstar_err = eval(functions.read_config_file("MSTAR_ERR"))*msun rhostar_master = eval(functions.read_config_file("RHOSTAR")) rhostar_err = eval(functions.read_config_file("RHOSTAR_ERR")) def calculate_rstar(mstar,rhostar): rstar = (mstar/(rhostar*(4./3.)*pi))**(1./3.) return rstar rstar_master = calculate_rstar(mstar_master,rhostar_master)
######################## ### Start of program ### ######################## ### Set file_path file_path = sys.argv[1] file_path_temp = file_path + "temp/" file_path_reduced = file_path + "reduced/" file_name = sys.argv[2] hdulist = pyfits.open(file_path + file_name) object_mjd = hdulist[0].header['MJD-OBS'] hdulist.close() camera = functions.read_config_file("CAMERA") grating = functions.read_config_file("GRATING") dichroic = functions.read_config_file("DICHROIC") combine_aps = functions.read_config_file("COMBINE_APERTURES") task = functions.read_config_file("TASK") no_apertures = eval(functions.read_config_file("NO_APERTURES")) print "This script applies NeAr arc image to calibrate the object spectrum " +file_name ### Get slice numbers and arc images to use arc_list = functions.read_ascii(file_path_temp + "arcs_to_use.txt") coo = functions.read_ascii(file_path_temp+"master_coo") coo = functions.read_table(coo) ### Calculate the fractional weight of each arc arc_weight = []
return flux ### Syntax for transit model ### transitmodel(V.ctypes.data_as(POINTER(c_double)),ldtype.ctypes.data_as(POINTER(c_long)),byref(phase),byref(dtype),byref(la),byref(lb),byref(flux)) ### dtype = 1, ldtype = [4,4] ### Global constants au = 1.496*10**11 msun = 1.988435*10**30 rsun = 6.955*10**8 mjup = 1.8988*10**27 rjup = 6.9173*10**7 day = 60.*60.*24. gconst = 6.67*10**(-11) t0_global = floor(eval(functions.read_config_file("T0"))) tested_params = [] chisq_log = [] def lc_chisq(initial_params,free_param_names,fixed_param_names,fixed_param_values,lc,plot_pdf,output_data): #print initial_params global period_i,t0_i,rsum_i,rratio_i,i_0_i,ld1_i,ld2_i ### Give dummy values to avoid error [period_i,t0_i,rsum_i,rratio_i,i_0_i,ld1_i,ld2_i] = [1,1,1,1,1,1,1] #offsets = [] ld1_coeff = [] ld2_coeff = [] ### Set parameter names
file_path = sys.argv[1] file_path_temp = file_path + "temp/" file_path_reduced = file_path + "reduced/" file_name = sys.argv[2] print "This script uses iraf.fxcor to generate a CCF for " +file_name + " using synthetic templates" program_dir = os.getcwd() + "/" #Save the current working directory ### Load fxcor RV measurements fxcor_stellar = functions.read_ascii(file_path_reduced + "fxcor_stellar.txt") fxcor_stellar = functions.read_table(fxcor_stellar) ### Load grating / camera settings grating = functions.read_config_file("GRATING") dichroic = functions.read_config_file("RT560") region_w1 = functions.read_param_file(grating+"_"+dichroic+"_w1") region_w2 = functions.read_param_file(grating+"_"+dichroic+"_w2") ### Load location of library synthetic_library = functions.read_param_file("RV_SPECTRAL_LIBRARY") ### Load RV fxcor region stellar_region = functions.read_param_file("STELLAR_REGION") ### Determine best aperture ### by finding the flux ratios of apertures ### We use only the best aperture for generating the CCF aperture_weights = list(find_flux_weights(file_name))
dist = abs(input_list[len(input_list)-i][0] - starting_pos) if dist <= float(no_apertures): sequence.append(input_list[len(input_list)-i][0]) i = i+1 n = n+1 else: n = n i = i+1 return sequence ######################## ### Start of program ### ######################## ### Read from config file no_apertures = int(functions.read_config_file("NO_APERTURES")) no_stars = int(functions.read_config_file("NO_STARS")) se_path = functions.read_param_file("SE_PATH") program_dir = os.getcwd()+"/" ### Set file_path file_path = sys.argv[1] file_path_temp = file_path + "temp/" file_path_reduced = file_path + "reduced/" file_name = sys.argv[2] interactive = functions.read_config_file("INTERACT") image_slices_list = functions.read_ascii(file_path_temp + "slice_" + file_name+".txt") image_slices_list = functions.read_table(image_slices_list)
def find_flux_weights(file_name): os.chdir(program_dir) if functions.read_config_file("COMBINE_APERTURES") == "false": no_apertures = eval(functions.read_config_file("NO_APERTURES")) multispec_name = "spec_"+file_name os.chdir(file_path_reduced) ### Load spectrum print "Finding best aperture" aperture_flux = [] i = 1 while i <= no_apertures: try: os.system("rm -f " + file_path_reduced + "aperture.fits") iraf.scopy( input = file_path_reduced + multispec_name,\ output = file_path_reduced + "aperture.fits",\ w1 = region_w1,\ w2 = region_w2,\ apertures = i,\ bands = "",\ beams = "",\ apmodulus = 0,\ format = "multispec",\ renumber = 1,\ offset = 0,\ clobber = 1,\ merge = 1,\ rebin = 1,\ verbose = 1) spectrum_maximum = iraf.imstat( images = file_path_reduced + "aperture.fits",\ fields = "midpt",\ lower = "INDEF",\ upper = "INDEF",\ nclip = 1,\ lsigma = 5.0,\ usigma = 5.0,\ binwidth = 0.1,\ format = 1,\ cache = 1,\ mode = "al",\ Stdout = 1) spectrum_maximum = float(spectrum_maximum[1]) aperture_flux.append(spectrum_maximum) os.system("rm -f " + file_path_reduced + "aperture.fits") i = i + 1 except (IrafError,ValueError): print "Aperture " + str(i) + " not found" aperture_flux.append(0) i = i + 1 aperture_flux = array(aperture_flux) aperture_flux = aperture_flux / sum(aperture_flux) os.chdir(program_dir) else: aperture_flux = array([1.]) return aperture_flux
def main(file_path): ### Setup setup_dir(file_path) if functions.read_config_file("DELETE_ALL") == "true": delete_all(file_path) ### Make bias if not os.path.exists(file_path+"temp/master_dark.fits"): import master_dark master_dark.main(file_path) ### Make flatfield if not os.path.exists(file_path+"temp/master_flat.fits"): flatfield.main(file_path) ### load sciencelist sciencelist_temp = functions.find_objname(file_path,functions.read_config_file("OBJECT_HEADER")) ### Check if each one has been fully downloaded sciencelist = [] for fits in sciencelist_temp: try: test = pyfits.getdata(fits) sciencelist.append(fits) print "OK",fits except ValueError: pass for fits in sciencelist: fits_base = string.split(fits,"/")[-1] fits_base = string.split(fits_base,".")[0] if not os.path.exists(file_path+"reduced/"+fits_base+".fits"): print "********************************" print "Reducing",fits fits_path = process(fits,file_path+"reduced/") flatfield.apply_flatfield(fits_path,file_path+"temp/master_flat.fits",file_path+"temp/master_dark.fits") ### Now extract sources in reference image, match, and do photometry import fistar,transcoord,fiphot refimage = functions.read_config_file("REFERENCE_IMAGE") refimage_coords=fistar.fistar(file_path+"reduced/"+refimage) reflist = loadtxt(functions.read_config_file("OBJECT_LIST")) ###reformat reflist so that it reflects the refimage actual star coordinates ### So that the extraction coordinates are exact new_reflist = [] for star in reflist: dist = sqrt((star[1]-refimage_coords[:,1])**2 + (star[2]-refimage_coords[:,2])**2) indx = argmin(dist) star[1] = refimage_coords[indx,1] star[2] = refimage_coords[indx,2] new_reflist.append(star) savetxt(file_path+"reduced/object_list",array(new_reflist)) for fits in sciencelist: fits_base = string.split(fits,"/")[-1] fits_base = string.split(fits_base,".")[0] if not os.path.exists(file_path+"/reduced/"+fits_base+".fits.phot"): ### transform the coordinates of extraction transcoord.transcoord(file_path+"/reduced/"+fits_base+".fits",file_path+"reduced/object_list",file_path+"reduced/"+refimage+".fistar") ### Now apply fiphot and get real photometry out fiphot.fiphot(file_path+"/reduced/"+fits_base+".fits")
exits from app """ def exit(self): answer = tk.messagebox.askyesno("TVManiac", "Do you want to exit?", parent=self.master) if answer: self.master.destroy() """ switches incognito mode """ def switch_incognito(self): if functions.INCOGNITO: self.incognito_button.configure(bg="#8B0000", text="OFF") functions.INCOGNITO = False else: self.incognito_button.configure(bg="#006400", text="ON") functions.INCOGNITO = True if __name__ == '__main__': root = tk.Tk() root.geometry('1300x750') functions.read_config_file("config_file.txt") icon_path = functions.ICONS_PATH + "television.png" root.iconphoto(True, tk.PhotoImage(file=icon_path)) root.resizable(False, False) app = BaseWindow(root) root.mainloop()
def mcmc_loop(initial_params,default_params,free_param_names,fixed_param_names,fixed_param_values,prior_params,prior_mean,prior_std,prior_func,lc,plot_pdf,cadence): import random global chisq_log,tested_params ### Run an intial round to get baseline chisq initial_params_temp = initial_params * default_params + default_params chisq_base = 0 for n in range(len(lc)): lc_n = lc[n] chisq_base += lc_chisq(initial_params_temp,free_param_names,fixed_param_names,fixed_param_values,lc_n,plot_pdf,False,cadence[n]) print "Running MCMC to sample the parameter space" nwalkers = int(eval(functions.read_config_file("WALKERS"))) nmcmc = int(eval(functions.read_config_file("MCMC"))) nburn = int(eval(functions.read_config_file("NBURN"))) nthreads = 1 param_tolerance_names = ["ecosw","esinw","period","t0","beta","fratio","theta","edepth","phi"] param_tolerances = [0.0001,0.3,0.00000001,0.000001,0.1,0.001,0.1,0.3,0.1] default_tolerance = 0.0001 chisq_log,stellar_params,tested_params= [],[],[] ndim = len(initial_params) #nwalkers = 20 p0 = [] for i in range(nwalkers): pi = [] for j in range(len(initial_params)): tolerance = default_tolerance if j < len(free_param_names): for k in range(len(param_tolerance_names)): if param_tolerance_names[k] == free_param_names[j]: tolerance = param_tolerances[k] break pi.append(random.gauss(initial_params[j],tolerance)) p0.append(pi) sampler = emcee.EnsembleSampler(nwalkers, ndim, calc_probability, args=[default_params,free_param_names,fixed_param_names,fixed_param_values,prior_params,prior_mean,prior_std,prior_func,lc,chisq_base,plot_pdf,cadence],threads=nthreads) pos, prob, state = sampler.run_mcmc(p0, nburn) sampler.reset() master_pos = [] master_prob = [] best_prob = -9999999 best_pos = p0[0] for result in sampler.sample(pos, iterations=nmcmc, storechain=False): position,probability = result[0],result[1] for i in range(len(position)): if functions.isnan(probability[i]): if probability[i] > best_prob: best_pos = list(position[i]) best_prob = probability[i] master_prob.append(probability[i]) master_pos.append(list(position[i])) print "iteration finished" print best_pos return array(best_pos)
msun = 1.988435*10**30 rsun = 6.955*10**8 mjup = 1.8988*10**27 rjup = 6.9173*10**7 day = 60.*60.*24. gconst = 6.67*10**(-11) ### Read from config file ### Load initial parameters and lightcurve temp_param_names = [] temp_param_vals = [] temp_param_range = [] lclist = functions.read_ascii(functions.read_config_file("INPUT_LC_LIST")) lc = [] for lc_n in lclist: lc.append(loadtxt(lc_n)) cadence = [] for i in lc: cadence.append(functions.find_cadence(i)) lc_ld1 = eval(functions.read_config_file("LC_LD1")) lc_ld1_err = eval(functions.read_config_file("LC_LD1_ERR")) lc_ld2 = eval(functions.read_config_file("LC_LD2")) lc_ld2_err = eval(functions.read_config_file("LC_LD2_ERR")) for i in range(len(lc_ld1)): temp_param_names.append("lc_ld1")
### Read from param and config files model_path_flux = functions.read_param_file("MODEL_PATH_FLUX") model_path_norm = functions.read_param_file("MODEL_PATH_NORM") ### Find the region within which to flux normalise flux_normalise_w1 = eval(functions.read_param_file("NORM_REGION_w1")) flux_normalise_w2 = eval(functions.read_param_file("NORM_REGION_w2")) ### Find initial estimate of properties hdulist = pyfits.open(file_path + file_name) object_name = hdulist[0].header["OBJECT"] hdulist.close() print "Analysing ",object_name hsmso_connect = functions.read_config_file("HSMSO_CONNECT") hscand_connect = functions.read_config_file("HSCAND_CONNECT") default_teff = float(functions.read_config_file("TEFF_ESTIMATE")) default_logg = float(functions.read_config_file("LOGG_ESTIMATE")) teff_ini,logg_ini = functions.estimate_teff_logg(object_name,hsmso_connect,hscand_connect,default_teff,default_logg) feh_ini = 0.0 print "Initial estimate of teff, logg: ",str(teff_ini),str(logg_ini) ### Change directory to reduced/ program_dir = os.getcwd() + "/" #Save the current working directory os.chdir(file_path_reduced) #Change to ../reduced/ dir ### Load in spectra flux_spectrum = functions.read_ascii("fluxcal_" + file_name + ".dat") flux_spectrum = functions.read_table(flux_spectrum)
msun = 1.988435*10**30 rsun = 6.955*10**8 mjup = 1.8988*10**27 rjup = 6.9173*10**7 day = 60.*60.*24. gconst = 6.67*10**(-11) ### Read from config file ### Load initial parameters and lightcurve temp_param_names = [] temp_param_vals = [] temp_param_range = [] lc = functions.read_config_file("INPUT_LC") lc = loadtxt(lc) lc_ld1 = eval(functions.read_config_file("LC_LD1")) lc_ld1_err = eval(functions.read_config_file("LC_LD1_ERR")) lc_ld2 = eval(functions.read_config_file("LC_LD2")) lc_ld2_err = eval(functions.read_config_file("LC_LD2_ERR")) for i in range(len(lc_ld1)): temp_param_names.append("lc_ld1") temp_param_vals.append(lc_ld1[i]) temp_param_range.append(lc_ld1_err[i]) temp_param_names.append("lc_ld2") temp_param_vals.append(lc_ld2[i]) temp_param_range.append(lc_ld2_err[i]) temp_param_names.append("period")
### usage: python update_RV.py file_path file_name ######################## ### Start of program ### ######################## ### Set file path file_path = sys.argv[1] file_path_temp = file_path + "temp/" file_path_reduced = file_path + "reduced/" ### Set file name file_name = sys.argv[2] ### Find info from config file grating = functions.read_config_file("GRATING") resolution = int(grating[1:]) dichroic = functions.read_config_file("DICHROIC") ### Set program dir and change working directory program_dir = os.getcwd() + "/" #Save the current working directory os.chdir(file_path_reduced) #Change to ../temp/ dir ### Find info from the fits header hdulist = pyfits.open(file_path + file_name) object_name = hdulist[0].header["OBJECT"] dateobs = hdulist[0].header["DATE-OBS"] mjd = hdulist[0].header["MJD-OBS"] exptime = hdulist[0].header["EXPTIME"] comment = hdulist[0].header["NOTES"] hdulist.close()
######################## file_path = sys.argv[1] file_path_temp = file_path + "temp/" file_path_reduced = file_path + "reduced/" file_name = sys.argv[2] file_name_floor = string.split(file_name, "_")[-1] fits = pyfits.open(file_path + file_name_floor) candidate = fits[0].header["OBJECT"] ### Read in spectral regions for RV cc stellar_region = functions.read_param_file("STELLAR_REGION") print stellar_region ### Find out number of apertures used if functions.read_config_file("COMBINE_APERTURES") == "false": no_apertures = int(functions.read_config_file("NO_APERTURES")) else: no_apertures = 1 ### Check if target is mdwarf teff, logg = functions.estimate_teff_logg(file_path, file_name_floor, candidate, "true", "true", 5500, 4.5) if teff < 3800: no_apertures = 3 stellar_region = "*" if teff > 7500: stellar_region = "a6450-6700" print "This script uses iraf.fxcor to find RV solution of " + file_name