def loop_teff_logg(data_type,data_spectrum,teff,logg,feh,start_lambda,end_lambda): teff_space = [] logg_space = [] chisq_space = [] teff_min = teff - 1000 teff_max = teff + 1000 if teff < 4500: teff_min = int(3500) if teff > 8000: teff_max = int(9000) shift = find_shift(data_type,data_spectrum,teff,logg,feh,start_lambda,end_lambda) ### Create grid teff_i = teff_min while teff_i <= teff_max: teff_space.append(teff_i) teff_i = teff_i + 250 logg_i = 0.0 while logg_i <= 5.0: logg_space.append(logg_i) logg_i = logg_i + 0.5 teff_space = array(teff_space) logg_space = array(logg_space) (X,Y) = meshgrid(teff_space,logg_space) ### Create chisq array teff_i = teff_min while teff_i <= teff_max: logg_line = [] logg_i = 0.0 while logg_i <= 5.0: chisq_i = test_template(data_type,data_spectrum,teff_i,logg_i,0.0,start_lambda,end_lambda,shift) logg_line.append(chisq_i) logg_i = logg_i + 0.5 chisq_space.append(logg_line) teff_i = teff_i + 250 chisq_space = array(chisq_space) chisq_space = transpose(chisq_space) # chisq_space = spectype_functions.normalise_array(chisq_space) # chisq_space = log(chisq_space) ### Find min teff_min,logg_min = spectype_functions.find_2d_min(chisq_space) teff_min = teff_space[teff_min] logg_min = logg_space[logg_min] # ### Normalise the array #chisq_space = exp(- chisq_space **2 / 2) #chisq_space = spectype_functions.normalise_array(chisq_space) # print chisq_space ### Crop the chisq space immediately surrounding the absolute min teff_space_cropped,logg_space_cropped,cropped_space =spectype_functions.chop_array(teff_space,logg_space,chisq_space,teff_min,logg_min,500,1.0) #cropped_space = log(cropped_space) cropped_space = -1 *(cropped_space - cropped_space.max()) ### Use scipy to fit a least sq 2D gaussian to the cropped region gauss_fit = spectype_functions.fitgaussian(cropped_space) gauss_height = gauss_fit[0] gauss_width_x = gauss_fit[3] gauss_width_y = gauss_fit[4] ### Check if the gaussian fit makes sense if gauss_height > 100 or gauss_width_x > 20 or gauss_width_y > 20: gauss_height = 0.00001 gauss_width_x = 99999. gauss_width_y = 99999. # plt.clf() # plt.contourf(teff_space,logg_space,chisq_space,20,cmap=plt.get_cmap("jet")) # plt.scatter(teff_min,logg_min,s=50,color="r",marker="x") # plt.xlabel("T_eff") # plt.ylabel("logg") # plt.xlim(max(teff_space),min(teff_space)) # plt.ylim(max(logg_space),min(logg_space)) # plt.title(object_name +" " + str(start_lambda) + "-" + str(end_lambda) + "A, Teff=" + str(teff_min) + " logg=" + str(logg_min)) # plt.show() return teff_space,logg_space,chisq_space,gauss_height,gauss_width_x,gauss_width_y
flux_spectrum = transpose(array(flux_spectrum)) flux_spectrum = spectype_functions.normalise(flux_spectrum,flux_normalise_w1,flux_normalise_w2) reddening_chisq_list.append(master_norm_array * calculate_chisq_from_input_regions("flux",flux_spectrum,teff_ini,logg_ini,feh_ini,teff_regions)) ################################ ### Sum the reddening arrays ### ################################ ### Find weights! height_weights = [] x_weights = [] y_weights = [] for chisq_space in reddening_chisq_list: ### Find min teff_min,logg_min = spectype_functions.find_2d_min(chisq_space) teff_min = teff_space[teff_min] logg_min = logg_space[logg_min] ### Crop the chisq space immediately surrounding the absolute min teff_space_cropped,logg_space_cropped,cropped_space =spectype_functions.chop_array(teff_space,logg_space,chisq_space,teff_min,logg_min,500,1.0) #cropped_space = log(cropped_space) cropped_space = -1 *(cropped_space - cropped_space.max()) ### Use scipy to fit a least sq 2D gaussian to the cropped region gauss_fit = spectype_functions.fitgaussian(cropped_space) gauss_height = gauss_fit[0] gauss_width_x = gauss_fit[3] gauss_width_y = gauss_fit[4] ### Check if the gaussian fit makes sense