for i in range(len(catalogue_df.index)): print '\n-- Treating {} @ {}'.format(catalogue_df.iloc[i].name, catalogue_df.iloc[i].Red_file) codeName = catalogue_df.iloc[i].name fits_file = catalogue_df.iloc[i].Red_file ouput_folder = '{}{}/'.format(catalogue_dict['Obj_Folder'], codeName) if codeName == '8': #Get object objName = codeName redshift_factor = 1 + catalogue_df.iloc[i].z_Red #Spectrum data wave_obs, flux_obs, header_0_obs = dz.get_spectra_data(fits_file) lick_idcs_df = read_csv(ouput_folder + codeName + lickIndcs_extension, delim_whitespace = True, header = 0, index_col = 0, comment='L') #Dirty trick to avoid the Line_label row wave_join, wave_max = catalogue_df.loc[codeName].join_wavelength, catalogue_df.loc[codeName].Wmax_Red idx_obj_join, idx_obj_max_Red = searchsorted(wave_obs, [wave_join, wave_max]) len_red_region = idx_obj_max_Red - idx_obj_join #Load reduction dataframe reduction_folder = catalogue_df.loc[codeName].obsfolder dz_reduc.declare_catalogue(reduction_folder, verbose=False) #Load telluric star files idcs_stars = (dz_reduc.reducDf.reduc_tag == 'norm_narrow') Files_Folders = dz_reduc.reducDf.loc[idcs_stars, 'file_location'].values Files_Names = dz_reduc.reducDf.loc[idcs_stars, 'file_name'].values objects = dz_reduc.reducDf.loc[idcs_stars, 'frame_tag'].values objects = array(['Feige'])
] # flux_calibrated = ['/home/vital/Astrodata/WHT_2016_04/Night1/objects/MRK36_Blue_cr_f_t_w_e_fglobal.fits', # '/home/vital/Astrodata/WHT_2016_04/Night1/objects/MRK36_Red_cr_f_t_w_bg_e_fglobal.fits'] flux_calibrated = [ '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/objects/MRK36_A1/MRK36_A1_Blue_fglobal.fits', '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/objects/MRK36_A2/MRK36_A2_Blue_fglobal.fits', '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/objects/MRK36_A1/MRK36_A1_Red_fglobal.fits', '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/objects/MRK36_A2/MRK36_A2_Red_fglobal.fits', ] for i in range(len(flux_calibrated)): # color = 'Blue' if 'Blue' in extracted_files[i] else 'Red' CodeName, FileName, FileFolder = dz.Analyze_Address(flux_calibrated[i]) wavelength, Flux_array, Header_0 = dz.get_spectra_data(flux_calibrated[i]) # for j in range(Header_0['NAXIS2']): # # color_plot = 'orangish' if j == 0 else 'dark blue' # dz.data_plot(wavelength, Flux_array[j], label = 'Apperture {} {}'.format(j, color), color=dz.colorVector[color_plot]) dz.data_plot(wavelength, Flux_array, label=FileName) dz.FigWording(r'Wavelength $(\AA)$', 'Flux ' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', 'MRK36') dz.display_fig()
# flux_calibrated = ['/home/vital/Astrodata/WHT_2016_04/Night1/objects/MRK36_Blue_cr_f_t_w_e_fglobal.fits', # '/home/vital/Astrodata/WHT_2016_04/Night1/objects/MRK36_Red_cr_f_t_w_bg_e_fglobal.fits'] flux_calibrated = [ '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/objects/MRK36_A1/MRK36_A1_Blue_fglobal.fits', '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/objects/MRK36_A2/MRK36_A2_Blue_fglobal.fits', '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/objects/MRK36_A1/MRK36_A1_Red_fglobal.fits', '/home/vital/Dropbox/Astrophysics/Data/WHT_observations/objects/MRK36_A2/MRK36_A2_Red_fglobal.fits', ] for i in range(len(flux_calibrated)): # color = 'Blue' if 'Blue' in extracted_files[i] else 'Red' CodeName, FileName, FileFolder = dz.Analyze_Address(flux_calibrated[i]) wavelength, Flux_array, Header_0 = dz.get_spectra_data(flux_calibrated[i]) # for j in range(Header_0['NAXIS2']): # # color_plot = 'orangish' if j == 0 else 'dark blue' # dz.data_plot(wavelength, Flux_array[j], label = 'Apperture {} {}'.format(j, color), color=dz.colorVector[color_plot]) dz.data_plot(wavelength, Flux_array, label = FileName) dz.FigWording(r'Wavelength $(\AA)$', 'Flux ' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', 'MRK36') dz.display_fig()
for objName in catalogue_df.loc[dz.idx_include].index: local_refenrence = objName.replace('_','-') quick_reference = catalogue_df.loc[objName].quick_index print local_refenrence, '->', quick_reference ouput_folder = '{}{}/'.format(catalogue_dict['Obj_Folder'], objName) fits_file = catalogue_df.loc[objName].reduction_fits blue_fits = catalogue_df.loc[objName].Blue_file red_fits = catalogue_df.loc[objName].Red_file fits_file = catalogue_df.loc[objName].reduction_fits Wave_O, Int_O, ExtraData_T = dz.get_spectra_data(fits_file) Wave_B, Int_B, ExtraData_B = dz.get_spectra_data(blue_fits) Wave_R, Int_R, ExtraData_R = dz.get_spectra_data(red_fits) labels_format = 'SHOC579' if Wave_O[0] < 4000 else '8' line_wave = obj_lines[labels_format].values() line_label1 = obj_lines[labels_format].keys() plt.plot(Wave_O, Int_O/factor_norm) ax = plt.gca() if quick_reference == 'FTDTR-10': # ax.set_ylim(**format_plot[objName]['ylims']) ax.set_ylim(bottom=-1,top=150)
'{reduc_folder}objects/{calibStar}_Red_slit8.0_n.fits'.format( reduc_folder=catalogue_df.iloc[i].obsfolder, calibStar=calibration_star)): star_file = '{reduc_folder}objects/{calibStar}_Red_slit8.0_n.fits'.format( reduc_folder=catalogue_df.iloc[i].obsfolder, calibStar=calibration_star) else: star_file = '{reduc_folder}objects/{calibStar}_Red_slit1.0_n.fits'.format( reduc_folder=catalogue_df.iloc[i].obsfolder, calibStar=calibration_star) print #Spectra data wave_obs, flux_obs, header_0_obs = dz.get_spectra_data(fits_file, ext=0) wave_star, flux_star, header_0_star = dz.get_spectra_data(star_file, ext=0) print '---Telluric star', codeName, os.path.isfile(fits_file), len( flux_star.shape) if len(flux_star.shape) == 3: flux_star = flux_star[0][0] #Plot data dz.data_plot(wave_obs, flux_obs, label='Observed spectrum', linestyle='step', graph_axis=dz.ax1) dz.data_plot(wave_star,
#Locate the files objName = catalogue_df.iloc[i].name fits_file = catalogue_df.iloc[i].reduction_fits ouput_folder = '{}{}/'.format(catalogue_dict['Obj_Folder'], objName) lineslog_address = '{objfolder}{codeName}{lineslog_extension}'.format( objfolder=ouput_folder, codeName=objName, lineslog_extension=lineslog_extension) print '-- Treating {} @ {}'.format(objName, fits_file) #Load object data object_data = catalogue_df.iloc[i] lineslog_frame = dz.load_lineslog_frame(lineslog_address) Wave, Flux, ExtraData = dz.get_spectra_data(fits_file) #Load reddening curve for the lines lines_wavelengths = lineslog_frame.lambda_theo.values lines_Xx = dz.reddening_Xx(lines_wavelengths, red_curve, R_v) lines_f = dz.flambda_from_Xx(lines_Xx, red_curve, R_v) lineslog_frame['line_f'] = lines_f #Determine recombination coefficients for several combinations ratios_dict = dz.compare_RecombCoeffs(object_data, lineslog_frame) cHbeta_all_MagEr, n_all_MagEr = LinfitLinearRegression( ratios_dict['all_x'], ratios_dict['all_y']) trendline_all = cHbeta_all_MagEr * ratios_dict['all_x'] + n_all_MagEr cHbeta_in_MagEr, n_in_MagEr = LinfitLinearRegression( ratios_dict['in_x'], ratios_dict['in_y'])
#Joining pointing joining_wavelength = catalogue_df.iloc[i].join_wavelength #Treat each arm file for color in ['Blue', 'Red']: fits_file = catalogue_df.iloc[i]['z{}_file'.format(color)] print fits_file CodeName, FileName_Blue, FileFolder = dz.Analyze_Address(fits_file) wave, flux, ExtraData = dz.get_spectra_data(fits_file) dz.data_plot(wave, flux, label = '{} {} arm'.format(CodeName, color), color=color_dict[color]) idx_point = searchsorted(wave, joining_wavelength) if (wave[0] < joining_wavelength) and (joining_wavelength < wave[-1]): # dz.data_plot(wave[idx_point], flux[idx_point], label = 'Joining lambda {} $\AA$'.format(joining_wavelength), color=dz.colorVector['green'], markerstyle = 'o') dz.Axis.axvline(joining_wavelength, label = 'Joining lambda {} $\AA$'.format(joining_wavelength), color=dz.colorVector['green']) else: mean_continuum_flux = median(flux) #dz.data_plot(joining_wavelength, mean_continuum_flux, label = 'Joining lambda {} $\AA$'.format(joining_wavelength), color=dz.colorVector['green'], markerstyle = 'o') dz.Axis.axvline(joining_wavelength, label = 'Joining lambda {} $\AA$'.format(joining_wavelength), color=dz.colorVector['green']) mean_flux = median(flux) dz.Axis.set_ylim(mean_flux / 15, mean_flux * 10)
#Move the files to their folder for arm_color in ['Blue', 'Red']: for calibration in ['flocal', 'fglobal']: #Locate the file reduction_tag = 'flux_calibrated_objects_' + calibration idx_target = (dz.reducDf.frame_tag == target_object) & ( dz.reducDf.reduc_tag == reduction_tag) & ( dz.reducDf.ISIARM == '{color} arm'.format(color=arm_color)) fits_address = dz.reducDf.file_location[idx_target].values[ 0] + dz.reducDf.file_name[idx_target].values[0] #Get header wavelength, Flux_array, Header_0 = dz.get_spectra_data( fits_address) #Data to store night_obs = Header_0['DATE-OBS'] time_obs = pd.to_datetime('{}T{}'.format( night_obs, Header_0['UTSTART'])) appertures_n = int( Header_0['NAXIS2']) if 'NAXIS2' in Header_0 else 1 #Create one entry for each apperture for aperture in range(appertures_n): properties_dict = {} properties_dict['objcode'] = objcode properties_dict['obscode'] = obs properties_dict['obsfolder'] = data_folder
R_v = 3.4 red_curve = 'G03' cHbeta_type = 'cHbeta_reduc' #Loop through files for i in range(len(catalogue_df.index)): print '-- Treating {}'.format(catalogue_df.iloc[i].name) #Locate the objects objName = catalogue_df.iloc[i].name ouput_folder = '{}{}/'.format(catalogue_dict['Obj_Folder'], objName) fits_file = catalogue_df.iloc[i].reduction_fits #Get reduce spectrum data Wave_T, Int_T, ExtraData_T = dz.get_spectra_data(fits_file) Wave_N, Int_N, ExtraData_N = dz.get_spectra_data(ouput_folder + objName + nebular_exten) Wave_S, Int_S, ExtraData_S = dz.get_spectra_data(ouput_folder + objName + Stellar_ext) #Perform the reddening correction cHbeta = catalogue_df.iloc[i][cHbeta_type] Int_T_dered = dz.derreddening_spectrum(Wave_T, Int_T, reddening_curve=red_curve, cHbeta=cHbeta.nominal_value, R_v=R_v) #Increase the range of Wave_S so it is greater than the observational range Wave_StellarExtension = np.linspace(3000.0, 3399.0, 200)
key_codes, description, latex_format = loadtxt(format_file, dtype=str, delimiter=';', unpack=True) #Rows indeces and columns from the dataframe list_exported = list(OrderedDict.fromkeys(export_df.folder_code.values)) #trick to keep the order catalogue_df = pd.DataFrame(columns = key_codes) print list_exported for objcode in list_exported: #Data from arm for color in ['Blue', 'Red']: calibration = 'fglobal' file_address = '{root_folder}{obj_folder}/{code_obj}_{color}_{calib}.fits'.format(root_folder=objects_folder, obj_folder=objcode, code_obj=objcode, color=color, calib=calibration) wavelength, Flux_array, Header_0 = dz.get_spectra_data(file_address) catalogue_df.loc[objcode, 'calibration'] = calibration catalogue_df.loc[objcode, '{}_file'.format(color)] = file_address catalogue_df.loc[objcode, 'Wmin_{}'.format(color)] = wavelength[0] catalogue_df.loc[objcode, 'Wmax_{}'.format(color)] = wavelength[-1] catalogue_df.loc[objcode, '{}_Grating'.format(color)] = Header_0['ISIGRAT'] catalogue_df.loc[objcode, '{}_CENWAVE'.format(color)] = Header_0['CENWAVE'] #Data from night catalogue_df.loc[objcode, 'Dichroic'] = Header_0['ISIDICHR'] catalogue_df.loc[objcode, 'RA'] = Header_0['RA'] catalogue_df.loc[objcode, 'DEC'] = Header_0['DEC'] catalogue_df.loc[objcode, 'UT_OBS'] = pd.to_datetime('{}T{}'.format(Header_0['DATE-OBS'], Header_0['UTSTART'])) #Data from export
for i in range(len(catalogue_df.index)): #Object objName = catalogue_df.iloc[i].name #Joining pointing joining_wavelength = catalogue_df.iloc[i].join_wavelength #Treat each arm file blue_fits_file = catalogue_df.iloc[i]['zBlue_file'] red_fits_file = catalogue_df.iloc[i]['zRed_file'] CodeName_Blue, FileName_Blue, FileFolder_Blue = dz.Analyze_Address(blue_fits_file) CodeName_Red, FileName_Red, FileFolder_Red = dz.Analyze_Address(red_fits_file) wave_Blue, flux_Blue, ExtraData_Blue = dz.get_spectra_data(blue_fits_file) wave_Red, flux_Red, ExtraData_Red = dz.get_spectra_data(red_fits_file) idx_blue = searchsorted(wave_Blue, joining_wavelength) idx_red = searchsorted(wave_Red, joining_wavelength) wave_comb = concatenate([wave_Blue[0:idx_blue], wave_Red[idx_red:-1]]) flux_comb = concatenate([flux_Blue[0:idx_blue], flux_Red[idx_red:-1]]) dz.data_plot(wave_comb, flux_comb, label = '{} combined arms emission'.format(objName)) dz.FigWording(r'Wavelength $(\AA)$', 'Flux ' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', 'Redshift correction') #Store the figure output_pickle = FileFolder_Blue + script_code + '_' + CodeName_Blue + '_combined_emission' dz.save_manager(output_pickle, save_pickle = True)
#Locate the files ouput_folder = '{}{}/'.format(catalogue_dict['Obj_Folder'], objName) fits_reduc = catalogue_df.iloc[i].reduction_fits fits_emission = catalogue_df.iloc[i].stellar_fits fits_stellar = ouput_folder + objName + '_StellarContinuum.fits' lineslog_address = '{objfolder}{codeName}{lineslog_extension}'.format( objfolder=ouput_folder, codeName=objName, lineslog_extension=AbundancesFileExtension) if isfile(fits_stellar): # if i < 3: #Extract observational data wave_reduc, flux_reduc, header_0_reduc = dz.get_spectra_data( fits_reduc) wave_emis, flux_emis, header_emis = dz.get_spectra_data(fits_emission) wave_stellar, flux_stellar, header_stellar = dz.get_spectra_data( fits_stellar) reduc_lineslog_df = dz.load_lineslog_frame(lineslog_address) #Perform the reddening correction cHbeta = catalogue_df.iloc[i][cHbeta_type] dz.deredden_lines(cHbeta, reduc_lineslog_df) #Measure Hbeta flux Hbeta_wavelengths = reduc_lineslog_df.loc[ 'H1_4861A', ['Wave1', 'Wave2', 'Wave3', 'Wave4', 'Wave5', 'Wave6']].values Hbeta_dist = random.normal( reduc_lineslog_df.loc['H1_4861A'].line_Int.nominal_value,
#Load catalogue dataframe catalogue_dict = dz.import_catalogue() catalogue_df = dz.load_excel_DF('/home/vital/Dropbox/Astrophysics/Data/WHT_observations/WHT_Galaxies_properties.xlsx') lickIndcs_ext = '_lick_indeces.txt' ouput_folder = '{}{}/'.format(catalogue_dict['Obj_Folder'], objName) lick_idcs_df = read_csv(ouput_folder + objName + lickIndcs_ext, delim_whitespace = True, header = 0, index_col = 0, comment='L') #Dirty trick to avoid the Line_label row #Define fits file: ratios_dict = {} for extension in [0, 1]: fits_file = '/home/vital/Astrodata/WHT_2016_04/Night1/objects/IZW18_Red_cr_f_t_w_e_{testing_extension}_fglobal.fits'.format(testing_extension=dz_sr.testing_extension) #fits_file = '/home/vital/Astrodata/WHT_2016_04/Night1/objects/IZW18_Red_cr_f_t_w_bg_e_fglobal.fits' redshift_factor = 1 + catalogue_df.loc[objName].z_Red wave_obs, flux_obs, header_0_obs = dz.get_spectra_data(fits_file) wave = wave_obs / redshift_factor flux = flux_obs[extension] for line in S3_lines: dz.Current_Label = lick_idcs_df.loc[line].name dz.Current_Ion = lick_idcs_df.loc[line].Ion dz.Current_TheoLoc = lick_idcs_df.loc[line].lambda_theo selections = lick_idcs_df.loc[line][3:9].values #Proceed to measure line_data = dz.measure_line(wave, flux, selections, None, Measuring_Method = 'MC_lmfit', store_data = False) entry_key = '{}_ext{}'.format(line, extension) ratios_dict[entry_key] = ufloat(line_data.flux_intg, line_data.flux_intg_er)
for i in range(len(catalogue_df.index)): print "-- Treating {} @ {}".format(catalogue_df.iloc[i].name, AbundancesFileExtension) try: # Locate the objects objName = catalogue_df.iloc[i].name ouput_folder = "{}{}/".format(catalogue_dict["Obj_Folder"], objName) fits_file = catalogue_df.iloc[i].reduction_fits lineslog_address = "{objfolder}{codeName}{lineslog_extension}".format( objfolder=ouput_folder, codeName=objName, lineslog_extension=AbundancesFileExtension ) # Load object data lineslog_frame = dz.load_lineslog_frame(lineslog_address) wave, flux, header_0 = dz.get_spectra_data(fits_file) # Perform the reddening correction cHbeta = catalogue_df.iloc[i][cHbeta_type] dz.deredden_lines(cHbeta, lineslog_frame) spectrum_dered = dz.derreddening_continuum(wave, flux, cHbeta.nominal_value) # Import cHbeta coefficient # Te = catalogue_df.iloc[i].TeSIII if notnull(catalogue_df.iloc[i].TeSIII) else 10000.0 # nHeII_HII = catalogue_df.iloc[i].HeII_HII_from_S if notnull(catalogue_df.iloc[i].HeII_HII_from_S) else 0.1 # nHeIII_HII = catalogue_df.iloc[i].HeIII_HII_from_S if notnull(catalogue_df.iloc[i].HeIII_HII_from_S) else 0.0 # Hbeta_Flux = lineslog_frame.loc['H1_4861A', 'line_Int'] # Halpha_Flux = lineslog_frame.loc['H1_6563A', 'line_Int'] Te = 10000.0 nHeII_HII = 0.1
objectNewFolder = rootOutput + objName + '/' plotFolder = '{}input_data/'.format(objectNewFolder) plotAddress = '{}{}_lineGrid'.format(plotFolder, objName) fitsAddress = '{}{}_WHT.fits'.format(oldFolder, objName) objLogAddress = '{}{}_objParams.txt'.format(objectNewFolder, objName) lineslog_address = '{}{}{}'.format(oldFolder, objName, lineslog_ext) masksLogAddress = '{}{}{}'.format(oldFolder, objName, masklog_ext) newsLinesLogAddress = '{}{}_linesLog.txt'.format(objectNewFolder, objName) newsSpectrumAddress = '{}{}_WHT.txt'.format(objectNewFolder, objName) # Create folders make_folder(plotFolder) make_folder(objectNewFolder) # Get fits data wave, flux, etraData = dz.get_spectra_data(fitsAddress) # Get lines log data linesLogDf = dz.load_lineslog_frame(lineslog_address) linesLogDf.rename(columns=lineslogDfNewHeaders, inplace=True) linesLogDf.rename(index=lineslogDfNewIndeces, inplace=True) # Generate a grid plot and add continuum contribution in recombination lines lineFluxes = linesLogDf['line_Flux'].values linesLogDf['obs_flux'], linesLogDf['obs_fluxErr'] = nominal_values(lineFluxes), std_devs(lineFluxes) # WARNING this is a dangerous function bp.linesGrid(linesLogDf, wave, flux, plotAddress) linesLogDf['line_Flux'] = nominal_values(lineFluxes) # Compute O2_7319A_b flux
#Reddening properties R_v = 3.4 red_curve = 'G03' cHbeta_type = 'cHbeta_emis' #Loop through files for i in range(len(catalogue_df.index)): #Locate the objects objName = catalogue_df.iloc[i].name ouput_folder = '{}{}/'.format(catalogue_dict['Obj_Folder'], objName) fits_file = catalogue_df.iloc[i].reduction_fits nebular_fits = ouput_folder + objName + nebular_fits_exten Wave_T, Int_T, header_T = dz.get_spectra_data(fits_file) Wave_N, Int_N, header_T = dz.get_spectra_data(ouput_folder + objName + nebular_fits_exten) #Perform the reddening correction cHbeta = catalogue_df.iloc[i][cHbeta_type] Obs_spectrum_dered = dz.derreddening_spectrum(Wave_T, Int_T, reddening_curve=red_curve, cHbeta=cHbeta.nominal_value, R_v=R_v) spectrum_dered = Obs_spectrum_dered - Int_N #Generating the starlight files FileName = basename(fits_file) + stellar_files_exten Grid_FileName, Sl_OutputFile, Sl_OutputFolder, X_1Angs, Y_1Angs = dz.GenerateStarlightFiles(
#Define plot frame and colors dz.FigConf() #Locate the objects objName = 'SHOC579' ouput_folder = '{}{}/'.format(catalogue_dict['Obj_Folder'], objName) fits_file = catalogue_df.loc[objName].reduction_fits lineslog_address = '{objfolder}{codeName}{lineslog_extension}'.format( objfolder=ouput_folder, codeName=objName, lineslog_extension=AbundancesFileExtension) #Load object data object_data = catalogue_df.loc[objName] lineslog_frame = dz.load_lineslog_frame(lineslog_address) wave, flux, header_0 = dz.get_spectra_data(fits_file) wave_E, flux_E, header_E = dz.get_spectra_data( catalogue_df.loc[objName].emission_fits) #Perform the reddening correction cHbeta = catalogue_df.loc[objName, cHbeta_type] dz.deredden_lines(lineslog_frame, reddening_curve=red_curve, cHbeta=cHbeta, R_v=R_v) spectrum_dered = dz.derreddening_spectrum(wave, flux, reddening_curve=red_curve, cHbeta=cHbeta.nominal_value, R_v=R_v) Int_E = dz.derreddening_spectrum(wave_E,
print "\n-- Treating {} @ {}".format(catalogue_df.iloc[i].name, catalogue_df.iloc[i].Red_file) codeName = catalogue_df.iloc[i].name fits_file = catalogue_df.iloc[i].Red_file ouput_folder = "{}{}/".format(catalogue_dict["Obj_Folder"], codeName) if codeName is not "coso": # if codeName == '8': # Get object objName = codeName.translate(None, "[]") redshift_factor = 1 + catalogue_df.iloc[i].z_Red # Spectrum data wave_obs, flux_obs, header_0_obs = dz.get_spectra_data(fits_file) lick_idcs_df = read_csv( ouput_folder + codeName + lickIndcs_extension, delim_whitespace=True, header=0, index_col=0, comment="L" ) # Dirty trick to avoid the Line_label row wave_join, wave_max = catalogue_df.loc[codeName].join_wavelength, catalogue_df.loc[codeName].Wmax_Red idx_obj_join, idx_obj_max_Red = searchsorted(wave_obs, [wave_join, wave_max]) len_red_region = idx_obj_max_Red - idx_obj_join # Load reduction dataframe reduction_folder = catalogue_df.loc[codeName].obsfolder dz.declare_catalogue(reduction_folder, verbose=False) # Load telluric star files idcs_stars = dz.reducDf.reduc_tag == "norm_narrow" Files_Folders = dz.reducDf.loc[idcs_stars, "file_location"].values Files_Names = dz.reducDf.loc[idcs_stars, "file_name"].values
if objName == 'SHOC579': #Joining pointing joining_wavelength = catalogue_df.iloc[i].join_wavelength #Treat each arm file blue_fits_file = catalogue_df.iloc[i]['zBlue_file'] red_fits_file = catalogue_df.iloc[i]['zRed_file'] CodeName_Blue, FileName_Blue, FileFolder_Blue = dz.Analyze_Address( blue_fits_file) CodeName_Red, FileName_Red, FileFolder_Red = dz.Analyze_Address( red_fits_file) wave_Blue, flux_Blue, ExtraData_Blue = dz.get_spectra_data( blue_fits_file) wave_Red, flux_Red, ExtraData_Red = dz.get_spectra_data(red_fits_file) idx_blue = searchsorted(wave_Blue, joining_wavelength) idx_red = searchsorted(wave_Red, joining_wavelength) wave_comb = concatenate([wave_Blue[0:idx_blue], wave_Red[idx_red:-1]]) flux_comb = concatenate([flux_Blue[0:idx_blue], flux_Red[idx_red:-1]]) dz.data_plot(wave_Blue, flux_Blue, label='Blue arm') dz.data_plot(wave_Red, flux_Red, label='Red arm') dz.FigWording(r'Wavelength $(\AA)$', 'Flux ' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', '', ncols_leg=2)
cHbeta_type = 'cHbeta_reduc' nebular_fits_exten = '_NebularContinuum.fits' #Generate plot frame and colors dz.FigConf() #Loop through files for i in range(len(catalogue_df.index)): #Locate the objects objName = catalogue_df.iloc[i].name ouput_folder = '{}{}/'.format(catalogue_dict['Obj_Folder'], objName) fits_file = catalogue_df.iloc[i].reduction_fits nebular_fits = ouput_folder + objName + nebular_fits_exten Wave_T, Int_T, header_T = dz.get_spectra_data(fits_file) Wave_N, Int_N, header_T = dz.get_spectra_data(ouput_folder + objName + nebular_fits_exten) #Perform the reddening correction cHbeta = catalogue_df.iloc[i][cHbeta_type] spectrum_dered = dz.derreddening_continuum(Wave_T, Int_T - Int_N, cHbeta.nominal_value) #Generating the starlight files FileName = basename(fits_file) Grid_FileName, Sl_OutputFile, Sl_OutputFolder, X_1Angs, Y_1Angs = dz.GenerateStarlightFiles(ouput_folder, FileName, objName, catalogue_df.iloc[i], Wave_T, spectrum_dered) print '--Output file ', Sl_OutputFile #Plot the data dz.data_plot(Wave_T, spectrum_dered, "Reduced spectrum") dz.data_plot(X_1Angs, Y_1Angs, "Resampled spectrum", linestyle='--')
objName = catalogue_df.iloc[i].name print 'Treating object: ', objName #Locate the files ouput_folder = '{}{}/'.format(catalogue_dict['Obj_Folder'], objName) fits_reduc = catalogue_df.iloc[i].reduction_fits fits_emission = catalogue_df.iloc[i].stellar_fits fits_stellar = ouput_folder + objName + '_StellarContinuum.fits' lineslog_address = '{objfolder}{codeName}{lineslog_extension}'.format(objfolder = ouput_folder, codeName=objName, lineslog_extension=AbundancesFileExtension) if isfile(fits_stellar): # if i < 3: #Extract observational data wave_reduc, flux_reduc, header_0_reduc = dz.get_spectra_data(fits_reduc) wave_emis, flux_emis, header_emis = dz.get_spectra_data(fits_emission) wave_stellar, flux_stellar, header_stellar = dz.get_spectra_data(fits_stellar) reduc_lineslog_df = dz.load_lineslog_frame(lineslog_address) #Perform the reddening correction cHbeta = catalogue_df.iloc[i][cHbeta_type] dz.deredden_lines(cHbeta, reduc_lineslog_df) #Measure Hbeta flux Hbeta_wavelengths = reduc_lineslog_df.loc['H1_4861A', ['Wave1', 'Wave2', 'Wave3', 'Wave4', 'Wave5', 'Wave6']].values Hbeta_dist = random.normal(reduc_lineslog_df.loc['H1_4861A'].line_Int.nominal_value, reduc_lineslog_df.loc['H1_4861A'].line_Int.std_dev, MC_length) #Insert new section in pdf with dz.pdfDoc.create(Section('HII Galaxy: {}'.format(objName))):
CodeName, FileName, FileFolder = dz.Analyze_Address(fits_file) #IRAF task configuration dz.task_attributes['run folder'] = FileFolder dz.task_attributes['color'] = color dz.task_attributes['input'] = fits_file dz.task_attributes['output'] = z_fits_file dz.task_attributes['redshift'] = redshift dz.task_attributes['flux'] = 'yes' dz.run_iraf_task('dopcor') #Store file address in dataframe catalogue_df.iloc[i]['z{}_file'.format(color)] = z_fits_file #Load spectrum wave, flux, ExtraData = dz.get_spectra_data(fits_file) wave_z, flux_z, ExtraData_z = dz.get_spectra_data(z_fits_file) dz.data_plot(wave, flux, label = '{} {} arm'.format(CodeName, color)) dz.data_plot(wave_z, flux_z, label = '{} {} arm redshift corrected'.format(CodeName,color)) #Wording for the figure dz.FigWording(r'Wavelength $(\AA)$', 'Flux ' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', 'Redshift correction') #Store the figure output_address = FileFolder + script_code + '_' + CodeName + '_RedShiftCorrection' dz.save_manager(output_address, save_pickle = True) dz.save_dataframe(catalogue_df, catalogue_dict['dataframe']) print 'Data treated'
#Object objName = catalogue_df.loc[objName].name fits_file = objName + fits_file_Ext ouput_folder = '{}{}/'.format(catalogue_dict['Obj_Folder'], objName) #Output lines log dataframe lineslog_df = pd.DataFrame(columns=dz.saving_parameters_list) lines_log_address = ouput_folder + objName + lineslog_extension print '\n-- Treating {} @ {}'.format( objName, fits_file), catalogue_df.index.get_loc(objName), '/', n_objects #Spectrum data wave, flux, header_0 = dz.get_spectra_data(ouput_folder + fits_file) lick_idcs_df = pd.read_csv( ouput_folder + objName + lickIndcs_extension, delim_whitespace=True, header=0, index_col=0, comment='L') #Dirty trick to avoid the Line_label row #Start to loop through recorded line for i in range(len(lick_idcs_df.index)): try: print '-- Treating line:', lick_idcs_df.iloc[i].name
#Loop through files for i in range(len(catalogue_df.index)): print '-- Treating {}'.format(catalogue_df.iloc[i].name) #Locate the objects objName = catalogue_df.iloc[i].name if objName == 'SHOC579': ouput_folder = '{}{}/'.format(catalogue_dict['Obj_Folder'], objName) fits_file = catalogue_df.iloc[i].reduction_fits #Get reduce spectrum data Wave_O, Int_O, ExtraData_T = dz.get_spectra_data(fits_file) Wave_N, Int_N, ExtraData_N = dz.get_spectra_data(ouput_folder + objName + nebular_exten) Wave_S, Int_S, ExtraData_S = dz.get_spectra_data(ouput_folder + objName + Stellar_ext) Wave_E, Int_E, ExtraData_E = dz.get_spectra_data(ouput_folder + objName + emitting_ext) #Increase the range of Wave_S so it is greater than the observational range Wave_StellarExtension = linspace(3000.0, 3399.0, 200) Int_StellarExtension = zeros(len(Wave_StellarExtension)) #Increase the range of Wave_S so it is greater than the observational range Int_S = hstack((Int_StellarExtension, Int_S))
z_fits_file = fits_file.replace('.fits', '_z.fits') #IRAF task configuration dz_reduc.task_attributes['run folder'] = FileFolder dz_reduc.task_attributes['color'] = color dz_reduc.task_attributes['input'] = fits_file dz_reduc.task_attributes['output'] = z_fits_file dz_reduc.task_attributes['redshift'] = redshift dz_reduc.task_attributes['flux'] = 'yes' dz_reduc.run_iraf_task('dopcor') #Store file address in dataframe catalogue_df.loc[CodeName, 'z{}_file'.format(color)] = z_fits_file #Load spectrum wave, flux, ExtraData = dz.get_spectra_data(fits_file) wave_z, flux_z, ExtraData_z = dz.get_spectra_data(z_fits_file) dz.data_plot(wave, flux, label='{} {} arm'.format(CodeName, color)) dz.data_plot(wave_z, flux_z, label='{} {} arm redshift corrected'.format( CodeName, color)) #Wording for the figure dz.FigWording(r'Wavelength $(\AA)$', 'Flux ' + r'$(erg\,cm^{-2} s^{-1} \AA^{-1})$', 'Redshift correction') #Store the figure output_address = FileFolder + script_code + '_' + CodeName + '_RedShiftCorrection'
dz.observation_dict = dz.load_observation_dict(data_folder + 'observation_properties.txt') #Move the objects for target_object in dz.observation_dict['objects']: code_name = target_object.translate(None, "[]") #Move the files to their folder for arm_color in ['Blue', 'Red']: for calibration in ['flocal', 'fglobal']: reduction_tag = 'flux_calibrated_objects_' + calibration idx_target = (dz.reducDf.frame_tag == target_object) & (dz.reducDf.reduc_tag == reduction_tag) & (dz.reducDf.ISIARM == '{color} arm'.format(color = arm_color)) fits_address = dz.reducDf.file_location[idx_target].values[0] + dz.reducDf.file_name[idx_target].values[0] wavelength, Flux_array, Header_0 = dz.get_spectra_data(fits_address) if 'NAXIS2' in Header_0: appertures_n = int(Header_0['NAXIS2']) else: appertures_n = 1 night_obs = Header_0['DATE-OBS'] time_obs = pd.to_datetime('{}T{}'.format(night_obs, Header_0['UTSTART'])) if (night_obs == '2011-12-02') and (code_name == '4'): #Trick in for observations which are set to a new night night_obs = '2011-12-01' for aperture in range(appertures_n): properties_dict = OrderedDict().fromkeys(catalogue_colums)
failing_objects = [] for objName in catalogue_df.loc[dz.idx_include].index: # Article reference quick_reference = catalogue_df.loc[objName].quick_index print objName, (quick_reference) # Object folder oldFolder = '{}{}/'.format(catalogue_dict['Obj_Folder'], objName) objectNewFolder = root_folder + objName + '/' make_folder(objectNewFolder) # Get fits data fits_file = catalogue_df.loc[objName].reduction_fits wave, flux, etraData = dz.get_spectra_data(fits_file) # Get lines log data lineslog_address = '{}{}{}'.format(oldFolder,objName,lineslog_ext) linesLogDf = dz.load_lineslog_frame(lineslog_address) linesLogDf.rename(columns=lineslogDfNewHeaders, inplace=True) linesLogDf.rename(index=lineslogDfNewIndeces, inplace=True) # Generate a grid plot and add continuum contribution in recombination lines lineFluxes = linesLogDf['line_Flux'].values linesLogDf['obs_flux'], linesLogDf['obs_fluxErr'] = nominal_values(lineFluxes), std_devs(lineFluxes) plotFolder = '{}/input_data/'.format(objectNewFolder) make_folder(plotFolder) plotAddress = '{}{}_lineGrid'.format(plotFolder, objName) bp.linesGrid(linesLogDf, wave, flux, plotAddress)
lickIndcs_extension = '_lick_indeces.txt' #Declare object to treat objName = 'SHOC575_n2' #Load line regions ouput_folder = '{}{}/'.format(catalogue_dict['Obj_Folder'], objName) lick_idcs_df = read_csv(ouput_folder + objName + lickIndcs_extension, delim_whitespace=True, header=0, index_col=0, comment='L') #Dirty trick to avoid the Line_label row #Load spectrum data fits_file = catalogue_df.loc[objName].emission_fits wave, flux, header_0 = dz.get_spectra_data(fits_file) #Declare line to measure line = 'S3_9069A' #Establish current line lm.Current_Label = lick_idcs_df.loc[line].name lm.Current_Ion = lick_idcs_df.loc[line].Ion lm.Current_TheoLoc = lick_idcs_df.loc[line].lambda_theo selections = lick_idcs_df.loc[line][3:9].values #Proceed to measure start = timer() line_data = lm.measure_line(wave, flux, selections,
dz.FigConf() #Loop through files for i in range(len(catalogue_df.index)): try: print '-- Treating {}'.format(catalogue_df.iloc[i].name) #Locate the objects objName = catalogue_df.iloc[i].name ouput_folder = '{}{}/'.format(catalogue_dict['Obj_Folder'], objName) fits_file = catalogue_df.iloc[i].reduction_fits #Get reduce spectrum data Wave_T, Int_T, ExtraData_T = dz.get_spectra_data(fits_file) Wave_N, Int_N, ExtraData_N = dz.get_spectra_data(ouput_folder + objName + nebular_exten) Wave_S, Int_S, ExtraData_S = dz.get_spectra_data(ouput_folder + objName + Stellar_ext) #Increase the range of Wave_S so it is greater than the observational range Wave_StellarExtension = np.linspace(3000.0,3399.0,200) Int_StellarExtension = np.zeros(len(Wave_StellarExtension)) #Increase the range of Wave_S so it is greater than the observational range Int_S = np.hstack((Int_StellarExtension, Int_S)) Wave_S = np.hstack((Wave_StellarExtension, Wave_S)) #Resampling stellar spectra Interpolation = interp1d(Wave_S, Int_S, kind = 'slinear') Int_Stellar_Resampled = Interpolation(Wave_T)