From 31655b483aa35294e676799d84810e04feee2f80 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sat, 8 Feb 2020 22:06:58 -0700 Subject: [PATCH 01/42] analysis: Add composite_indv_detect module, starting from Zcalbase_gal version (iss #21) --- .../analysis/composite_indv_detect.py | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 Metallicity_Stack_Commons/analysis/composite_indv_detect.py diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py new file mode 100644 index 0000000..18ba17c --- /dev/null +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -0,0 +1,116 @@ +import numpy as np +from astropy.io import ascii as asc +from astropy.table import vstack +from astropy.table import Table +import glob + +from ..temp_metallicity_calc import metallicity_calculation + +def run_ind_detection(fitspath, dataset, average_value_ascii): + N_gal_tab = asc.read(average_value_ascii) + ID = N_gal_tab['ID'] + for aa in range(len(ID)): + ind_detection(fitspath, dataset, ID[aa]) + new_name = fitspath + 'Individual_ratio_temperature.tbl' + vertical_stacking(fitspath, dataset, new_name) + print('run complete') + + +def ind_detection(fitspath, dataset, bin_id): + get_det3_tab = asc.read(fitspath + 'get_det3_table2.tbl') + bin_tab = asc.read(fitspath + dataset + '_2d_binning_datadet3.tbl') + N_gal_tab = asc.read(fitspath + dataset + '_Average_R23_O32_Values.tbl') + stackmeas_tab = asc.read(fitspath + dataset + '_temperatures_metalicity.tbl') + + # From tables + Source_id = get_det3_tab['Individual_IDs'] + O4959 = get_det3_tab['O4959'] + O5007 = get_det3_tab['O5007'] + Bin_number = bin_tab['Bin_number'] + O2 = get_det3_tab['O2'] + O3 = get_det3_tab['O3'] + Hb = get_det3_tab['Hb'] + N_Galaxies = N_gal_tab['N_Galaxies'] + temp_bin = stackmeas_tab['Temperature'] + + R23 = get_det3_tab['R23'] + O32 = get_det3_tab['O32'] + + # Initializing Arrays + + Source_IDs = [] + Bin_ID = [] + two_beta = [] + three_beta = [] + OIII4959 = [] + OIII5007 = [] + HBeta = [] + average_temp = [] + R23_ind = [] + O32_ind = [] + + for ii in range(len(O2)): + if Bin_number[ii] == bin_id: + # print 'Bin_number:', Bin_number[ii], 'O2:', O2[ii], 'O3:', O3[ii], 'Hb:', Hb[ii] + Source_ID.append(Source_id[ii]) + Bin_ID.append(bin_id) + R23_ind.append(R23[ii]) + O32_ind.append(O32[ii]) + two_beta.append(O2[ii] / Hb[ii]) + three_beta.append(O3[ii] / Hb[ii]) + OIII4959.append(O4959[ii]) + OIII5007.append(O5007[ii]) + HBeta.append(Hb[ii]) + average_temp.append(temp_bin[bin_id]) + + individual_ascii = '/Users/reagenleimbach/Desktop/Zcalbase_gal/individual_detection/' + str( + bin_id) + '_individual_ratios_temp.tbl' + n = ('Source_ID', 'Bin_ID', 'Individual_R23', 'Individual_O32', 'two_beta', 'three_beta', 'OIII4959', 'OIII5007', + 'HBeta', 'Temperature') # 'ID', 'R23_Average', 'O32_Average' + ind_tab = Table( + [Source_ID, Bin_ID, R23_ind, O32_ind, two_beta, three_beta, OIII4959, OIII5007, HBeta, average_temp], + names=n) # ID, R23, O32, + asc.write(ind_tab, individual_ascii, format='fixed_width_two_line') + + +def individual_galaxy_table_stacking(fitspath, dataset, new_name): + individual_ascii = '/Users/reagenleimbach/Desktop/Zcalbase_gal/individual_detection/*_individual_ratios_temp.tbl' + table_files = glob.glob(individual_ascii) + table_files.sort() + + for ii in range(len(table_files)): + asc_tab = asc.read(table_files[ii]) + if ii == 0: + vstacking = asc_tab + else: + vstacking = vstack([vstacking, asc_tab]) + asc.write(vstacking, new_name, format='fixed_width_two_line', overwrite=True) + + +######NOT USING######### +def ind_metalicity_calculation(T_e, der_3727_HBETA, der_4959_HBETA, der_5007_HBETA, OIII5007, OIII4959, OIII4363, HBETA, + OII3727, dustatt=False): + # 12 +log(O+/H) = log(OII/Hb) +5.961 +1.676/t_2 - 0.4logt_2 - 0.034t_2 + log(1+1.35x) + # 12 +log(O++/H) = log(OIII/Hb)+6.200+1.251/t_3 - 0.55log(t_3) - 0.014(t_3) + # t_2 = 0.7*t_3 +0.17 + + if dustatt == False: + two_beta = OII3727 / HBETA + three_beta = (OIII4959 + OIII5007) / HBETA + else: + two_beta = der_3727_HBETA + three_beta = der_4959_HBETA + der_5007_HBETA + t_3 = T_e * 1e-4 + t_2 = 0.7 * t_3 + 0.17 + x2 = 1e-4 * 1e3 * t_2 ** (-0.5) + + O_s_ion_log = np.log10(two_beta) + 5.961 + 1.676 / t_2 - 0.4 * np.log10(t_2) - 0.034 * t_2 + np.log10( + 1 + 1.35 * x2) - 12 + O_d_ion_log = np.log10(three_beta) + 6.200 + 1.251 / t_3 - 0.55 * np.log10(t_3) - 0.014 * (t_3) - 12 + + O_s_ion = 10 ** (O_s_ion_log) + O_d_ion = 10 ** (O_d_ion_log) + com_O = O_s_ion + O_d_ion + com_O_log = np.log10(com_O) + 12 + + return O_s_ion, O_d_ion, com_O_log, O_s_ion_log, O_d_ion_log \ No newline at end of file From 447fbf5602b3b0ba64d65ee2a6c5ab1435ec522b Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 9 Feb 2020 13:29:04 -0700 Subject: [PATCH 02/42] analysis.composite_indv_detect: Remove unused codes (iss #21) --- .../analysis/composite_indv_detect.py | 32 ++----------------- 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index 18ba17c..aff5995 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -1,4 +1,3 @@ -import numpy as np from astropy.io import ascii as asc from astropy.table import vstack from astropy.table import Table @@ -6,7 +5,9 @@ from ..temp_metallicity_calc import metallicity_calculation + def run_ind_detection(fitspath, dataset, average_value_ascii): + N_gal_tab = asc.read(average_value_ascii) ID = N_gal_tab['ID'] for aa in range(len(ID)): @@ -85,32 +86,3 @@ def individual_galaxy_table_stacking(fitspath, dataset, new_name): else: vstacking = vstack([vstacking, asc_tab]) asc.write(vstacking, new_name, format='fixed_width_two_line', overwrite=True) - - -######NOT USING######### -def ind_metalicity_calculation(T_e, der_3727_HBETA, der_4959_HBETA, der_5007_HBETA, OIII5007, OIII4959, OIII4363, HBETA, - OII3727, dustatt=False): - # 12 +log(O+/H) = log(OII/Hb) +5.961 +1.676/t_2 - 0.4logt_2 - 0.034t_2 + log(1+1.35x) - # 12 +log(O++/H) = log(OIII/Hb)+6.200+1.251/t_3 - 0.55log(t_3) - 0.014(t_3) - # t_2 = 0.7*t_3 +0.17 - - if dustatt == False: - two_beta = OII3727 / HBETA - three_beta = (OIII4959 + OIII5007) / HBETA - else: - two_beta = der_3727_HBETA - three_beta = der_4959_HBETA + der_5007_HBETA - t_3 = T_e * 1e-4 - t_2 = 0.7 * t_3 + 0.17 - x2 = 1e-4 * 1e3 * t_2 ** (-0.5) - - O_s_ion_log = np.log10(two_beta) + 5.961 + 1.676 / t_2 - 0.4 * np.log10(t_2) - 0.034 * t_2 + np.log10( - 1 + 1.35 * x2) - 12 - O_d_ion_log = np.log10(three_beta) + 6.200 + 1.251 / t_3 - 0.55 * np.log10(t_3) - 0.014 * (t_3) - 12 - - O_s_ion = 10 ** (O_s_ion_log) - O_d_ion = 10 ** (O_d_ion_log) - com_O = O_s_ion + O_d_ion - com_O_log = np.log10(com_O) + 12 - - return O_s_ion, O_d_ion, com_O_log, O_s_ion_log, O_d_ion_log \ No newline at end of file From a38519d187a01e65d4974ecb8803d131fb7f8254 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 9 Feb 2020 13:31:18 -0700 Subject: [PATCH 03/42] analysis.composite_indv_detect: Create main function (iss #21) --- .../analysis/composite_indv_detect.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index aff5995..6a31ed0 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -6,6 +6,29 @@ from ..temp_metallicity_calc import metallicity_calculation +def main(fitspath, dataset, composite_file): + """ + Purpose: + Reads in composite table(s) containing bin information to + determine temperature-based metallicity from composite average + T_e and individual line ratios ([OII]/H-beta, [OIII]/H-beta) + + :param fitspath: + :param dataset: + :param average_value_ascii: + :return: + """ + + # Read in composite table + composite_table = asc.read(composite_file) + ID = composite_table['ID'].data + + det3_table = asc.read(fitspath + 'get_det3_table2.tbl') + bin_table = asc.read(fitspath + dataset + '_2d_binning_datadet3.tbl') + average_table = asc.read(fitspath + dataset + '_Average_R23_O32_Values.tbl') + stack_table = asc.read(fitspath + dataset + '_temperatures_metalicity.tbl') + + def run_ind_detection(fitspath, dataset, average_value_ascii): N_gal_tab = asc.read(average_value_ascii) From 3fa2c71fcca656db54ee616a02eca440430e2c40 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 9 Feb 2020 13:37:31 -0700 Subject: [PATCH 04/42] analysis.composite_indv_detect: Update docstrings for main() (iss #21) --- .../analysis/composite_indv_detect.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index 6a31ed0..5ca3775 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -13,10 +13,11 @@ def main(fitspath, dataset, composite_file): determine temperature-based metallicity from composite average T_e and individual line ratios ([OII]/H-beta, [OIII]/H-beta) - :param fitspath: - :param dataset: - :param average_value_ascii: - :return: + :param fitspath: str containing folder path + :param dataset: str containing sub-folder (specific to stacking approach) + :param composite_file: str containing filename of composite data + + :return: TBD """ # Read in composite table From 16673138804ad6e6629dbd323911d436b066d883 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 9 Feb 2020 13:43:09 -0700 Subject: [PATCH 05/42] analysis.composite_indv_detect: Use os.path.join (iss #21) --- .../analysis/composite_indv_detect.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index 5ca3775..40ce8f2 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -1,3 +1,5 @@ +from os.path import join + from astropy.io import ascii as asc from astropy.table import vstack from astropy.table import Table @@ -24,10 +26,11 @@ def main(fitspath, dataset, composite_file): composite_table = asc.read(composite_file) ID = composite_table['ID'].data - det3_table = asc.read(fitspath + 'get_det3_table2.tbl') - bin_table = asc.read(fitspath + dataset + '_2d_binning_datadet3.tbl') - average_table = asc.read(fitspath + dataset + '_Average_R23_O32_Values.tbl') - stack_table = asc.read(fitspath + dataset + '_temperatures_metalicity.tbl') + # Read in tables containing line ratios, bins, etc. + det3_table = asc.read(join(fitspath, 'get_det3_table2.tbl')) + bin_table = asc.read(join(fitspath, dataset+'_2d_binning_datadet3.tbl')) + average_table = asc.read(join(fitspath, dataset+'_Average_R23_O32_Values.tbl')) + stack_table = asc.read(join(fitspath, dataset+'_temperatures_metallicity.tbl')) def run_ind_detection(fitspath, dataset, average_value_ascii): From fb8fcd625c88b9bcd90b9206b77f7c786fde5b0c Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 9 Feb 2020 13:50:52 -0700 Subject: [PATCH 06/42] analysis.composite_indv_detect: Define variables (iss #21) --- .../analysis/composite_indv_detect.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index 40ce8f2..ed0b96a 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -32,6 +32,16 @@ def main(fitspath, dataset, composite_file): average_table = asc.read(join(fitspath, dataset+'_Average_R23_O32_Values.tbl')) stack_table = asc.read(join(fitspath, dataset+'_temperatures_metallicity.tbl')) + # Note: Need to update one of the above tables to contain temperature? and metallicity + + bin_no = bin_table['Bin_number'].data + + source_id = det3_table['Individual_IDs'].data + O2 = det3_table['O2'].data + O3 = det3_table['O3'].data + Hb = det3_table['Hb'].data + temp_bin = stackmeas_tab['Temperature'].data + def run_ind_detection(fitspath, dataset, average_value_ascii): From 7860e99d6d4c8914aa7da980b1d759e2b6fec8ea Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 9 Feb 2020 13:52:19 -0700 Subject: [PATCH 07/42] analysis.composite_indv_detect.main: Remove unused files (iss #21) --- Metallicity_Stack_Commons/analysis/composite_indv_detect.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index ed0b96a..bba9c5f 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -29,8 +29,10 @@ def main(fitspath, dataset, composite_file): # Read in tables containing line ratios, bins, etc. det3_table = asc.read(join(fitspath, 'get_det3_table2.tbl')) bin_table = asc.read(join(fitspath, dataset+'_2d_binning_datadet3.tbl')) - average_table = asc.read(join(fitspath, dataset+'_Average_R23_O32_Values.tbl')) - stack_table = asc.read(join(fitspath, dataset+'_temperatures_metallicity.tbl')) + + # Not used for now + # average_table = asc.read(join(fitspath, dataset+'_Average_R23_O32_Values.tbl')) + # stack_table = asc.read(join(fitspath, dataset+'_temperatures_metallicity.tbl')) # Note: Need to update one of the above tables to contain temperature? and metallicity From 196789d5e662249ef5e98a90da3ff80230333fd9 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 9 Feb 2020 14:02:12 -0700 Subject: [PATCH 08/42] analysis.composite_indv_detect.main: code re-organization; call metallicity_calculation; remove unused variables (iss #21) --- .../analysis/composite_indv_detect.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index bba9c5f..2584978 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -24,25 +24,27 @@ def main(fitspath, dataset, composite_file): # Read in composite table composite_table = asc.read(composite_file) - ID = composite_table['ID'].data + + bin_id = composite_table['ID'].data + bin_temp = composite_table['Temperature'].data # Read in tables containing line ratios, bins, etc. det3_table = asc.read(join(fitspath, 'get_det3_table2.tbl')) bin_table = asc.read(join(fitspath, dataset+'_2d_binning_datadet3.tbl')) + stack_table = asc.read(join(fitspath, dataset+'_temperatures_metallicity.tbl')) # Not used for now # average_table = asc.read(join(fitspath, dataset+'_Average_R23_O32_Values.tbl')) - # stack_table = asc.read(join(fitspath, dataset+'_temperatures_metallicity.tbl')) # Note: Need to update one of the above tables to contain temperature? and metallicity bin_no = bin_table['Bin_number'].data - source_id = det3_table['Individual_IDs'].data O2 = det3_table['O2'].data O3 = det3_table['O3'].data Hb = det3_table['Hb'].data - temp_bin = stackmeas_tab['Temperature'].data + + com_O_log, metal_dict = metallicity_calculation(temp_bin, O2/Hb, O3/Hb) def run_ind_detection(fitspath, dataset, average_value_ascii): From d2b2c4f16d1414ce19dee934c6117d95785794a2 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 9 Feb 2020 14:25:59 -0700 Subject: [PATCH 09/42] analysis.composite_indv_detect.main: Add temperature and metallicity columns (iss #21) --- .../analysis/composite_indv_detect.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index 2584978..8ebedc8 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -1,8 +1,9 @@ from os.path import join +import numpy as np from astropy.io import ascii as asc from astropy.table import vstack -from astropy.table import Table +from astropy.table import Table, Column import glob from ..temp_metallicity_calc import metallicity_calculation @@ -31,17 +32,20 @@ def main(fitspath, dataset, composite_file): # Read in tables containing line ratios, bins, etc. det3_table = asc.read(join(fitspath, 'get_det3_table2.tbl')) bin_table = asc.read(join(fitspath, dataset+'_2d_binning_datadet3.tbl')) - stack_table = asc.read(join(fitspath, dataset+'_temperatures_metallicity.tbl')) + + # Update [bin_table] to include two new columns + col_temp = Column(np.zeros(len(det3_table)), name='Temperature', + dtype=np.float32) + col_metal = Column(np.zeros(len(det3_table)), name='com_O_log', + dtype=np.float32) + det3_table.add_columns([col_temp, col_metal]) # Add at the end of table # Not used for now # average_table = asc.read(join(fitspath, dataset+'_Average_R23_O32_Values.tbl')) - # Note: Need to update one of the above tables to contain temperature? and metallicity - bin_no = bin_table['Bin_number'].data - - O2 = det3_table['O2'].data - O3 = det3_table['O3'].data + O2 = det3_table['O2'].data # [OII]3726,3728 fluxes + O3 = det3_table['O3'].data # [OIII]4959,5007 fluxes (Assume 3.1:1 ratio) Hb = det3_table['Hb'].data com_O_log, metal_dict = metallicity_calculation(temp_bin, O2/Hb, O3/Hb) From 5a7597d6c2bdfc4eceea0fe1d0ad35a378946e5c Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 9 Feb 2020 14:31:33 -0700 Subject: [PATCH 10/42] analysis.composite_indv_detect.main: Populate composite temperature for individual galaxies (iss #21) --- .../analysis/composite_indv_detect.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index 8ebedc8..3cd19eb 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -33,9 +33,14 @@ def main(fitspath, dataset, composite_file): det3_table = asc.read(join(fitspath, 'get_det3_table2.tbl')) bin_table = asc.read(join(fitspath, dataset+'_2d_binning_datadet3.tbl')) + # Populate composite temperature for individual galaxies + adopted_temp = np.zeros(len(det3_table)) + for comp_bin, comp_temp in zip(bin_id, bin_temp): + bin_idx = np.where(bin_table['Bin_number'].data == comp_bin)[0] + adopted_temp[bin_idx] = comp_temp + # Update [bin_table] to include two new columns - col_temp = Column(np.zeros(len(det3_table)), name='Temperature', - dtype=np.float32) + col_temp = Column(adopted_temp, name='Temperature') col_metal = Column(np.zeros(len(det3_table)), name='com_O_log', dtype=np.float32) det3_table.add_columns([col_temp, col_metal]) # Add at the end of table From 5e90c5d4e28006d64341151e76313043619dc0b3 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 9 Feb 2020 14:34:22 -0700 Subject: [PATCH 11/42] analysis.composite_indv_detect.main: Re-organize code for simplicity (iss #21) --- .../analysis/composite_indv_detect.py | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index 3cd19eb..a614b9e 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -32,6 +32,8 @@ def main(fitspath, dataset, composite_file): # Read in tables containing line ratios, bins, etc. det3_table = asc.read(join(fitspath, 'get_det3_table2.tbl')) bin_table = asc.read(join(fitspath, dataset+'_2d_binning_datadet3.tbl')) + # Not used for now + # average_table = asc.read(join(fitspath, dataset+'_Average_R23_O32_Values.tbl')) # Populate composite temperature for individual galaxies adopted_temp = np.zeros(len(det3_table)) @@ -39,21 +41,18 @@ def main(fitspath, dataset, composite_file): bin_idx = np.where(bin_table['Bin_number'].data == comp_bin)[0] adopted_temp[bin_idx] = comp_temp - # Update [bin_table] to include two new columns - col_temp = Column(adopted_temp, name='Temperature') - col_metal = Column(np.zeros(len(det3_table)), name='com_O_log', - dtype=np.float32) - det3_table.add_columns([col_temp, col_metal]) # Add at the end of table - - # Not used for now - # average_table = asc.read(join(fitspath, dataset+'_Average_R23_O32_Values.tbl')) - - bin_no = bin_table['Bin_number'].data O2 = det3_table['O2'].data # [OII]3726,3728 fluxes O3 = det3_table['O3'].data # [OIII]4959,5007 fluxes (Assume 3.1:1 ratio) - Hb = det3_table['Hb'].data + Hb = det3_table['Hb'].data # H-beta fluxes + + com_O_log, metal_dict = metallicity_calculation(adopted_temp, O2/Hb, O3/Hb) + + # Update [det3_table] to include two new columns + col_temp = Column(adopted_temp, name='Temperature') + col_metal = Column(com_O_log, name='com_O_log') + det3_table.add_columns([col_temp, col_metal]) # Add at the end (default) + - com_O_log, metal_dict = metallicity_calculation(temp_bin, O2/Hb, O3/Hb) def run_ind_detection(fitspath, dataset, average_value_ascii): From a49940a6cfba64a36c33085c63131bebf3c95087 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 9 Feb 2020 14:38:19 -0700 Subject: [PATCH 12/42] analysis.composite_indv_detect.main: Write table to [outfile] (iss #21) --- .../analysis/composite_indv_detect.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index a614b9e..8098777 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -9,7 +9,7 @@ from ..temp_metallicity_calc import metallicity_calculation -def main(fitspath, dataset, composite_file): +def main(fitspath, dataset, composite_file, outfile): """ Purpose: Reads in composite table(s) containing bin information to @@ -19,8 +19,7 @@ def main(fitspath, dataset, composite_file): :param fitspath: str containing folder path :param dataset: str containing sub-folder (specific to stacking approach) :param composite_file: str containing filename of composite data - - :return: TBD + :param outfile: str containing filename of output file """ # Read in composite table @@ -52,7 +51,8 @@ def main(fitspath, dataset, composite_file): col_metal = Column(com_O_log, name='com_O_log') det3_table.add_columns([col_temp, col_metal]) # Add at the end (default) - + # Write Astropy ASCII table containing composite T_e and derived metallicity + det3_table.write(outfile, format='ascii.fixed_width_two_line') def run_ind_detection(fitspath, dataset, average_value_ascii): From e969d115acd9464c0c27f996ee0db4c74eedb434 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 9 Feb 2020 14:40:14 -0700 Subject: [PATCH 13/42] analysis.composite_indv_detect.main: Remove run_ind_detection(), ind_detection(), individual_galaxy_table_stacking() - unused for now (iss #21) --- .../analysis/composite_indv_detect.py | 82 ------------------- 1 file changed, 82 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index 8098777..82c38d4 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -53,85 +53,3 @@ def main(fitspath, dataset, composite_file, outfile): # Write Astropy ASCII table containing composite T_e and derived metallicity det3_table.write(outfile, format='ascii.fixed_width_two_line') - - -def run_ind_detection(fitspath, dataset, average_value_ascii): - - N_gal_tab = asc.read(average_value_ascii) - ID = N_gal_tab['ID'] - for aa in range(len(ID)): - ind_detection(fitspath, dataset, ID[aa]) - new_name = fitspath + 'Individual_ratio_temperature.tbl' - vertical_stacking(fitspath, dataset, new_name) - print('run complete') - - -def ind_detection(fitspath, dataset, bin_id): - get_det3_tab = asc.read(fitspath + 'get_det3_table2.tbl') - bin_tab = asc.read(fitspath + dataset + '_2d_binning_datadet3.tbl') - N_gal_tab = asc.read(fitspath + dataset + '_Average_R23_O32_Values.tbl') - stackmeas_tab = asc.read(fitspath + dataset + '_temperatures_metalicity.tbl') - - # From tables - Source_id = get_det3_tab['Individual_IDs'] - O4959 = get_det3_tab['O4959'] - O5007 = get_det3_tab['O5007'] - Bin_number = bin_tab['Bin_number'] - O2 = get_det3_tab['O2'] - O3 = get_det3_tab['O3'] - Hb = get_det3_tab['Hb'] - N_Galaxies = N_gal_tab['N_Galaxies'] - temp_bin = stackmeas_tab['Temperature'] - - R23 = get_det3_tab['R23'] - O32 = get_det3_tab['O32'] - - # Initializing Arrays - - Source_IDs = [] - Bin_ID = [] - two_beta = [] - three_beta = [] - OIII4959 = [] - OIII5007 = [] - HBeta = [] - average_temp = [] - R23_ind = [] - O32_ind = [] - - for ii in range(len(O2)): - if Bin_number[ii] == bin_id: - # print 'Bin_number:', Bin_number[ii], 'O2:', O2[ii], 'O3:', O3[ii], 'Hb:', Hb[ii] - Source_ID.append(Source_id[ii]) - Bin_ID.append(bin_id) - R23_ind.append(R23[ii]) - O32_ind.append(O32[ii]) - two_beta.append(O2[ii] / Hb[ii]) - three_beta.append(O3[ii] / Hb[ii]) - OIII4959.append(O4959[ii]) - OIII5007.append(O5007[ii]) - HBeta.append(Hb[ii]) - average_temp.append(temp_bin[bin_id]) - - individual_ascii = '/Users/reagenleimbach/Desktop/Zcalbase_gal/individual_detection/' + str( - bin_id) + '_individual_ratios_temp.tbl' - n = ('Source_ID', 'Bin_ID', 'Individual_R23', 'Individual_O32', 'two_beta', 'three_beta', 'OIII4959', 'OIII5007', - 'HBeta', 'Temperature') # 'ID', 'R23_Average', 'O32_Average' - ind_tab = Table( - [Source_ID, Bin_ID, R23_ind, O32_ind, two_beta, three_beta, OIII4959, OIII5007, HBeta, average_temp], - names=n) # ID, R23, O32, - asc.write(ind_tab, individual_ascii, format='fixed_width_two_line') - - -def individual_galaxy_table_stacking(fitspath, dataset, new_name): - individual_ascii = '/Users/reagenleimbach/Desktop/Zcalbase_gal/individual_detection/*_individual_ratios_temp.tbl' - table_files = glob.glob(individual_ascii) - table_files.sort() - - for ii in range(len(table_files)): - asc_tab = asc.read(table_files[ii]) - if ii == 0: - vstacking = asc_tab - else: - vstacking = vstack([vstacking, asc_tab]) - asc.write(vstacking, new_name, format='fixed_width_two_line', overwrite=True) From 67fca6d495595d393534888c3f67cd82dd10a100 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 9 Feb 2020 14:46:29 -0700 Subject: [PATCH 14/42] analysis.composite_indv_detect.main: Remove unused imports (vstack, Table, glob) (iss #21) --- Metallicity_Stack_Commons/analysis/composite_indv_detect.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index 82c38d4..45a8242 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -2,9 +2,7 @@ import numpy as np from astropy.io import ascii as asc -from astropy.table import vstack -from astropy.table import Table, Column -import glob +from astropy.table import Column from ..temp_metallicity_calc import metallicity_calculation From 0eb57a3e941f0eaa43e434c8994b20d1cdb25ddd Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Tue, 11 Feb 2020 16:35:06 -0700 Subject: [PATCH 15/42] analysis.composite_indv_detect.main: Add det3 to handle cases without reliable emission lines (iss #21) --- .../analysis/composite_indv_detect.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index 45a8242..378eb28 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -7,7 +7,7 @@ from ..temp_metallicity_calc import metallicity_calculation -def main(fitspath, dataset, composite_file, outfile): +def main(fitspath, dataset, composite_file, outfile, det3=True): """ Purpose: Reads in composite table(s) containing bin information to @@ -18,6 +18,9 @@ def main(fitspath, dataset, composite_file, outfile): :param dataset: str containing sub-folder (specific to stacking approach) :param composite_file: str containing filename of composite data :param outfile: str containing filename of output file + :param det3: Bool indies whether individual galaxy files is limited to + those satisfying emission-line det3 requirement + Default: True """ # Read in composite table @@ -42,7 +45,15 @@ def main(fitspath, dataset, composite_file, outfile): O3 = det3_table['O3'].data # [OIII]4959,5007 fluxes (Assume 3.1:1 ratio) Hb = det3_table['Hb'].data # H-beta fluxes - com_O_log, metal_dict = metallicity_calculation(adopted_temp, O2/Hb, O3/Hb) + if det3 == True: + com_O_log, metal_dict = metallicity_calculation(adopted_temp, O2/Hb, O3/Hb) + else: + det3 = np.where(bin_table['Individual_Detections'])[0] + temp_com_O_log, temp_metal_dict = \ + metallicity_calculation(adopted_temp[det3], O2[det3]/Hb[det3], + O3[det3]/Hb[det3]) + com_O_log = np.zeros(len(det3_table)) + com_O_log[det3] = temp_com_O_log # Update [det3_table] to include two new columns col_temp = Column(adopted_temp, name='Temperature') From c5acfbd7930e4c285eb297d53dd81f6d7cc95e01 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Tue, 11 Feb 2020 17:02:49 -0700 Subject: [PATCH 16/42] analysis.composite_indv_detect.main: Pass in inputs for individual galaxy tables (iss #21) --- .../analysis/composite_indv_detect.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index 378eb28..d9b78f7 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -7,7 +7,7 @@ from ..temp_metallicity_calc import metallicity_calculation -def main(fitspath, dataset, composite_file, outfile, det3=True): +def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, outfile, det3=True): """ Purpose: Reads in composite table(s) containing bin information to @@ -17,6 +17,14 @@ def main(fitspath, dataset, composite_file, outfile, det3=True): :param fitspath: str containing folder path :param dataset: str containing sub-folder (specific to stacking approach) :param composite_file: str containing filename of composite data + :param indv_em_line_file: str containing filename that contains + emission-line information for each galaxy + For Zcalbase_gal, file is: 'get_det3_table2.tbl' + For Evolution-of-Galaxies, file is: TBD + :param indv_bin_file: str containing filename tha contains bin information + for each galaxy + For Zcalbase_gal, file is: dataset+'_2d_binning_datadet3.tbl' + For Evolution-of-Galaxies, file is: TBD :param outfile: str containing filename of output file :param det3: Bool indies whether individual galaxy files is limited to those satisfying emission-line det3 requirement @@ -30,8 +38,8 @@ def main(fitspath, dataset, composite_file, outfile, det3=True): bin_temp = composite_table['Temperature'].data # Read in tables containing line ratios, bins, etc. - det3_table = asc.read(join(fitspath, 'get_det3_table2.tbl')) - bin_table = asc.read(join(fitspath, dataset+'_2d_binning_datadet3.tbl')) + det3_table = asc.read(join(fitspath, indv_em_line_file)) + bin_table = asc.read(join(fitspath, dataset+indv_bin_file)) # Not used for now # average_table = asc.read(join(fitspath, dataset+'_Average_R23_O32_Values.tbl')) From 835f4b76f40e2b5ba197f67a605187b7d75f6c30 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Wed, 19 Feb 2020 16:33:43 -0700 Subject: [PATCH 17/42] analysis.composite_indv_detect.main: Change to use bin_ID naming convention (iss #25) --- Metallicity_Stack_Commons/analysis/composite_indv_detect.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index d9b78f7..67e00f0 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -34,7 +34,7 @@ def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, ou # Read in composite table composite_table = asc.read(composite_file) - bin_id = composite_table['ID'].data + bin_id = composite_table['bin_ID'].data bin_temp = composite_table['Temperature'].data # Read in tables containing line ratios, bins, etc. @@ -46,7 +46,7 @@ def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, ou # Populate composite temperature for individual galaxies adopted_temp = np.zeros(len(det3_table)) for comp_bin, comp_temp in zip(bin_id, bin_temp): - bin_idx = np.where(bin_table['Bin_number'].data == comp_bin)[0] + bin_idx = np.where(bin_table['bin_ID'].data == comp_bin)[0] adopted_temp[bin_idx] = comp_temp O2 = det3_table['O2'].data # [OII]3726,3728 fluxes From 9a858dcd527df6af14102fb9db4ebd8b9f130fdb Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Wed, 19 Feb 2020 16:41:11 -0700 Subject: [PATCH 18/42] analysis.composite_indv_detect.main: Use [LINE]_Flux_Observed convention for O2, O3, and Hb (iss #25) --- .../analysis/composite_indv_detect.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index 67e00f0..5e0fc0a 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -5,6 +5,7 @@ from astropy.table import Column from ..temp_metallicity_calc import metallicity_calculation +from .. import OIII_r def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, outfile, det3=True): @@ -49,9 +50,9 @@ def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, ou bin_idx = np.where(bin_table['bin_ID'].data == comp_bin)[0] adopted_temp[bin_idx] = comp_temp - O2 = det3_table['O2'].data # [OII]3726,3728 fluxes - O3 = det3_table['O3'].data # [OIII]4959,5007 fluxes (Assume 3.1:1 ratio) - Hb = det3_table['Hb'].data # H-beta fluxes + O2 = det3_table['OII_3727_Flux_Observed'].data # [OII]3726,3728 fluxes + O3 = det3_table['OIII_5007_Flux_Observed'].data * OIII_r # [OIII]4959,5007 fluxes (Assume 3.1:1 ratio) + Hb = det3_table['HBETA_Flux_Observed'].data # H-beta fluxes if det3 == True: com_O_log, metal_dict = metallicity_calculation(adopted_temp, O2/Hb, O3/Hb) From 50a28df97a37770ec62496fa49e67baa0df3b6d7 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sat, 22 Feb 2020 10:47:26 -0700 Subject: [PATCH 19/42] analysis.composite_indv_detect.main: Change to use T_e and 12+log(O/H) convention (issues #25, #21) --- Metallicity_Stack_Commons/analysis/composite_indv_detect.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index 5e0fc0a..9bf6409 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -36,7 +36,7 @@ def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, ou composite_table = asc.read(composite_file) bin_id = composite_table['bin_ID'].data - bin_temp = composite_table['Temperature'].data + bin_temp = composite_table['T_e'].data # Read in tables containing line ratios, bins, etc. det3_table = asc.read(join(fitspath, indv_em_line_file)) @@ -65,8 +65,8 @@ def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, ou com_O_log[det3] = temp_com_O_log # Update [det3_table] to include two new columns - col_temp = Column(adopted_temp, name='Temperature') - col_metal = Column(com_O_log, name='com_O_log') + col_temp = Column(adopted_temp, name='T_e') + col_metal = Column(com_O_log, name='12+log(O/H)') det3_table.add_columns([col_temp, col_metal]) # Add at the end (default) # Write Astropy ASCII table containing composite T_e and derived metallicity From 034b5f673ffd11091ba6ef8f1078bd27aca204ac Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sat, 22 Feb 2020 11:58:43 -0700 Subject: [PATCH 20/42] analysis.composite_indv_detect.main: docsstring update to be consistent with filename conventions (iss #21, #25) --- .../analysis/composite_indv_detect.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index 9bf6409..f1094c3 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -18,15 +18,16 @@ def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, ou :param fitspath: str containing folder path :param dataset: str containing sub-folder (specific to stacking approach) :param composite_file: str containing filename of composite data + e.g., '[dataset]/bin_derived_properties.tbl' or + '[dataset]/bin_derived_properties.revised.tbl' :param indv_em_line_file: str containing filename that contains emission-line information for each galaxy - For Zcalbase_gal, file is: 'get_det3_table2.tbl' - For Evolution-of-Galaxies, file is: TBD + e.g., 'individual_properties.tbl' :param indv_bin_file: str containing filename tha contains bin information for each galaxy - For Zcalbase_gal, file is: dataset+'_2d_binning_datadet3.tbl' - For Evolution-of-Galaxies, file is: TBD + e.g., '[dataset]/individual_bin_info.tbl' :param outfile: str containing filename of output file + e.g., '[dataset]/individual_derived_properties.tbl' :param det3: Bool indies whether individual galaxy files is limited to those satisfying emission-line det3 requirement Default: True From 4c173e0753be6e01d47a19f33120543b6b0c3225 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sat, 22 Feb 2020 12:03:04 -0700 Subject: [PATCH 21/42] analysis.composite_indv_detect.main: print statement when file exists; auto overwrite (iss #21) --- .../analysis/composite_indv_detect.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index f1094c3..a8a86e5 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -1,4 +1,5 @@ from os.path import join +from os.path import exists import numpy as np from astropy.io import ascii as asc @@ -71,4 +72,9 @@ def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, ou det3_table.add_columns([col_temp, col_metal]) # Add at the end (default) # Write Astropy ASCII table containing composite T_e and derived metallicity - det3_table.write(outfile, format='ascii.fixed_width_two_line') + + if exists(outfile): + print("File exists! Overwriting : ", outfile) + else: + print("Writing : ", outfile) + det3_table.write(outfile, overwrite=True, format='ascii.fixed_width_two_line') From a5a1aeb8991337d2375208fb327e2be6701f44c8 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sat, 29 Feb 2020 20:36:47 -0700 Subject: [PATCH 22/42] analysis.composite_indv_detect.main: Simplify if statement (iss #21) --- Metallicity_Stack_Commons/analysis/composite_indv_detect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index a8a86e5..31a863d 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -56,7 +56,7 @@ def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, ou O3 = det3_table['OIII_5007_Flux_Observed'].data * OIII_r # [OIII]4959,5007 fluxes (Assume 3.1:1 ratio) Hb = det3_table['HBETA_Flux_Observed'].data # H-beta fluxes - if det3 == True: + if det3: com_O_log, metal_dict = metallicity_calculation(adopted_temp, O2/Hb, O3/Hb) else: det3 = np.where(bin_table['Individual_Detections'])[0] From fddd7dac20c8043fe040cb90bd0a8b2dddb5b82c Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sat, 29 Feb 2020 20:38:49 -0700 Subject: [PATCH 23/42] analysis.composite_indv_detect.main: Minor fix in docstrings (iss #21) --- Metallicity_Stack_Commons/analysis/composite_indv_detect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index 31a863d..46a85c8 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -29,7 +29,7 @@ def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, ou e.g., '[dataset]/individual_bin_info.tbl' :param outfile: str containing filename of output file e.g., '[dataset]/individual_derived_properties.tbl' - :param det3: Bool indies whether individual galaxy files is limited to + :param det3: Bool indicates whether individual galaxy files is limited to those satisfying emission-line det3 requirement Default: True """ From ce87545ef1726a9592262edd03ea0b283fcaf4ac Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sat, 29 Feb 2020 20:40:11 -0700 Subject: [PATCH 24/42] analysis.composite_indv_detect.main: Rename det3_table to indv_em_line_table (iss #21) --- .../analysis/composite_indv_detect.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index 46a85c8..33b7ae7 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -41,20 +41,20 @@ def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, ou bin_temp = composite_table['T_e'].data # Read in tables containing line ratios, bins, etc. - det3_table = asc.read(join(fitspath, indv_em_line_file)) + indv_em_line_table = asc.read(join(fitspath, indv_em_line_file)) bin_table = asc.read(join(fitspath, dataset+indv_bin_file)) # Not used for now # average_table = asc.read(join(fitspath, dataset+'_Average_R23_O32_Values.tbl')) # Populate composite temperature for individual galaxies - adopted_temp = np.zeros(len(det3_table)) + adopted_temp = np.zeros(len(indv_em_line_table)) for comp_bin, comp_temp in zip(bin_id, bin_temp): bin_idx = np.where(bin_table['bin_ID'].data == comp_bin)[0] adopted_temp[bin_idx] = comp_temp - O2 = det3_table['OII_3727_Flux_Observed'].data # [OII]3726,3728 fluxes - O3 = det3_table['OIII_5007_Flux_Observed'].data * OIII_r # [OIII]4959,5007 fluxes (Assume 3.1:1 ratio) - Hb = det3_table['HBETA_Flux_Observed'].data # H-beta fluxes + O2 = indv_em_line_table['OII_3727_Flux_Observed'].data # [OII]3726,3728 fluxes + O3 = indv_em_line_table['OIII_5007_Flux_Observed'].data * OIII_r # [OIII]4959,5007 fluxes (Assume 3.1:1 ratio) + Hb = indv_em_line_table['HBETA_Flux_Observed'].data # H-beta fluxes if det3: com_O_log, metal_dict = metallicity_calculation(adopted_temp, O2/Hb, O3/Hb) @@ -63,13 +63,13 @@ def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, ou temp_com_O_log, temp_metal_dict = \ metallicity_calculation(adopted_temp[det3], O2[det3]/Hb[det3], O3[det3]/Hb[det3]) - com_O_log = np.zeros(len(det3_table)) + com_O_log = np.zeros(len(indv_em_line_table)) com_O_log[det3] = temp_com_O_log # Update [det3_table] to include two new columns col_temp = Column(adopted_temp, name='T_e') col_metal = Column(com_O_log, name='12+log(O/H)') - det3_table.add_columns([col_temp, col_metal]) # Add at the end (default) + indv_em_line_table.add_columns([col_temp, col_metal]) # Add at the end (default) # Write Astropy ASCII table containing composite T_e and derived metallicity @@ -77,4 +77,4 @@ def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, ou print("File exists! Overwriting : ", outfile) else: print("Writing : ", outfile) - det3_table.write(outfile, overwrite=True, format='ascii.fixed_width_two_line') + indv_em_line_table.write(outfile, overwrite=True, format='ascii.fixed_width_two_line') From c6bbf8d9d7ad7ebac905750132116d50ec77d794 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sat, 29 Feb 2020 20:45:10 -0700 Subject: [PATCH 25/42] analysis.composite_indv_detect.main: Rename det3_table to indv_em_line_table - minor (iss #21) --- Metallicity_Stack_Commons/analysis/composite_indv_detect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index 33b7ae7..9bd9e82 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -66,7 +66,7 @@ def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, ou com_O_log = np.zeros(len(indv_em_line_table)) com_O_log[det3] = temp_com_O_log - # Update [det3_table] to include two new columns + # Update [indv_em_line_table] to include two new columns col_temp = Column(adopted_temp, name='T_e') col_metal = Column(com_O_log, name='12+log(O/H)') indv_em_line_table.add_columns([col_temp, col_metal]) # Add at the end (default) From cceb3db7fe674e17b128dab1dea65f9c1b87d828 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sat, 29 Feb 2020 20:46:29 -0700 Subject: [PATCH 26/42] analysis.composite_indv_detect.main: Rename bin_table to indv_bin_info_table (iss #21) --- Metallicity_Stack_Commons/analysis/composite_indv_detect.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index 9bd9e82..708e801 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -42,14 +42,14 @@ def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, ou # Read in tables containing line ratios, bins, etc. indv_em_line_table = asc.read(join(fitspath, indv_em_line_file)) - bin_table = asc.read(join(fitspath, dataset+indv_bin_file)) + indv_bin_info_table = asc.read(join(fitspath, dataset+indv_bin_file)) # Not used for now # average_table = asc.read(join(fitspath, dataset+'_Average_R23_O32_Values.tbl')) # Populate composite temperature for individual galaxies adopted_temp = np.zeros(len(indv_em_line_table)) for comp_bin, comp_temp in zip(bin_id, bin_temp): - bin_idx = np.where(bin_table['bin_ID'].data == comp_bin)[0] + bin_idx = np.where(indv_bin_info_table['bin_ID'].data == comp_bin)[0] adopted_temp[bin_idx] = comp_temp O2 = indv_em_line_table['OII_3727_Flux_Observed'].data # [OII]3726,3728 fluxes @@ -59,7 +59,7 @@ def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, ou if det3: com_O_log, metal_dict = metallicity_calculation(adopted_temp, O2/Hb, O3/Hb) else: - det3 = np.where(bin_table['Individual_Detections'])[0] + det3 = np.where(indv_bin_info_table['Individual_Detections'])[0] temp_com_O_log, temp_metal_dict = \ metallicity_calculation(adopted_temp[det3], O2[det3]/Hb[det3], O3[det3]/Hb[det3]) From 7287278ec017d023cef1e926339efba300f3f579 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Thu, 5 Mar 2020 13:54:23 -0700 Subject: [PATCH 27/42] Add init in analysis (iss #21) --- Metallicity_Stack_Commons/analysis/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Metallicity_Stack_Commons/analysis/__init__.py diff --git a/Metallicity_Stack_Commons/analysis/__init__.py b/Metallicity_Stack_Commons/analysis/__init__.py new file mode 100644 index 0000000..e69de29 From 7cb79949b4dd435590f29f78846b3ae95493c0de Mon Sep 17 00:00:00 2001 From: Reagen Leimbach Date: Thu, 12 Mar 2020 15:58:23 -0700 Subject: [PATCH 28/42] Changed the Flux_Observed to Flux_Gaussian --- .../analysis/composite_indv_detect.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index 708e801..0302665 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -42,7 +42,9 @@ def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, ou # Read in tables containing line ratios, bins, etc. indv_em_line_table = asc.read(join(fitspath, indv_em_line_file)) - indv_bin_info_table = asc.read(join(fitspath, dataset+indv_bin_file)) + # indv_bin_info_table = asc.read(join(fitspath, dataset+indv_bin_file)) + print(indv_bin_file) + indv_bin_info_table = asc.read(join(fitspath, indv_bin_file)) # Not used for now # average_table = asc.read(join(fitspath, dataset+'_Average_R23_O32_Values.tbl')) @@ -52,9 +54,10 @@ def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, ou bin_idx = np.where(indv_bin_info_table['bin_ID'].data == comp_bin)[0] adopted_temp[bin_idx] = comp_temp - O2 = indv_em_line_table['OII_3727_Flux_Observed'].data # [OII]3726,3728 fluxes - O3 = indv_em_line_table['OIII_5007_Flux_Observed'].data * OIII_r # [OIII]4959,5007 fluxes (Assume 3.1:1 ratio) - Hb = indv_em_line_table['HBETA_Flux_Observed'].data # H-beta fluxes + O2 = indv_em_line_table['OII_3727_Flux_Gaussian'].data # [OII]3726,3728 fluxes + O3 = indv_em_line_table['OIII_5007_Flux_Gaussian'].data * OIII_r # [OIII]4959,5007 fluxes (Assume 3.1:1 ratio) + Hb = indv_em_line_table['HBETA_Flux_Gaussian'].data # H-beta fluxes + if det3: com_O_log, metal_dict = metallicity_calculation(adopted_temp, O2/Hb, O3/Hb) From 19bf0aa5b2035bdb3bec2a1b28cff7cffa4e0438 Mon Sep 17 00:00:00 2001 From: Caroline McCormick Date: Sat, 14 Mar 2020 14:18:27 -0700 Subject: [PATCH 29/42] Changed the np where in the det3 else to be if detection is 1.0 or 0.5. --- Metallicity_Stack_Commons/analysis/composite_indv_detect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index 0302665..c7cd46f 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -62,7 +62,7 @@ def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, ou if det3: com_O_log, metal_dict = metallicity_calculation(adopted_temp, O2/Hb, O3/Hb) else: - det3 = np.where(indv_bin_info_table['Individual_Detections'])[0] + det3 = np.where((indv_bin_info_table['Detection'] == 1.0) | (indv_bin_info_table['Detection'] == 0.5))[0] temp_com_O_log, temp_metal_dict = \ metallicity_calculation(adopted_temp[det3], O2[det3]/Hb[det3], O3[det3]/Hb[det3]) From 2d3bf60d2ed6ded00769ae3d446d2d122707041a Mon Sep 17 00:00:00 2001 From: Reagen Leimbach Date: Sat, 14 Mar 2020 18:02:31 -0700 Subject: [PATCH 30/42] Added bin_ID to the output table so that the individual spectrum all have their associated bin_ID --- .../analysis/composite_indv_detect.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index 0302665..95da7c7 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -50,9 +50,11 @@ def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, ou # Populate composite temperature for individual galaxies adopted_temp = np.zeros(len(indv_em_line_table)) + bin_id_indv = np.zeros(len(indv_em_line_table)) for comp_bin, comp_temp in zip(bin_id, bin_temp): bin_idx = np.where(indv_bin_info_table['bin_ID'].data == comp_bin)[0] adopted_temp[bin_idx] = comp_temp + bin_id_indv[bin_idx] = comp_bin O2 = indv_em_line_table['OII_3727_Flux_Gaussian'].data # [OII]3726,3728 fluxes O3 = indv_em_line_table['OIII_5007_Flux_Gaussian'].data * OIII_r # [OIII]4959,5007 fluxes (Assume 3.1:1 ratio) @@ -69,10 +71,11 @@ def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, ou com_O_log = np.zeros(len(indv_em_line_table)) com_O_log[det3] = temp_com_O_log - # Update [indv_em_line_table] to include two new columns + # Update [indv_em_line_table] to include three new columns + col_bin_id = Column(bin_id_indv, name='bin_ID') col_temp = Column(adopted_temp, name='T_e') col_metal = Column(com_O_log, name='12+log(O/H)') - indv_em_line_table.add_columns([col_temp, col_metal]) # Add at the end (default) + indv_em_line_table.add_columns([col_temp, col_metal, col_bin_id]) # Add at the end (default) # Write Astropy ASCII table containing composite T_e and derived metallicity From dfdab4ada80100acdd88ef9c2bed1e1415797df1 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sat, 14 Mar 2020 21:14:23 -0700 Subject: [PATCH 31/42] analysis.composite_indv_detect.main: Define new astropy Table with just the content that is needed (iss #21) --- .../analysis/composite_indv_detect.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index a4aa23e..d3d17f2 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -3,7 +3,7 @@ import numpy as np from astropy.io import ascii as asc -from astropy.table import Column +from astropy.table import Table from ..temp_metallicity_calc import metallicity_calculation from .. import OIII_r @@ -60,7 +60,6 @@ def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, ou O3 = indv_em_line_table['OIII_5007_Flux_Gaussian'].data * OIII_r # [OIII]4959,5007 fluxes (Assume 3.1:1 ratio) Hb = indv_em_line_table['HBETA_Flux_Gaussian'].data # H-beta fluxes - if det3: com_O_log, metal_dict = metallicity_calculation(adopted_temp, O2/Hb, O3/Hb) else: @@ -72,10 +71,9 @@ def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, ou com_O_log[det3] = temp_com_O_log # Update [indv_em_line_table] to include three new columns - col_bin_id = Column(bin_id_indv, name='bin_ID') - col_temp = Column(adopted_temp, name='T_e') - col_metal = Column(com_O_log, name='12+log(O/H)') - indv_em_line_table.add_columns([col_temp, col_metal, col_bin_id]) # Add at the end (default) + arr0 = [indv_em_line_table['ID'], bin_id_indv, adopted_temp, com_O_log] + names0 = ['ID', 'bin_ID', 'T_e', '12+log(O/H)'] + indv_derived_prop_table = Table(arr0, names=names0) # Write Astropy ASCII table containing composite T_e and derived metallicity @@ -83,4 +81,4 @@ def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, ou print("File exists! Overwriting : ", outfile) else: print("Writing : ", outfile) - indv_em_line_table.write(outfile, overwrite=True, format='ascii.fixed_width_two_line') + indv_derived_prop_table.write(outfile, overwrite=True, format='ascii.fixed_width_two_line') From 0501ff924c35584af43e311789f46c7f3c096529 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sat, 14 Mar 2020 21:29:58 -0700 Subject: [PATCH 32/42] analysis.composite_indv_detect.main: Include other columns in output table using [metal_dict] (iss #21) --- .../analysis/composite_indv_detect.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index d3d17f2..acbfaa2 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -70,9 +70,14 @@ def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, ou com_O_log = np.zeros(len(indv_em_line_table)) com_O_log[det3] = temp_com_O_log - # Update [indv_em_line_table] to include three new columns + # Define [indv_derived_prop_table] to include ID, bin_ID, composite T_e, + # and 12+log(O/H) arr0 = [indv_em_line_table['ID'], bin_id_indv, adopted_temp, com_O_log] names0 = ['ID', 'bin_ID', 'T_e', '12+log(O/H)'] + + # Include other metallicities + arr0 += list(metal_dict.values()) + names0 += metal_dict.keys indv_derived_prop_table = Table(arr0, names=names0) # Write Astropy ASCII table containing composite T_e and derived metallicity From bfb155e02c65885174e65bedad63fd2bc6312a5f Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sat, 14 Mar 2020 21:31:03 -0700 Subject: [PATCH 33/42] analysis.composite_indv_detect.main: Remove extra line break (iss #21) --- Metallicity_Stack_Commons/analysis/composite_indv_detect.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index acbfaa2..a17a822 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -81,7 +81,6 @@ def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, ou indv_derived_prop_table = Table(arr0, names=names0) # Write Astropy ASCII table containing composite T_e and derived metallicity - if exists(outfile): print("File exists! Overwriting : ", outfile) else: From 2e0fb0c37ceaf6613a44a73340ed0deefcc8dbd7 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 15 Mar 2020 11:25:15 -0700 Subject: [PATCH 34/42] analysis.composite_indv_detect.main: Bug fix, need to define metal_dict for det3=True case (iss #21) --- Metallicity_Stack_Commons/analysis/composite_indv_detect.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index a17a822..4458950 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -70,6 +70,11 @@ def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, ou com_O_log = np.zeros(len(indv_em_line_table)) com_O_log[det3] = temp_com_O_log + metal_dict = dict() + for key0 in temp_metal_dict.keys(): + metal_dict[key0] = np.zeros(len(indv_em_line_table)) + metal_dict[key0][det3] = temp_metal_dict[key0] + # Define [indv_derived_prop_table] to include ID, bin_ID, composite T_e, # and 12+log(O/H) arr0 = [indv_em_line_table['ID'], bin_id_indv, adopted_temp, com_O_log] From bd98f51f0d96f02adac4b93c2b13e6525f1a2e35 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 15 Mar 2020 11:27:04 -0700 Subject: [PATCH 35/42] analysis.composite_indv_detect.main: Bug fix in names0 addition (iss #21) --- Metallicity_Stack_Commons/analysis/composite_indv_detect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index 4458950..18a2584 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -82,7 +82,7 @@ def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, ou # Include other metallicities arr0 += list(metal_dict.values()) - names0 += metal_dict.keys + names0 += metal_dict.keys() indv_derived_prop_table = Table(arr0, names=names0) # Write Astropy ASCII table containing composite T_e and derived metallicity From f07d2447405f39827a9b0024c9f43868572b01ac Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 15 Mar 2020 11:38:00 -0700 Subject: [PATCH 36/42] merge column_names to use in composite_indv_detect (iss #21) --- Metallicity_Stack_Commons/column_names.py | 136 ++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 Metallicity_Stack_Commons/column_names.py diff --git a/Metallicity_Stack_Commons/column_names.py b/Metallicity_Stack_Commons/column_names.py new file mode 100644 index 0000000..3ad850f --- /dev/null +++ b/Metallicity_Stack_Commons/column_names.py @@ -0,0 +1,136 @@ +from . import line_name, line_type + + +# Need to define here +def line_fit_suffix_add(line_name0, line_type0): + """ + Purpose: + Simple list comprehension combining emission line fit suffixes with + the emission line. This works for individual lines + + :param line_name0: str containing the line name + :param line_type0: str containing the emisison-line type (e.g., 'Balmer') + :return: gauss_lines_names: list with str formatted as [LINE]_[SUFFIX] + """ + + gauss_lines_names = ['{}_{}'.format(line_name0, suffix) for suffix in gauss_names0] + if line_type0 == 'Balmer': + gauss_lines_names += ['{}_{}'.format(line_name0, suffix) for suffix in balmer_names0] + + return gauss_lines_names + + +# These are common/general column names + +# Column names for bin information +bin_names0 = ['bin_ID', 'N_stack', 'Detection'] + +# Column names for individual galaxies/spectra +indv_names0 = ['ID', 'logR23', 'logO32', 'logM', 'logLHb', 'two_beta', 'three_beta'] + +# Dust attenuation +dust0 = ['E(B-V)', 'HgHb', 'HdHb'] + +# Column names for bin information in stellar mass and H-beta luminosity +bin_mzevolve_names0 = ['logM_min', 'logM_max', 'logM_avg', 'logM_median', + 'logLHb_min', 'logLHb_max', 'logLHb_avg', 'logLHb_median'] + +# Column names for bin information in R23 and O32 line ratios +bin_zcalbase_names0 = ['logR23_min', 'logR23_max', 'logR23_avg', 'logR23_median', + 'logO32_min', 'logO32_max', 'logO32_avg', 'logO32_median'] + +# Column names for composite line ratios +bin_ratios0 = ['logR23_composite', 'logO32_composite', + 'two_beta_composite', 'three_beta_composite'] + +# Column names for Gaussian fitting +# This is just the suffix +gauss_names0 = ['Flux_Gaussian', 'Flux_Observed', 'S/N', 'Center', 'Norm', + 'Median', 'Sigma'] +balmer_names0 = ['Abs_Norm', 'Abs_Sigma'] + +# Emission-line fit column names with [LINE] prefix +gauss_lines_names0 = [] +for line0, type0 in zip(line_name, line_type): + gauss_lines_names0 += line_fit_suffix_add(line0, type0) + + +# Temperature and metallicity properties +temp_metal_names0 = ['T_e', '12+log(O/H)', 'log(O+/H)', 'log(O++/H)', 'O+/H', 'O++/H'] + +# Dictionary containing filenames +filename_dict = dict() + +# Bin-related files +filename_dict['bin_info'] = 'bin_info.tbl' +filename_dict['bin_valid'] = 'bin_validation.tbl' +filename_dict['bin_fit'] = 'bin_emission_line_fit.tbl' +filename_dict['bin_fit_rev'] = filename_dict['bin_fit'].replace('.tbl', '.revised.tbl') +filename_dict['bin_derived_prop'] = 'bin_derived_properties.tbl' +filename_dict['bin_derived_prop_rev'] = filename_dict['bin_derived_prop'].replace('.tbl', '.revised.tbl') + +# Individual galaxy/spectra-related files +filename_dict['indv_prop'] = 'individual_properties.tbl' +filename_dict['indv_bin_info'] = 'individual_bin_info.tbl' +filename_dict['indv_derived_prop'] = 'individual_derived_properties.tbl' + + +def merge_column_names(*args): + """ + Purpose: + Merges multiple lists containing column names. + + Usage: + column_names = merge_column_names(bin_names0, indv_names0) + + :param args: An undefined number of lists + :return merge_list: + """ + + merge_list = list() + + arg_count = len(args) + if arg_count > 0: + for elem in args: + merge_list += elem + + return merge_list + + +def remove_from_list(list0, remove_entries): + """ + Purpose: + Remove entries from list + + :param list0: list of column names + :param remove_entries: list of column names to remove + """ + + dup_list0 = list0.copy() + + for entry in remove_entries: + dup_list0.remove(entry) + + return dup_list0 + + +def indv_R23_O32(): + """ + Purpose: + Use remove_from_list() to provide simplified list that contains ID, logR23 and logO32 + + :return: list containing just ID, logR23, logO32 + """ + + return remove_from_list(indv_names0, ['logM', 'logLHb']) + + +def indv_M_LHb(): + """ + Purpose: + Use remove_from_list() to provide simplified list that contains ID, logM and logLHb + + :return: list containing just ID, logM, logLHb + """ + + return remove_from_list(indv_names0, ['logR23', 'logO32']) From daa8199fc90d2992294e4b0e8bf06eadaf8dec60 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 15 Mar 2020 11:44:42 -0700 Subject: [PATCH 37/42] temp_metallicity_calc.metallicity_calculation: Use column_names temp_metal_names0 convention (iss #21, #25) --- Metallicity_Stack_Commons/temp_metallicity_calc.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Metallicity_Stack_Commons/temp_metallicity_calc.py b/Metallicity_Stack_Commons/temp_metallicity_calc.py index 839cdb6..0a4fa76 100644 --- a/Metallicity_Stack_Commons/temp_metallicity_calc.py +++ b/Metallicity_Stack_Commons/temp_metallicity_calc.py @@ -1,6 +1,7 @@ import numpy as np from . import k_dict +from .column_names import temp_metal_names0 k_4363 = k_dict['OIII_4363'] k_5007 = k_dict['OIII_5007'] @@ -73,7 +74,8 @@ def metallicity_calculation(T_e, TWO_BETA, THREE_BETA): com_O = O_s_ion + O_d_ion com_O_log = np.log10(com_O) + 12 - metal_dict = dict(O_s_ion=O_s_ion, O_d_ion=O_d_ion, - O_s_ion_log=O_s_ion_log, O_d_ion_log=O_d_ion_log) + keys = temp_metal_names0[2:] + arr0 = [O_s_ion, O_d_ion, O_s_ion_log, O_d_ion_log] + metal_dict = dict(zip(keys, arr0)) return com_O_log, metal_dict From 4b586bd9e7407b4d6e0cd81f0d9e0ef24292c01d Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 15 Mar 2020 12:36:32 -0700 Subject: [PATCH 38/42] analysis.composite_indv_detect.main: Use column_names definition (iss #21) --- .../analysis/composite_indv_detect.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index 18a2584..77655fe 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -7,6 +7,10 @@ from ..temp_metallicity_calc import metallicity_calculation from .. import OIII_r +from ..column_names import bin_names0, indv_names0, temp_metal_names0 + +ID_name = indv_names0[0] +bin_ID_name = bin_names0[0] def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, outfile, det3=True): @@ -77,8 +81,8 @@ def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, ou # Define [indv_derived_prop_table] to include ID, bin_ID, composite T_e, # and 12+log(O/H) - arr0 = [indv_em_line_table['ID'], bin_id_indv, adopted_temp, com_O_log] - names0 = ['ID', 'bin_ID', 'T_e', '12+log(O/H)'] + arr0 = [indv_em_line_table[ID_name], bin_id_indv, adopted_temp, com_O_log] + names0 = [ID_name, bin_ID_name] + temp_metal_names0[:2] # Include other metallicities arr0 += list(metal_dict.values()) From bb5f6809f12ac13b2ec980c614470a69bef93f74 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 15 Mar 2020 12:48:12 -0700 Subject: [PATCH 39/42] analysis.composite_indv_detect.main: Use definition for composite_file (iss #21) --- .../analysis/composite_indv_detect.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index 77655fe..ef5372b 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -8,12 +8,14 @@ from ..temp_metallicity_calc import metallicity_calculation from .. import OIII_r from ..column_names import bin_names0, indv_names0, temp_metal_names0 +from ..column_names import filename_dict ID_name = indv_names0[0] bin_ID_name = bin_names0[0] -def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, outfile, det3=True): +def main(fitspath, dataset, indv_em_line_file, indv_bin_file, outfile, + revised=False, det3=True): """ Purpose: Reads in composite table(s) containing bin information to @@ -22,9 +24,11 @@ def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, ou :param fitspath: str containing folder path :param dataset: str containing sub-folder (specific to stacking approach) - :param composite_file: str containing filename of composite data - e.g., '[dataset]/bin_derived_properties.tbl' or - '[dataset]/bin_derived_properties.revised.tbl' + + Files identified by default + composite_file: str containing filename of composite data + e.g., '[dataset]/bin_derived_properties.tbl' or + '[dataset]/bin_derived_properties.revised.tbl' :param indv_em_line_file: str containing filename that contains emission-line information for each galaxy e.g., 'individual_properties.tbl' @@ -38,6 +42,13 @@ def main(fitspath, dataset, composite_file, indv_em_line_file, indv_bin_file, ou Default: True """ + t_comp = filename_dict['bin_derived_prop'] if not revised else \ + filename_dict['bin_derived_prop'] + composite_file = os.path.join(fitspath, dataset, t_comp) + if not exists(composite_file): + print("ERROR: File not found"+composite_file) + return + # Read in composite table composite_table = asc.read(composite_file) From 3c66dd7507b661f4a13a537a75914af3f86cf877 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 15 Mar 2020 12:53:16 -0700 Subject: [PATCH 40/42] analysis.composite_indv_detect.main: Use definition for indv_em_line_file; fix bug with os use of join (iss #21) --- .../analysis/composite_indv_detect.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index ef5372b..c1a3055 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -44,9 +44,9 @@ def main(fitspath, dataset, indv_em_line_file, indv_bin_file, outfile, t_comp = filename_dict['bin_derived_prop'] if not revised else \ filename_dict['bin_derived_prop'] - composite_file = os.path.join(fitspath, dataset, t_comp) + composite_file = join(fitspath, dataset, t_comp) if not exists(composite_file): - print("ERROR: File not found"+composite_file) + print("ERROR: File not found! "+composite_file) return # Read in composite table @@ -55,10 +55,14 @@ def main(fitspath, dataset, indv_em_line_file, indv_bin_file, outfile, bin_id = composite_table['bin_ID'].data bin_temp = composite_table['T_e'].data + indv_em_line_file = join(fitspath, dataset, filename_dict['indv_prop']) + if not exists(indv_em_line_file): + print("ERROR: File not found! "+indv_em_line_file) + return + # Read in tables containing line ratios, bins, etc. - indv_em_line_table = asc.read(join(fitspath, indv_em_line_file)) - # indv_bin_info_table = asc.read(join(fitspath, dataset+indv_bin_file)) - print(indv_bin_file) + indv_em_line_table = asc.read(indv_em_line_file) + indv_bin_info_table = asc.read(join(fitspath, indv_bin_file)) # Not used for now # average_table = asc.read(join(fitspath, dataset+'_Average_R23_O32_Values.tbl')) From 4e3cce8f9f6f3011af5e92e5dd2b4df64e6054ce Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 15 Mar 2020 12:56:24 -0700 Subject: [PATCH 41/42] analysis.composite_indv_detect.main: Use definition for indv_bin_file; Add hash documentation (iss #21) --- .../analysis/composite_indv_detect.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index c1a3055..36d7e6b 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -14,7 +14,7 @@ bin_ID_name = bin_names0[0] -def main(fitspath, dataset, indv_em_line_file, indv_bin_file, outfile, +def main(fitspath, dataset, outfile, revised=False, det3=True): """ Purpose: @@ -42,6 +42,7 @@ def main(fitspath, dataset, indv_em_line_file, indv_bin_file, outfile, Default: True """ + # Define [composite_file] t_comp = filename_dict['bin_derived_prop'] if not revised else \ filename_dict['bin_derived_prop'] composite_file = join(fitspath, dataset, t_comp) @@ -55,17 +56,23 @@ def main(fitspath, dataset, indv_em_line_file, indv_bin_file, outfile, bin_id = composite_table['bin_ID'].data bin_temp = composite_table['T_e'].data + # Define [indv_em_line_file] indv_em_line_file = join(fitspath, dataset, filename_dict['indv_prop']) if not exists(indv_em_line_file): print("ERROR: File not found! "+indv_em_line_file) return - # Read in tables containing line ratios, bins, etc. + # Read in tables containing line ratios, etc. indv_em_line_table = asc.read(indv_em_line_file) - indv_bin_info_table = asc.read(join(fitspath, indv_bin_file)) - # Not used for now - # average_table = asc.read(join(fitspath, dataset+'_Average_R23_O32_Values.tbl')) + # Define [indv_bin_file] + indv_bin_file = join(fitspath, dataset, filename_dict['indv_bin_info']) + if not exists(indv_bin_file): + print("ERROR: File not found! "+indv_bin_file) + return + + # Read in tables containing bin info for individual + indv_bin_info_table = asc.read(indv_bin_file) # Populate composite temperature for individual galaxies adopted_temp = np.zeros(len(indv_em_line_table)) From f8c5530a04ab646d19020910ba9df58ba44d5baf Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 15 Mar 2020 13:00:14 -0700 Subject: [PATCH 42/42] analysis.composite_indv_detect.main: Use definition for indv_derived_prop -> outfile; Update docstrings (iss #21) --- .../analysis/composite_indv_detect.py | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index 36d7e6b..9e75238 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -14,8 +14,7 @@ bin_ID_name = bin_names0[0] -def main(fitspath, dataset, outfile, - revised=False, det3=True): +def main(fitspath, dataset, revised=False, det3=True): """ Purpose: Reads in composite table(s) containing bin information to @@ -24,22 +23,24 @@ def main(fitspath, dataset, outfile, :param fitspath: str containing folder path :param dataset: str containing sub-folder (specific to stacking approach) + :param revised: Bool indicates whether to use revised bin properties + (e.g., *.revised.tbl files) + :param det3: Bool indicates whether individual galaxy files is limited to + those satisfying emission-line det3 requirement + Default: True Files identified by default composite_file: str containing filename of composite data e.g., '[dataset]/bin_derived_properties.tbl' or '[dataset]/bin_derived_properties.revised.tbl' - :param indv_em_line_file: str containing filename that contains - emission-line information for each galaxy - e.g., 'individual_properties.tbl' - :param indv_bin_file: str containing filename tha contains bin information - for each galaxy - e.g., '[dataset]/individual_bin_info.tbl' - :param outfile: str containing filename of output file - e.g., '[dataset]/individual_derived_properties.tbl' - :param det3: Bool indicates whether individual galaxy files is limited to - those satisfying emission-line det3 requirement - Default: True + indv_em_line_file: str containing filename that contains + emission-line information for each galaxy + e.g., 'individual_properties.tbl' + indv_bin_file: str containing filename tha contains bin information + for each galaxy + e.g., '[dataset]/individual_bin_info.tbl' + outfile: str containing filename of output file + e.g., '[dataset]/individual_derived_properties.tbl' """ # Define [composite_file] @@ -111,6 +112,8 @@ def main(fitspath, dataset, outfile, names0 += metal_dict.keys() indv_derived_prop_table = Table(arr0, names=names0) + outfile = join(fitspath, dataset, filename_dict['indv_derived_prop']) + # Write Astropy ASCII table containing composite T_e and derived metallicity if exists(outfile): print("File exists! Overwriting : ", outfile)