def sed_to_alpha(sed, Q): # Initialize cs = 3e10 # cm s-1 alpha = 0.0 spitzer_system = convert_lib.set_SCAO() band_name_list = [ 'J', 'H', 'K', 'IR1', 'IR2', 'IR3', 'IR4', 'MP1', ] log_l_F = [] e_log_l_F = [] log_l = [] yso_class = '' # Make lambda and flux*lambda list for i, band_name in enumerate(band_name_list): # Choose the band that detected. if Q[i] != 'A' and Q[i] != 'S': continue # Index start at 3 because we skip band J, H, and K. band_flux = sed[i] e_band_flux = sed[8 + i] wavelength = 10 * spitzer_system[band_name][1] # um # Specific freq. to specific flux cvt = cs / (wavelength**2) # cm-1 s-1 log_l_F.append(np.log(wavelength * cvt * band_flux)) e_log_l_F.append( np.log(wavelength * (e_band_flux + band_flux) / band_flux)) log_l.append(np.log(wavelength)) print(log_l_F) print(log_l) print(e_log_l_F) w_log_l_F = np.divide(1, np.array(e_log_l_F)) paras = np.polyfit(x=log_l_F, y=log_l, deg=1, w=w_log_l_F) alpha = paras[0] # Plot the result for debugging ''' p = np.poly1d(paras) x_samples = np.logspace( np.log10(spitzer_system['IR1'][1]), np.log10(spitzer_system['MP1'][1]), 10 ) plt.plot(np.log10(x_samples), p(np.log10(x_samples))) plt.scatter(log_l, log_l_F, c = 'r') plt.xlabel(r"log($\lambda$)") plt.ylabel(r"log($\lambda F_{\lambda}$)") plt.show() ''' return alpha
#-------------------------------------------- # Main code if __name__ == "__main__": VERBOSE = 0 # Measure time start_time = time.time() #----------------------------------- # Load argv if len(argv) != 2: print("The number of arguments is wrong.") print("tbl_to_sed_An_2011.py [An 2011 table]") exit() inp_table_name = argv[1] #----------------------------------- # Load data from input table SCAO_system = convert_lib.set_SCAO() inp_table = np.loadtxt(inp_table_name, dtype=str) JUmag = np.array(np.transpose([inp_table[:, 4], inp_table[:, 5]]), dtype=float) HUmag = np.array(np.transpose([inp_table[:, 6], inp_table[:, 7]]), dtype=float) KUmag = np.array(np.transpose([inp_table[:, 8], inp_table[:, 9]]), dtype=float) IR1mag = np.array(inp_table[:, 10], dtype=float) IR2mag = np.array(inp_table[:, 11], dtype=float) IR3mag = np.array(inp_table[:, 12], dtype=float) IR4mag = np.array(inp_table[:, 13], dtype=float) MP1mag = np.array(inp_table[:, 14], dtype=float) #----------------------------------- JUflux = convert_lib.ensemble_mag_to_mjy(JUmag, 'J', SCAO_system) HUflux = convert_lib.ensemble_mag_to_mjy(HUmag, 'H', SCAO_system)
# Measure time start_time = time.time() #----------------------------------- # Load argv if len(argv) != 5: print ("The number of arguments is wrong.") print ("Usage: plot_corner_exU.py [band index code] [sed table] [cls table] [Q table]") print ("Example: plot_corner_exU.py 678 sed_table.txt cls_table.txt Q_table.txt") exit() band_index_code = argv[1] sed_table_name = argv[2] cls_table_name = argv[3] Q_table_name = argv[4] #----------------------------------- # Initialize the band system SCAO_system = set_SCAO() bands = [ 'J', 'H', 'K', 'IR1', 'IR2', 'IR3', 'IR4', 'MP1' ] #----------------------------------- # Load data print("Load data") sed_table = np.loadtxt(sed_table_name) cls_table = np.loadtxt(cls_table_name, dtype = int)
def sed_to_alpha(sed, Q): # Initialize cs = 3e10 # cm s-1 alpha = 0.0 spitzer_system = convert_lib.set_SCAO() band_name_list = [ 'K', 'IR1', 'IR2', 'IR3', 'IR4', 'MP1', ] log_l_F = [] e_log_l_F = [] log_l = [] yso_class = '' # Make lambda and flux*lambda list for i, band_name in enumerate(band_name_list): # Choose the band that detected. if Q[2 + i] != 'A': continue # Index start at 3 because we skip band J, H, and K. band_flux = sed[2 + i] e_band_flux = sed[8 + 2 + i] wavelength = 1e-4 * spitzer_system[band_name][1] # um to cm # Specific freq. to specific flux cvt = cs / (wavelength**2) # cm-1 s-1 log_l_F.append(np.log(wavelength * cvt * band_flux)) e_log_l_F.append( np.log(wavelength * (e_band_flux + band_flux) / band_flux)) log_l.append(np.log(wavelength)) w_log_l_F = np.divide(1, np.array(e_log_l_F)) try: paras = np.polyfit(log_l_F, log_l, 1, w=w_log_l_F) except: exit() # Calculate alpha and derive yso class alpha = paras[0] if alpha >= 0.3: yso_class = 'I' elif alpha >= -0.3 and alpha < 0.3: yso_class = 'Flat' elif alpha >= -1.6 and alpha < -0.3: yso_class = 'II' elif alpha < -1.6: yso_class = 'III' #-------------------------------------------- # For debugging # Plot the result for debugging ''' p = np.poly1d(paras) x_samples = np.logspace( np.log10(spitzer_system['IR1'][1]), np.log10(spitzer_system['MP1'][1]), 10 ) plt.plot(np.log10(x_samples), p(np.log10(x_samples))) plt.scatter( log_l, log_l_F, c = 'r', label = r'$\alpha$=%f, Class %s' % (alpha, yso_class)) plt.xlabel(r"log($\lambda$)") plt.ylabel(r"log($\lambda F_{\lambda}$)") plt.legend() plt.show() ''' return alpha, yso_class