From cf5acf76049e58d6008805b3cac3d69b7cfff1f5 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 19 Jan 2020 15:51:54 -0700 Subject: [PATCH 01/65] Add error_prop module with construct_pdf() function [iss #5] --- Metallicity_Stack_Commons/error_prop.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Metallicity_Stack_Commons/error_prop.py diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py new file mode 100644 index 0000000..a7df691 --- /dev/null +++ b/Metallicity_Stack_Commons/error_prop.py @@ -0,0 +1,18 @@ +from chun_codes import random_pdf, compute_onesig_pdf + +def construct_pdf(values, RMS, seed_i=1, n_iter=1000): + ''' + Constructs probability distribution function (PDF) based on input + values and their associated uncertainty + + :param values: list or numpy array of values/parameters + :param RMS: 1-sigma errors associated with values (same dimension) + :param seed_i: integer value for initial seed for np.random. Default: 1 + :param n_iter: Number of iterations. Default: 1000 + + :return pdf_arr: numpy array of size (size of values, n_iter) + ''' + + pdf_arr = random_pdf(values, RMS, seed_i=seed_i, n_iter=n_iter, silent=False) + + return pdf_arr From a97937aca21365e34371e71d4db157ef46934f05 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Tue, 28 Jan 2020 16:58:22 -0700 Subject: [PATCH 02/65] Add error_prop_chuncodes function - handles emission lines (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 65 +++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index a7df691..1fdedd0 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -1,5 +1,7 @@ from chun_codes import random_pdf, compute_onesig_pdf +from . import line_name +''' def construct_pdf(values, RMS, seed_i=1, n_iter=1000): ''' Constructs probability distribution function (PDF) based on input @@ -16,3 +18,66 @@ def construct_pdf(values, RMS, seed_i=1, n_iter=1000): pdf_arr = random_pdf(values, RMS, seed_i=seed_i, n_iter=n_iter, silent=False) return pdf_arr +''' + +def error_prop_chuncodes(path, flux_file, prop_file, verify_file): + + flux_tab0 = asc.read(flux_file) + prop_tab0 = asc.read(prop_file) + verify_tab = asc.read(verify_file) + + detect = verify_tab['Detection'] + detection = np.where((detect == 1))[0] + + ID = verify_tab['ID'] + ID_detect = ID[detection] + print(ID_detect) + + flux_tab = flux_tab0[detection] + prop_tab = prop_tab0[detection] + + flux_cols = [str0+'_Flux_Gaussian' for str0 in line_name] + flux_rms_cols = [str0+'_RMS' for str0 in line_name] + + #Comment out for now + #Temp = prop_tab['Temperature'].data + #com_O_log = prop_tab['com_O_log'].data + #O_s_ion = prop_tab['O_s_ion'].data + #O_d_ion = prop_tab['O_d_ion'].data + #log_O_s = prop_tab['log_O_s'].data + #log_O_d = prop_tab['log_O_d'].data + + ## Error calculation + + # Initialize Dictionary for flux_gpdf + flux_propdist_dict = {} + flux_xpeak = {} + flux_lowhigh = {} + + #flux_data = [OII_flux, Hbeta_flux, Hdelta_flux, Hgamma_flux, OIII4363_flux, OIII4959_flux, OIII5007_flux] + #RMS_data = [OII_RMS, Hbeta_RMS, Hdelta_RMS, Hgamma_RMS, OIII4363_RMS, OIII4959_RMS, OIII5007_RMS] + + for aa,flux,rms in zip(range(len(flux_cols)),flux_cols,flux_rms_cols): + flux_gpdf = random_pdf(flux_tab[flux], flux_tab[rms], seed_i=aa, + n_iter=1000, silent=False) + err, xpeak = compute_onesig_pdf(flux_gpdf, flux_tab[flux], usepeak=True, + silent=True, verbose=True) + + # Fill In Dictionary + flux_propdist_dict[line_name[aa] + '_pdf'] = flux_gpdf + flux_xpeak[line_name[aa] + '_xpeak'] = xpeak + flux_lowhigh[line_name[aa] + '_lowhigh_error'] = err + + flux_tab0[line_name[aa] + '_Flux_Gaussian'][detection] = xpeak + + # Edit ASCII Table + new_flux_file = flux_file.replace('.tbl', 'revised.tbl') + + asc.write(flux_tab0, new_flux_file, format='fixed_width_two_line') + + # Save npz files + np.savez(path + 'flux_propdist.npz', **flux_propdist_dict) + np.savez(path + 'flux_errors.npz', **flux_lowhigh) + np.savez(path + 'flux_xpeak.npz', **flux_xpeak) + np.savez(path + 'Te_errors.npz', **Te_lowhigh) + From abf6b11963b463448ba9bf84287b27cbbea95afa Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Tue, 11 Feb 2020 16:51:05 -0700 Subject: [PATCH 03/65] error_prop: PEP8 and clean-up (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 34 +++++++++++++------------ 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index 1fdedd0..2a8a5cd 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -1,7 +1,9 @@ from chun_codes import random_pdf, compute_onesig_pdf from . import line_name +from astropy.io import ascii as asc +import numpy as np -''' +""" def construct_pdf(values, RMS, seed_i=1, n_iter=1000): ''' Constructs probability distribution function (PDF) based on input @@ -18,10 +20,10 @@ def construct_pdf(values, RMS, seed_i=1, n_iter=1000): pdf_arr = random_pdf(values, RMS, seed_i=seed_i, n_iter=n_iter, silent=False) return pdf_arr -''' +""" -def error_prop_chuncodes(path, flux_file, prop_file, verify_file): +def error_prop_chuncodes(path, flux_file, prop_file, verify_file): flux_tab0 = asc.read(flux_file) prop_tab0 = asc.read(prop_file) verify_tab = asc.read(verify_file) @@ -34,30 +36,30 @@ def error_prop_chuncodes(path, flux_file, prop_file, verify_file): print(ID_detect) flux_tab = flux_tab0[detection] - prop_tab = prop_tab0[detection] + # prop_tab = prop_tab0[detection] flux_cols = [str0+'_Flux_Gaussian' for str0 in line_name] flux_rms_cols = [str0+'_RMS' for str0 in line_name] - #Comment out for now - #Temp = prop_tab['Temperature'].data - #com_O_log = prop_tab['com_O_log'].data - #O_s_ion = prop_tab['O_s_ion'].data - #O_d_ion = prop_tab['O_d_ion'].data - #log_O_s = prop_tab['log_O_s'].data - #log_O_d = prop_tab['log_O_d'].data + # Comment out for now + # Temp = prop_tab['Temperature'].data + # com_O_log = prop_tab['com_O_log'].data + # O_s_ion = prop_tab['O_s_ion'].data + # O_d_ion = prop_tab['O_d_ion'].data + # log_O_s = prop_tab['log_O_s'].data + # log_O_d = prop_tab['log_O_d'].data - ## Error calculation + # Error calculation # Initialize Dictionary for flux_gpdf flux_propdist_dict = {} flux_xpeak = {} flux_lowhigh = {} - #flux_data = [OII_flux, Hbeta_flux, Hdelta_flux, Hgamma_flux, OIII4363_flux, OIII4959_flux, OIII5007_flux] - #RMS_data = [OII_RMS, Hbeta_RMS, Hdelta_RMS, Hgamma_RMS, OIII4363_RMS, OIII4959_RMS, OIII5007_RMS] + # flux_data = [OII_flux, Hbeta_flux, Hdelta_flux, Hgamma_flux, OIII4363_flux, OIII4959_flux, OIII5007_flux] + # RMS_data = [OII_RMS, Hbeta_RMS, Hdelta_RMS, Hgamma_RMS, OIII4363_RMS, OIII4959_RMS, OIII5007_RMS] - for aa,flux,rms in zip(range(len(flux_cols)),flux_cols,flux_rms_cols): + for aa, flux, rms in zip(range(len(flux_cols)), flux_cols, flux_rms_cols): flux_gpdf = random_pdf(flux_tab[flux], flux_tab[rms], seed_i=aa, n_iter=1000, silent=False) err, xpeak = compute_onesig_pdf(flux_gpdf, flux_tab[flux], usepeak=True, @@ -79,5 +81,5 @@ def error_prop_chuncodes(path, flux_file, prop_file, verify_file): np.savez(path + 'flux_propdist.npz', **flux_propdist_dict) np.savez(path + 'flux_errors.npz', **flux_lowhigh) np.savez(path + 'flux_xpeak.npz', **flux_xpeak) - np.savez(path + 'Te_errors.npz', **Te_lowhigh) + # np.savez(path + 'Te_errors.npz', **Te_lowhigh) From 1878cec97691fdebf9528efce4bcb81de33b488a Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Thu, 5 Mar 2020 08:28:52 -0700 Subject: [PATCH 04/65] Add RMS (iss #25) --- Metallicity_Stack_Commons/column_names.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Metallicity_Stack_Commons/column_names.py b/Metallicity_Stack_Commons/column_names.py index 3ad850f..3e5d303 100644 --- a/Metallicity_Stack_Commons/column_names.py +++ b/Metallicity_Stack_Commons/column_names.py @@ -46,7 +46,7 @@ def line_fit_suffix_add(line_name0, line_type0): # Column names for Gaussian fitting # This is just the suffix gauss_names0 = ['Flux_Gaussian', 'Flux_Observed', 'S/N', 'Center', 'Norm', - 'Median', 'Sigma'] + 'Median', 'Sigma', 'RMS'] balmer_names0 = ['Abs_Norm', 'Abs_Sigma'] # Emission-line fit column names with [LINE] prefix From 7ede45411d0741fc30f315baf2ed9305209aa328 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Thu, 5 Mar 2020 09:15:43 -0700 Subject: [PATCH 05/65] Define ratios module to get all ratios (iss #5) --- Metallicity_Stack_Commons/ratios.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Metallicity_Stack_Commons/ratios.py diff --git a/Metallicity_Stack_Commons/ratios.py b/Metallicity_Stack_Commons/ratios.py new file mode 100644 index 0000000..bace6ae --- /dev/null +++ b/Metallicity_Stack_Commons/ratios.py @@ -0,0 +1,13 @@ +from . import line_name + +def error_prop_flux_ratios(flux_dict): + """ + Purpose: + Primary code to determine a variety of line ratios based on a dictionary + containing emission-line fluxes + + :param flux_dict: dictionary containing line ratios + :return: + """ + + two_beta = flux_dict['OII_3727'] \ No newline at end of file From f949e74b9bce886bc04079fa3cee1362c7a0f1de Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sat, 7 Mar 2020 12:09:23 -0600 Subject: [PATCH 06/65] ratioserror_prop_flux_ratios: Define flux ratios and return flux_ratios_dict (iss #5) --- Metallicity_Stack_Commons/ratios.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/Metallicity_Stack_Commons/ratios.py b/Metallicity_Stack_Commons/ratios.py index bace6ae..ebeed0c 100644 --- a/Metallicity_Stack_Commons/ratios.py +++ b/Metallicity_Stack_Commons/ratios.py @@ -1,4 +1,8 @@ -from . import line_name +import numpy as np + +from . import line_name_short +from .temp_metallicity_calc import R_calculation + def error_prop_flux_ratios(flux_dict): """ @@ -7,7 +11,25 @@ def error_prop_flux_ratios(flux_dict): containing emission-line fluxes :param flux_dict: dictionary containing line ratios - :return: + :return flux_ratios_dict: dictionary containing flux ratios """ - two_beta = flux_dict['OII_3727'] \ No newline at end of file + OII = flux_dict[line_name_short['OII']] + OIII = flux_dict[line_name_short['OIII']] + Hb = flux_dict[line_name_short['HB']] + OIII4363 = flux_dict[line_name_short['4363']] + + two_beta = OII/Hb + three_beta = OIII/Hb + logR23 = np.log10(two_beta + three_beta) + logO32 = np.log10(OIII/OII) + + flux_ratios_dict = dict() + flux_ratios_dict['two_beta'] = two_beta + flux_ratios_dict['three_beta'] = three_beta + flux_ratios_dict['logR23'] = logR23 + flux_ratios_dict['logO32'] = logO32 + + R_calculation(OIII4363, OIII) + + return flux_ratios_dict From 963cedf22c96a91525662aea12b1e3c5de40bd9f Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sat, 7 Mar 2020 12:17:02 -0600 Subject: [PATCH 07/65] ratios.error_prop_flux_ratios: Minor documentation (iss #5) --- Metallicity_Stack_Commons/ratios.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Metallicity_Stack_Commons/ratios.py b/Metallicity_Stack_Commons/ratios.py index ebeed0c..30b3ea6 100644 --- a/Metallicity_Stack_Commons/ratios.py +++ b/Metallicity_Stack_Commons/ratios.py @@ -14,16 +14,19 @@ def error_prop_flux_ratios(flux_dict): :return flux_ratios_dict: dictionary containing flux ratios """ + # Retrieve emission line fluxes OII = flux_dict[line_name_short['OII']] OIII = flux_dict[line_name_short['OIII']] Hb = flux_dict[line_name_short['HB']] OIII4363 = flux_dict[line_name_short['4363']] + # Define flux ratios two_beta = OII/Hb three_beta = OIII/Hb logR23 = np.log10(two_beta + three_beta) logO32 = np.log10(OIII/OII) + # Define dictionary of flux ratios flux_ratios_dict = dict() flux_ratios_dict['two_beta'] = two_beta flux_ratios_dict['three_beta'] = three_beta From 52e9f7168f6a8d23d316da03f0e6934f1e05cede Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 8 Mar 2020 22:56:27 -0400 Subject: [PATCH 08/65] Update init to master version via git checkout (iss #5) --- Metallicity_Stack_Commons/__init__.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Metallicity_Stack_Commons/__init__.py b/Metallicity_Stack_Commons/__init__.py index 82051f2..6b9b89b 100644 --- a/Metallicity_Stack_Commons/__init__.py +++ b/Metallicity_Stack_Commons/__init__.py @@ -3,6 +3,7 @@ from datetime import date import os import getpass +import numpy as np version = "0.1.0" @@ -10,7 +11,7 @@ line_type = ['Oxy2', 'Balmer', 'Balmer', 'Single', 'Balmer', 'Single', 'Single'] line_name = ['OII_3727', 'HDELTA', 'HGAMMA', 'OIII_4363', 'HBETA', 'OIII_4958', 'OIII_5007'] -fitting_lines_dict = {"lambda0":lambda0, "line_type":line_type, "line_name":line_name} +fitting_lines_dict = {"lambda0": lambda0, "line_type": line_type, "line_name": line_name} all_lambda0 = [lambda0[0]] + [3728.91] + lambda0[1:] all_line_name = ['OII_3726', 'OII_3729'] + line_name[1:] @@ -22,13 +23,16 @@ scalefact = 1e-17 +# Flux ratio of [OIII]5007 to [OIII]4959 +OIII_r = 3.1 + # Define k values for dust attenuation k_values = cardelli(lambda0 * u.Angstrom) -k_dict = dict(zip(line_name,k_values)) +k_dict = dict(zip(line_name, k_values)) def exclude_outliers(objno): - ''' + """ Exclude spectra that are identified as outliers. Generally this is because the spectra have very high S/N on the continuum. @@ -37,19 +41,19 @@ def exclude_outliers(objno): :return: flag: numpy array of zeros and ones - ''' + """ flag = np.zeros(len(objno), dtype=int) bad_data = np.array(['32007727', '32101412', '42006031', '32035286', '14023705']) for ii in range(len(bad_data)): - idx = [xx for xx in range(len(objno)) if bad_data[ii] == str(objno[xx])][0] + idx = [xx for xx in range(len(objno)) if bad_data[ii] in str(objno[xx])] flag[idx] = 1 return flag def dir_date(org_name, path_init='', year=False): - ''' + """ Purpose: This function finds and returns the path to a directory named after the current date (MMDDYYYY). If the directory doesn't exist yet, it creates @@ -70,13 +74,13 @@ def dir_date(org_name, path_init='', year=False): "Path already exists" --> prints this message if the current date directory already exists. fitspath --> prints the path to the directory. - ''' + """ today = date.today() list_path = [path_init, org_name, "%02i%02i" % (today.month, today.day), ''] if year: - list_path[-2] += "i%02i%02i" % today.year + list_path[-2] += "%02i" % today.year fitspath = os.path.join(*list_path) try: @@ -86,6 +90,7 @@ def dir_date(org_name, path_init='', year=False): return fitspath + def get_user(): username = getpass.getuser() if username == 'reagenleimbach': From 076193356297569bf718aee7b1203e630c51b888 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 8 Mar 2020 22:58:29 -0400 Subject: [PATCH 09/65] init: Define line_name_short list (iss #5) --- Metallicity_Stack_Commons/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Metallicity_Stack_Commons/__init__.py b/Metallicity_Stack_Commons/__init__.py index 6b9b89b..da5be3d 100644 --- a/Metallicity_Stack_Commons/__init__.py +++ b/Metallicity_Stack_Commons/__init__.py @@ -11,6 +11,9 @@ line_type = ['Oxy2', 'Balmer', 'Balmer', 'Single', 'Balmer', 'Single', 'Single'] line_name = ['OII_3727', 'HDELTA', 'HGAMMA', 'OIII_4363', 'HBETA', 'OIII_4958', 'OIII_5007'] +line_name_short = {"OII": line_name[0], "4363": line_name[3], + "HB": line_name[4], "OIII": line_name[-1]} + fitting_lines_dict = {"lambda0": lambda0, "line_type": line_type, "line_name": line_name} all_lambda0 = [lambda0[0]] + [3728.91] + lambda0[1:] From bc5bbae7fa9d10b8705a46d518d24615650a290b Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 8 Mar 2020 23:01:57 -0400 Subject: [PATCH 10/65] init: PEP8 formatting (iss #5, #11) --- Metallicity_Stack_Commons/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Metallicity_Stack_Commons/__init__.py b/Metallicity_Stack_Commons/__init__.py index da5be3d..08388fc 100644 --- a/Metallicity_Stack_Commons/__init__.py +++ b/Metallicity_Stack_Commons/__init__.py @@ -9,7 +9,8 @@ lambda0 = [3726.18, 4101.73, 4340.46, 4363.21, 4861.32, 4958.91, 5006.84] line_type = ['Oxy2', 'Balmer', 'Balmer', 'Single', 'Balmer', 'Single', 'Single'] -line_name = ['OII_3727', 'HDELTA', 'HGAMMA', 'OIII_4363', 'HBETA', 'OIII_4958', 'OIII_5007'] +line_name = ['OII_3727', 'HDELTA', 'HGAMMA', 'OIII_4363', 'HBETA', 'OIII_4958', + 'OIII_5007'] line_name_short = {"OII": line_name[0], "4363": line_name[3], "HB": line_name[4], "OIII": line_name[-1]} From 8751ff8fe00797453a1d50eec9159a4fe670228c Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 8 Mar 2020 23:06:42 -0400 Subject: [PATCH 11/65] ratios: import OIII_r and use in error_prop_flux_ratios (iss #5) --- Metallicity_Stack_Commons/ratios.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Metallicity_Stack_Commons/ratios.py b/Metallicity_Stack_Commons/ratios.py index 30b3ea6..9e0f4b5 100644 --- a/Metallicity_Stack_Commons/ratios.py +++ b/Metallicity_Stack_Commons/ratios.py @@ -1,6 +1,6 @@ import numpy as np -from . import line_name_short +from . import line_name_short, OIII_r from .temp_metallicity_calc import R_calculation @@ -22,9 +22,9 @@ def error_prop_flux_ratios(flux_dict): # Define flux ratios two_beta = OII/Hb - three_beta = OIII/Hb + three_beta = OIII_r * OIII/Hb logR23 = np.log10(two_beta + three_beta) - logO32 = np.log10(OIII/OII) + logO32 = np.log10(OIII_r * OIII/OII) # Define dictionary of flux ratios flux_ratios_dict = dict() From 9d6a540a932e0b08cf460cb20b72a7bafcdb3ae4 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 8 Mar 2020 23:26:08 -0400 Subject: [PATCH 12/65] ratios.error_prop_flux_ratios: Add R to flux_ratios_dict (iss #5) --- Metallicity_Stack_Commons/ratios.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Metallicity_Stack_Commons/ratios.py b/Metallicity_Stack_Commons/ratios.py index 9e0f4b5..613cbc4 100644 --- a/Metallicity_Stack_Commons/ratios.py +++ b/Metallicity_Stack_Commons/ratios.py @@ -33,6 +33,6 @@ def error_prop_flux_ratios(flux_dict): flux_ratios_dict['logR23'] = logR23 flux_ratios_dict['logO32'] = logO32 - R_calculation(OIII4363, OIII) + flux_ratios_dict['R'] = R_calculation(OIII4363, OIII) return flux_ratios_dict From a95834f70cff670734bb36783e02d888a82470bf Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 15 Mar 2020 14:23:49 -0700 Subject: [PATCH 13/65] merge column_names module to use in error_prop (iss #5) --- 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 b2ab0a3249a25303c56190b016a5dc308f8c1f3f Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 15 Mar 2020 14:53:29 -0700 Subject: [PATCH 14/65] error_prop.error_prop_chuncodes: Use filenames_dict for convenience (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index 2a8a5cd..0ba2d7b 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -1,8 +1,13 @@ +from os.path import join + from chun_codes import random_pdf, compute_onesig_pdf from . import line_name from astropy.io import ascii as asc import numpy as np +from .column_names import filename_dict + + """ def construct_pdf(values, RMS, seed_i=1, n_iter=1000): ''' @@ -23,9 +28,14 @@ def construct_pdf(values, RMS, seed_i=1, n_iter=1000): """ -def error_prop_chuncodes(path, flux_file, prop_file, verify_file): +def error_prop_chuncodes(path): + flux_file = join(path, filename_dict['bin_fit']) flux_tab0 = asc.read(flux_file) + + prop_file = join(path, filename_dict['bin_derived_prop']) prop_tab0 = asc.read(prop_file) + + verify_file = join(path, filename_dict['bin_valid']) verify_tab = asc.read(verify_file) detect = verify_tab['Detection'] @@ -36,7 +46,7 @@ def error_prop_chuncodes(path, flux_file, prop_file, verify_file): print(ID_detect) flux_tab = flux_tab0[detection] - # prop_tab = prop_tab0[detection] + prop_tab = prop_tab0[detection] flux_cols = [str0+'_Flux_Gaussian' for str0 in line_name] flux_rms_cols = [str0+'_RMS' for str0 in line_name] From c21f690e7111a62bdf6744bf6709b124c2c5cd67 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 15 Mar 2020 14:55:30 -0700 Subject: [PATCH 15/65] error_prop.error_prop_chuncodes: Use proper column names for temperature and metallicities (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index 0ba2d7b..fd13fcf 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -51,13 +51,12 @@ def error_prop_chuncodes(path): flux_cols = [str0+'_Flux_Gaussian' for str0 in line_name] flux_rms_cols = [str0+'_RMS' for str0 in line_name] - # Comment out for now - # Temp = prop_tab['Temperature'].data - # com_O_log = prop_tab['com_O_log'].data - # O_s_ion = prop_tab['O_s_ion'].data - # O_d_ion = prop_tab['O_d_ion'].data - # log_O_s = prop_tab['log_O_s'].data - # log_O_d = prop_tab['log_O_d'].data + Temp = prop_tab['T_e'].data + com_O_log = prop_tab['12+log(O/H)'].data + O_s_ion = prop_tab['O+/H'].data + O_d_ion = prop_tab['O++/H'].data + log_O_s = prop_tab['log(O+/H)'].data + log_O_d = prop_tab['log(O++/H)'].data # Error calculation From 89b01cb6daf9d362dc34ebacab6711408bba16fc Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 15 Mar 2020 15:35:54 -0700 Subject: [PATCH 16/65] column_names.remove_from_list: Allow for py2 and py3 compatibility --- Metallicity_Stack_Commons/column_names.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Metallicity_Stack_Commons/column_names.py b/Metallicity_Stack_Commons/column_names.py index 3ad850f..7664eb4 100644 --- a/Metallicity_Stack_Commons/column_names.py +++ b/Metallicity_Stack_Commons/column_names.py @@ -1,4 +1,8 @@ from . import line_name, line_type +import sys + +# Get python version +py_vers = sys.version_info.major # Need to define here @@ -106,7 +110,10 @@ def remove_from_list(list0, remove_entries): :param remove_entries: list of column names to remove """ - dup_list0 = list0.copy() + if py_vers == 3: + dup_list0 = list0.copy() + if py_vers == 2: + dup_list0 = list(list0) for entry in remove_entries: dup_list0.remove(entry) From d8f2cb1d54bda77f6577c0d60792af641c191ddb Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 15 Mar 2020 16:12:25 -0700 Subject: [PATCH 17/65] analysis.composite_indv_detect.main: Fix bug - wrong if statement --- 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 9e75238..dc2556c 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -87,7 +87,7 @@ def main(fitspath, dataset, revised=False, det3=True): 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: + if not det3: com_O_log, metal_dict = metallicity_calculation(adopted_temp, O2/Hb, O3/Hb) else: det3 = np.where((indv_bin_info_table['Detection'] == 1.0) | (indv_bin_info_table['Detection'] == 0.5))[0] From 26bd82041f53e8e2b4c3571491d00327931501b9 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 15 Mar 2020 16:21:46 -0700 Subject: [PATCH 18/65] analysis.composite_indv_detect.main: Fix bug - not passing Detect info --- .../analysis/composite_indv_detect.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index dc2556c..1592f1d 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -57,6 +57,13 @@ def main(fitspath, dataset, revised=False, det3=True): bin_id = composite_table['bin_ID'].data bin_temp = composite_table['T_e'].data + # Read in validation table + valid_file = join(fitspath, dataset, filename_dict['bin_valid']) + if not exists(valid_file): + print("ERROR: File not found! "+valid_file) + return + valid_table = asc.read(valid_file) + # Define [indv_em_line_file] indv_em_line_file = join(fitspath, dataset, filename_dict['indv_prop']) if not exists(indv_em_line_file): @@ -78,10 +85,12 @@ def main(fitspath, dataset, revised=False, det3=True): # 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): + detect_indv = np.zeros(len(indv_em_line_table)) + for comp_bin, comp_temp, detect in zip(bin_id, bin_temp, valid_table['Detection']): 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 + detect_indv[bin_idx] = detect 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) @@ -90,7 +99,7 @@ def main(fitspath, dataset, revised=False, det3=True): if not det3: com_O_log, metal_dict = metallicity_calculation(adopted_temp, O2/Hb, O3/Hb) else: - det3 = np.where((indv_bin_info_table['Detection'] == 1.0) | (indv_bin_info_table['Detection'] == 0.5))[0] + det3 = np.where((detect_indv == 1.0) | (detect_indv == 0.5))[0] temp_com_O_log, temp_metal_dict = \ metallicity_calculation(adopted_temp[det3], O2[det3]/Hb[det3], O3[det3]/Hb[det3]) From 5f46f9fd5470d9e42a866d21eb0a49ef4d3785f3 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 15 Mar 2020 16:54:54 -0700 Subject: [PATCH 19/65] error_prop.error_prop_chuncodes: Simplify name to work with ratios (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index fd13fcf..ade9694 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -75,7 +75,7 @@ def error_prop_chuncodes(path): silent=True, verbose=True) # Fill In Dictionary - flux_propdist_dict[line_name[aa] + '_pdf'] = flux_gpdf + flux_propdist_dict[line_name[aa]] = flux_gpdf flux_xpeak[line_name[aa] + '_xpeak'] = xpeak flux_lowhigh[line_name[aa] + '_lowhigh_error'] = err From 3519d9382731efa0eda96941a1fb4c66066c0626 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 15 Mar 2020 16:57:40 -0700 Subject: [PATCH 20/65] error_prop.error_prop_chuncodes: use filename_dict for output file (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index ade9694..f656907 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -82,7 +82,7 @@ def error_prop_chuncodes(path): flux_tab0[line_name[aa] + '_Flux_Gaussian'][detection] = xpeak # Edit ASCII Table - new_flux_file = flux_file.replace('.tbl', 'revised.tbl') + new_flux_file = join(path, filename_dict['bin_fit_rev']) asc.write(flux_tab0, new_flux_file, format='fixed_width_two_line') From 3e6153a5a75f679eff65ab3734857b011fa3747a Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 15 Mar 2020 16:59:10 -0700 Subject: [PATCH 21/65] error_prop.error_prop_chuncodes: print statement for overwriting output file (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index f656907..9695222 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -84,7 +84,11 @@ def error_prop_chuncodes(path): # Edit ASCII Table new_flux_file = join(path, filename_dict['bin_fit_rev']) - asc.write(flux_tab0, new_flux_file, format='fixed_width_two_line') + if exists(new_flux_file): + print("Overwriting: "+new_flux_file) + else: + print("Writing: "+new_flux_file) + asc.write(flux_tab0, new_flux_file, overwrite=True, format='fixed_width_two_line') # Save npz files np.savez(path + 'flux_propdist.npz', **flux_propdist_dict) From dd561e502b3c412cafd8fafafec4460513a23852 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 15 Mar 2020 17:22:19 -0700 Subject: [PATCH 22/65] analysis.composite_indv_detect.main: Bug fix - O3 scaling issue (iss #32) --- .../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 1592f1d..a3c51f3 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -92,9 +92,10 @@ def main(fitspath, dataset, revised=False, det3=True): bin_id_indv[bin_idx] = comp_bin detect_indv[bin_idx] = detect - 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 + 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]5007 fluxes + O3 = O3 * (1+1/OIII_r) #Scale to include OIII4959; Assume 3.1:1 ratio + Hb = indv_em_line_table['HBETA_Flux_Gaussian'].data # H-beta fluxes if not det3: com_O_log, metal_dict = metallicity_calculation(adopted_temp, O2/Hb, O3/Hb) From 4aa1c0830c6af46610804bb1fefc2452f6329940 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Wed, 18 Mar 2020 20:41:51 -0700 Subject: [PATCH 23/65] analysis.composite_indv_detect.main: Include logR23, logO32, two_beta, three_beta (iss #21) --- .../analysis/composite_indv_detect.py | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index a3c51f3..f8c3967 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -13,6 +13,11 @@ ID_name = indv_names0[0] bin_ID_name = bin_names0[0] +logR23_name = indv_names0[1] +logO32_name = indv_names0[2] +two_beta_name = indv_names0[5] +three_beta_name = indv_names0[6] + def main(fitspath, dataset, revised=False, det3=True): """ @@ -94,11 +99,17 @@ def main(fitspath, dataset, revised=False, det3=True): 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]5007 fluxes - O3 = O3 * (1+1/OIII_r) #Scale to include OIII4959; Assume 3.1:1 ratio + O3 = O3 * (1+1/OIII_r) # Scale to include OIII4959; Assume 3.1:1 ratio Hb = indv_em_line_table['HBETA_Flux_Gaussian'].data # H-beta fluxes + two_beta = O2/Hb + three_beta = O3/Hb + logR23 = np.log10(two_beta + three_beta) + logO32 = np.log10(O3/O2) + if not det3: - com_O_log, metal_dict = metallicity_calculation(adopted_temp, O2/Hb, O3/Hb) + com_O_log, metal_dict = \ + metallicity_calculation(adopted_temp, two_beta, three_beta) else: det3 = np.where((detect_indv == 1.0) | (detect_indv == 0.5))[0] temp_com_O_log, temp_metal_dict = \ @@ -114,8 +125,10 @@ def main(fitspath, dataset, revised=False, det3=True): # Define [indv_derived_prop_table] to include ID, bin_ID, composite T_e, # and 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] + arr0 = [indv_em_line_table[ID_name], bin_id_indv, logR23, logO32, + two_beta, three_beta, adopted_temp, com_O_log] + names0 = [ID_name, bin_ID_name, logR23_name, logO32_name, two_beta_name, + three_beta_name] + temp_metal_names0[:2] # Include other metallicities arr0 += list(metal_dict.values()) From faad27107a68b328603f846a14f037bd13a1a1a1 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Thu, 19 Mar 2020 08:35:56 -0700 Subject: [PATCH 24/65] error_prop.construct_pdf: Use ratios.error_prop_flux_ratios (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index 9695222..5c67e7f 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -6,7 +6,7 @@ import numpy as np from .column_names import filename_dict - +from .ratios import error_prop_flux_ratios """ def construct_pdf(values, RMS, seed_i=1, n_iter=1000): @@ -96,3 +96,6 @@ def error_prop_chuncodes(path): np.savez(path + 'flux_xpeak.npz', **flux_xpeak) # np.savez(path + 'Te_errors.npz', **Te_lowhigh) + # Obtain distributions of line ratios: logR23, logO32, two_beta, three_beta, R + flux_ratios_dict = error_prop_flux_ratios(flux_propdist_dict) + From eb7ab246cc410af286c6a2a097d41ba06c635abd Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Thu, 19 Mar 2020 08:37:50 -0700 Subject: [PATCH 25/65] Update temp_metallicity_cal to master version via git checkout (iss #5) --- .../temp_metallicity_calc.py | 118 +++++++++++------- 1 file changed, 70 insertions(+), 48 deletions(-) diff --git a/Metallicity_Stack_Commons/temp_metallicity_calc.py b/Metallicity_Stack_Commons/temp_metallicity_calc.py index 477d858..5c1af77 100644 --- a/Metallicity_Stack_Commons/temp_metallicity_calc.py +++ b/Metallicity_Stack_Commons/temp_metallicity_calc.py @@ -1,60 +1,82 @@ import numpy as np -import matplotlib.pyplot as plt -from astropy.io import fits -from astropy.io import ascii as asc -from astropy.table import vstack, hstack -from matplotlib.backends.backend_pdf import PdfPages -from astropy.table import Table, Column -from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes -from mpl_toolkits.axes_grid1.inset_locator import mark_inset -from os.path import exists -import numpy.ma as ma -from matplotlib.gridspec import GridSpec -from pylab import subplots_adjust -from astropy.convolution import Box1DKernel, convolve -from scipy.optimize import curve_fit -import scipy.integrate as integ -from mpl_toolkits.mplot3d import Axes3D -import sys - -#For generalizing for several users -from getpass import getuser -from astropy import units as u -from chun_codes.cardelli import * - -#Constants +from . import k_dict + +from .column_names import temp_metal_names0, remove_from_list + +k_4363 = k_dict['OIII_4363'] +k_5007 = k_dict['OIII_5007'] + +# Constants a = 13205 b = 0.92506 c = 0.98062 -def R_calculation(OIII4363, OIII5007, EBV, k_4363, k_5007): - - R_value = OIII4363/(OIII5007*(1+1/3.1))* 10**(0.4*EBV*(k_4363-k_5007)) - return R_value + +def R_calculation(OIII4363, OIII5007, EBV): + """ + Computes the excitation flux ratio of [OIII]4363 to [OIII]5007. + Adopts a 3.1-to-1 ratio for 5007/4959 + + :param OIII4363: numpy array of OIII4363 fluxes + :param OIII5007: numpy array of OIII5007 fluxes + :param EBV: numpy array of E(B-V). Set to zero if not applying attenuation + + :return R_value: O++ excitation flux ratio + """ + + R_value = OIII4363 / (OIII5007 * (1 + 1 / 3.1)) * 10 ** (0.4 * EBV * (k_4363 - k_5007)) + + return R_value + def temp_calculation(R): - #T_e = a(-log(R)-b)^(-c) - T_e = a*(-np.log10(R)-b)**(-1*c) - print(T_e) + """ + Computes electron temperature (T_e) from O++ excitation flux ratio + + Formula is: + T_e = a(-log(R)-b)^(-c) + where a = 13025, b=0.92506, and c=0.98062 (Nicholls et al. 2014) + + :param R: numpy array of O++ excitation flux ratio (see R_calculation) + + :return T_e: numpy array of T_e (Kelvins) + """ + + T_e = a * (-np.log10(R) - b) ** (-1 * c) + return T_e -def metallicity_calculation(T_e, TWO_BETA, THREE_BETA): #metallicity spelled wrong go back and change it if you have time -#(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 - - 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) + +def metallicity_calculation(T_e, TWO_BETA, THREE_BETA): + """ + Determines 12+log(O/H) from electron temperature and [OII]/Hb and [OIII]/Hb flux ratio + + :param T_e: numpy array of temperature (see temp_calculation) + :param TWO_BETA: numpy array of [OII]/Hb flux ratio + :param THREE_BETA: numpy array of [OIII]/Hb flux ratio + + :return com_O_log: numpy array of 12+log(O/H) + :return metal_dict: dictionary containing O+/H, O++/H, log(O+/H), log(O++/H) + """ + + t_3 = T_e * 1e-4 + t_2 = 0.7 * t_3 + 0.17 + x2 = 1e-4 * 1e3 * t_2 ** (-0.5) + + # Equations from Izotov et al. (2006) + 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 + com_O_log = np.log10(com_O) + 12 + + key_dict = remove_from_list(temp_metal_names0, ['T_e', '12+log(O/H)']) + key_values = [O_s_ion_log, O_d_ion_log, O_s_ion, O_d_ion] # Order matters here + metal_dict = dict(zip(key_dict, key_values)) - return O_s_ion , O_d_ion, com_O_log, O_s_ion_log, O_d_ion_log + return com_O_log, metal_dict From 248cb674702bad575ac1c194b0d5aff0509a1e9f Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Thu, 19 Mar 2020 08:45:18 -0700 Subject: [PATCH 26/65] error_prop.error_prop_chuncodes: Add documentation about detection (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index 5c67e7f..799ec29 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -39,6 +39,9 @@ def error_prop_chuncodes(path): verify_tab = asc.read(verify_file) detect = verify_tab['Detection'] + + # For now we are only considering those with reliable detection and + # excluding those with reliable non-detections (detect = 0.5) detection = np.where((detect == 1))[0] ID = verify_tab['ID'] From 282c40247df59d0b153c7319922e5776f85b0a16 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Thu, 19 Mar 2020 08:47:55 -0700 Subject: [PATCH 27/65] error_prop.error_prop_chuncodes: Rename names for some dict (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index 799ec29..bd7066d 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -64,9 +64,9 @@ def error_prop_chuncodes(path): # Error calculation # Initialize Dictionary for flux_gpdf - flux_propdist_dict = {} - flux_xpeak = {} - flux_lowhigh = {} + flux_pdf_dict = dict() + flux_peak = dict() + flux_lowhigh = dict() # flux_data = [OII_flux, Hbeta_flux, Hdelta_flux, Hgamma_flux, OIII4363_flux, OIII4959_flux, OIII5007_flux] # RMS_data = [OII_RMS, Hbeta_RMS, Hdelta_RMS, Hgamma_RMS, OIII4363_RMS, OIII4959_RMS, OIII5007_RMS] @@ -78,8 +78,8 @@ def error_prop_chuncodes(path): silent=True, verbose=True) # Fill In Dictionary - flux_propdist_dict[line_name[aa]] = flux_gpdf - flux_xpeak[line_name[aa] + '_xpeak'] = xpeak + flux_pdf_dict[line_name[aa]] = flux_gpdf + flux_peak[line_name[aa] + '_xpeak'] = xpeak flux_lowhigh[line_name[aa] + '_lowhigh_error'] = err flux_tab0[line_name[aa] + '_Flux_Gaussian'][detection] = xpeak @@ -94,11 +94,11 @@ def error_prop_chuncodes(path): asc.write(flux_tab0, new_flux_file, overwrite=True, format='fixed_width_two_line') # Save npz files - np.savez(path + 'flux_propdist.npz', **flux_propdist_dict) + np.savez(path + 'flux_propdist.npz', **flux_pdf_dict) np.savez(path + 'flux_errors.npz', **flux_lowhigh) - np.savez(path + 'flux_xpeak.npz', **flux_xpeak) + np.savez(path + 'flux_peak.npz', **flux_peak) # np.savez(path + 'Te_errors.npz', **Te_lowhigh) # Obtain distributions of line ratios: logR23, logO32, two_beta, three_beta, R - flux_ratios_dict = error_prop_flux_ratios(flux_propdist_dict) + flux_ratios_dict = error_prop_flux_ratios(flux_pdf_dict) From 4e9bff7e32f0157128cafaec00d9e32bd3a7f5fe Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Thu, 19 Mar 2020 08:48:37 -0700 Subject: [PATCH 28/65] error_prop: Import os.path.exists (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index bd7066d..dfcc359 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -1,4 +1,4 @@ -from os.path import join +from os.path import join, exists from chun_codes import random_pdf, compute_onesig_pdf from . import line_name @@ -101,4 +101,3 @@ def error_prop_chuncodes(path): # Obtain distributions of line ratios: logR23, logO32, two_beta, three_beta, R flux_ratios_dict = error_prop_flux_ratios(flux_pdf_dict) - From 6abd538f992edfd066ddb2ae374b68e3d19e67b8 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Thu, 26 Mar 2020 22:56:13 -0700 Subject: [PATCH 29/65] ratios.error_prop_flux_ratios: Include EBV as optional input and pass into R_calculation (iss #5) --- Metallicity_Stack_Commons/ratios.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Metallicity_Stack_Commons/ratios.py b/Metallicity_Stack_Commons/ratios.py index 613cbc4..d1393f2 100644 --- a/Metallicity_Stack_Commons/ratios.py +++ b/Metallicity_Stack_Commons/ratios.py @@ -4,13 +4,15 @@ from .temp_metallicity_calc import R_calculation -def error_prop_flux_ratios(flux_dict): +def error_prop_flux_ratios(flux_dict, EBV=None): """ Purpose: Primary code to determine a variety of line ratios based on a dictionary containing emission-line fluxes :param flux_dict: dictionary containing line ratios + :param EBV: array of E(B-V). Same dimensions as contents of flux_dict + :return flux_ratios_dict: dictionary containing flux ratios """ @@ -33,6 +35,10 @@ def error_prop_flux_ratios(flux_dict): flux_ratios_dict['logR23'] = logR23 flux_ratios_dict['logO32'] = logO32 - flux_ratios_dict['R'] = R_calculation(OIII4363, OIII) + if EBV is None: + print("Not applying dust attenuation correction") + EBV = np.zeros(OIII4363.shape) + + flux_ratios_dict['R'] = R_calculation(OIII4363, OIII, EBV) return flux_ratios_dict From ce6ed42c970378a037448384cb0c82662d43728e Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Thu, 26 Mar 2020 23:03:48 -0700 Subject: [PATCH 30/65] error_prop.error_prop_chuncodes: Call temp_calculation and metallicity_calculation to derive distribution of T_e and metallicity (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index dfcc359..6fd440c 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -7,6 +7,7 @@ from .column_names import filename_dict from .ratios import error_prop_flux_ratios +from .temp_metallicity_calc import temp_calculation, metallicity_calculation """ def construct_pdf(values, RMS, seed_i=1, n_iter=1000): @@ -38,7 +39,7 @@ def error_prop_chuncodes(path): verify_file = join(path, filename_dict['bin_valid']) verify_tab = asc.read(verify_file) - detect = verify_tab['Detection'] + detect = verify_tab['Detection'] # For now we are only considering those with reliable detection and # excluding those with reliable non-detections (detect = 0.5) @@ -101,3 +102,8 @@ def error_prop_chuncodes(path): # Obtain distributions of line ratios: logR23, logO32, two_beta, three_beta, R flux_ratios_dict = error_prop_flux_ratios(flux_pdf_dict) + + Te_dict = temp_calculation(flux_ratios_dict['R']) + com_O_log_pdf, metal_dict = \ + metallicity_calculation(Te_dict, flux_ratios_dict['two_beta'], + flux_ratios_dict['three_beta']) From 5080795d5221d03ecabf785765a3f2d5df2dd9bb Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Fri, 27 Mar 2020 13:42:23 -0700 Subject: [PATCH 31/65] error_prop.error_prop_chuncodes: Add binned_data boolean flag and modify to handle binned_data == True (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 35 ++++++++++++++----------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index 6fd440c..7c08765 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -29,28 +29,31 @@ def construct_pdf(values, RMS, seed_i=1, n_iter=1000): """ -def error_prop_chuncodes(path): - flux_file = join(path, filename_dict['bin_fit']) - flux_tab0 = asc.read(flux_file) +def error_prop_chuncodes(path, binned_data=True): - prop_file = join(path, filename_dict['bin_derived_prop']) - prop_tab0 = asc.read(prop_file) + # Define files to read in for binned data + if binned_data: + flux_file = join(path, filename_dict['bin_fit']) + prop_file = join(path, filename_dict['bin_derived_prop']) + verify_file = join(path, filename_dict['bin_valid']) - verify_file = join(path, filename_dict['bin_valid']) - verify_tab = asc.read(verify_file) + flux_tab0 = asc.read(flux_file) + prop_tab0 = asc.read(prop_file) - detect = verify_tab['Detection'] + if binned_data: + verify_tab = asc.read(verify_file) + detect = verify_tab['Detection'] - # For now we are only considering those with reliable detection and - # excluding those with reliable non-detections (detect = 0.5) - detection = np.where((detect == 1))[0] + # For now we are only considering those with reliable detection and + # excluding those with reliable non-detections (detect = 0.5) + detection = np.where((detect == 1))[0] - ID = verify_tab['ID'] - ID_detect = ID[detection] - print(ID_detect) + ID = verify_tab['bin_ID'].data + ID_detect = ID[detection] + print(ID_detect) - flux_tab = flux_tab0[detection] - prop_tab = prop_tab0[detection] + flux_tab = flux_tab0[detection] + prop_tab = prop_tab0[detection] flux_cols = [str0+'_Flux_Gaussian' for str0 in line_name] flux_rms_cols = [str0+'_RMS' for str0 in line_name] From e8d45b02ab4ab79f3cd88303f01bc0c42cfe57b5 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Fri, 27 Mar 2020 13:44:03 -0700 Subject: [PATCH 32/65] error_prop.error_prop_chuncodes: Remove extra print statements (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index 7c08765..12a9903 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -77,9 +77,8 @@ def error_prop_chuncodes(path, binned_data=True): for aa, flux, rms in zip(range(len(flux_cols)), flux_cols, flux_rms_cols): flux_gpdf = random_pdf(flux_tab[flux], flux_tab[rms], seed_i=aa, - n_iter=1000, silent=False) - err, xpeak = compute_onesig_pdf(flux_gpdf, flux_tab[flux], usepeak=True, - silent=True, verbose=True) + n_iter=1000) + err, xpeak = compute_onesig_pdf(flux_gpdf, flux_tab[flux], usepeak=True) # Fill In Dictionary flux_pdf_dict[line_name[aa]] = flux_gpdf From 89ac1aaa3f5d5524fd6616859e687b5fc1d8cd9e Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Fri, 27 Mar 2020 13:48:13 -0700 Subject: [PATCH 33/65] error_prop.error_prop_chuncodes: Rename variables between detect and detction (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index 12a9903..1669168 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -37,23 +37,23 @@ def error_prop_chuncodes(path, binned_data=True): prop_file = join(path, filename_dict['bin_derived_prop']) verify_file = join(path, filename_dict['bin_valid']) - flux_tab0 = asc.read(flux_file) - prop_tab0 = asc.read(prop_file) + flux_tab0 = asc.read(flux_file) + prop_tab0 = asc.read(prop_file) if binned_data: verify_tab = asc.read(verify_file) - detect = verify_tab['Detection'] + detection = verify_tab['Detection'].data # For now we are only considering those with reliable detection and # excluding those with reliable non-detections (detect = 0.5) - detection = np.where((detect == 1))[0] + detect_idx = np.where((detection == 1))[0] ID = verify_tab['bin_ID'].data - ID_detect = ID[detection] + ID_detect = ID[detect_idx] print(ID_detect) - flux_tab = flux_tab0[detection] - prop_tab = prop_tab0[detection] + flux_tab = flux_tab0[detect_idx] + prop_tab = prop_tab0[detect_idx] flux_cols = [str0+'_Flux_Gaussian' for str0 in line_name] flux_rms_cols = [str0+'_RMS' for str0 in line_name] @@ -85,7 +85,7 @@ def error_prop_chuncodes(path, binned_data=True): flux_peak[line_name[aa] + '_xpeak'] = xpeak flux_lowhigh[line_name[aa] + '_lowhigh_error'] = err - flux_tab0[line_name[aa] + '_Flux_Gaussian'][detection] = xpeak + flux_tab0[line_name[aa] + '_Flux_Gaussian'][detect_idx] = xpeak # Edit ASCII Table new_flux_file = join(path, filename_dict['bin_fit_rev']) From a0193635664fa9bd96d0b6c2d2690f693c2988bf Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Fri, 27 Mar 2020 14:00:14 -0700 Subject: [PATCH 34/65] error_prop: Rename error_prop_chuncodes to fluxes_derived_prop (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index 1669168..d0e26da 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -29,7 +29,19 @@ def construct_pdf(values, RMS, seed_i=1, n_iter=1000): """ -def error_prop_chuncodes(path, binned_data=True): +def fluxes_derived_prop(path, binned_data=True): + """ + Purpose: + Use measurements and their uncertainties to perform a randomization + approach. The randomization is performed on individual emission lines. + It carries that information to derived flux ratios and then + determines electron temperature and metallicity + + :param path: str of full path + :param binned_data: bool for whether to analysis binned data. Default: True + + :return: + """ # Define files to read in for binned data if binned_data: From 2fb824fdc1dfd9c4262e2778c349f71ae1ff9a6f Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Fri, 27 Mar 2020 14:00:52 -0700 Subject: [PATCH 35/65] error_prop: Remove unused codes (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index d0e26da..12a5dfb 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -9,25 +9,6 @@ from .ratios import error_prop_flux_ratios from .temp_metallicity_calc import temp_calculation, metallicity_calculation -""" -def construct_pdf(values, RMS, seed_i=1, n_iter=1000): - ''' - Constructs probability distribution function (PDF) based on input - values and their associated uncertainty - - :param values: list or numpy array of values/parameters - :param RMS: 1-sigma errors associated with values (same dimension) - :param seed_i: integer value for initial seed for np.random. Default: 1 - :param n_iter: Number of iterations. Default: 1000 - - :return pdf_arr: numpy array of size (size of values, n_iter) - ''' - - pdf_arr = random_pdf(values, RMS, seed_i=seed_i, n_iter=n_iter, silent=False) - - return pdf_arr -""" - def fluxes_derived_prop(path, binned_data=True): """ From c9771c0cb4314826fc1dc983d6a0afe1e961d07e Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Fri, 27 Mar 2020 14:41:17 -0700 Subject: [PATCH 36/65] error_prop.fluxes_derived_prop: Error propogation for derived properties in clean fashion with for loop; renaming clean-up (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 27 ++++++++++++++++--------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index 12a5dfb..325c629 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -5,7 +5,7 @@ from astropy.io import ascii as asc import numpy as np -from .column_names import filename_dict +from .column_names import filename_dict, temp_metal_names0 from .ratios import error_prop_flux_ratios from .temp_metallicity_calc import temp_calculation, metallicity_calculation @@ -51,13 +51,6 @@ def fluxes_derived_prop(path, binned_data=True): flux_cols = [str0+'_Flux_Gaussian' for str0 in line_name] flux_rms_cols = [str0+'_RMS' for str0 in line_name] - Temp = prop_tab['T_e'].data - com_O_log = prop_tab['12+log(O/H)'].data - O_s_ion = prop_tab['O+/H'].data - O_d_ion = prop_tab['O++/H'].data - log_O_s = prop_tab['log(O+/H)'].data - log_O_d = prop_tab['log(O++/H)'].data - # Error calculation # Initialize Dictionary for flux_gpdf @@ -90,9 +83,9 @@ def fluxes_derived_prop(path, binned_data=True): asc.write(flux_tab0, new_flux_file, overwrite=True, format='fixed_width_two_line') # Save npz files - np.savez(path + 'flux_propdist.npz', **flux_pdf_dict) + np.savez(path + 'flux_pdf.npz', **flux_pdf_dict) np.savez(path + 'flux_errors.npz', **flux_lowhigh) - np.savez(path + 'flux_peak.npz', **flux_peak) + np.savez(path + 'flux_peaks.npz', **flux_peak) # np.savez(path + 'Te_errors.npz', **Te_lowhigh) # Obtain distributions of line ratios: logR23, logO32, two_beta, three_beta, R @@ -102,3 +95,17 @@ def fluxes_derived_prop(path, binned_data=True): com_O_log_pdf, metal_dict = \ metallicity_calculation(Te_dict, flux_ratios_dict['two_beta'], flux_ratios_dict['three_beta']) + + # Loop for each derived properties (T_e, metallicity, etc.) + metal_error = dict() + metal_peak = dict() + for names0 in temp_metal_names0[2:]: + arr0 = prop_tab[names0].data + + err_prop, peak_prop = compute_onesig_pdf(metal_dict[names0], arr0, + usepeak=True) + metal_error[names0+'_lowhigh_error'] = err_prop + metal_peak[names0+'_peak'] = peak_prop + + np.savez(path+'metal_errors.npz', **metal_error) + np.savez(path+'metal_peaks.npz', **metal_peak) \ No newline at end of file From 8338707fc95c26fabc61a2c31161eb75ae5b3346 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Fri, 27 Mar 2020 14:50:51 -0700 Subject: [PATCH 37/65] column_names: Add npz_filename_dict (iss #5, #25) --- Metallicity_Stack_Commons/column_names.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Metallicity_Stack_Commons/column_names.py b/Metallicity_Stack_Commons/column_names.py index 3ad850f..66a6b3f 100644 --- a/Metallicity_Stack_Commons/column_names.py +++ b/Metallicity_Stack_Commons/column_names.py @@ -74,6 +74,14 @@ def line_fit_suffix_add(line_name0, line_type0): filename_dict['indv_bin_info'] = 'individual_bin_info.tbl' filename_dict['indv_derived_prop'] = 'individual_derived_properties.tbl' +# numpy files +npz_filename_dict = dict() +npz_filename_dict['flux_pdf'] = 'flux_pdf.npz' +npz_filename_dict['flux_errors'] = 'flux_errors.npz' +npz_filename_dict['flux_peak'] = 'flux_peak.npz' +npz_filename_dict['metal_errors'] = 'metal_errors.npz' +npz_filename_dict['metal_peak'] = 'metal_peak.npz' + def merge_column_names(*args): """ From 45ab1dae6a47d42b3d573cb079e97d8f6212bc72 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Fri, 27 Mar 2020 14:57:22 -0700 Subject: [PATCH 38/65] column_namesfluxes_derived_prop: Use npz_filename_dict; simplify writing out npz files (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 31 ++++++++++++++++++++----- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index 325c629..c53b8c1 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -5,7 +5,7 @@ from astropy.io import ascii as asc import numpy as np -from .column_names import filename_dict, temp_metal_names0 +from .column_names import filename_dict, temp_metal_names0, npz_filename_dict from .ratios import error_prop_flux_ratios from .temp_metallicity_calc import temp_calculation, metallicity_calculation @@ -83,9 +83,17 @@ def fluxes_derived_prop(path, binned_data=True): asc.write(flux_tab0, new_flux_file, overwrite=True, format='fixed_width_two_line') # Save npz files - np.savez(path + 'flux_pdf.npz', **flux_pdf_dict) - np.savez(path + 'flux_errors.npz', **flux_lowhigh) - np.savez(path + 'flux_peaks.npz', **flux_peak) + npz_files = [npz_filename_dict['flux_pdf'], + npz_filename_dict['flux_errors'], + npz_filename_dict['flux_peak']] + dict_list = [flux_pdf_dict, flux_lowhigh, flux_peak] + for file, dict_input in zip(npz_files, dict_list): + npz_outfile = join(path, file) + if exists(npz_outfile): + print("Overwriting : "+npz_outfile) + else: + print("Writing : "+npz_outfile) + np.savez(npz_outfile, **dict_input) # np.savez(path + 'Te_errors.npz', **Te_lowhigh) # Obtain distributions of line ratios: logR23, logO32, two_beta, three_beta, R @@ -107,5 +115,16 @@ def fluxes_derived_prop(path, binned_data=True): metal_error[names0+'_lowhigh_error'] = err_prop metal_peak[names0+'_peak'] = peak_prop - np.savez(path+'metal_errors.npz', **metal_error) - np.savez(path+'metal_peaks.npz', **metal_peak) \ No newline at end of file + npz_files = [npz_filename_dict['metal_errors'], + npz_filename_dict['metal_peak']] + dict_list = [metal_error, metal_peak] + for file, dict_input in zip(npz_files, dict_list): + npz_outfile = join(path, file) + if exists(npz_outfile): + print("Overwriting : "+npz_outfile) + else: + print("Writing : "+npz_outfile) + np.savez(npz_outfile, **dict_input) + + np.savez(join(path, 'metal_errors.npz'), **metal_error) + np.savez(join(path, 'metal_peaks.npz'), **metal_peak) From 34290d1ec7bf686a1e70af28483f7286662e5a45 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Fri, 27 Mar 2020 15:09:22 -0700 Subject: [PATCH 39/65] error_prop.fluxes_derived_prop: xpeak -> peak (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index c53b8c1..cd71f35 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -64,14 +64,14 @@ def fluxes_derived_prop(path, binned_data=True): for aa, flux, rms in zip(range(len(flux_cols)), flux_cols, flux_rms_cols): flux_gpdf = random_pdf(flux_tab[flux], flux_tab[rms], seed_i=aa, n_iter=1000) - err, xpeak = compute_onesig_pdf(flux_gpdf, flux_tab[flux], usepeak=True) + err, peak = compute_onesig_pdf(flux_gpdf, flux_tab[flux], usepeak=True) # Fill In Dictionary flux_pdf_dict[line_name[aa]] = flux_gpdf - flux_peak[line_name[aa] + '_xpeak'] = xpeak + flux_peak[line_name[aa] + '_peak'] = peak flux_lowhigh[line_name[aa] + '_lowhigh_error'] = err - flux_tab0[line_name[aa] + '_Flux_Gaussian'][detect_idx] = xpeak + flux_tab0[line_name[aa] + '_Flux_Gaussian'][detect_idx] = peak # Edit ASCII Table new_flux_file = join(path, filename_dict['bin_fit_rev']) From fab7db57e7f8f7d13cdbe7e872c6eec1e7df0bda Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Fri, 27 Mar 2020 15:10:01 -0700 Subject: [PATCH 40/65] error_prop.fluxes_derived_prop: Delete unneeded np.savez calls (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index cd71f35..46de733 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -125,6 +125,3 @@ def fluxes_derived_prop(path, binned_data=True): else: print("Writing : "+npz_outfile) np.savez(npz_outfile, **dict_input) - - np.savez(join(path, 'metal_errors.npz'), **metal_error) - np.savez(join(path, 'metal_peaks.npz'), **metal_peak) From c158d24140ff343076977e904cdebc967e0a98b6 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Fri, 27 Mar 2020 15:11:59 -0700 Subject: [PATCH 41/65] error_prop: Add write_npz function (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index 46de733..fde5d4c 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -10,6 +10,16 @@ from .temp_metallicity_calc import temp_calculation, metallicity_calculation +def write_npz(npz_files, dict_list): + for file, dict_input in zip(npz_files, dict_list): + npz_outfile = join(path, file) + if exists(npz_outfile): + print("Overwriting : "+npz_outfile) + else: + print("Writing : "+npz_outfile) + np.savez(npz_outfile, **dict_input) + + def fluxes_derived_prop(path, binned_data=True): """ Purpose: From 7ca1c2f857a68beadc5eabbc1dcc74ff86823ffd Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Fri, 27 Mar 2020 15:13:25 -0700 Subject: [PATCH 42/65] error_prop.fluxes_derived_prop: Refactor with write_npz() (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index fde5d4c..f62a054 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -97,13 +97,7 @@ def fluxes_derived_prop(path, binned_data=True): npz_filename_dict['flux_errors'], npz_filename_dict['flux_peak']] dict_list = [flux_pdf_dict, flux_lowhigh, flux_peak] - for file, dict_input in zip(npz_files, dict_list): - npz_outfile = join(path, file) - if exists(npz_outfile): - print("Overwriting : "+npz_outfile) - else: - print("Writing : "+npz_outfile) - np.savez(npz_outfile, **dict_input) + write_npz(npz_files, dict_list) # np.savez(path + 'Te_errors.npz', **Te_lowhigh) # Obtain distributions of line ratios: logR23, logO32, two_beta, three_beta, R @@ -128,10 +122,4 @@ def fluxes_derived_prop(path, binned_data=True): npz_files = [npz_filename_dict['metal_errors'], npz_filename_dict['metal_peak']] dict_list = [metal_error, metal_peak] - for file, dict_input in zip(npz_files, dict_list): - npz_outfile = join(path, file) - if exists(npz_outfile): - print("Overwriting : "+npz_outfile) - else: - print("Writing : "+npz_outfile) - np.savez(npz_outfile, **dict_input) + write_npz(npz_files, dict_list) From 615e5a8484bfc516d037bc796947a0caeb9987c9 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Fri, 27 Mar 2020 15:17:05 -0700 Subject: [PATCH 43/65] temp_metallicity_calc.metallicity_calculation: Change output - single dict containing all metallicity (iss #5, #6) --- Metallicity_Stack_Commons/temp_metallicity_calc.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Metallicity_Stack_Commons/temp_metallicity_calc.py b/Metallicity_Stack_Commons/temp_metallicity_calc.py index 5c1af77..b953054 100644 --- a/Metallicity_Stack_Commons/temp_metallicity_calc.py +++ b/Metallicity_Stack_Commons/temp_metallicity_calc.py @@ -56,8 +56,7 @@ def metallicity_calculation(T_e, TWO_BETA, THREE_BETA): :param TWO_BETA: numpy array of [OII]/Hb flux ratio :param THREE_BETA: numpy array of [OIII]/Hb flux ratio - :return com_O_log: numpy array of 12+log(O/H) - :return metal_dict: dictionary containing O+/H, O++/H, log(O+/H), log(O++/H) + :return metal_dict: dictionary containing 12+log(O/H), O+/H, O++/H, log(O+/H), log(O++/H) """ t_3 = T_e * 1e-4 @@ -75,8 +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 - key_dict = remove_from_list(temp_metal_names0, ['T_e', '12+log(O/H)']) - key_values = [O_s_ion_log, O_d_ion_log, O_s_ion, O_d_ion] # Order matters here + key_dict = remove_from_list(temp_metal_names0, ['T_e']) + key_values = [com_O_log, O_s_ion_log, O_d_ion_log, O_s_ion, O_d_ion] # Order matters here metal_dict = dict(zip(key_dict, key_values)) - return com_O_log, metal_dict + return metal_dict From 1910886afe1f80f9113638d1693395ff479a8c23 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Fri, 27 Mar 2020 15:20:03 -0700 Subject: [PATCH 44/65] error_prop.fluxes_derived_prop: Revise call to metallicity_calculation (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index f62a054..37d5837 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -104,14 +104,13 @@ def fluxes_derived_prop(path, binned_data=True): flux_ratios_dict = error_prop_flux_ratios(flux_pdf_dict) Te_dict = temp_calculation(flux_ratios_dict['R']) - com_O_log_pdf, metal_dict = \ - metallicity_calculation(Te_dict, flux_ratios_dict['two_beta'], - flux_ratios_dict['three_beta']) + metal_dict = metallicity_calculation(Te_dict, flux_ratios_dict['two_beta'], + flux_ratios_dict['three_beta']) # Loop for each derived properties (T_e, metallicity, etc.) metal_error = dict() metal_peak = dict() - for names0 in temp_metal_names0[2:]: + for names0 in temp_metal_names0[1:]: arr0 = prop_tab[names0].data err_prop, peak_prop = compute_onesig_pdf(metal_dict[names0], arr0, From e13c27d5ef124f51bab9a04a9f701511e9e3ca07 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Fri, 27 Mar 2020 15:21:20 -0700 Subject: [PATCH 45/65] error_prop.write_npz: Pass in path variable (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index 37d5837..87795bf 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -10,7 +10,7 @@ from .temp_metallicity_calc import temp_calculation, metallicity_calculation -def write_npz(npz_files, dict_list): +def write_npz(path, npz_files, dict_list): for file, dict_input in zip(npz_files, dict_list): npz_outfile = join(path, file) if exists(npz_outfile): @@ -97,7 +97,7 @@ def fluxes_derived_prop(path, binned_data=True): npz_filename_dict['flux_errors'], npz_filename_dict['flux_peak']] dict_list = [flux_pdf_dict, flux_lowhigh, flux_peak] - write_npz(npz_files, dict_list) + write_npz(path, npz_files, dict_list) # np.savez(path + 'Te_errors.npz', **Te_lowhigh) # Obtain distributions of line ratios: logR23, logO32, two_beta, three_beta, R @@ -121,4 +121,4 @@ def fluxes_derived_prop(path, binned_data=True): npz_files = [npz_filename_dict['metal_errors'], npz_filename_dict['metal_peak']] dict_list = [metal_error, metal_peak] - write_npz(npz_files, dict_list) + write_npz(path, npz_files, dict_list) From 6ecf23d0fe7e05afcbd685698c00168ba5537465 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Fri, 27 Mar 2020 15:27:00 -0700 Subject: [PATCH 46/65] error_prop.fluxes_derived_prop: Include T_e in compute_onesig_pdf (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index 87795bf..9040f1c 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -110,11 +110,12 @@ def fluxes_derived_prop(path, binned_data=True): # Loop for each derived properties (T_e, metallicity, etc.) metal_error = dict() metal_peak = dict() - for names0 in temp_metal_names0[1:]: + for names0 in temp_metal_names0: arr0 = prop_tab[names0].data - err_prop, peak_prop = compute_onesig_pdf(metal_dict[names0], arr0, - usepeak=True) + pdf_arr = Te_dict if names0 == 'T_e' else metal_dict[names0] + err_prop, peak_prop = compute_onesig_pdf(pdf_arr, arr0, usepeak=True) + metal_error[names0+'_lowhigh_error'] = err_prop metal_peak[names0+'_peak'] = peak_prop From 1d5300e5a83e74f4bc1bb5cdb4cbcb2ab59a3e55 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Fri, 27 Mar 2020 15:30:54 -0700 Subject: [PATCH 47/65] error_prop.fluxes_derived_prop: Variable rename for clarity - Te_dict -> Te_pdf, metal_peak -> derived_prop_peak, metal_error -> derived_prop_error (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index 9040f1c..39cad1c 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -103,23 +103,23 @@ def fluxes_derived_prop(path, binned_data=True): # Obtain distributions of line ratios: logR23, logO32, two_beta, three_beta, R flux_ratios_dict = error_prop_flux_ratios(flux_pdf_dict) - Te_dict = temp_calculation(flux_ratios_dict['R']) - metal_dict = metallicity_calculation(Te_dict, flux_ratios_dict['two_beta'], + Te_pdf = temp_calculation(flux_ratios_dict['R']) + metal_dict = metallicity_calculation(Te_pdf, flux_ratios_dict['two_beta'], flux_ratios_dict['three_beta']) # Loop for each derived properties (T_e, metallicity, etc.) - metal_error = dict() - metal_peak = dict() + derived_prop_error = dict() + derived_prop_peak = dict() for names0 in temp_metal_names0: arr0 = prop_tab[names0].data - pdf_arr = Te_dict if names0 == 'T_e' else metal_dict[names0] + pdf_arr = Te_pdf if names0 == 'T_e' else metal_dict[names0] err_prop, peak_prop = compute_onesig_pdf(pdf_arr, arr0, usepeak=True) - metal_error[names0+'_lowhigh_error'] = err_prop - metal_peak[names0+'_peak'] = peak_prop + derived_prop_error[names0+'_lowhigh_error'] = err_prop + derived_prop_peak[names0+'_peak'] = peak_prop npz_files = [npz_filename_dict['metal_errors'], npz_filename_dict['metal_peak']] - dict_list = [metal_error, metal_peak] + dict_list = [derived_prop_error, derived_prop_peak] write_npz(path, npz_files, dict_list) From 531c0b74a2ab35a95bb8ed6b8fb84bcca2a57cf5 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Fri, 27 Mar 2020 21:15:19 -0700 Subject: [PATCH 48/65] error_prop.fluxes_derived_prop: Define derived_prop_pdf_dict to include all derived properties (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index 39cad1c..eec4051 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -103,9 +103,13 @@ def fluxes_derived_prop(path, binned_data=True): # Obtain distributions of line ratios: logR23, logO32, two_beta, three_beta, R flux_ratios_dict = error_prop_flux_ratios(flux_pdf_dict) + derived_prop_pdf_dict = dict() Te_pdf = temp_calculation(flux_ratios_dict['R']) + derived_prop_pdf_dict[temp_metal_names0[0]] = Te_pdf + metal_dict = metallicity_calculation(Te_pdf, flux_ratios_dict['two_beta'], flux_ratios_dict['three_beta']) + derived_prop_pdf_dict.update(metal_dict) # Loop for each derived properties (T_e, metallicity, etc.) derived_prop_error = dict() @@ -113,8 +117,8 @@ def fluxes_derived_prop(path, binned_data=True): for names0 in temp_metal_names0: arr0 = prop_tab[names0].data - pdf_arr = Te_pdf if names0 == 'T_e' else metal_dict[names0] - err_prop, peak_prop = compute_onesig_pdf(pdf_arr, arr0, usepeak=True) + err_prop, peak_prop = \ + compute_onesig_pdf(derived_prop_pdf_dict[names0], arr0, usepeak=True) derived_prop_error[names0+'_lowhigh_error'] = err_prop derived_prop_peak[names0+'_peak'] = peak_prop From 79edc7a2b438cddace8c4279d162776eda3b9830 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Fri, 27 Mar 2020 21:16:24 -0700 Subject: [PATCH 49/65] error_prop.fluxes_derived_prop: Rename variable to indicte dict (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index eec4051..1b74495 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -112,18 +112,18 @@ def fluxes_derived_prop(path, binned_data=True): derived_prop_pdf_dict.update(metal_dict) # Loop for each derived properties (T_e, metallicity, etc.) - derived_prop_error = dict() - derived_prop_peak = dict() + derived_prop_error_dict = dict() + derived_prop_peak_dict = dict() for names0 in temp_metal_names0: arr0 = prop_tab[names0].data err_prop, peak_prop = \ compute_onesig_pdf(derived_prop_pdf_dict[names0], arr0, usepeak=True) - derived_prop_error[names0+'_lowhigh_error'] = err_prop - derived_prop_peak[names0+'_peak'] = peak_prop + derived_prop_error_dict[names0+'_lowhigh_error'] = err_prop + derived_prop_peak_dict[names0+'_peak'] = peak_prop npz_files = [npz_filename_dict['metal_errors'], npz_filename_dict['metal_peak']] - dict_list = [derived_prop_error, derived_prop_peak] + dict_list = [derived_prop_error_dict, derived_prop_peak_dict] write_npz(path, npz_files, dict_list) From 09ba5a5608ce232723bcddbe957b37064b4746af Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Fri, 27 Mar 2020 21:24:49 -0700 Subject: [PATCH 50/65] column_names: Name changes in npz_filename_dict (iss #5, #25) --- Metallicity_Stack_Commons/column_names.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Metallicity_Stack_Commons/column_names.py b/Metallicity_Stack_Commons/column_names.py index 66a6b3f..afcbfa7 100644 --- a/Metallicity_Stack_Commons/column_names.py +++ b/Metallicity_Stack_Commons/column_names.py @@ -79,8 +79,9 @@ def line_fit_suffix_add(line_name0, line_type0): npz_filename_dict['flux_pdf'] = 'flux_pdf.npz' npz_filename_dict['flux_errors'] = 'flux_errors.npz' npz_filename_dict['flux_peak'] = 'flux_peak.npz' -npz_filename_dict['metal_errors'] = 'metal_errors.npz' -npz_filename_dict['metal_peak'] = 'metal_peak.npz' +npz_filename_dict['der_prop_pdf'] = 'derived_properties_pdf.npz' +npz_filename_dict['der_prop_errors'] = 'derived_properties_errors.npz' +npz_filename_dict['der_prop_peak'] = 'derived_properties_peak.npz' def merge_column_names(*args): From 4da4a0f029b693cbbe105c31603f456850f4fc73 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Fri, 27 Mar 2020 21:26:21 -0700 Subject: [PATCH 51/65] error_prop.fluxes_derived_prop: Use new filenames for npz; Include pdf file for derived properties (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index 1b74495..5a0c1be 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -123,7 +123,9 @@ def fluxes_derived_prop(path, binned_data=True): derived_prop_error_dict[names0+'_lowhigh_error'] = err_prop derived_prop_peak_dict[names0+'_peak'] = peak_prop - npz_files = [npz_filename_dict['metal_errors'], - npz_filename_dict['metal_peak']] - dict_list = [derived_prop_error_dict, derived_prop_peak_dict] + npz_files = [npz_filename_dict['der_prop_pdf'], + npz_filename_dict['der_prop_errors'], + npz_filename_dict['der_prop_peak']] + dict_list = [derived_prop_pdf_dict, derived_prop_error_dict, + derived_prop_peak_dict] write_npz(path, npz_files, dict_list) From 0f4f8c2e2766d140f46ce020742a9b5a967fe644 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Fri, 27 Mar 2020 21:41:46 -0700 Subject: [PATCH 52/65] error_prop.fluxes_derived_prop: Update prop_tab0 and write binned derived properties table (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index 5a0c1be..337ac3b 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -123,6 +123,17 @@ def fluxes_derived_prop(path, binned_data=True): derived_prop_error_dict[names0+'_lowhigh_error'] = err_prop derived_prop_peak_dict[names0+'_peak'] = peak_prop + prop_tab0[names0][detect_idx] = peak_prop + + # Edit ASCII Table + new_prop_file = join(path, filename_dict['bin_derived_prop_rev']) + + if exists(new_prop_file): + print("Overwriting: "+new_prop_file) + else: + print("Writing: "+new_prop_file) + asc.write(prop_tab0, new_prop_file, overwrite=True, format='fixed_width_two_line') + npz_files = [npz_filename_dict['der_prop_pdf'], npz_filename_dict['der_prop_errors'], npz_filename_dict['der_prop_peak']] From 6dcc496b89812fc440217404d2f61fc9489c7a54 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 29 Mar 2020 13:52:25 -0700 Subject: [PATCH 53/65] Bump version: 0.5.0 -> 0.6.0 (iss #5) --- Metallicity_Stack_Commons/__init__.py | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Metallicity_Stack_Commons/__init__.py b/Metallicity_Stack_Commons/__init__.py index 5ef8158..d9874d8 100644 --- a/Metallicity_Stack_Commons/__init__.py +++ b/Metallicity_Stack_Commons/__init__.py @@ -5,7 +5,7 @@ import getpass import numpy as np -version = "0.5.0" +version = "0.6.0" lambda0 = [3726.18, 4101.73, 4340.46, 4363.21, 4861.32, 4958.91, 5006.84] line_type = ['Oxy2', 'Balmer', 'Balmer', 'Single', 'Balmer', 'Single', 'Single'] diff --git a/setup.py b/setup.py index 14d774f..c0e6c3b 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name='Metallicity_Stack_Commons', - version='0.5.0', + version='0.6.0', packages=find_packages('Metallicity_Stack_Commons'), url='https://github.com/astrochun/Metallicity_Stack_Commons', license='MIT License', From 2b9be57c791510dc6048b288e1a26ab457b92ac7 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 29 Mar 2020 14:19:18 -0700 Subject: [PATCH 54/65] error_prop.fluxes_derived_prop: flux_gpdf -> flux_pdf; Additional documentation (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index 337ac3b..9dd76a4 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -61,38 +61,33 @@ def fluxes_derived_prop(path, binned_data=True): flux_cols = [str0+'_Flux_Gaussian' for str0 in line_name] flux_rms_cols = [str0+'_RMS' for str0 in line_name] - # Error calculation - - # Initialize Dictionary for flux_gpdf + # Initialize dictionary flux_pdf_dict = dict() flux_peak = dict() flux_lowhigh = dict() - # flux_data = [OII_flux, Hbeta_flux, Hdelta_flux, Hgamma_flux, OIII4363_flux, OIII4959_flux, OIII5007_flux] - # RMS_data = [OII_RMS, Hbeta_RMS, Hdelta_RMS, Hgamma_RMS, OIII4363_RMS, OIII4959_RMS, OIII5007_RMS] - + # Randomization for emission-line fluxes for aa, flux, rms in zip(range(len(flux_cols)), flux_cols, flux_rms_cols): - flux_gpdf = random_pdf(flux_tab[flux], flux_tab[rms], seed_i=aa, - n_iter=1000) - err, peak = compute_onesig_pdf(flux_gpdf, flux_tab[flux], usepeak=True) + flux_pdf = random_pdf(flux_tab[flux], flux_tab[rms], seed_i=aa, + n_iter=1000) + err, peak = compute_onesig_pdf(flux_pdf, flux_tab[flux], usepeak=True) # Fill In Dictionary - flux_pdf_dict[line_name[aa]] = flux_gpdf + flux_pdf_dict[line_name[aa]] = flux_pdf flux_peak[line_name[aa] + '_peak'] = peak flux_lowhigh[line_name[aa] + '_lowhigh_error'] = err flux_tab0[line_name[aa] + '_Flux_Gaussian'][detect_idx] = peak - # Edit ASCII Table + # Write revised ASCII Table new_flux_file = join(path, filename_dict['bin_fit_rev']) - if exists(new_flux_file): print("Overwriting: "+new_flux_file) else: print("Writing: "+new_flux_file) asc.write(flux_tab0, new_flux_file, overwrite=True, format='fixed_width_two_line') - # Save npz files + # Save flux npz files npz_files = [npz_filename_dict['flux_pdf'], npz_filename_dict['flux_errors'], npz_filename_dict['flux_peak']] @@ -103,10 +98,14 @@ def fluxes_derived_prop(path, binned_data=True): # Obtain distributions of line ratios: logR23, logO32, two_beta, three_beta, R flux_ratios_dict = error_prop_flux_ratios(flux_pdf_dict) + # Initialize dictionary derived_prop_pdf_dict = dict() + + # Calculate temperature distribution Te_pdf = temp_calculation(flux_ratios_dict['R']) derived_prop_pdf_dict[temp_metal_names0[0]] = Te_pdf + # Calculate metallicity distribution metal_dict = metallicity_calculation(Te_pdf, flux_ratios_dict['two_beta'], flux_ratios_dict['three_beta']) derived_prop_pdf_dict.update(metal_dict) From 3c4dad8dfb3b64f64333662e70174431aad3cf0e Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 29 Mar 2020 14:21:49 -0700 Subject: [PATCH 55/65] error_prop.write_npz: Add docstrings (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index 9dd76a4..0f274fb 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -11,6 +11,16 @@ def write_npz(path, npz_files, dict_list): + """ + Purpose: + Write numpy files with provided dictionaries + + :param path: str - prefix for filename output + :param npz_files: list - contains npz file names + :param dict_list: list - contains dictionaries for each corresponding npz file + + :return: Write npz files + """ for file, dict_input in zip(npz_files, dict_list): npz_outfile = join(path, file) if exists(npz_outfile): From 431a17ba74f33557f31fd21373edf341bbe2b47b Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 29 Mar 2020 14:28:45 -0700 Subject: [PATCH 56/65] error_prop.fluxes_derived_prop: Code clean-up with additional documentation and simple re-organization (iss #5) --- Metallicity_Stack_Commons/error_prop.py | 28 +++++++++++++++++-------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/error_prop.py index 0f274fb..f300b5c 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/error_prop.py @@ -71,7 +71,11 @@ def fluxes_derived_prop(path, binned_data=True): flux_cols = [str0+'_Flux_Gaussian' for str0 in line_name] flux_rms_cols = [str0+'_RMS' for str0 in line_name] - # Initialize dictionary + # + # EMISSION-LINE SECTION + # + + # Initialize dictionaries flux_pdf_dict = dict() flux_peak = dict() flux_lowhigh = dict() @@ -82,14 +86,15 @@ def fluxes_derived_prop(path, binned_data=True): n_iter=1000) err, peak = compute_onesig_pdf(flux_pdf, flux_tab[flux], usepeak=True) - # Fill In Dictionary + # Fill in dictionary flux_pdf_dict[line_name[aa]] = flux_pdf flux_peak[line_name[aa] + '_peak'] = peak flux_lowhigh[line_name[aa] + '_lowhigh_error'] = err + # Update values flux_tab0[line_name[aa] + '_Flux_Gaussian'][detect_idx] = peak - # Write revised ASCII Table + # Write revised emission-line fit ASCII table new_flux_file = join(path, filename_dict['bin_fit_rev']) if exists(new_flux_file): print("Overwriting: "+new_flux_file) @@ -103,13 +108,18 @@ def fluxes_derived_prop(path, binned_data=True): npz_filename_dict['flux_peak']] dict_list = [flux_pdf_dict, flux_lowhigh, flux_peak] write_npz(path, npz_files, dict_list) - # np.savez(path + 'Te_errors.npz', **Te_lowhigh) # Obtain distributions of line ratios: logR23, logO32, two_beta, three_beta, R flux_ratios_dict = error_prop_flux_ratios(flux_pdf_dict) - # Initialize dictionary + # + # DERIVED PROPERTIES SECTION + # + + # Initialize dictionaries derived_prop_pdf_dict = dict() + derived_prop_error_dict = dict() + derived_prop_peak_dict = dict() # Calculate temperature distribution Te_pdf = temp_calculation(flux_ratios_dict['R']) @@ -121,28 +131,28 @@ def fluxes_derived_prop(path, binned_data=True): derived_prop_pdf_dict.update(metal_dict) # Loop for each derived properties (T_e, metallicity, etc.) - derived_prop_error_dict = dict() - derived_prop_peak_dict = dict() for names0 in temp_metal_names0: arr0 = prop_tab[names0].data err_prop, peak_prop = \ compute_onesig_pdf(derived_prop_pdf_dict[names0], arr0, usepeak=True) + # Fill in dictionary derived_prop_error_dict[names0+'_lowhigh_error'] = err_prop derived_prop_peak_dict[names0+'_peak'] = peak_prop + # Update values prop_tab0[names0][detect_idx] = peak_prop - # Edit ASCII Table + # Write revised properties ASCII table new_prop_file = join(path, filename_dict['bin_derived_prop_rev']) - if exists(new_prop_file): print("Overwriting: "+new_prop_file) else: print("Writing: "+new_prop_file) asc.write(prop_tab0, new_prop_file, overwrite=True, format='fixed_width_two_line') + # Save derived properties npz files npz_files = [npz_filename_dict['der_prop_pdf'], npz_filename_dict['der_prop_errors'], npz_filename_dict['der_prop_peak']] From b46fbe78a4c61b65b9354093c58f7f57bc8b5e18 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Mon, 30 Mar 2020 16:31:01 -0700 Subject: [PATCH 57/65] ratios.error_prop_flux_ratios: Bug fix for using OIII_r incorrectly (iss #32) --- Metallicity_Stack_Commons/ratios.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Metallicity_Stack_Commons/ratios.py b/Metallicity_Stack_Commons/ratios.py index d1393f2..227b64e 100644 --- a/Metallicity_Stack_Commons/ratios.py +++ b/Metallicity_Stack_Commons/ratios.py @@ -24,9 +24,9 @@ def error_prop_flux_ratios(flux_dict, EBV=None): # Define flux ratios two_beta = OII/Hb - three_beta = OIII_r * OIII/Hb + three_beta = (1+1/OIII_r) * OIII/Hb logR23 = np.log10(two_beta + three_beta) - logO32 = np.log10(OIII_r * OIII/OII) + logO32 = np.log10((1+1/OIII_r) * OIII/OII) # Define dictionary of flux ratios flux_ratios_dict = dict() From 0c177175ec2055455acb829ed1592dc3e2b3ff90 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Tue, 31 Mar 2020 16:42:51 -0700 Subject: [PATCH 58/65] Bug fix: incorrect calling of metallicity_calculation(); Change metallicity_calculation() to allow for det3 keyword input (iss #41) --- .../analysis/composite_indv_detect.py | 22 +++++---------- .../temp_metallicity_calc.py | 28 +++++++++++++------ 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index a3c51f3..ed056f7 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -94,28 +94,20 @@ def main(fitspath, dataset, revised=False, det3=True): 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]5007 fluxes - O3 = O3 * (1+1/OIII_r) #Scale to include OIII4959; Assume 3.1:1 ratio + O3 = O3 * (1+1/OIII_r) # Scale to include OIII4959; Assume 3.1:1 ratio Hb = indv_em_line_table['HBETA_Flux_Gaussian'].data # H-beta fluxes if not det3: - com_O_log, metal_dict = metallicity_calculation(adopted_temp, O2/Hb, O3/Hb) + metal_dict = metallicity_calculation(adopted_temp, O2/Hb, O3/Hb) else: - det3 = np.where((detect_indv == 1.0) | (detect_indv == 0.5))[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(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] + det3_idx = np.where((detect_indv == 1.0) | (detect_indv == 0.5))[0] + metal_dict = \ + metallicity_calculation(adopted_temp, O2/Hb, O3/Hb, det3=det3_idx) # Define [indv_derived_prop_table] to include ID, bin_ID, composite T_e, # and 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] + arr0 = [indv_em_line_table[ID_name], bin_id_indv, adopted_temp] + names0 = [ID_name, bin_ID_name] + temp_metal_names0[0] # Include other metallicities arr0 += list(metal_dict.values()) diff --git a/Metallicity_Stack_Commons/temp_metallicity_calc.py b/Metallicity_Stack_Commons/temp_metallicity_calc.py index b953054..1194d65 100644 --- a/Metallicity_Stack_Commons/temp_metallicity_calc.py +++ b/Metallicity_Stack_Commons/temp_metallicity_calc.py @@ -48,7 +48,7 @@ def temp_calculation(R): return T_e -def metallicity_calculation(T_e, TWO_BETA, THREE_BETA): +def metallicity_calculation(T_e, TWO_BETA, THREE_BETA, det3=None): """ Determines 12+log(O/H) from electron temperature and [OII]/Hb and [OIII]/Hb flux ratio @@ -59,15 +59,27 @@ def metallicity_calculation(T_e, TWO_BETA, THREE_BETA): :return metal_dict: dictionary containing 12+log(O/H), O+/H, O++/H, log(O+/H), log(O++/H) """ - t_3 = T_e * 1e-4 - t_2 = 0.7 * t_3 + 0.17 - x2 = 1e-4 * 1e3 * t_2 ** (-0.5) + n_sample = len(T_e) + t_3 = np.zeros(n_sample) + t_2 = np.zeros(n_sample) + x2 = np.zeros(n_sample) + + if det3 is None: + det3 = np.arange(n_sample) + + t_3[det3] = T_e[det3] * 1e-4 + t_2[det3] = 0.7 * t_3[det3] + 0.17 + x2[det3] = 1e-4 * 1e3 * t_2[det3] ** (-0.5) + + O_s_ion_log = np.zeros(n_sample) + O_d_ion_log = np.zeros(n_sample) # Equations from Izotov et al. (2006) - 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_log[det3] = np.log10(TWO_BETA[det3]) + 5.961 + 1.676 / t_2[det3] \ + - 0.4 * np.log10(t_2[det3]) - 0.034 * t_2[det3] + \ + np.log10(1 + 1.35 * x2[det3]) - 12 + O_d_ion_log[det3] = np.log10(THREE_BETA[det3]) + 6.200 + 1.251 / t_3[det3] \ + - 0.55 * np.log10(t_3[det3]) - 0.014 * (t_3[det3]) - 12 O_s_ion = 10 ** O_s_ion_log O_d_ion = 10 ** O_d_ion_log From 83c0a4287dced8a81e4ab97d58acc6c632ccb42a Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Tue, 31 Mar 2020 22:43:28 -0700 Subject: [PATCH 59/65] Move fitting module into analysis subpackage; Update code to fix relative imports (iss #39) --- Metallicity_Stack_Commons/{ => analysis}/fitting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename Metallicity_Stack_Commons/{ => analysis}/fitting.py (99%) diff --git a/Metallicity_Stack_Commons/fitting.py b/Metallicity_Stack_Commons/analysis/fitting.py similarity index 99% rename from Metallicity_Stack_Commons/fitting.py rename to Metallicity_Stack_Commons/analysis/fitting.py index fcd701f..98e4487 100644 --- a/Metallicity_Stack_Commons/fitting.py +++ b/Metallicity_Stack_Commons/analysis/fitting.py @@ -2,7 +2,7 @@ from astropy.convolution import Box1DKernel, convolve from astropy.io import ascii as asc -from . import scalefact, wavelength_dict +from .. import scalefact, wavelength_dict con1 = wavelength_dict['OII_3729'] / wavelength_dict['OII_3726'] # Ratio of OII doublet line From 6ad3e701c852bb31dbb7cf3512388825af1f221d Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Tue, 31 Mar 2020 22:46:27 -0700 Subject: [PATCH 60/65] plotting.balmer: Update to use relative imports for analysis.fitting (iss #39) --- Metallicity_Stack_Commons/plotting/balmer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Metallicity_Stack_Commons/plotting/balmer.py b/Metallicity_Stack_Commons/plotting/balmer.py index e042313..7addc0e 100644 --- a/Metallicity_Stack_Commons/plotting/balmer.py +++ b/Metallicity_Stack_Commons/plotting/balmer.py @@ -14,7 +14,7 @@ from astropy.io import ascii as asc from matplotlib.backends.backend_pdf import PdfPages -from ..fitting import gauss, double_gauss +from ..analysis.fitting import gauss, double_gauss from .. import scalefact, wavelength_dict From 02def692a2c00957c0224618f212d0ddbbb27857 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Tue, 31 Mar 2020 22:54:41 -0700 Subject: [PATCH 61/65] Move attenuation module into analysis subpackage; Update to fix relative imports (iss #39) --- Metallicity_Stack_Commons/{ => analysis}/attenuation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename Metallicity_Stack_Commons/{ => analysis}/attenuation.py (98%) diff --git a/Metallicity_Stack_Commons/attenuation.py b/Metallicity_Stack_Commons/analysis/attenuation.py similarity index 98% rename from Metallicity_Stack_Commons/attenuation.py rename to Metallicity_Stack_Commons/analysis/attenuation.py index 9b7dd37..ebb857b 100644 --- a/Metallicity_Stack_Commons/attenuation.py +++ b/Metallicity_Stack_Commons/analysis/attenuation.py @@ -2,7 +2,7 @@ from astropy.table import Table import numpy as np -from . import k_dict +from .. import k_dict HgHb_CaseB = 0.468 # Hg/Hb ratio for zero reddening From 0f524fcf7566176a2f992d924f7d1f60cca29a37 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Tue, 7 Apr 2020 16:18:29 -0700 Subject: [PATCH 62/65] analysis.composite_indv_detect.main: Fix mistake in list parsing (iss #41) --- 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 ed056f7..7421d3a 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -107,7 +107,7 @@ def main(fitspath, dataset, revised=False, det3=True): # Define [indv_derived_prop_table] to include ID, bin_ID, composite T_e, # and 12+log(O/H) arr0 = [indv_em_line_table[ID_name], bin_id_indv, adopted_temp] - names0 = [ID_name, bin_ID_name] + temp_metal_names0[0] + names0 = [ID_name, bin_ID_name, temp_metal_names0[0]] # Include other metallicities arr0 += list(metal_dict.values()) From b233f49ac2bc1cbaeaaa8ec2f90815d2f01bff9c Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Tue, 7 Apr 2020 21:08:41 -0700 Subject: [PATCH 63/65] Update temp_metallicity_calc to include hotfix/v0.6.2 fix (iss #39) --- .../temp_metallicity_calc.py | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/Metallicity_Stack_Commons/temp_metallicity_calc.py b/Metallicity_Stack_Commons/temp_metallicity_calc.py index b953054..1194d65 100644 --- a/Metallicity_Stack_Commons/temp_metallicity_calc.py +++ b/Metallicity_Stack_Commons/temp_metallicity_calc.py @@ -48,7 +48,7 @@ def temp_calculation(R): return T_e -def metallicity_calculation(T_e, TWO_BETA, THREE_BETA): +def metallicity_calculation(T_e, TWO_BETA, THREE_BETA, det3=None): """ Determines 12+log(O/H) from electron temperature and [OII]/Hb and [OIII]/Hb flux ratio @@ -59,15 +59,27 @@ def metallicity_calculation(T_e, TWO_BETA, THREE_BETA): :return metal_dict: dictionary containing 12+log(O/H), O+/H, O++/H, log(O+/H), log(O++/H) """ - t_3 = T_e * 1e-4 - t_2 = 0.7 * t_3 + 0.17 - x2 = 1e-4 * 1e3 * t_2 ** (-0.5) + n_sample = len(T_e) + t_3 = np.zeros(n_sample) + t_2 = np.zeros(n_sample) + x2 = np.zeros(n_sample) + + if det3 is None: + det3 = np.arange(n_sample) + + t_3[det3] = T_e[det3] * 1e-4 + t_2[det3] = 0.7 * t_3[det3] + 0.17 + x2[det3] = 1e-4 * 1e3 * t_2[det3] ** (-0.5) + + O_s_ion_log = np.zeros(n_sample) + O_d_ion_log = np.zeros(n_sample) # Equations from Izotov et al. (2006) - 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_log[det3] = np.log10(TWO_BETA[det3]) + 5.961 + 1.676 / t_2[det3] \ + - 0.4 * np.log10(t_2[det3]) - 0.034 * t_2[det3] + \ + np.log10(1 + 1.35 * x2[det3]) - 12 + O_d_ion_log[det3] = np.log10(THREE_BETA[det3]) + 6.200 + 1.251 / t_3[det3] \ + - 0.55 * np.log10(t_3[det3]) - 0.014 * (t_3[det3]) - 12 O_s_ion = 10 ** O_s_ion_log O_d_ion = 10 ** O_d_ion_log From 5d2587f648013e5de36970573e77243a09e18d64 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Tue, 7 Apr 2020 21:14:53 -0700 Subject: [PATCH 64/65] Move error_prop, ratios, and temp_metallicity_calc into analysis sub-package (iss #39) --- Metallicity_Stack_Commons/{ => analysis}/error_prop.py | 2 +- Metallicity_Stack_Commons/{ => analysis}/ratios.py | 0 .../{ => analysis}/temp_metallicity_calc.py | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename Metallicity_Stack_Commons/{ => analysis}/error_prop.py (98%) rename Metallicity_Stack_Commons/{ => analysis}/ratios.py (100%) rename Metallicity_Stack_Commons/{ => analysis}/temp_metallicity_calc.py (97%) diff --git a/Metallicity_Stack_Commons/error_prop.py b/Metallicity_Stack_Commons/analysis/error_prop.py similarity index 98% rename from Metallicity_Stack_Commons/error_prop.py rename to Metallicity_Stack_Commons/analysis/error_prop.py index f300b5c..69a020f 100644 --- a/Metallicity_Stack_Commons/error_prop.py +++ b/Metallicity_Stack_Commons/analysis/error_prop.py @@ -5,7 +5,7 @@ from astropy.io import ascii as asc import numpy as np -from .column_names import filename_dict, temp_metal_names0, npz_filename_dict +from ..column_names import filename_dict, temp_metal_names0, npz_filename_dict from .ratios import error_prop_flux_ratios from .temp_metallicity_calc import temp_calculation, metallicity_calculation diff --git a/Metallicity_Stack_Commons/ratios.py b/Metallicity_Stack_Commons/analysis/ratios.py similarity index 100% rename from Metallicity_Stack_Commons/ratios.py rename to Metallicity_Stack_Commons/analysis/ratios.py diff --git a/Metallicity_Stack_Commons/temp_metallicity_calc.py b/Metallicity_Stack_Commons/analysis/temp_metallicity_calc.py similarity index 97% rename from Metallicity_Stack_Commons/temp_metallicity_calc.py rename to Metallicity_Stack_Commons/analysis/temp_metallicity_calc.py index 1194d65..b4312a1 100644 --- a/Metallicity_Stack_Commons/temp_metallicity_calc.py +++ b/Metallicity_Stack_Commons/analysis/temp_metallicity_calc.py @@ -2,7 +2,7 @@ from . import k_dict -from .column_names import temp_metal_names0, remove_from_list +from ..column_names import temp_metal_names0, remove_from_list k_4363 = k_dict['OIII_4363'] k_5007 = k_dict['OIII_5007'] From b35661d389735a06f97e30105e0f25f5882fb4ce Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Tue, 7 Apr 2020 21:15:35 -0700 Subject: [PATCH 65/65] analysis.composite_indv_detect: Update to use correct relative imports for temp_metallicity_calc (iss #39) --- 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 a3c51f3..eec20f5 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -5,7 +5,7 @@ from astropy.io import ascii as asc from astropy.table import Table -from ..temp_metallicity_calc import metallicity_calculation +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