def calculate_L_Lbol(Halpha_EW, Halpha_EW_err, spt): chi_interp = interp1d(kastclassify.defs.chi_factor_types, kastclassify.defs.chi_factor_values, bounds_error=False, fill_value=np.nan) chi_err_interp = interp1d(kastclssify.defs.chi_factor_types, kastclassify.defs.chi_factor_values_err, bounds_error=False, fill_value=np.nan) stype = typeToNum(spt) chi = chi_interp(stype) chi_err = chi_err_interp(stype) Lratio = chi * Halpha_EW Lratio_err = chi_err * Halpha_EW_err return Lratio, Lratio_err
def calc_spec_info(filepath, plot=False, no_index_trials=100, no_EW_trials=30, diag_path=None): t1 = datetime.datetime.now() #collecting header info print('Reading in {}'.format(filepath)) spec = kastredux.readSpectrum(filepath) spec.name = fits.getheader(filepath)['OBJECT'] ra = fits.getheader(filepath)['RA'] dec = fits.getheader(filepath)['DEC'] date = fits.getheader(filepath)['DATE'] filename = os.path.basename(filepath) if plot: spec.plot() plt.show() if diag_path is not None: spec.plot() plt.savefig(diag_path + spec.name + '_spec.png') print('Classifying by standard comparison...') spt, stand_name, spt_chi2, spt_scale = classify_by_standard( spec, ref='all', plot=plot, diag_path=diag_path) print('Done!') print('Measuring indices...') indices = {} for ref in list(kastclassify.defs.index_dict): print('Mesuring index set {}...'.format(ref)) indices[ref] = measure_index_set(spec, ref=ref, no_trials=no_index_trials) print('Done!') print('Done!') print('Measuring Equivalent Widths...') EWs = {} for ref in list(kastclassify_EW_dict): print('Measuring EW for {}...'.format(ref)) EWs[ref] = measure_EW_element(spec, ref=ref, plot=plot, no_trials=no_EW_trials, diag_path=diag_path) print('Done!') print('Done!') #calculating with the measurements print('Calculating spectral types by index...') index_spt, zeta_info, metallicity_class = classify_by_index( spec, index_dict=indices) print('Done!') print('Calculating L_Halpha/L_bol...') Lratio, Lratio_err = calculate_L_Lbol(EWs['Halpha']['EW'], EWs['Halpha']['EW_err'], spt) print('Done!') plt.close('all') #unpacking results print('Packaging results...') results = {} results['name'] = spec.name results['filename'] = filename results['RA'] = ra results['DEC'] = dec results['OBSDATE'] = date results['spt'] = spt results['subtype'] = typeToNum(spt) - 10 results['spt_chi2'] = spt_chi2 results['spt_scale'] = spt_scale for ref in list(indices): for name in list(indices[ref]): results[ref + '_' + name] = indices[ref][name][0] results[ref + '_' + name + '_err'] = indices[ref][name][1] for ref in list(EWs): for name in list(EWs[ref]): results[ref + '_' + name + '_(Angstrom)'] = EWs[ref][name] for ref in list(index_spt): results[ref] = index_spt[ref] results['zeta'] = zeta_info[0] results['zeta_err'] = zeta_info[1] results['metallicity_class'] = metallicity_class results['L_Halpha/L_bol'] = Lratio results['L_Halpha/L_bol_err'] = Lratio_err print('Done!') t2 = datetime.datetime.now() dt = t2 - t1 print('All done in {}! All done at {}'.format(dt, t2)) return results