From db6b34594612d527697ea8d665383bc91bd1b5c2 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sat, 6 Feb 2021 23:43:14 -0700 Subject: [PATCH 01/42] sphinx-quickstart initialization --- docs/Makefile | 20 +++++++++++++++ docs/make.bat | 35 +++++++++++++++++++++++++ docs/requirements.txt | 3 +++ docs/source/conf.py | 60 +++++++++++++++++++++++++++++++++++++++++++ docs/source/index.rst | 20 +++++++++++++++ docs/source/intro.rst | 14 ++++++++++ 6 files changed, 152 insertions(+) create mode 100644 docs/Makefile create mode 100644 docs/make.bat create mode 100644 docs/requirements.txt create mode 100644 docs/source/conf.py create mode 100644 docs/source/index.rst create mode 100644 docs/source/intro.rst diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 00000000..d0c3cbf1 --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = source +BUILDDIR = build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 00000000..9534b018 --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=source +set BUILDDIR=build + +if "%1" == "" goto help + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/docs/requirements.txt b/docs/requirements.txt new file mode 100644 index 00000000..4eaec8a9 --- /dev/null +++ b/docs/requirements.txt @@ -0,0 +1,3 @@ +sphinx>=3.0 +sphinx-rtd-theme==0.5.1 +sphinx-autodoc-typehints==1.11.1 diff --git a/docs/source/conf.py b/docs/source/conf.py new file mode 100644 index 00000000..3ec7b364 --- /dev/null +++ b/docs/source/conf.py @@ -0,0 +1,60 @@ +# Configuration file for the Sphinx documentation builder. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +import os +import sys +import sphinx_rtd_theme +import sphinx_autodoc_typehints + +sys.path.insert(0, os.path.abspath('../../')) + +# -- Project information ----------------------------------------------------- + +project = 'metallicity-stack-commons' +copyright = '2021, Chun Ly, Reagen Leimbach, and Caroline McCormick' +author = 'Chun Ly, Reagen Leimbach, and Caroline McCormick' + +# The full version, including alpha/beta/rc tags +release = '1.4.0' + + +# -- General configuration --------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + "sphinx_rtd_theme", + "sphinx.ext.autodoc", + "sphinx_autodoc_typehints", +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = [] + + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = 'sphinx_rtd_theme' + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] \ No newline at end of file diff --git a/docs/source/index.rst b/docs/source/index.rst new file mode 100644 index 00000000..71118ff8 --- /dev/null +++ b/docs/source/index.rst @@ -0,0 +1,20 @@ +.. metallicity-stack-commons documentation master file, created by + sphinx-quickstart on Sat Feb 6 23:30:49 2021. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to metallicity-stack-commons's documentation! +===================================================== + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + intro.rst + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/docs/source/intro.rst b/docs/source/intro.rst new file mode 100644 index 00000000..54417efe --- /dev/null +++ b/docs/source/intro.rst @@ -0,0 +1,14 @@ +Metallicity_Stack_Commons +========================= + +Set of common codes used in metallicity studies that use the stacking +techniques + +|GitHub build| |GitHub top language| |GitHub release (latest by date)| +|GitHub| + +.. |GitHub build| image:: https://github.com/astrochun/Metallicity_Stack_Commons/workflows/Python%20package/badge.svg? + :target: https://github.com/astrochun/Metallicity_Stack_Commons/actions?query=workflow%3A%22Python+package%22 +.. |GitHub top language| image:: https://img.shields.io/github/languages/top/astrochun/Metallicity_Stack_Commons +.. |GitHub release (latest by date)| image:: https://img.shields.io/github/v/release/astrochun/Metallicity_Stack_Commons +.. |GitHub| image:: https://img.shields.io/github/license/astrochun/Metallicity_Stack_Commons?color=blue \ No newline at end of file From 4abcda26a46d1a5bafd88e081d75cf68eecd8b9c Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sat, 6 Feb 2021 23:59:36 -0700 Subject: [PATCH 02/42] Add API documentation --- .../Metallicity_Stack_Commons.analysis.rst | 61 +++++++++++++++++++ .../Metallicity_Stack_Commons.others.rst | 21 +++++++ docs/source/Metallicity_Stack_Commons.rst | 29 +++++++++ .../Metallicity_Stack_Commons.submodules.rst | 31 ++++++++++ docs/source/index.rst | 1 + docs/source/modules.rst | 7 +++ 6 files changed, 150 insertions(+) create mode 100644 docs/source/Metallicity_Stack_Commons.analysis.rst create mode 100644 docs/source/Metallicity_Stack_Commons.others.rst create mode 100644 docs/source/Metallicity_Stack_Commons.rst create mode 100644 docs/source/Metallicity_Stack_Commons.submodules.rst create mode 100644 docs/source/modules.rst diff --git a/docs/source/Metallicity_Stack_Commons.analysis.rst b/docs/source/Metallicity_Stack_Commons.analysis.rst new file mode 100644 index 00000000..bfb0925c --- /dev/null +++ b/docs/source/Metallicity_Stack_Commons.analysis.rst @@ -0,0 +1,61 @@ +``analysis`` subpackage +======================= + +Submodules +---------- + +Metallicity\_Stack\_Commons.analysis.attenuation module +------------------------------------------------------- + +.. automodule:: Metallicity_Stack_Commons.analysis.attenuation + :members: + :undoc-members: + :show-inheritance: + +Metallicity\_Stack\_Commons.analysis.composite\_indv\_detect module +------------------------------------------------------------------- + +.. automodule:: Metallicity_Stack_Commons.analysis.composite_indv_detect + :members: + :undoc-members: + :show-inheritance: + +Metallicity\_Stack\_Commons.analysis.error\_prop module +------------------------------------------------------- + +.. automodule:: Metallicity_Stack_Commons.analysis.error_prop + :members: + :undoc-members: + :show-inheritance: + +Metallicity\_Stack\_Commons.analysis.fitting module +--------------------------------------------------- + +.. automodule:: Metallicity_Stack_Commons.analysis.fitting + :members: + :undoc-members: + :show-inheritance: + +Metallicity\_Stack\_Commons.analysis.ratios module +-------------------------------------------------- + +.. automodule:: Metallicity_Stack_Commons.analysis.ratios + :members: + :undoc-members: + :show-inheritance: + +Metallicity\_Stack\_Commons.analysis.temp\_metallicity\_calc module +------------------------------------------------------------------- + +.. automodule:: Metallicity_Stack_Commons.analysis.temp_metallicity_calc + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: Metallicity_Stack_Commons.analysis + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/Metallicity_Stack_Commons.others.rst b/docs/source/Metallicity_Stack_Commons.others.rst new file mode 100644 index 00000000..33e94296 --- /dev/null +++ b/docs/source/Metallicity_Stack_Commons.others.rst @@ -0,0 +1,21 @@ +``others`` subpackage +================== + +Submodules +---------- + +Metallicity\_Stack\_Commons.others.extract\_deep2\_data module +-------------------------------------------------------------- + +.. automodule:: Metallicity_Stack_Commons.others.extract_deep2_data + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: Metallicity_Stack_Commons.others + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/Metallicity_Stack_Commons.rst b/docs/source/Metallicity_Stack_Commons.rst new file mode 100644 index 00000000..814ecb37 --- /dev/null +++ b/docs/source/Metallicity_Stack_Commons.rst @@ -0,0 +1,29 @@ +Metallicity\_Stack\_Commons package +=================================== + +Subpackages +----------- + +.. toctree:: + :maxdepth: 4 + + Metallicity_Stack_Commons.analysis + Metallicity_Stack_Commons.others + + +Submodules +---------- + +.. toctree:: + :maxdepth: 4 + + Metallicity_Stack_Commons.submodules + + +Common functions +---------------- + +.. automodule:: Metallicity_Stack_Commons + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/Metallicity_Stack_Commons.submodules.rst b/docs/source/Metallicity_Stack_Commons.submodules.rst new file mode 100644 index 00000000..472c05ab --- /dev/null +++ b/docs/source/Metallicity_Stack_Commons.submodules.rst @@ -0,0 +1,31 @@ +Metallicity\_Stack\_Commons.column\_names module +------------------------------------------------ + +.. automodule:: Metallicity_Stack_Commons.column_names + :members: + :undoc-members: + :show-inheritance: + +Metallicity\_Stack\_Commons.logging module +------------------------------------------ + +.. automodule:: Metallicity_Stack_Commons.logging + :members: + :undoc-members: + :show-inheritance: + +Metallicity\_Stack\_Commons.update\_det4363\_info module +-------------------------------------------------------- + +.. automodule:: Metallicity_Stack_Commons.update_det4363_info + :members: + :undoc-members: + :show-inheritance: + +Metallicity\_Stack\_Commons.valid\_table module +----------------------------------------------- + +.. automodule:: Metallicity_Stack_Commons.valid_table + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/index.rst b/docs/source/index.rst index 71118ff8..d33ae32a 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -11,6 +11,7 @@ Welcome to metallicity-stack-commons's documentation! :caption: Contents: intro.rst + modules.rst Indices and tables ================== diff --git a/docs/source/modules.rst b/docs/source/modules.rst new file mode 100644 index 00000000..b2dfd94e --- /dev/null +++ b/docs/source/modules.rst @@ -0,0 +1,7 @@ +API Documentation +================= + +.. toctree:: + :maxdepth: 4 + + Metallicity_Stack_Commons From 6658fb498af6b8c18e152260771b00c32a8e9ef3 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 7 Feb 2021 00:28:51 -0700 Subject: [PATCH 03/42] Type hinting and update docstrings for analysis.attenuation module --- .../analysis/attenuation.py | 98 +++++++++++-------- 1 file changed, 57 insertions(+), 41 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/attenuation.py b/Metallicity_Stack_Commons/analysis/attenuation.py index ad688efd..c7eea134 100644 --- a/Metallicity_Stack_Commons/analysis/attenuation.py +++ b/Metallicity_Stack_Commons/analysis/attenuation.py @@ -1,3 +1,5 @@ +from typing import Union + import numpy as np from .. import k_dict, line_name_short @@ -19,25 +21,27 @@ k_HDELTA = k_dict[HD] -def compute_EBV(ratio, source='HgHb', zero_neg=True, verbose=False, log=None): +def compute_EBV(ratio: Union[float, np.ndarray], source: str = 'HgHb', + zero_neg: bool = True, verbose: bool = False, + log: type(log_stdout) = log_stdout()): """ - Purpose: - Determines E(B-V) from Hg/Hb or Hd/Hb flux ratios using Case B assumptions - - :param ratio: float or numpy array containing Hg/Hb or Hd/Hb - :param source: str indicate ratio type. Either 'HgHb' or 'HdHb'. Default: 'HgHb' - :param zero_neg: boolean to indicate whether to zero out negative reddening. Default: True - :param verbose: bool to write verbose message to stdout. Default: file only + Determines E(B-V) from Hg/Hb or Hd/Hb flux ratios using Case B assumptions + + :param ratio: Float or array containing Hg/Hb or Hd/Hb values + :param source: Indicate ratio type. Either 'HgHb' or 'HdHb'. + Default: 'HgHb' + :param zero_neg: Indicate whether to zero out negative reddening. + Default: True + :param verbose: Write verbose message to stdout. Default: file only :param log: LogClass or logging object - :return EBV: float or numpy array containing E(B-V). - Note: Not correcting for negative reddening - :return EBV_peak: float or numpy array return when it is a 2-D distribution + :return EBV: E(B-V) values + Note: Not correcting for negative reddening + :rtype: float|np.ndarray + :return EBV_peak: E(B-V) peak values + :rtype: float|np.ndarray """ - if log is None: - log = log_stdout() - log_verbose(log, "starting ...", verbose=verbose) if isinstance(ratio, list): @@ -87,22 +91,22 @@ def compute_EBV(ratio, source='HgHb', zero_neg=True, verbose=False, log=None): return EBV -def compute_A(EBV, verbose=False, log=None): +def compute_A(EBV: float, verbose: bool = False, + log: type(log_stdout) = log_stdout()) -> dict: """ - Purpose: - Compute A(Lambda) for all possible emission lines + Compute A(Lambda) for all possible emission lines - :param EBV: float value of E(B-V) - Has not been configured to handle a large array. Some array handling would be needed - :param verbose: bool to write verbose message to stdout. Default: file only + :param EBV: E(B-V) value + Has not been configured to handle a large array. + Some array handling would be needed + + :param verbose: Write verbose message to stdout. + Default: file only :param log: LogClass or logging object - :return A_dict: dict containing A(lambda) with keys identical to k_dict + :return A_dict: Contains A(lambda) with keys identical to ``k_dict`` """ - if log is None: - log = log_stdout() - log_verbose(log, "starting ...", verbose=verbose) k_arr = np.array(list(k_dict.values())) @@ -114,11 +118,25 @@ def compute_A(EBV, verbose=False, log=None): return A_dict -def line_ratio_atten(ratio, EBV, wave_top, wave_bottom, verbose=False, - log=None): +def line_ratio_atten(ratio: Union[float, np.ndarray], + EBV: Union[float, np.ndarray], + wave_top: str, wave_bottom: str, + verbose: bool = False, + log: type(log_stdout) = log_stdout()) -> \ + Union[float, np.ndarray]: + """ + Determine dust-corrected emission-line ratios + + :param ratio: Float or array of observed flux ratios + :param EBV: E(B-V) value(s) + :param wave_top: Emission-line name for flux ratio numerator + :param wave_bottom: Emission-line name for flux ratio denominator + :param verbose: Write verbose message to stdout. + Default: file only + :param log: LogClass or logging object - if log is None: - log = log_stdout() + :return ratio_atten: Float or array of dust-corrected flux ratios + """ log_verbose(log, "starting ...", verbose=verbose) @@ -131,28 +149,26 @@ def line_ratio_atten(ratio, EBV, wave_top, wave_bottom, verbose=False, return ratio_atten -def Hb_SFR(log_LHb, EBV, verbose=False, log=None): +def Hb_SFR(log_LHb: Union[float, np.ndarray], + EBV: Union[float, np.ndarray], + verbose: bool = False, + log: type(log_stdout) = log_stdout()) -> \ + Union[float, np.ndarray]: """ - Purpose: - Determine dust-corrected SFR using the H-beta luminosity and a - measurement for nebular attenuation + Determine dust-corrected SFR using the H-beta luminosity and a + measurement for nebular attenuation Equation below is based on Eq. 2 in Ly et al. (2015), ApJ, 805, 45 DOI: https://doi.org/10.1088/0004-637X/805/1/45 - :param log_LHb: numpy array or float containing logarithm of H-beta - luminosity in units of erg/s - :param EBV: numpy array or float providing E(B-V) - :param verbose: bool to write verbose message to stdout. Default: file only + :param log_LHb: Logarithm of H-beta luminosity in units of erg/s + :param EBV: E(B-V) value(s) + :param verbose: Write verbose message to stdout. Default: file only :param log: LogClass or logging object - :return logSFR: numpy array or float containing the SFR in - logarithmic units of M_sun/yr + :return logSFR: SFRs in logarithmic units of M_sun/yr """ - if log is None: - log = log_stdout() - log_verbose(log, "starting ...", verbose=verbose) logSFR = np.log10(4.4e-42 * HaHb_CaseB) + 0.4*EBV*k_HBETA + log_LHb From 65b7b36f191444021d8fec29da4a411a5d732e52 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 7 Feb 2021 00:35:49 -0700 Subject: [PATCH 04/42] Type hinting and update docstrings for analysis.error_prop module --- .../analysis/error_prop.py | 51 ++++++++----------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/error_prop.py b/Metallicity_Stack_Commons/analysis/error_prop.py index 7f7b81f8..03bf95fd 100644 --- a/Metallicity_Stack_Commons/analysis/error_prop.py +++ b/Metallicity_Stack_Commons/analysis/error_prop.py @@ -15,23 +15,18 @@ from ..logging import log_stdout, log_verbose -def write_npz(path, npz_files, dict_list, verbose=False, log=None): +def write_npz(path: str, npz_files: list, dict_list: list, + verbose: bool = False, log: type(log_stdout) = log_stdout()): """ - Purpose: - Write numpy files with provided dictionaries + 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 - :param verbose: bool to write verbose message to stdout. Default: file only + :param path: Prefix for filename output + :param npz_files: NPZ file names + :param dict_list: List of dict for each corresponding npz file + :param verbose: Write verbose message to stdout. Default: file only :param log: LogClass or logging object - - :return: Write npz files """ - if log is None: - log = log_stdout() - log_verbose(log, "starting ...", verbose=verbose) for file, dict_input in zip(npz_files, dict_list): @@ -45,27 +40,25 @@ def write_npz(path, npz_files, dict_list, verbose=False, log=None): log_verbose(log, "finished.", verbose=verbose) -def fluxes_derived_prop(path, raw=False, binned_data=True, apply_dust=False, - revised=True, verbose=False, log=None): +def fluxes_derived_prop(path: str, raw: bool = False, + binned_data: bool = True, apply_dust: bool = False, + revised: bool = True, verbose: bool = False, + log: type(log_stdout) = log_stdout()): """ - 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 raw: bool to do a simple calculation, no randomization. Default: False - :param binned_data: bool for whether to analysis binned data. Default: True - :param apply_dust: bool for whether to apply dust attenuation. Default: False - :param revised: bool to indicate if revised validation table is used. Default: True - :param verbose: bool to write verbose message to stdout. Default: file only + 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: Full path + :param raw: Do a simple calculation, no randomization. Default: False + :param binned_data: Whether to analyze binned data. Default: True + :param apply_dust: Whether to apply dust attenuation. Default: False + :param revised: Indicate if revised validation table is used. Default: True + :param verbose: Write verbose message to stdout. Default: file only :param log: LogClass or logging object """ - if log is None: - log = log_stdout() - log_verbose(log, "starting ...", verbose=verbose) # Define files to read in for binned data From 9dc0736b6e578a45172c3da13225d4a7d7d1e7f9 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 7 Feb 2021 00:50:06 -0700 Subject: [PATCH 05/42] Type hinting and update docstrings for analysis.fitting module --- Metallicity_Stack_Commons/analysis/fitting.py | 131 +++++++++--------- 1 file changed, 62 insertions(+), 69 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/fitting.py b/Metallicity_Stack_Commons/analysis/fitting.py index 380a167c..90d08d77 100644 --- a/Metallicity_Stack_Commons/analysis/fitting.py +++ b/Metallicity_Stack_Commons/analysis/fitting.py @@ -1,3 +1,4 @@ +from typing import Union import numpy as np from astropy.convolution import Box1DKernel, convolve from astropy.io import ascii as asc @@ -9,37 +10,35 @@ con1 = wavelength_dict['OII_3729'] / wavelength_dict['OII_3726'] -def gauss(x, xbar, s, a, c): +def gauss(x: np.ndarray, xbar: float, s: float, a: float, c: float) \ + -> np.ndarray: """ - Purpose: - Function providing Gaussian profile for curve_fit + Function providing Gaussian profile for curve_fit - :param x: wavelength array - :param xbar: central wavelength of Gaussian fit - :param s: sigma (width) of Gaussian fit - :param a: amplitude of Gaussian fit - :param c: continuum constant for Gaussian fit + :param x: Wavelength array + :param xbar: Central wavelength of Gaussian fit + :param s: Sigma (width) of Gaussian fit + :param a: Amplitude of Gaussian fit + :param c: Continuum constant for Gaussian fit - :return: - Gaussian fit + :return: Gaussian fit """ return a * np.exp(-(x - xbar) ** 2 / (2 * s ** 2)) + c -def double_gauss(x, xbar, s1, a1, c, s2, a2): +def double_gauss(x: np.ndarray, xbar: float, s1: float, a1: float, c: float, + s2: float, a2: float) -> np.array: """ - Purpose: - Function providing double Gaussian profile (emission and absorption) - for curve_fit - - :param x: wavelength array - :param xbar: central wavelength of Gaussian fit - :param s1: sigma (width) of first Gaussian fit - :param a1: amplitude of first Gaussian fit - :param c: continuum constant for Gaussian fit + Function providing double Gaussian profile (emission and absorption) + for curve_fit - :param s2: sigma (width) of second Gaussian fit - :param a2: amplitude of second Gaussian fit + :param x: Wavelength array + :param xbar: Central wavelength of Gaussian fit + :param s1: Sigma (width) of first Gaussian fit (positive) + :param a1: Amplitude of first Gaussian fit + :param c: Continuum constant for Gaussian fit + :param s2: Sigma (width) of second Gaussian fit (absorption) + :param a2: Amplitude of second Gaussian fit :return: Double Gaussian fit """ @@ -48,49 +47,44 @@ def double_gauss(x, xbar, s1, a1, c, s2, a2): a2 * np.exp(-(x - xbar) ** 2 / (2 * s2 ** 2)) -def oxy2_gauss(x, xbar, s1, a1, c, s2, a2): +def oxy2_gauss(x: np.ndarray, xbar: float, s1: float, a1: float, c: float, + s2: float, a2: float) -> np.ndarray: """ - Purpose: - Function providing [OII] doublet Gaussian profile for curve_fit + Function providing [OII] doublet Gaussian profile for curve_fit - :param x: wavelength array - :param xbar: central wavelength of [OII]3726 Gaussian fit - :param s1: sigma (width) of [OII]3726 Gaussian fit - :param a1: amplitude of [OII]3726 Gaussian fit - :param c: continuum constant for Gaussian fit - :param s2: sigma (width) of [OII]3728 Gaussian fit - :param a2: amplitude of [OII]3728 Gaussian fit + :param x: Wavelength array + :param xbar: Central wavelength of [OII]3726 Gaussian fit + :param s1: Sigma (width) of [OII]3726 Gaussian fit + :param a1: Amplitude of [OII]3726 Gaussian fit + :param c: Continuum constant for Gaussian fit + :param s2: Sigma (width) of [OII]3728 Gaussian fit + :param a2: Amplitude of [OII]3728 Gaussian fit :return: [OII] doublet Gaussian fit - """ return a1 * np.exp(-(x - xbar) ** 2 / (2 * s1 ** 2)) + c + \ a2 * np.exp(-(x - (xbar * con1)) ** 2 / (2 * s2 ** 2)) -def rms_func(wave, dispersion, lambda_in, y0, sigma_array, mask_flag, - verbose=False, log=None): +def rms_func(wave: np.ndarray, dispersion: float, lambda_in: float, + y0: np.ndarray, sigma_array: float, mask_flag: np.ndarray, + verbose: bool = False, log: type(log_stdout) = log_stdout()): """ - Purpose: - Compute rms in the spectra - - :param wave: numpy array containing rest wavelengths - :param dispersion: spectral dispersion in AA/pix - :param lambda_in: central wavelength of fit - :param y0: numpy array containing spectra in units of erg/s/cm2/AA - :param sigma_array: Gaussian sigma - :param mask_flag: numpy array indicating spectra that are masked for OH - skyline contamintion - :param verbose: bool to write verbose message to stdout. Default: file only + Compute rms in the spectra + + :param wave: Array of rest wavelengths + :param dispersion: Spectral dispersion in AA/pix + :param lambda_in: Central wavelength of fit + :param y0: Array of fluxes in units of erg/s/cm2/AA + :param sigma_array: Gaussian sigma (AA) + :param mask_flag: Indicates spectra are masked for OH skyline contamination + :param verbose: Write verbose message to stdout. Default: file only :param log: LogClass or logging object :return: """ - if log is None: - log = log_stdout() - log_verbose(log, "starting ...", verbose=verbose) x_idx = np.where((np.abs(wave - lambda_in) <= 100) & (mask_flag == 0))[0] @@ -112,28 +106,26 @@ def rms_func(wave, dispersion, lambda_in, y0, sigma_array, mask_flag, return ini_sig / scalefact, RMS_pix -def OIII4363_flux_limit(combine_flux_ascii, verbose=False, log=None): +def OIII4363_flux_limit(combine_flux_file: str, verbose: bool = False, + log: type(log_stdout) = log_stdout()) -> \ + Union[None, np.ndarray]: """ - Purpose: - Determine 3-sigma limit on [OIII]4363 based on H-gamma measurements + Determine 3-sigma limit on [OIII]4363 based on H-gamma measurements - :param combine_flux_ascii: filename of ASCII file containing emission-line - flux measurements - :param verbose: bool to write verbose message to stdout. Default: file only + :param combine_flux_file: Filename of ASCII file containing emission-line + flux measurements + :param verbose: Write verbose message to stdout. Default: file only :param log: LogClass or logging object - :return: numpy array containing 3-sigma flux limit + :return flux_limit: Array containing 3-sigma flux limit """ - if log is None: - log = log_stdout() - log_verbose(log, "starting ...", verbose=verbose) try: - combine_fits = asc.read(combine_flux_ascii) + combine_fits = asc.read(combine_flux_file) except FileNotFoundError: - log.warning(f"File not found! {combine_flux_ascii}") + log.warning(f"File not found! {combine_flux_file}") return Hgamma = combine_fits['HGAMMA_Flux_Observed'].data @@ -145,19 +137,20 @@ def OIII4363_flux_limit(combine_flux_ascii, verbose=False, log=None): return flux_limit -def movingaverage_box1D(values, width, boundary='fill', fill_value=0.0): +def movingaverage_box1D(values: np.ndarray, width: float, + boundary: str = 'fill', fill_value: float = 0.0)\ + -> np.ndarray: """ - Purpose: - Applies as boxcar kernel to smooth spectra + Applies as boxcar kernel to smooth spectra - :param values: numpy array containing the spectrum - :param width: float containing width for smoothing - :param boundary: handling of boundary values. + :param values: Array containing the spectrum + :param width: Width for smoothing + :param boundary: Handling of boundary values. Options are: 'None', 'fill', 'wrap', and 'extend' See astropy.convolution.convolve for more information - :param fill_value: float to indicate fill value for default boundary='fill' + :param fill_value: Indicate fill value for default boundary='fill' - :return smooth: numpy array contained the smoothed/convolved spectrum + :return smooth: Array contained the smoothed/convolved spectrum """ box_kernel = Box1DKernel(width) From 5023f21a9da6637c24af6e72be136908d116ffe6 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 7 Feb 2021 00:53:57 -0700 Subject: [PATCH 06/42] Type hinting and update docstrings for analysis.ratios module --- Metallicity_Stack_Commons/analysis/ratios.py | 25 +++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/ratios.py b/Metallicity_Stack_Commons/analysis/ratios.py index b8c1f58d..5ea1fe11 100644 --- a/Metallicity_Stack_Commons/analysis/ratios.py +++ b/Metallicity_Stack_Commons/analysis/ratios.py @@ -6,25 +6,22 @@ from ..logging import log_stdout, log_verbose -def flux_ratios(flux_dict, binned_data=False, get_R=True, verbose=False, - log=None): +def flux_ratios(flux_dict: dict, binned_data: bool = False, + get_R: bool = True, verbose: bool = False, + log: type(log_stdout) = log_stdout()) -> dict: """ - Purpose: - Primary code to determine a variety of line ratios based on a dictionary - containing emission-line fluxes - - :param flux_dict: dict containing line ratios - :param get_R: bool to indicate to populate with OIII4363/OIII5007 flux ratio - :param binned_data: bool for whether to analysis binned data. Default: False - :param verbose: bool to write verbose message to stdout. Default: file only + Primary code to determine a variety of line ratios based on a dict + containing emission-line fluxes + + :param flux_dict: Contains emission-line fluxes + :param get_R: Indicates populating OIII4363/OIII5007 flux ratio + :param binned_data: Whether to analyze binned data. Default: False + :param verbose: Write verbose message to stdout. Default: file only :param log: LogClass or logging object - :return flux_ratios_dict: dict containing flux ratios + :return flux_ratios_dict: Contains emission-line flux ratios """ - if log is None: - log = log_stdout() - log_verbose(log, "starting ...", verbose=verbose) if not binned_data: From bf856d63969c1a38824abf887ced87fb7cd0babc Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 7 Feb 2021 11:51:13 -0700 Subject: [PATCH 07/42] Type hinting and update docstrings for analysis.temp_metallicity_calc module --- .../analysis/temp_metallicity_calc.py | 59 +++++++++++-------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/temp_metallicity_calc.py b/Metallicity_Stack_Commons/analysis/temp_metallicity_calc.py index a46d1fb0..a9ee3164 100644 --- a/Metallicity_Stack_Commons/analysis/temp_metallicity_calc.py +++ b/Metallicity_Stack_Commons/analysis/temp_metallicity_calc.py @@ -1,3 +1,4 @@ +from typing import Union import numpy as np from .. import k_dict, OIII_r @@ -16,22 +17,23 @@ c = 0.98062 -def R_calculation(OIII4363, OIII5007, verbose=False, log=None): +def R_calculation(OIII4363: Union[float, np.ndarray], + OIII5007: Union[float, np.ndarray], + verbose: bool = False, + log: type(log_stdout) = log_stdout()) \ + -> Union[float, np.ndarray]: """ 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 verbose: bool to write verbose message to stdout. Default: file only + :param OIII4363: OIII4363 fluxes + :param OIII5007: OIII5007 fluxes + :param verbose: Write verbose message to stdout. Default: file only :param log: LogClass or logging object :return R_value: O++ excitation flux ratio """ - if log is None: - log = log_stdout() - log_verbose(log, "starting ...", verbose=verbose) R_value = OIII4363 / (OIII5007 * (1 + 1/OIII_r)) @@ -40,7 +42,9 @@ def R_calculation(OIII4363, OIII5007, verbose=False, log=None): return R_value -def temp_calculation(R, EBV=None, verbose=False, log=None): +def temp_calculation(R: np.ndarray, EBV: Union[None, np.ndarray] = None, + verbose: bool = False, + log: type(log_stdout) = log_stdout()) -> np.ndarray: """ Computes electron temperature (T_e) from O++ excitation flux ratio @@ -48,17 +52,14 @@ def temp_calculation(R, EBV=None, verbose=False, log=None): 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) - :param EBV: numpy array of E(B-V). Set to zero if not applying attenuation - :param verbose: bool to write verbose message to stdout. Default: file only + :param R: Array of O++ excitation flux ratio (see R_calculation) + :param EBV: Array of E(B-V). Set to zero if not applying attenuation + :param verbose: Write verbose message to stdout. Default: file only :param log: LogClass or logging object - :return T_e: numpy array of T_e (Kelvins) + :return T_e: Array of T_e (Kelvins) """ - if log is None: - log = log_stdout() - log_verbose(log, "starting ...", verbose=verbose) arr_shape = R.shape @@ -75,23 +76,29 @@ def temp_calculation(R, EBV=None, verbose=False, log=None): return T_e -def metallicity_calculation(T_e, TWO_BETA, THREE_BETA, EBV=None, det3=None, - verbose=False, log=None): +def metallicity_calculation(T_e: np.ndarray, TWO_BETA: np.ndarray, + THREE_BETA: np.ndarray, + EBV: Union[None, np.ndarray] = None, + det3: Union[None, np.ndarray] = None, + verbose: bool = False, + log: type(log_stdout) = log_stdout()) -> dict: """ - Determines 12+log(O/H) from electron temperature and [OII]/Hb and [OIII]/Hb flux ratio + 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 - :param EBV: Optional array input containing EBV distribution + :param T_e: Array of electron temperatures (see ``temp_calculation``) + :param TWO_BETA: Array of [OII]/Hb flux ratios + :param THREE_BETA: Array of [OIII]/Hb flux ratios + :param EBV: Optional array containing EBV distribution :param det3: Optional array to pass in to identify those satisfying det3 requirements. Default: None means full array is considered - Note: for MC inputs, a 1-D np.array index satisfying det3 - requirements will suffice - :param verbose: bool to write verbose message to stdout. Default: file only + + Note: for Monte Carlo inputs, a 1-D np.array index satisfying + det3 requirements will suffice + :param verbose: Write verbose message to stdout. Default: file only :param log: LogClass or logging object - :return metal_dict: dict containing 12+log(O/H), O+/H, O++/H, log(O+/H), log(O++/H) + :return metal_dict: Contains 12+log(O/H), O+/H, O++/H, log(O+/H), log(O++/H) """ if log is None: From da7b9bb20a5f639eae122810f0f6a40e77decf17 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 7 Feb 2021 11:57:53 -0700 Subject: [PATCH 08/42] Type hinting and update docstrings for analysis.composite_indv_detect module --- .../analysis/composite_indv_detect.py | 50 ++++++++++--------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index 2b115554..c4444830 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -21,40 +21,42 @@ three_beta_name = indv_names0[6] -def main(fitspath, dataset, revised=False, det3=True, verbose=False, log=None): +def main(fitspath: str, dataset: str, revised: bool = False, + det3: bool = True, verbose: bool = False, + log: type(log_stdout) = log_stdout()): """ - Purpose: - Reads in composite table(s) containing bin information to - determine temperature-based metallicity from composite average - T_e and individual line ratios ([OII]/H-beta, [OIII]/H-beta) - - :param fitspath: str containing folder path - :param dataset: str containing sub-folder (specific to stacking approach) - :param revised: Bool indicates whether to use revised bin properties - (e.g., *.revised.tbl files) - :param det3: Bool indicates whether individual galaxy files is limited to + Reads in composite table(s) containing bin information to + determine temperature-based metallicity from composite average + T_e and individual line ratios ([OII]/H-beta, [OIII]/H-beta) + + :param fitspath: Folder full path + :param dataset: Sub-folder path (specific to stacking approach) + :param revised: Indicates whether to use revised bin properties + (e.g., *.revised.tbl files). Default: False + :param det3: Indicates whether individual galaxy files is limited to those satisfying emission-line det3 requirement Default: True - :param verbose: bool to write verbose message to stdout. Default: file only + :param verbose: Write verbose message to stdout. Default: file only :param log: LogClass or logging object - Files identified by default - composite_file: str containing filename of composite data - e.g., '[dataset]/bin_derived_properties.tbl' or - '[dataset]/bin_derived_properties.revised.tbl' - indv_em_line_file: str containing filename that contains - emission-line information for each galaxy + + Files identified by default: + + composite_file: Filename of composite data + e.g., '[dataset]/bin_derived_properties.tbl', + '[dataset]/bin_derived_properties.revised.tbl' + + indv_em_line_file: Filename that contains emission-line information + for each galaxy e.g., 'individual_properties.tbl' - indv_bin_file: str containing filename tha contains bin information - for each galaxy + + indv_bin_file: Filename that contains bin information for each galaxy e.g., '[dataset]/individual_bin_info.tbl' - outfile: str containing filename of output file + + outfile: Filename of output file e.g., '[dataset]/individual_derived_properties.tbl' """ - if log is None: - log = log_stdout() - log_verbose(log, "starting ...", verbose=verbose) # Define [composite_file] From a7b21d913325433f24698d98428f0cdb8bf531f5 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 7 Feb 2021 12:07:45 -0700 Subject: [PATCH 09/42] Type hinting and update docstrings for MSC __init__ module --- Metallicity_Stack_Commons/__init__.py | 51 +++++++++++++++------------ 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/Metallicity_Stack_Commons/__init__.py b/Metallicity_Stack_Commons/__init__.py index 0c44a122..4d78bfd6 100644 --- a/Metallicity_Stack_Commons/__init__.py +++ b/Metallicity_Stack_Commons/__init__.py @@ -1,3 +1,5 @@ +from typing import Union + from chun_codes.cardelli import cardelli import astropy.units as u from datetime import date @@ -51,22 +53,20 @@ k_dict = dict(zip(line_name, k_values)) -def exclude_outliers(objno, verbose=False, log=None): +def exclude_outliers(objno: Union[list, np.ndarray], verbose: bool = False, + log: type(log_stdout) = log_stdout()) -> np.ndarray: """ Exclude spectra that are identified as outliers. Generally this is because the spectra have very high S/N on the continuum. - :param objno: list or numpy array of eight-digit identifier - :param verbose: bool to write verbose message to stdout. Default: file only + :param objno: Array of eight-digit identifier + :param verbose: Write verbose message to stdout. Default: file only :param log: LogClass or logging object - :return flag: numpy array of zeros and ones + :return flag: Array of zeros (not flagged) and ones (flagged """ - if log is None: - log = log_stdout() - log_verbose(log, "starting ...", verbose=verbose) flag = np.zeros(len(objno), dtype=int) @@ -81,31 +81,29 @@ def exclude_outliers(objno, verbose=False, log=None): return flag -def dir_date(folder_name, path_init='', year=False, verbose=False, log=None): +def dir_date(folder_name: str, path_init: str = '', year: bool = False, + verbose: bool = False, log: type(log_stdout) = log_stdout()) \ + -> str: """ - 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 - a new directory named after the current date in the provided folder_name - directory. + 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 + a new directory named after the current date in the provided + ``folder_name`` directory. - From https://github.com/rafia37/Evolution-of-Galaxies/blob/master/general.py + Originally from https://github.com/rafia37/Evolution-of-Galaxies/blob/master/general.py Usage: - fitspath = dir_date(folder_name, path_init='', year=True) + fitspath = dir_date(folder_name, year=True) - :param folder_name: str containing directory for date subdirectory will be in + :param folder_name: Directory for date subdirectory will be in :param path_init: root path. Default: empty string :param year: Indicate whether to include year in date folder. Default: False - :param verbose: bool to write verbose message to stdout. Default: file only + :param verbose: Write verbose message to stdout. Default: file only :param log: LogClass or logging object :return fitspath: Full path to the date directory """ - if log is None: - log = log_stdout() - log_verbose(log, "starting ...", verbose=verbose) today = date.today() @@ -125,10 +123,17 @@ def dir_date(folder_name, path_init='', year=False, verbose=False, log=None): return fitspath -def get_user(username=None, verbose=False, log=None): +def get_user(username: Union[None, str] = None, + verbose: bool = False, log=None) -> str: + """ + Get the corresponding path for a given ``username`` + + :param username: Optional input for username + :param verbose: Write verbose message to stdout. Default: file only + :param log: LogClass or logging object - if log is None: - log = log_stdout() + :return fitspath: Full path to the date directory + """ log_verbose(log, "starting ...", verbose=verbose) From 69b6f091ce348c953ba3512c4db1471d27ae223b Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 7 Feb 2021 12:24:23 -0700 Subject: [PATCH 10/42] Fix bug with log input (CI build fail) --- 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 4d78bfd6..60ec930e 100644 --- a/Metallicity_Stack_Commons/__init__.py +++ b/Metallicity_Stack_Commons/__init__.py @@ -124,7 +124,8 @@ def dir_date(folder_name: str, path_init: str = '', year: bool = False, def get_user(username: Union[None, str] = None, - verbose: bool = False, log=None) -> str: + verbose: bool = False, + log: type(log_stdout) = log_stdout()) -> str: """ Get the corresponding path for a given ``username`` From 30d5c2edc4d3318817311261e1e2efcb1e147d83 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 7 Feb 2021 12:24:42 -0700 Subject: [PATCH 11/42] Type hinting and update docstrings for column_names module --- Metallicity_Stack_Commons/column_names.py | 46 +++++++++++------------ 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/Metallicity_Stack_Commons/column_names.py b/Metallicity_Stack_Commons/column_names.py index 9070b53b..04d6b6bc 100644 --- a/Metallicity_Stack_Commons/column_names.py +++ b/Metallicity_Stack_Commons/column_names.py @@ -6,15 +6,15 @@ # Need to define here -def line_fit_suffix_add(line_name0, line_type0): +def line_fit_suffix_add(line_name0: str, line_type0: str) -> list: """ - Purpose: - Simple list comprehension combining emission line fit suffixes with - the emission line. This works for individual lines + Simple list comprehension combining emission line fit suffixes with + the emission line. This works for individual lines + + :param line_name0: Line name + :param line_type0: Emission-line type (e.g., 'Balmer') - :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] + :return: List of strings formatted as [LINE]_[SUFFIX] """ gauss_lines_names = [f"{line_name0}_{suffix}" for suffix in gauss_names0] @@ -111,16 +111,16 @@ def line_fit_suffix_add(line_name0, line_type0): '.valid1.dustcorr.npz') -def merge_column_names(*args): +def merge_column_names(*args: list) -> list: """ - Purpose: - Merges multiple lists containing column names. + 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: + + :return merge_list: Merged list """ merge_list = list() @@ -133,13 +133,13 @@ def merge_column_names(*args): return merge_list -def remove_from_list(list0, remove_entries): +def remove_from_list(list0: list, remove_entries: list) -> list: """ Purpose: - Remove entries from list + Remove entries from list of column names - :param list0: list of column names - :param remove_entries: list of column names to remove + :param list0: List of column names + :param remove_entries: List of column names to remove """ if py_vers == 3: @@ -153,23 +153,23 @@ def remove_from_list(list0, remove_entries): return dup_list0 -def indv_R23_O32(): +def indv_R23_O32() -> list: """ - Purpose: - Use remove_from_list() to provide simplified list that contains ID, logR23 and logO32 + Use remove_from_list() to provide simplified list that contains + ID, logR23 and logO32 - :return: list containing just ID, logR23, logO32 + :return: List containing just ID, logR23, logO32 """ return remove_from_list(indv_names0, ['logM', 'logLHb']) -def indv_M_LHb(): +def indv_M_LHb() -> list: """ - Purpose: - Use remove_from_list() to provide simplified list that contains ID, logM and logLHb + Use remove_from_list() to provide simplified list that contains + ID, logM and logLHb - :return: list containing just ID, logM, logLHb + :return: List containing just ID, logM, logLHb """ return remove_from_list(indv_names0, ['logR23', 'logO32']) From ca14b04b0f90f3ed81456d3da7e9d6a383a3da51 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 7 Feb 2021 12:38:51 -0700 Subject: [PATCH 12/42] Type hinting and update docstrings for logging module --- Metallicity_Stack_Commons/logging.py | 37 +++++++++++++++------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/Metallicity_Stack_Commons/logging.py b/Metallicity_Stack_Commons/logging.py index 60d3f8df..338c47a5 100644 --- a/Metallicity_Stack_Commons/logging.py +++ b/Metallicity_Stack_Commons/logging.py @@ -1,6 +1,7 @@ import sys from os.path import join from os import uname +from typing import Union from getpass import getuser from socket import gethostname @@ -16,21 +17,19 @@ class LogClass: """ - Purpose: - Main class to log information to stdout and ASCII logfile + Main class to log information to stdout and ASCII logfile Note: This code is identical to the one used in ReQUIAM: https://github.com/ualibraries/ReQUIAM To use: - log = LogClass(log_dir, logfile).get_logger() + log = LogClass(log_dir, logfile).get_logger() - Parameters: - log_dir: Relative path for exported logfile directory - logfile: Filename for exported log file + :param log_dir: Relative path for exported logfile directory + :param logfile: Filename for exported log file """ - def __init__(self, log_dir, logfile): + def __init__(self, log_dir: str, logfile: str): self.LOG_FILENAME = join(log_dir, logfile) def get_logger(self): @@ -54,7 +53,10 @@ def get_logger(self): return log -def log_stdout(): +def log_stdout() -> type(logging.getLogger()): + """ + Returns stdout logging object + """ log_level = logging.INFO log = logging.getLogger("stdout_logger") if not log.handlers: @@ -68,11 +70,11 @@ def log_stdout(): return log -def get_user_hostname(): +def get_user_hostname() -> dict: """ - Purpose: - Retrieve user, hostname, IP, and OS configuration - :return sys_info: dictionary with 'user' 'hostname' and 'ip' dictionary + Retrieve user, hostname, IP, and OS configuration + + :return: Dictionary with 'user' 'hostname' and 'ip' keys """ sys_info = dict() @@ -87,15 +89,16 @@ def get_user_hostname(): return sys_info -def log_verbose(log, message, verbose=False): +def log_verbose(log: Union[type(logging.getLogger()), logging.Logger], + message: str, verbose: bool = False): """ - Purpose: - Log message depending on verbosity + Log message depending on verbosity :param log: LogClass or logging object - :param message: str - :param verbose: bool to write verbose message to stdout. Default: file only + :param message: Message + :param verbose: Write verbose message to stdout. Default: file only """ + if verbose: log.info(message) # Write to stdout else: From 894e054a3506af25df230db4ba9e3a52a8a397e9 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 7 Feb 2021 12:45:55 -0700 Subject: [PATCH 13/42] Type hinting and update docstrings for valid_table module --- Metallicity_Stack_Commons/valid_table.py | 70 ++++++++++-------------- 1 file changed, 28 insertions(+), 42 deletions(-) diff --git a/Metallicity_Stack_Commons/valid_table.py b/Metallicity_Stack_Commons/valid_table.py index e13c0629..ecd687de 100644 --- a/Metallicity_Stack_Commons/valid_table.py +++ b/Metallicity_Stack_Commons/valid_table.py @@ -6,34 +6,26 @@ from .column_names import filename_dict, valid_table_names0 # , bin_names0, remove_from_list -def make_validation_table(fitspath): +def make_validation_table(fitspath: str): """ - Purpose: - This function creates a validation table for a given binning set. The validation table - contains a OIII4363 detection column where 1.0 means detection, 0.5 means non-detection with - reliable OIII5007, and 0.0 means unreliable non-detection. - This function will be run every time the analysis is completed and will create a validation - table for every analysis. + This function creates a validation table for a given binning set. + The validation table contains a OIII4363 detection column where 1.0 + means detection, 0.5 means non-detection with reliable OIII5007, and + 0.0 means unreliable non-detection. This function will be run every + time the analysis is completed and will create a validation table + for every analysis. Usage: valid_table.make_validation_table(fitspath, bin_type_str) - Params: - fitspath --> a string of the file path where the input file is and where the output file - will be placed. - not in use: - bin_type_str --> a string describing the binning type. (e.g. 'massLHbetabin' or 'massbin') - --> This is dataset for Zcalbase_gal analysis - - Returns: - None + :param fitspath: Full file path where the input file is and where the + output file will be placed. Outputs: - fitspath + 'bin_validation.tbl' --> a validation table containing bin IDs; - number of galaxies in each bin; and - column indicating OIII4363 detection/non-detection - OIII4363_Flux_Observed - OIII4363_S/N + fitspath + 'bin_validation.tbl' + Validation table containing bin IDs; number of galaxies in each bin; + and column indicating OIII4363 detection/non-detection, + OIII4363_Flux_Observed, OIII4363_S/N """ bin_table = asc.read(fitspath + filename_dict['bin_info']) @@ -88,33 +80,27 @@ def make_validation_table(fitspath): ''' -def compare_to_by_eye(fitspath, dataset): +def compare_to_by_eye(fitspath: str, dataset: str): """ - Purpose -> This function takes the automated validation table and checks it against - inputted measurement that are determined by eye. These inputted measurements - are in the np.where statements. It outputs a revised validation table based - on the inputted measurements. - - Usage -> valid_table.make_validation_table(fitspath, dataset) + This function takes the automated validation table and checks it against + inputted measurement that are determined by eye. These inputted + measurements are in the np.where statements. It outputs a revised + validation table based on the inputted measurements. - Params: - fitspath --> a string of the file path where the input file is and where the output file - will be placed - dataset --> a string that is used to determine which eye measurements to use + Usage: + valid_table.make_validation_table(fitspath, dataset) - Returns: - None + :param fitspath: Full file path where the input file is and where the + output file will be placed. + :param dataset: Determine which eye measurements to use Outputs: - fitspath + 'bin_validation_revised.tbl' and '.csv' --> - a validation table containing bin IDs; - number of galaxies in each bin; and - column indicating OIII4363 detection/non-detection - OIII4363_Flux_Observed - OIII4363_S/N - Notes - + fitspath + 'bin_validation_revised.tbl' and '.csv' + Validation table containing bin IDs; number of galaxies in each bin; + and column indicating OIII4363 detection/non-detection, + OIII4363_Flux_Observed, OIII4363_S/N, Notes """ + ver_table = fitspath + filename_dict['bin_valid'] ver_tab = asc.read(ver_table) indicate = ver_tab['Detection'] From 59302699b0c5d4115b2a0ebad825190e35c35ae6 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 7 Feb 2021 12:47:37 -0700 Subject: [PATCH 14/42] Fix too short title underline --- docs/source/Metallicity_Stack_Commons.others.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/Metallicity_Stack_Commons.others.rst b/docs/source/Metallicity_Stack_Commons.others.rst index 33e94296..c5bb33e4 100644 --- a/docs/source/Metallicity_Stack_Commons.others.rst +++ b/docs/source/Metallicity_Stack_Commons.others.rst @@ -1,5 +1,5 @@ ``others`` subpackage -================== +===================== Submodules ---------- From 59241183c97b1d84667b3e3108f328a989444d9d Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 7 Feb 2021 12:51:01 -0700 Subject: [PATCH 15/42] Fix sphinx compile issues for analysis.temp_metallicity_calc module --- Metallicity_Stack_Commons/analysis/temp_metallicity_calc.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/temp_metallicity_calc.py b/Metallicity_Stack_Commons/analysis/temp_metallicity_calc.py index a9ee3164..f03152c1 100644 --- a/Metallicity_Stack_Commons/analysis/temp_metallicity_calc.py +++ b/Metallicity_Stack_Commons/analysis/temp_metallicity_calc.py @@ -49,15 +49,15 @@ def temp_calculation(R: np.ndarray, EBV: Union[None, np.ndarray] = None, 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) + T_e = a(-log(R)-b)^(-c) + where a = 13025, b=0.92506, and c=0.98062 (Nicholls et al. 2014) :param R: Array of O++ excitation flux ratio (see R_calculation) :param EBV: Array of E(B-V). Set to zero if not applying attenuation :param verbose: Write verbose message to stdout. Default: file only :param log: LogClass or logging object - :return T_e: Array of T_e (Kelvins) + :return: Array of T_e (Kelvins) """ log_verbose(log, "starting ...", verbose=verbose) From b760b99b19e74748d8af2269e597f7739eb6a54e Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 7 Feb 2021 15:01:44 -0700 Subject: [PATCH 16/42] Fix sphinx error message in composite_indv_detect module - WARNING: Inline emphasis start-string without end-string. --- Metallicity_Stack_Commons/analysis/composite_indv_detect.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index c4444830..9dc2bb76 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -32,14 +32,13 @@ def main(fitspath: str, dataset: str, revised: bool = False, :param fitspath: Folder full path :param dataset: Sub-folder path (specific to stacking approach) :param revised: Indicates whether to use revised bin properties - (e.g., *.revised.tbl files). Default: False + (e.g., revised.tbl files). Default: False :param det3: Indicates whether individual galaxy files is limited to those satisfying emission-line det3 requirement Default: True :param verbose: Write verbose message to stdout. Default: file only :param log: LogClass or logging object - Files identified by default: composite_file: Filename of composite data From e676f85d15d1c54ae912c1557b9ad4df2d3086f5 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 7 Feb 2021 15:18:14 -0700 Subject: [PATCH 17/42] Add plotting subpackage docs - Type hinting and update docstrings for plotting.balmer module --- Metallicity_Stack_Commons/plotting/balmer.py | 72 +++++++++---------- .../Metallicity_Stack_Commons.plotting.rst | 21 ++++++ docs/source/Metallicity_Stack_Commons.rst | 2 +- 3 files changed, 57 insertions(+), 38 deletions(-) create mode 100644 docs/source/Metallicity_Stack_Commons.plotting.rst diff --git a/Metallicity_Stack_Commons/plotting/balmer.py b/Metallicity_Stack_Commons/plotting/balmer.py index a48fc815..fbb31713 100644 --- a/Metallicity_Stack_Commons/plotting/balmer.py +++ b/Metallicity_Stack_Commons/plotting/balmer.py @@ -9,10 +9,13 @@ """ from os.path import join +from typing import Union + 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 Table from matplotlib.backends.backend_pdf import PdfPages from ..analysis.fitting import gauss, double_gauss @@ -26,25 +29,22 @@ n_cols = 3 -def extract_fit(astropy_table, line_name, balmer=False, verbose=False, - log=None): +def extract_fit(astropy_table: Table, line_name: str, balmer: bool = False, + verbose: bool = False, log: type(log_stdout) = log_stdout()) \ + -> Union[None, dict]: """ - Purpose: - Extract best fit from table and fluxes, return a list of - fitting parameters and fluxes + Extract best fit from table and fluxes, return a list of + fitting parameters and fluxes :param astropy_table: Astropy table containing fitting result - :param line_name: line to extract fit results - :param balmer: boolean to indicate whether line is a Balmer line - :param verbose: bool to write verbose message to stdout. Default: file only + :param line_name: Name of Line to extract fit results + :param balmer: Indicate whether line is a Balmer line + :param verbose: Write verbose message to stdout. Default: file only :param log: LogClass or logging object - :return result_dict: dict of fitting results + :return: Fitting results """ - if log is None: - log = log_stdout() - log_verbose(log, "starting ...", verbose=verbose) try: @@ -78,22 +78,23 @@ def extract_fit(astropy_table, line_name, balmer=False, verbose=False, return result_dict -def fitting_result(wave, y_norm, lambda_cen, line_fit, line_fit_neg, - flux_gauss, flux_spec, use_revised=False): +def fitting_result(wave: np.ndarray, y_norm: np.ndarray, lambda_cen: float, + line_fit: list, line_fit_neg: list, flux_gauss: float, + flux_spec: float, use_revised: bool = False) -> dict: """ - Purpose: - Returns fitting results based on inputs of best fit + Returns fitting results based on inputs of best fit - :param wave: numpy array of rest-frame wavelength + :param wave: Array of rest-frame wavelengths :param y_norm: Normalize 1-D spectra in units of 10^-17 erg/s/cm2/AA :param lambda_cen: Central wavelength in Angstroms - :param line_fit: list containing Balmer emission fits - :param line_fit_neg: list containing the absorption ("stellar") Balmer fit - :param flux_gauss: float containing flux from Gaussian model - :param flux_spec: float containing flux from spectrum (above median) - :param use_revised: bool to indicate whether fluxes have been revised. Default: False - - :return fit_dict: dict of fitting results + :param line_fit: List containing Balmer emission fits + :param line_fit_neg: List containing the absorption ("stellar") Balmer fit + :param flux_gauss: Flux from Gaussian model + :param flux_spec: Flux from spectrum (above median) + :param use_revised: Indicate whether fluxes have been revised. + Default: False + + :return: Dictionary of fitting results """ dx = wave[2] - wave[1] @@ -125,23 +126,20 @@ def fitting_result(wave, y_norm, lambda_cen, line_fit, line_fit_neg, # noinspection PyUnboundLocalVariable -def HbHgHd_fits(fitspath, out_pdf_prefix='HbHgHd_fits', - use_revised=False, verbose=False, log=None): +def HbHgHd_fits(fitspath: str, out_pdf_prefix: str ='HbHgHd_fits', + use_revised: bool = False, verbose: bool = False, + log: type(log_stdout) = log_stdout()): """ - Purpose: - Generate PDF plots that illustrate H-delta, H-gamma, and H-beta line - profiles and best fit - - :param fitspath: full path (str) - :param out_pdf_prefix: Prefix for outpute PDF file (str) - :param use_revised: Indicate whether to use regular or revised tables (bool) - :param verbose: bool to write verbose message to stdout. Default: file only + Generate PDF plots that illustrate H-delta, H-gamma, and H-beta line + profiles and best fit + + :param fitspath: Full path + :param out_pdf_prefix: Prefix for output PDF file + :param use_revised: Indicate whether to use regular or revised tables + :param verbose: Write verbose message to stdout. Default: file only :param log: LogClass or logging object """ - if log is None: - log = log_stdout() - log_verbose(log, "starting ...", verbose=verbose) comp_spec_file = join(fitspath, filename_dict['comp_spec']) diff --git a/docs/source/Metallicity_Stack_Commons.plotting.rst b/docs/source/Metallicity_Stack_Commons.plotting.rst new file mode 100644 index 00000000..25642bd4 --- /dev/null +++ b/docs/source/Metallicity_Stack_Commons.plotting.rst @@ -0,0 +1,21 @@ +``plotting`` subpackage +======================= + +Submodules +---------- + +Metallicity\_Stack\_Commons.plotting.balmer module +-------------------------------------------------------------- + +.. automodule:: Metallicity_Stack_Commons.plotting.balmer + :members: + :undoc-members: + :show-inheritance: + +Module contents +--------------- + +.. automodule:: Metallicity_Stack_Commons.plotting + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/Metallicity_Stack_Commons.rst b/docs/source/Metallicity_Stack_Commons.rst index 814ecb37..c94b36e1 100644 --- a/docs/source/Metallicity_Stack_Commons.rst +++ b/docs/source/Metallicity_Stack_Commons.rst @@ -9,7 +9,7 @@ Subpackages Metallicity_Stack_Commons.analysis Metallicity_Stack_Commons.others - + Metallicity_Stack_Commons.plotting Submodules ---------- From 25e1abf3c8a1b6637871d241a3cc18e26760ef00 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 7 Feb 2021 15:21:35 -0700 Subject: [PATCH 18/42] Add sphinx-build GitHub Actions --- .github/workflows/sphinx-build.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/workflows/sphinx-build.yml diff --git a/.github/workflows/sphinx-build.yml b/.github/workflows/sphinx-build.yml new file mode 100644 index 00000000..a633c57a --- /dev/null +++ b/.github/workflows/sphinx-build.yml @@ -0,0 +1,19 @@ +name: "Sphinx Docs Check" +on: + push: + paths: + - 'docs/**' + - 'Metallicity_Stack_Commons/**' + pull_request: + paths: + - 'docs/**' + - 'Metallicity_Stack_Commons/**' + +jobs: + docs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: ammaraskar/sphinx-action@master + with: + docs-folder: "docs/" \ No newline at end of file From 2feb19d1512e842e98918a8902974987d909415d Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 7 Feb 2021 15:30:15 -0700 Subject: [PATCH 19/42] Adjust :return description in analysis.attenuation module - Minor PEP8 whitespace fixes --- Metallicity_Stack_Commons/analysis/attenuation.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/attenuation.py b/Metallicity_Stack_Commons/analysis/attenuation.py index c7eea134..57ca9975 100644 --- a/Metallicity_Stack_Commons/analysis/attenuation.py +++ b/Metallicity_Stack_Commons/analysis/attenuation.py @@ -104,14 +104,14 @@ def compute_A(EBV: float, verbose: bool = False, Default: file only :param log: LogClass or logging object - :return A_dict: Contains A(lambda) with keys identical to ``k_dict`` + :return: A(lambda) with keys identical to ``k_dict`` """ log_verbose(log, "starting ...", verbose=verbose) - k_arr = np.array(list(k_dict.values())) + k_arr = np.array(list(k_dict.values())) - A_arr = k_arr * EBV + A_arr = k_arr * EBV A_dict = dict(zip(list(k_dict.keys()), A_arr)) log_verbose(log, "finished.", verbose=verbose) @@ -123,7 +123,7 @@ def line_ratio_atten(ratio: Union[float, np.ndarray], wave_top: str, wave_bottom: str, verbose: bool = False, log: type(log_stdout) = log_stdout()) -> \ - Union[float, np.ndarray]: + Union[float, np.ndarray]: """ Determine dust-corrected emission-line ratios @@ -135,12 +135,12 @@ def line_ratio_atten(ratio: Union[float, np.ndarray], Default: file only :param log: LogClass or logging object - :return ratio_atten: Float or array of dust-corrected flux ratios + :return: Float or array of dust-corrected flux ratios """ log_verbose(log, "starting ...", verbose=verbose) - k_top = k_dict[wave_top] + k_top = k_dict[wave_top] k_bottom = k_dict[wave_bottom] ratio_atten = ratio * 10**(0.4*EBV*(k_top - k_bottom)) @@ -166,7 +166,7 @@ def Hb_SFR(log_LHb: Union[float, np.ndarray], :param verbose: Write verbose message to stdout. Default: file only :param log: LogClass or logging object - :return logSFR: SFRs in logarithmic units of M_sun/yr + :return: SFRs in logarithmic units of M_sun/yr """ log_verbose(log, "starting ...", verbose=verbose) From 9a3943c6ccb71d45fb1d7a553923c377960d0bba Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 7 Feb 2021 15:39:06 -0700 Subject: [PATCH 20/42] Adjust :return: descriptions in analysis.fitting module --- Metallicity_Stack_Commons/analysis/fitting.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/fitting.py b/Metallicity_Stack_Commons/analysis/fitting.py index 90d08d77..a0a2211f 100644 --- a/Metallicity_Stack_Commons/analysis/fitting.py +++ b/Metallicity_Stack_Commons/analysis/fitting.py @@ -117,7 +117,7 @@ def OIII4363_flux_limit(combine_flux_file: str, verbose: bool = False, :param verbose: Write verbose message to stdout. Default: file only :param log: LogClass or logging object - :return flux_limit: Array containing 3-sigma flux limit + :return: Array containing 3-sigma flux limit """ log_verbose(log, "starting ...", verbose=verbose) @@ -150,7 +150,7 @@ def movingaverage_box1D(values: np.ndarray, width: float, See astropy.convolution.convolve for more information :param fill_value: Indicate fill value for default boundary='fill' - :return smooth: Array contained the smoothed/convolved spectrum + :return: Array contained the smoothed/convolved spectrum """ box_kernel = Box1DKernel(width) From 129cceb680a9a628c6c658b7f9ea94649b65d06e Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 7 Feb 2021 15:39:26 -0700 Subject: [PATCH 21/42] Adjust :return: description in analysis.ratios module --- Metallicity_Stack_Commons/analysis/ratios.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Metallicity_Stack_Commons/analysis/ratios.py b/Metallicity_Stack_Commons/analysis/ratios.py index 5ea1fe11..ae0f63ed 100644 --- a/Metallicity_Stack_Commons/analysis/ratios.py +++ b/Metallicity_Stack_Commons/analysis/ratios.py @@ -19,7 +19,7 @@ def flux_ratios(flux_dict: dict, binned_data: bool = False, :param verbose: Write verbose message to stdout. Default: file only :param log: LogClass or logging object - :return flux_ratios_dict: Contains emission-line flux ratios + :return: Emission-line flux ratios """ log_verbose(log, "starting ...", verbose=verbose) From 18bae613ac4659d653937ee693a819b08f5813c4 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 7 Feb 2021 15:40:21 -0700 Subject: [PATCH 22/42] Adjust :return: descriptions in analysis.temp_metallicity_calc module --- Metallicity_Stack_Commons/analysis/temp_metallicity_calc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/temp_metallicity_calc.py b/Metallicity_Stack_Commons/analysis/temp_metallicity_calc.py index f03152c1..4d2936d1 100644 --- a/Metallicity_Stack_Commons/analysis/temp_metallicity_calc.py +++ b/Metallicity_Stack_Commons/analysis/temp_metallicity_calc.py @@ -31,7 +31,7 @@ def R_calculation(OIII4363: Union[float, np.ndarray], :param verbose: Write verbose message to stdout. Default: file only :param log: LogClass or logging object - :return R_value: O++ excitation flux ratio + :return: O++ excitation flux ratio """ log_verbose(log, "starting ...", verbose=verbose) @@ -98,7 +98,7 @@ def metallicity_calculation(T_e: np.ndarray, TWO_BETA: np.ndarray, :param verbose: Write verbose message to stdout. Default: file only :param log: LogClass or logging object - :return metal_dict: Contains 12+log(O/H), O+/H, O++/H, log(O+/H), log(O++/H) + :return: Contains 12+log(O/H), O+/H, O++/H, log(O+/H), log(O++/H) """ if log is None: From 425a5c53432e2f00b0e43983b5052d3b2dfec872 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 7 Feb 2021 15:43:33 -0700 Subject: [PATCH 23/42] Adjust/add :return: descriptions in column_names module --- Metallicity_Stack_Commons/column_names.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Metallicity_Stack_Commons/column_names.py b/Metallicity_Stack_Commons/column_names.py index 04d6b6bc..e20e428b 100644 --- a/Metallicity_Stack_Commons/column_names.py +++ b/Metallicity_Stack_Commons/column_names.py @@ -120,7 +120,7 @@ def merge_column_names(*args: list) -> list: :param args: An undefined number of lists - :return merge_list: Merged list + :return: Merged list """ merge_list = list() @@ -140,6 +140,8 @@ def remove_from_list(list0: list, remove_entries: list) -> list: :param list0: List of column names :param remove_entries: List of column names to remove + + :return: List of column names after removal """ if py_vers == 3: From 49e06932a5d27fcf01cdc610dd6435fc92010fbb Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 7 Feb 2021 15:45:42 -0700 Subject: [PATCH 24/42] Adjust top-level docstrings for plotting.balmer module --- Metallicity_Stack_Commons/plotting/balmer.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Metallicity_Stack_Commons/plotting/balmer.py b/Metallicity_Stack_Commons/plotting/balmer.py index fbb31713..9ad8da9b 100644 --- a/Metallicity_Stack_Commons/plotting/balmer.py +++ b/Metallicity_Stack_Commons/plotting/balmer.py @@ -1,11 +1,11 @@ """ - balmer - ------ +balmer +------ - Generates plots illustrating Balmer recombination lines +Generates plots illustrating Balmer recombination lines - This code was created from: - https://github.com/astrochun/Zcalbase_gal/blob/master/Analysis/DEEP2_R23_O32/balmer_plots.py +This code was created from: + https://github.com/astrochun/Zcalbase_gal/blob/master/Analysis/DEEP2_R23_O32/balmer_plots.py """ from os.path import join From 3f4f0ac58c0c39ac3055b79820e2858dd3110fd7 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 7 Feb 2021 15:56:28 -0700 Subject: [PATCH 25/42] Type hinting and update docstrings for update_det4363_info module --- .../update_det4363_info.py | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/Metallicity_Stack_Commons/update_det4363_info.py b/Metallicity_Stack_Commons/update_det4363_info.py index 158a5393..eff8ad95 100644 --- a/Metallicity_Stack_Commons/update_det4363_info.py +++ b/Metallicity_Stack_Commons/update_det4363_info.py @@ -1,27 +1,28 @@ +from typing import Tuple +import numpy as np + from chun_codes import match_nosort +from astropy.table import Table + from .logging import log_stdout, log_verbose -def get_index(det4363_table, input_table, column_name, verbose=False, - log=None): +def get_index(det4363_table: Table, input_table: Table, column_name: str, + verbose: bool = False, log: type(log_stdout) = log_stdout()) -> \ + Tuple[np.ndarray, np.ndarray]: """ - Purpose: - Uses either OBJNO or AP/SLIT info to get index for an existing table + Uses either OBJNO or AP/SLIT info to get index for an existing table - :param det4363_table: astropy table containing DEEP2 [OIII]4363-detected sample - :param input_table: astropy table containing the entire sample to be updated - :param column_name: str containing column for cross-matching - :param verbose: bool to write verbose message to stdout. Default: file only + :param det4363_table: Astropy table containing DEEP2 [OIII]4363-detected sample + :param input_table: Astropy table containing the entire sample to be updated + :param column_name: Column name for cross-matching + :param verbose: Write verbose message to stdout. Default: file only :param log: LogClass or logging object - :return det4363_idx: Numpy index arrays containing for det4363_table and input_table - :return input_idx: numpy index array for input + :return: Index arrays for ``det4363_table``, ``input_table`` """ - if log is None: - log = log_stdout() - log_verbose(log, "starting ...", verbose=verbose) if column_name != 'OBJNO' or column_name != 'SLIT' or column_name != 'AP': From 2938cf109535651425eec72a5879ef5f960bf1a4 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 7 Feb 2021 15:58:59 -0700 Subject: [PATCH 26/42] Adjust :return: descriptions in __init__ module --- Metallicity_Stack_Commons/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Metallicity_Stack_Commons/__init__.py b/Metallicity_Stack_Commons/__init__.py index 60ec930e..3b4be295 100644 --- a/Metallicity_Stack_Commons/__init__.py +++ b/Metallicity_Stack_Commons/__init__.py @@ -64,7 +64,7 @@ def exclude_outliers(objno: Union[list, np.ndarray], verbose: bool = False, :param verbose: Write verbose message to stdout. Default: file only :param log: LogClass or logging object - :return flag: Array of zeros (not flagged) and ones (flagged + :return: Array of zeros (not flagged) and ones (flagged """ log_verbose(log, "starting ...", verbose=verbose) @@ -101,7 +101,7 @@ def dir_date(folder_name: str, path_init: str = '', year: bool = False, :param verbose: Write verbose message to stdout. Default: file only :param log: LogClass or logging object - :return fitspath: Full path to the date directory + :return: Full path to the date directory """ log_verbose(log, "starting ...", verbose=verbose) @@ -133,7 +133,7 @@ def get_user(username: Union[None, str] = None, :param verbose: Write verbose message to stdout. Default: file only :param log: LogClass or logging object - :return fitspath: Full path to the date directory + :return: Full path to the date directory """ log_verbose(log, "starting ...", verbose=verbose) From ce5c8c5704e4e5c0087566f31f3d22f70f8e9247 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Sun, 7 Feb 2021 16:13:27 -0700 Subject: [PATCH 27/42] Type hinting and update docstrings for attenuation.compute_EBV for different returns --- Metallicity_Stack_Commons/analysis/attenuation.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/attenuation.py b/Metallicity_Stack_Commons/analysis/attenuation.py index 57ca9975..b585d2cf 100644 --- a/Metallicity_Stack_Commons/analysis/attenuation.py +++ b/Metallicity_Stack_Commons/analysis/attenuation.py @@ -1,4 +1,4 @@ -from typing import Union +from typing import Union, Tuple import numpy as np @@ -23,7 +23,8 @@ def compute_EBV(ratio: Union[float, np.ndarray], source: str = 'HgHb', zero_neg: bool = True, verbose: bool = False, - log: type(log_stdout) = log_stdout()): + log: type(log_stdout) = log_stdout()) -> \ + Union[np.ndarray, Tuple[np.ndarray, np.ndarray]]: """ Determines E(B-V) from Hg/Hb or Hd/Hb flux ratios using Case B assumptions @@ -35,11 +36,11 @@ def compute_EBV(ratio: Union[float, np.ndarray], source: str = 'HgHb', :param verbose: Write verbose message to stdout. Default: file only :param log: LogClass or logging object - :return EBV: E(B-V) values - Note: Not correcting for negative reddening - :rtype: float|np.ndarray - :return EBV_peak: E(B-V) peak values - :rtype: float|np.ndarray + :return: E(B-V) values, E(B-V) peak values + + Note: + When only E(B-V) values is returned, correction does not account + for negative reddening """ log_verbose(log, "starting ...", verbose=verbose) From 306a9226bbd9a251bfdf7714ed4e29f9fd50d1cd Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Mon, 8 Feb 2021 19:06:19 -0700 Subject: [PATCH 28/42] Fix type hinting for attenuation.compute_EBV --- Metallicity_Stack_Commons/analysis/attenuation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Metallicity_Stack_Commons/analysis/attenuation.py b/Metallicity_Stack_Commons/analysis/attenuation.py index b585d2cf..ad25286d 100644 --- a/Metallicity_Stack_Commons/analysis/attenuation.py +++ b/Metallicity_Stack_Commons/analysis/attenuation.py @@ -24,7 +24,7 @@ def compute_EBV(ratio: Union[float, np.ndarray], source: str = 'HgHb', zero_neg: bool = True, verbose: bool = False, log: type(log_stdout) = log_stdout()) -> \ - Union[np.ndarray, Tuple[np.ndarray, np.ndarray]]: + Union[float, np.ndarray, Tuple[np.ndarray, np.ndarray]]: """ Determines E(B-V) from Hg/Hb or Hd/Hb flux ratios using Case B assumptions From fc5ddd1088b01ddc7b7a4489e85b7e4c276f6407 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Mon, 8 Feb 2021 19:28:12 -0700 Subject: [PATCH 29/42] Adjust type hinting and docstrings for log inputs - analysis.attenuation - analysis.composite_indv_detect - analysis.error_prop - analysis.fitting - analysis.ratios - analysis.temp_metallicity_calc - plotting.balmer - logging - update_det4363_info --- Metallicity_Stack_Commons/__init__.py | 6 +++--- .../analysis/attenuation.py | 17 +++++++++-------- .../analysis/composite_indv_detect.py | 6 ++++-- .../analysis/error_prop.py | 7 ++++--- Metallicity_Stack_Commons/analysis/fitting.py | 9 +++++---- Metallicity_Stack_Commons/analysis/ratios.py | 5 +++-- .../analysis/temp_metallicity_calc.py | 14 +++++++------- Metallicity_Stack_Commons/logging.py | 8 +++----- Metallicity_Stack_Commons/plotting/balmer.py | 9 +++++---- .../update_det4363_info.py | 5 +++-- 10 files changed, 46 insertions(+), 40 deletions(-) diff --git a/Metallicity_Stack_Commons/__init__.py b/Metallicity_Stack_Commons/__init__.py index 3b4be295..649f438c 100644 --- a/Metallicity_Stack_Commons/__init__.py +++ b/Metallicity_Stack_Commons/__init__.py @@ -62,7 +62,7 @@ def exclude_outliers(objno: Union[list, np.ndarray], verbose: bool = False, :param objno: Array of eight-digit identifier :param verbose: Write verbose message to stdout. Default: file only - :param log: LogClass or logging object + :param log: logging.Logger object :return: Array of zeros (not flagged) and ones (flagged """ @@ -99,7 +99,7 @@ def dir_date(folder_name: str, path_init: str = '', year: bool = False, :param path_init: root path. Default: empty string :param year: Indicate whether to include year in date folder. Default: False :param verbose: Write verbose message to stdout. Default: file only - :param log: LogClass or logging object + :param log: logging.Logger object :return: Full path to the date directory """ @@ -131,7 +131,7 @@ def get_user(username: Union[None, str] = None, :param username: Optional input for username :param verbose: Write verbose message to stdout. Default: file only - :param log: LogClass or logging object + :param log: logging.Logger object :return: Full path to the date directory """ diff --git a/Metallicity_Stack_Commons/analysis/attenuation.py b/Metallicity_Stack_Commons/analysis/attenuation.py index ad25286d..d5daf134 100644 --- a/Metallicity_Stack_Commons/analysis/attenuation.py +++ b/Metallicity_Stack_Commons/analysis/attenuation.py @@ -1,3 +1,4 @@ +from logging import Logger from typing import Union, Tuple import numpy as np @@ -23,7 +24,7 @@ def compute_EBV(ratio: Union[float, np.ndarray], source: str = 'HgHb', zero_neg: bool = True, verbose: bool = False, - log: type(log_stdout) = log_stdout()) -> \ + log: Logger = log_stdout()) -> \ Union[float, np.ndarray, Tuple[np.ndarray, np.ndarray]]: """ Determines E(B-V) from Hg/Hb or Hd/Hb flux ratios using Case B assumptions @@ -34,7 +35,7 @@ def compute_EBV(ratio: Union[float, np.ndarray], source: str = 'HgHb', :param zero_neg: Indicate whether to zero out negative reddening. Default: True :param verbose: Write verbose message to stdout. Default: file only - :param log: LogClass or logging object + :param log: logging.Logger object :return: E(B-V) values, E(B-V) peak values @@ -93,7 +94,7 @@ def compute_EBV(ratio: Union[float, np.ndarray], source: str = 'HgHb', def compute_A(EBV: float, verbose: bool = False, - log: type(log_stdout) = log_stdout()) -> dict: + log: Logger = log_stdout()) -> dict: """ Compute A(Lambda) for all possible emission lines @@ -103,7 +104,7 @@ def compute_A(EBV: float, verbose: bool = False, :param verbose: Write verbose message to stdout. Default: file only - :param log: LogClass or logging object + :param log: logging.Logger object :return: A(lambda) with keys identical to ``k_dict`` """ @@ -123,7 +124,7 @@ def line_ratio_atten(ratio: Union[float, np.ndarray], EBV: Union[float, np.ndarray], wave_top: str, wave_bottom: str, verbose: bool = False, - log: type(log_stdout) = log_stdout()) -> \ + log: Logger = log_stdout()) -> \ Union[float, np.ndarray]: """ Determine dust-corrected emission-line ratios @@ -134,7 +135,7 @@ def line_ratio_atten(ratio: Union[float, np.ndarray], :param wave_bottom: Emission-line name for flux ratio denominator :param verbose: Write verbose message to stdout. Default: file only - :param log: LogClass or logging object + :param log: logging.Logger object :return: Float or array of dust-corrected flux ratios """ @@ -153,7 +154,7 @@ def line_ratio_atten(ratio: Union[float, np.ndarray], def Hb_SFR(log_LHb: Union[float, np.ndarray], EBV: Union[float, np.ndarray], verbose: bool = False, - log: type(log_stdout) = log_stdout()) -> \ + log: Logger = log_stdout()) -> \ Union[float, np.ndarray]: """ Determine dust-corrected SFR using the H-beta luminosity and a @@ -165,7 +166,7 @@ def Hb_SFR(log_LHb: Union[float, np.ndarray], :param log_LHb: Logarithm of H-beta luminosity in units of erg/s :param EBV: E(B-V) value(s) :param verbose: Write verbose message to stdout. Default: file only - :param log: LogClass or logging object + :param log: logging.Logger object :return: SFRs in logarithmic units of M_sun/yr """ diff --git a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py index 9dc2bb76..dc1197f0 100644 --- a/Metallicity_Stack_Commons/analysis/composite_indv_detect.py +++ b/Metallicity_Stack_Commons/analysis/composite_indv_detect.py @@ -1,3 +1,5 @@ +from logging import Logger + from os.path import join from os.path import exists @@ -23,7 +25,7 @@ def main(fitspath: str, dataset: str, revised: bool = False, det3: bool = True, verbose: bool = False, - log: type(log_stdout) = log_stdout()): + log: Logger = log_stdout()): """ Reads in composite table(s) containing bin information to determine temperature-based metallicity from composite average @@ -37,7 +39,7 @@ def main(fitspath: str, dataset: str, revised: bool = False, those satisfying emission-line det3 requirement Default: True :param verbose: Write verbose message to stdout. Default: file only - :param log: LogClass or logging object + :param log: logging.Logger object Files identified by default: diff --git a/Metallicity_Stack_Commons/analysis/error_prop.py b/Metallicity_Stack_Commons/analysis/error_prop.py index 03bf95fd..857812e3 100644 --- a/Metallicity_Stack_Commons/analysis/error_prop.py +++ b/Metallicity_Stack_Commons/analysis/error_prop.py @@ -1,3 +1,4 @@ +from logging import Logger from os.path import join, exists from chun_codes import random_pdf, compute_onesig_pdf @@ -16,7 +17,7 @@ def write_npz(path: str, npz_files: list, dict_list: list, - verbose: bool = False, log: type(log_stdout) = log_stdout()): + verbose: bool = False, log: Logger = log_stdout()): """ Write numpy files with provided dictionaries @@ -24,7 +25,7 @@ def write_npz(path: str, npz_files: list, dict_list: list, :param npz_files: NPZ file names :param dict_list: List of dict for each corresponding npz file :param verbose: Write verbose message to stdout. Default: file only - :param log: LogClass or logging object + :param log: logging.Logger object """ log_verbose(log, "starting ...", verbose=verbose) @@ -56,7 +57,7 @@ def fluxes_derived_prop(path: str, raw: bool = False, :param apply_dust: Whether to apply dust attenuation. Default: False :param revised: Indicate if revised validation table is used. Default: True :param verbose: Write verbose message to stdout. Default: file only - :param log: LogClass or logging object + :param log: logging.Logger object """ log_verbose(log, "starting ...", verbose=verbose) diff --git a/Metallicity_Stack_Commons/analysis/fitting.py b/Metallicity_Stack_Commons/analysis/fitting.py index a0a2211f..61d2e153 100644 --- a/Metallicity_Stack_Commons/analysis/fitting.py +++ b/Metallicity_Stack_Commons/analysis/fitting.py @@ -1,3 +1,4 @@ +from logging import Logger from typing import Union import numpy as np from astropy.convolution import Box1DKernel, convolve @@ -69,7 +70,7 @@ def oxy2_gauss(x: np.ndarray, xbar: float, s1: float, a1: float, c: float, def rms_func(wave: np.ndarray, dispersion: float, lambda_in: float, y0: np.ndarray, sigma_array: float, mask_flag: np.ndarray, - verbose: bool = False, log: type(log_stdout) = log_stdout()): + verbose: bool = False, log: Logger = log_stdout()): """ Compute rms in the spectra @@ -80,7 +81,7 @@ def rms_func(wave: np.ndarray, dispersion: float, lambda_in: float, :param sigma_array: Gaussian sigma (AA) :param mask_flag: Indicates spectra are masked for OH skyline contamination :param verbose: Write verbose message to stdout. Default: file only - :param log: LogClass or logging object + :param log: logging.Logger object :return: """ @@ -107,7 +108,7 @@ def rms_func(wave: np.ndarray, dispersion: float, lambda_in: float, def OIII4363_flux_limit(combine_flux_file: str, verbose: bool = False, - log: type(log_stdout) = log_stdout()) -> \ + log: Logger = log_stdout()) -> \ Union[None, np.ndarray]: """ Determine 3-sigma limit on [OIII]4363 based on H-gamma measurements @@ -115,7 +116,7 @@ def OIII4363_flux_limit(combine_flux_file: str, verbose: bool = False, :param combine_flux_file: Filename of ASCII file containing emission-line flux measurements :param verbose: Write verbose message to stdout. Default: file only - :param log: LogClass or logging object + :param log: logging.Logger object :return: Array containing 3-sigma flux limit """ diff --git a/Metallicity_Stack_Commons/analysis/ratios.py b/Metallicity_Stack_Commons/analysis/ratios.py index ae0f63ed..d3aaa967 100644 --- a/Metallicity_Stack_Commons/analysis/ratios.py +++ b/Metallicity_Stack_Commons/analysis/ratios.py @@ -1,3 +1,4 @@ +from logging import Logger import numpy as np from .. import line_name_short, OIII_r @@ -8,7 +9,7 @@ def flux_ratios(flux_dict: dict, binned_data: bool = False, get_R: bool = True, verbose: bool = False, - log: type(log_stdout) = log_stdout()) -> dict: + log: Logger = log_stdout()) -> dict: """ Primary code to determine a variety of line ratios based on a dict containing emission-line fluxes @@ -17,7 +18,7 @@ def flux_ratios(flux_dict: dict, binned_data: bool = False, :param get_R: Indicates populating OIII4363/OIII5007 flux ratio :param binned_data: Whether to analyze binned data. Default: False :param verbose: Write verbose message to stdout. Default: file only - :param log: LogClass or logging object + :param log: logging.Logger object :return: Emission-line flux ratios """ diff --git a/Metallicity_Stack_Commons/analysis/temp_metallicity_calc.py b/Metallicity_Stack_Commons/analysis/temp_metallicity_calc.py index 4d2936d1..f1b3cf65 100644 --- a/Metallicity_Stack_Commons/analysis/temp_metallicity_calc.py +++ b/Metallicity_Stack_Commons/analysis/temp_metallicity_calc.py @@ -1,3 +1,4 @@ +from logging import Logger from typing import Union import numpy as np @@ -19,8 +20,7 @@ def R_calculation(OIII4363: Union[float, np.ndarray], OIII5007: Union[float, np.ndarray], - verbose: bool = False, - log: type(log_stdout) = log_stdout()) \ + verbose: bool = False, log: Logger = log_stdout()) \ -> Union[float, np.ndarray]: """ Computes the excitation flux ratio of [OIII]4363 to [OIII]5007. @@ -29,7 +29,7 @@ def R_calculation(OIII4363: Union[float, np.ndarray], :param OIII4363: OIII4363 fluxes :param OIII5007: OIII5007 fluxes :param verbose: Write verbose message to stdout. Default: file only - :param log: LogClass or logging object + :param log: logging.Logger object :return: O++ excitation flux ratio """ @@ -44,7 +44,7 @@ def R_calculation(OIII4363: Union[float, np.ndarray], def temp_calculation(R: np.ndarray, EBV: Union[None, np.ndarray] = None, verbose: bool = False, - log: type(log_stdout) = log_stdout()) -> np.ndarray: + log: Logger = log_stdout()) -> np.ndarray: """ Computes electron temperature (T_e) from O++ excitation flux ratio @@ -55,7 +55,7 @@ def temp_calculation(R: np.ndarray, EBV: Union[None, np.ndarray] = None, :param R: Array of O++ excitation flux ratio (see R_calculation) :param EBV: Array of E(B-V). Set to zero if not applying attenuation :param verbose: Write verbose message to stdout. Default: file only - :param log: LogClass or logging object + :param log: logging.Logger object :return: Array of T_e (Kelvins) """ @@ -81,7 +81,7 @@ def metallicity_calculation(T_e: np.ndarray, TWO_BETA: np.ndarray, EBV: Union[None, np.ndarray] = None, det3: Union[None, np.ndarray] = None, verbose: bool = False, - log: type(log_stdout) = log_stdout()) -> dict: + log: Logger = log_stdout()) -> dict: """ Determines 12+log(O/H) from electron temperature and [OII]/Hb and [OIII]/Hb flux ratio @@ -96,7 +96,7 @@ def metallicity_calculation(T_e: np.ndarray, TWO_BETA: np.ndarray, Note: for Monte Carlo inputs, a 1-D np.array index satisfying det3 requirements will suffice :param verbose: Write verbose message to stdout. Default: file only - :param log: LogClass or logging object + :param log: logging.Logger object :return: Contains 12+log(O/H), O+/H, O++/H, log(O+/H), log(O++/H) """ diff --git a/Metallicity_Stack_Commons/logging.py b/Metallicity_Stack_Commons/logging.py index 338c47a5..d4f8194d 100644 --- a/Metallicity_Stack_Commons/logging.py +++ b/Metallicity_Stack_Commons/logging.py @@ -1,7 +1,6 @@ import sys from os.path import join from os import uname -from typing import Union from getpass import getuser from socket import gethostname @@ -9,7 +8,6 @@ import logging - log_format = '%(asctime)s %(levelname)7s - %(module)21s %(funcName)23s : %(message)s' formatter = logging.Formatter(log_format, "%H:%M:%S") file_formatter = logging.Formatter(log_format, "%H:%M:%S") @@ -53,7 +51,7 @@ def get_logger(self): return log -def log_stdout() -> type(logging.getLogger()): +def log_stdout() -> logging.Logger: """ Returns stdout logging object """ @@ -89,12 +87,12 @@ def get_user_hostname() -> dict: return sys_info -def log_verbose(log: Union[type(logging.getLogger()), logging.Logger], +def log_verbose(log: logging.Logger, message: str, verbose: bool = False): """ Log message depending on verbosity - :param log: LogClass or logging object + :param log: logging.Logger object :param message: Message :param verbose: Write verbose message to stdout. Default: file only """ diff --git a/Metallicity_Stack_Commons/plotting/balmer.py b/Metallicity_Stack_Commons/plotting/balmer.py index 9ad8da9b..32e66bc0 100644 --- a/Metallicity_Stack_Commons/plotting/balmer.py +++ b/Metallicity_Stack_Commons/plotting/balmer.py @@ -8,6 +8,7 @@ https://github.com/astrochun/Zcalbase_gal/blob/master/Analysis/DEEP2_R23_O32/balmer_plots.py """ +from logging import Logger from os.path import join from typing import Union @@ -30,7 +31,7 @@ def extract_fit(astropy_table: Table, line_name: str, balmer: bool = False, - verbose: bool = False, log: type(log_stdout) = log_stdout()) \ + verbose: bool = False, log: Logger = log_stdout()) \ -> Union[None, dict]: """ Extract best fit from table and fluxes, return a list of @@ -40,7 +41,7 @@ def extract_fit(astropy_table: Table, line_name: str, balmer: bool = False, :param line_name: Name of Line to extract fit results :param balmer: Indicate whether line is a Balmer line :param verbose: Write verbose message to stdout. Default: file only - :param log: LogClass or logging object + :param log: logging.Logger object :return: Fitting results """ @@ -128,7 +129,7 @@ def fitting_result(wave: np.ndarray, y_norm: np.ndarray, lambda_cen: float, # noinspection PyUnboundLocalVariable def HbHgHd_fits(fitspath: str, out_pdf_prefix: str ='HbHgHd_fits', use_revised: bool = False, verbose: bool = False, - log: type(log_stdout) = log_stdout()): + log: Logger = log_stdout()): """ Generate PDF plots that illustrate H-delta, H-gamma, and H-beta line profiles and best fit @@ -137,7 +138,7 @@ def HbHgHd_fits(fitspath: str, out_pdf_prefix: str ='HbHgHd_fits', :param out_pdf_prefix: Prefix for output PDF file :param use_revised: Indicate whether to use regular or revised tables :param verbose: Write verbose message to stdout. Default: file only - :param log: LogClass or logging object + :param log: logging.Logger object """ log_verbose(log, "starting ...", verbose=verbose) diff --git a/Metallicity_Stack_Commons/update_det4363_info.py b/Metallicity_Stack_Commons/update_det4363_info.py index eff8ad95..731a64d1 100644 --- a/Metallicity_Stack_Commons/update_det4363_info.py +++ b/Metallicity_Stack_Commons/update_det4363_info.py @@ -1,3 +1,4 @@ +from logging import Logger from typing import Tuple import numpy as np @@ -9,7 +10,7 @@ def get_index(det4363_table: Table, input_table: Table, column_name: str, - verbose: bool = False, log: type(log_stdout) = log_stdout()) -> \ + verbose: bool = False, log: Logger = log_stdout()) -> \ Tuple[np.ndarray, np.ndarray]: """ Uses either OBJNO or AP/SLIT info to get index for an existing table @@ -18,7 +19,7 @@ def get_index(det4363_table: Table, input_table: Table, column_name: str, :param input_table: Astropy table containing the entire sample to be updated :param column_name: Column name for cross-matching :param verbose: Write verbose message to stdout. Default: file only - :param log: LogClass or logging object + :param log: logging.Logger object :return: Index arrays for ``det4363_table``, ``input_table`` """ From 67d40d2c18200e395e25c97138e81a81072ca56b Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Mon, 8 Feb 2021 19:29:00 -0700 Subject: [PATCH 30/42] extract_deep2_data: Adjust type hinting and docstrings for log inputs - Switch log default --- Metallicity_Stack_Commons/others/extract_deep2_data.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Metallicity_Stack_Commons/others/extract_deep2_data.py b/Metallicity_Stack_Commons/others/extract_deep2_data.py index bbe28ef5..4b0bdc38 100644 --- a/Metallicity_Stack_Commons/others/extract_deep2_data.py +++ b/Metallicity_Stack_Commons/others/extract_deep2_data.py @@ -1,3 +1,4 @@ +from logging import Logger from os.path import exists, join from os import symlink import numpy as np @@ -10,16 +11,14 @@ from ..column_names import filename_dict -def main(infile: str, log=None): +def main(infile: str, log: Logger = log_stdout()): """ Import previous DEEP2 Ly et al. (2015) dataset and export an astropy Table called bin_fit.tbl :param infile: Input filename - :param log: LogClass or logging object + :param log: logging.Logger object """ - if log is None: - log = log_stdout() log.info(f"Reading : {infile}") orig_tab = fits.getdata(infile) From c947b132a0c5654fca4f33224fc71b2ef8735348 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Mon, 8 Feb 2021 19:38:31 -0700 Subject: [PATCH 31/42] Update sphinx-build GitHub actions to include chun_codes --- .github/workflows/sphinx-build.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sphinx-build.yml b/.github/workflows/sphinx-build.yml index a633c57a..31fb0166 100644 --- a/.github/workflows/sphinx-build.yml +++ b/.github/workflows/sphinx-build.yml @@ -13,7 +13,16 @@ jobs: docs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 - - uses: ammaraskar/sphinx-action@master + - name: Checkout chun_codes + uses: actions/checkout@v2 + with: + repository: astrochun/chun_codes + path: chun_codes + - name: Install chun_codes + run: | + python setup.py install + working-directory: chun_codes + - name: Sphinx build + uses: ammaraskar/sphinx-action@master with: docs-folder: "docs/" \ No newline at end of file From 9c660d6070e85687ec7389f1446c28c6a559ae80 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Mon, 8 Feb 2021 19:45:59 -0700 Subject: [PATCH 32/42] Use develop option for build of chun_codes in sphinx-build GitHub Actions --- .github/workflows/sphinx-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sphinx-build.yml b/.github/workflows/sphinx-build.yml index 31fb0166..b7427aab 100644 --- a/.github/workflows/sphinx-build.yml +++ b/.github/workflows/sphinx-build.yml @@ -20,7 +20,7 @@ jobs: path: chun_codes - name: Install chun_codes run: | - python setup.py install + python3 setup.py develop working-directory: chun_codes - name: Sphinx build uses: ammaraskar/sphinx-action@master From f7ab9620aa113b625cc5d81c56e4b29f6e280f8c Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Mon, 8 Feb 2021 19:51:55 -0700 Subject: [PATCH 33/42] Use setup-python action in sphinx-build - Specify python-version --- .github/workflows/sphinx-build.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sphinx-build.yml b/.github/workflows/sphinx-build.yml index b7427aab..aa8a0593 100644 --- a/.github/workflows/sphinx-build.yml +++ b/.github/workflows/sphinx-build.yml @@ -12,7 +12,15 @@ on: jobs: docs: runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.8'] + steps: + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} - name: Checkout chun_codes uses: actions/checkout@v2 with: @@ -20,7 +28,7 @@ jobs: path: chun_codes - name: Install chun_codes run: | - python3 setup.py develop + python setup.py install working-directory: chun_codes - name: Sphinx build uses: ammaraskar/sphinx-action@master From ef443982975b082b8fcfbc3739fc94767a4f8a89 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Mon, 8 Feb 2021 20:02:40 -0700 Subject: [PATCH 34/42] Use actions-checkout for MSC --- .github/workflows/sphinx-build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/sphinx-build.yml b/.github/workflows/sphinx-build.yml index aa8a0593..c7d1d6df 100644 --- a/.github/workflows/sphinx-build.yml +++ b/.github/workflows/sphinx-build.yml @@ -21,6 +21,8 @@ jobs: uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} + - name: Checkout MSC + uses: actions/checkout@v2 - name: Checkout chun_codes uses: actions/checkout@v2 with: From fe4b43108b58edb8de2942e9c6ca3067c7bec4e2 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Mon, 8 Feb 2021 20:17:24 -0700 Subject: [PATCH 35/42] Update README for GitHub badges for GitHub Action status --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 21adf406..a97dfb4d 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ # Metallicity_Stack_Commons Set of common codes used in metallicity studies that use the stacking techniques -[![GitHub build](https://github.com/astrochun/Metallicity_Stack_Commons/workflows/Python%20package/badge.svg?)](https://github.com/astrochun/Metallicity_Stack_Commons/actions?query=workflow%3A%22Python+package%22) +[![GitHub Workflow Status (main)](https://img.shields.io/github/workflow/status/astrochun/Metallicity_Stack_Commons/Python%20package/main?color=blue&label=build%20%28main%29&logo=github)](https://github.com/astrochun/Metallicity_Stack_Commons/actions?query=workflow%3A%22Python+package%22+branch%3Amain) +[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/astrochun/Metallicity_Stack_Commons/Python%20package?color=blue&label=build%20%28latest%29&logo=github)](https://github.com/astrochun/Metallicity_Stack_Commons/actions?query=workflow%3A%22Python+package%22) +[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/astrochun/Metallicity_Stack_Commons/Sphinx%20Docs%20Check?label=docs&color=blue)](https://github.com/astrochun/Metallicity_Stack_Commons/actions?query=workflow%3A%22Sphinx+Docs+Check%22) ![GitHub top language](https://img.shields.io/github/languages/top/astrochun/Metallicity_Stack_Commons) ![GitHub release (latest by date)](https://img.shields.io/github/v/release/astrochun/Metallicity_Stack_Commons) ![GitHub](https://img.shields.io/github/license/astrochun/Metallicity_Stack_Commons?color=blue) \ No newline at end of file From 995ca9d83c34ad0bde64903b7ef879471344f927 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Mon, 8 Feb 2021 20:18:33 -0700 Subject: [PATCH 36/42] Fix typo: main -> master branch --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a97dfb4d..099c6abe 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Metallicity_Stack_Commons Set of common codes used in metallicity studies that use the stacking techniques -[![GitHub Workflow Status (main)](https://img.shields.io/github/workflow/status/astrochun/Metallicity_Stack_Commons/Python%20package/main?color=blue&label=build%20%28main%29&logo=github)](https://github.com/astrochun/Metallicity_Stack_Commons/actions?query=workflow%3A%22Python+package%22+branch%3Amain) +[![GitHub Workflow Status (master)](https://img.shields.io/github/workflow/status/astrochun/Metallicity_Stack_Commons/Python%20package/master?color=blue&label=build%20%28master%29&logo=github)](https://github.com/astrochun/Metallicity_Stack_Commons/actions?query=workflow%3A%22Python+package%22+branch%3Amaster) [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/astrochun/Metallicity_Stack_Commons/Python%20package?color=blue&label=build%20%28latest%29&logo=github)](https://github.com/astrochun/Metallicity_Stack_Commons/actions?query=workflow%3A%22Python+package%22) [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/astrochun/Metallicity_Stack_Commons/Sphinx%20Docs%20Check?label=docs&color=blue)](https://github.com/astrochun/Metallicity_Stack_Commons/actions?query=workflow%3A%22Sphinx+Docs+Check%22) ![GitHub top language](https://img.shields.io/github/languages/top/astrochun/Metallicity_Stack_Commons) From cb59f0047dd229b19870ea948e8bbf67e74c352f Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Mon, 8 Feb 2021 20:25:04 -0700 Subject: [PATCH 37/42] Update GitHub badges in intro.rst --- docs/source/intro.rst | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/source/intro.rst b/docs/source/intro.rst index 54417efe..7bc25d50 100644 --- a/docs/source/intro.rst +++ b/docs/source/intro.rst @@ -4,11 +4,15 @@ Metallicity_Stack_Commons Set of common codes used in metallicity studies that use the stacking techniques -|GitHub build| |GitHub top language| |GitHub release (latest by date)| -|GitHub| +|GitHub build (master)| |GitHub build| |docs| +|GitHub top language| |GitHub release (latest by date)| |GitHub| -.. |GitHub build| image:: https://github.com/astrochun/Metallicity_Stack_Commons/workflows/Python%20package/badge.svg? +.. |GitHub build (master)| image:: https://img.shields.io/github/workflow/status/astrochun/Metallicity_Stack_Commons/Python%20package/master?color=blue&label=build%20%28master%29&logo=github + :target: https://github.com/astrochun/Metallicity_Stack_Commons/actions?query=workflow%3A%22Python+package%22+branch%3Amaster +.. |GitHub build| image:: https://img.shields.io/github/workflow/status/astrochun/Metallicity_Stack_Commons/Python%20package?color=blue&label=build%20%28latest%29&logo=github :target: https://github.com/astrochun/Metallicity_Stack_Commons/actions?query=workflow%3A%22Python+package%22 +.. |docs| image:: https://img.shields.io/github/workflow/status/astrochun/Metallicity_Stack_Commons/Sphinx%20Docs%20Check?label=docs&color=blue + :target: https://github.com/astrochun/Metallicity_Stack_Commons/actions?query=workflow%3A%22Sphinx+Docs+Check%22 .. |GitHub top language| image:: https://img.shields.io/github/languages/top/astrochun/Metallicity_Stack_Commons .. |GitHub release (latest by date)| image:: https://img.shields.io/github/v/release/astrochun/Metallicity_Stack_Commons .. |GitHub| image:: https://img.shields.io/github/license/astrochun/Metallicity_Stack_Commons?color=blue \ No newline at end of file From eab1a41fac8662185689f1f716f57778db5045b0 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Mon, 8 Feb 2021 20:28:44 -0700 Subject: [PATCH 38/42] Adjust type hinting and docstrings for __init__ --- Metallicity_Stack_Commons/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Metallicity_Stack_Commons/__init__.py b/Metallicity_Stack_Commons/__init__.py index 649f438c..32a1ebe2 100644 --- a/Metallicity_Stack_Commons/__init__.py +++ b/Metallicity_Stack_Commons/__init__.py @@ -1,3 +1,4 @@ +from logging import Logger from typing import Union from chun_codes.cardelli import cardelli @@ -54,7 +55,7 @@ def exclude_outliers(objno: Union[list, np.ndarray], verbose: bool = False, - log: type(log_stdout) = log_stdout()) -> np.ndarray: + log: Logger = log_stdout()) -> np.ndarray: """ Exclude spectra that are identified as outliers. @@ -82,7 +83,7 @@ def exclude_outliers(objno: Union[list, np.ndarray], verbose: bool = False, def dir_date(folder_name: str, path_init: str = '', year: bool = False, - verbose: bool = False, log: type(log_stdout) = log_stdout()) \ + verbose: bool = False, log: Logger = log_stdout()) \ -> str: """ This function finds and returns the path to a directory named after the @@ -124,8 +125,7 @@ def dir_date(folder_name: str, path_init: str = '', year: bool = False, def get_user(username: Union[None, str] = None, - verbose: bool = False, - log: type(log_stdout) = log_stdout()) -> str: + verbose: bool = False, log: Logger = log_stdout()) -> str: """ Get the corresponding path for a given ``username`` From 0df743ba1d52faacdd474c1cad650a3102f685f2 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Mon, 8 Feb 2021 20:35:05 -0700 Subject: [PATCH 39/42] Adjust type hinting in error_prop --- Metallicity_Stack_Commons/analysis/error_prop.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Metallicity_Stack_Commons/analysis/error_prop.py b/Metallicity_Stack_Commons/analysis/error_prop.py index 857812e3..1ddc85a8 100644 --- a/Metallicity_Stack_Commons/analysis/error_prop.py +++ b/Metallicity_Stack_Commons/analysis/error_prop.py @@ -44,7 +44,7 @@ def write_npz(path: str, npz_files: list, dict_list: list, def fluxes_derived_prop(path: str, raw: bool = False, binned_data: bool = True, apply_dust: bool = False, revised: bool = True, verbose: bool = False, - log: type(log_stdout) = log_stdout()): + log: Logger = log_stdout()): """ Use measurements and their uncertainties to perform a randomization approach. The randomization is performed on individual emission lines. From 4b76c19a2040dfe689c9308936702bf29acf99ca Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Mon, 8 Feb 2021 22:24:48 -0700 Subject: [PATCH 40/42] temp_metallicity_calc: Remove log handling for None --- Metallicity_Stack_Commons/analysis/temp_metallicity_calc.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/Metallicity_Stack_Commons/analysis/temp_metallicity_calc.py b/Metallicity_Stack_Commons/analysis/temp_metallicity_calc.py index f1b3cf65..38b41673 100644 --- a/Metallicity_Stack_Commons/analysis/temp_metallicity_calc.py +++ b/Metallicity_Stack_Commons/analysis/temp_metallicity_calc.py @@ -101,9 +101,6 @@ def metallicity_calculation(T_e: np.ndarray, TWO_BETA: np.ndarray, :return: Contains 12+log(O/H), O+/H, O++/H, log(O+/H), log(O++/H) """ - if log is None: - log = log_stdout() - log_verbose(log, "starting ...", verbose=verbose) arr_shape = T_e.shape From c3a611e4c79c744580cde56c0bdbc96b5b7f8beb Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Mon, 8 Feb 2021 22:25:13 -0700 Subject: [PATCH 41/42] Update docs/source/conf.py --- docs/source/conf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 3ec7b364..07af3d5b 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -24,7 +24,7 @@ author = 'Chun Ly, Reagen Leimbach, and Caroline McCormick' # The full version, including alpha/beta/rc tags -release = '1.4.0' +release = '1.3.1' # -- General configuration --------------------------------------------------- @@ -57,4 +57,4 @@ # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] \ No newline at end of file +html_static_path = ['_static'] From 6d09395f945fb75cfd2df1fcdf29339eadc2750d Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Mon, 8 Feb 2021 22:29:38 -0700 Subject: [PATCH 42/42] Type hint for LogClass.get_logger --- Metallicity_Stack_Commons/logging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Metallicity_Stack_Commons/logging.py b/Metallicity_Stack_Commons/logging.py index d4f8194d..89afc580 100644 --- a/Metallicity_Stack_Commons/logging.py +++ b/Metallicity_Stack_Commons/logging.py @@ -30,7 +30,7 @@ class LogClass: def __init__(self, log_dir: str, logfile: str): self.LOG_FILENAME = join(log_dir, logfile) - def get_logger(self): + def get_logger(self) -> logging.Logger: file_log_level = logging.DEBUG # This is for file logging log = logging.getLogger("main_logger") if not log.handlers: