Skip to content

Commit 976e627

Browse files
committed
Merge branch 'release/1.4.0' #101
2 parents 6823bdc + 82c361a commit 976e627

37 files changed

Lines changed: 1011 additions & 407 deletions

.github/workflows/sphinx-build.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: "Sphinx Docs Check"
2+
on:
3+
push:
4+
paths:
5+
- 'docs/**'
6+
- 'Metallicity_Stack_Commons/**'
7+
pull_request:
8+
paths:
9+
- 'docs/**'
10+
- 'Metallicity_Stack_Commons/**'
11+
12+
jobs:
13+
docs:
14+
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
python-version: ['3.8']
18+
19+
steps:
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v2
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
- name: Checkout MSC
25+
uses: actions/checkout@v2
26+
- name: Checkout chun_codes
27+
uses: actions/checkout@v2
28+
with:
29+
repository: astrochun/chun_codes
30+
path: chun_codes
31+
- name: Install chun_codes
32+
run: |
33+
python setup.py install
34+
working-directory: chun_codes
35+
- name: Sphinx build
36+
uses: ammaraskar/sphinx-action@master
37+
with:
38+
docs-folder: "docs/"

Metallicity_Stack_Commons/__init__.py

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from logging import Logger
2+
from typing import Union
3+
14
from chun_codes.cardelli import cardelli
25
import astropy.units as u
36
from datetime import date
@@ -7,7 +10,7 @@
710

811
from .logging import log_stdout, log_verbose
912

10-
version = "1.3.1"
13+
version = "1.4.0"
1114

1215
lambda0 = [3726.18, 4101.73, 4340.46, 4363.21, 4861.32, 4958.91, 5006.84]
1316
line_type = ['Oxy2', 'Balmer', 'Balmer', 'Single', 'Balmer', 'Single', 'Single']
@@ -51,22 +54,20 @@
5154
k_dict = dict(zip(line_name, k_values))
5255

5356

54-
def exclude_outliers(objno, verbose=False, log=None):
57+
def exclude_outliers(objno: Union[list, np.ndarray], verbose: bool = False,
58+
log: Logger = log_stdout()) -> np.ndarray:
5559
"""
5660
Exclude spectra that are identified as outliers.
5761
5862
Generally this is because the spectra have very high S/N on the continuum.
5963
60-
:param objno: list or numpy array of eight-digit identifier
61-
:param verbose: bool to write verbose message to stdout. Default: file only
62-
:param log: LogClass or logging object
64+
:param objno: Array of eight-digit identifier
65+
:param verbose: Write verbose message to stdout. Default: file only
66+
:param log: logging.Logger object
6367
64-
:return flag: numpy array of zeros and ones
68+
:return: Array of zeros (not flagged) and ones (flagged
6569
"""
6670

67-
if log is None:
68-
log = log_stdout()
69-
7071
log_verbose(log, "starting ...", verbose=verbose)
7172

7273
flag = np.zeros(len(objno), dtype=int)
@@ -81,31 +82,29 @@ def exclude_outliers(objno, verbose=False, log=None):
8182
return flag
8283

8384

84-
def dir_date(folder_name, path_init='', year=False, verbose=False, log=None):
85+
def dir_date(folder_name: str, path_init: str = '', year: bool = False,
86+
verbose: bool = False, log: Logger = log_stdout()) \
87+
-> str:
8588
"""
86-
Purpose:
87-
This function finds and returns the path to a directory named after the
88-
current date (MMDDYYYY). If the directory doesn't exist yet, it creates
89-
a new directory named after the current date in the provided folder_name
90-
directory.
89+
This function finds and returns the path to a directory named after the
90+
current date (MMDDYYYY). If the directory doesn't exist yet, it creates
91+
a new directory named after the current date in the provided
92+
``folder_name`` directory.
9193
92-
From https://github.com/rafia37/Evolution-of-Galaxies/blob/master/general.py
94+
Originally from https://github.com/rafia37/Evolution-of-Galaxies/blob/master/general.py
9395
9496
Usage:
95-
fitspath = dir_date(folder_name, path_init='', year=True)
97+
fitspath = dir_date(folder_name, year=True)
9698
97-
:param folder_name: str containing directory for date subdirectory will be in
99+
:param folder_name: Directory for date subdirectory will be in
98100
:param path_init: root path. Default: empty string
99101
:param year: Indicate whether to include year in date folder. Default: False
100-
:param verbose: bool to write verbose message to stdout. Default: file only
101-
:param log: LogClass or logging object
102+
:param verbose: Write verbose message to stdout. Default: file only
103+
:param log: logging.Logger object
102104
103-
:return fitspath: Full path to the date directory
105+
:return: Full path to the date directory
104106
"""
105107

106-
if log is None:
107-
log = log_stdout()
108-
109108
log_verbose(log, "starting ...", verbose=verbose)
110109

111110
today = date.today()
@@ -125,10 +124,17 @@ def dir_date(folder_name, path_init='', year=False, verbose=False, log=None):
125124
return fitspath
126125

127126

128-
def get_user(username=None, verbose=False, log=None):
127+
def get_user(username: Union[None, str] = None,
128+
verbose: bool = False, log: Logger = log_stdout()) -> str:
129+
"""
130+
Get the corresponding path for a given ``username``
131+
132+
:param username: Optional input for username
133+
:param verbose: Write verbose message to stdout. Default: file only
134+
:param log: logging.Logger object
129135
130-
if log is None:
131-
log = log_stdout()
136+
:return: Full path to the date directory
137+
"""
132138

133139
log_verbose(log, "starting ...", verbose=verbose)
134140

Metallicity_Stack_Commons/analysis/attenuation.py

Lines changed: 66 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from logging import Logger
2+
from typing import Union, Tuple
3+
14
import numpy as np
25

36
from .. import k_dict, line_name_short
@@ -19,24 +22,27 @@
1922
k_HDELTA = k_dict[HD]
2023

2124

22-
def compute_EBV(ratio, source='HgHb', zero_neg=True, verbose=False, log=None):
23-
"""
24-
Purpose:
25-
Determines E(B-V) from Hg/Hb or Hd/Hb flux ratios using Case B assumptions
26-
27-
:param ratio: float or numpy array containing Hg/Hb or Hd/Hb
28-
:param source: str indicate ratio type. Either 'HgHb' or 'HdHb'. Default: 'HgHb'
29-
:param zero_neg: boolean to indicate whether to zero out negative reddening. Default: True
30-
:param verbose: bool to write verbose message to stdout. Default: file only
31-
:param log: LogClass or logging object
32-
33-
:return EBV: float or numpy array containing E(B-V).
34-
Note: Not correcting for negative reddening
35-
:return EBV_peak: float or numpy array return when it is a 2-D distribution
25+
def compute_EBV(ratio: Union[float, np.ndarray], source: str = 'HgHb',
26+
zero_neg: bool = True, verbose: bool = False,
27+
log: Logger = log_stdout()) -> \
28+
Union[float, np.ndarray, Tuple[np.ndarray, np.ndarray]]:
3629
"""
30+
Determines E(B-V) from Hg/Hb or Hd/Hb flux ratios using Case B assumptions
31+
32+
:param ratio: Float or array containing Hg/Hb or Hd/Hb values
33+
:param source: Indicate ratio type. Either 'HgHb' or 'HdHb'.
34+
Default: 'HgHb'
35+
:param zero_neg: Indicate whether to zero out negative reddening.
36+
Default: True
37+
:param verbose: Write verbose message to stdout. Default: file only
38+
:param log: logging.Logger object
3739
38-
if log is None:
39-
log = log_stdout()
40+
:return: E(B-V) values, E(B-V) peak values
41+
42+
Note:
43+
When only E(B-V) values is returned, correction does not account
44+
for negative reddening
45+
"""
4046

4147
log_verbose(log, "starting ...", verbose=verbose)
4248

@@ -87,42 +93,56 @@ def compute_EBV(ratio, source='HgHb', zero_neg=True, verbose=False, log=None):
8793
return EBV
8894

8995

90-
def compute_A(EBV, verbose=False, log=None):
96+
def compute_A(EBV: float, verbose: bool = False,
97+
log: Logger = log_stdout()) -> dict:
9198
"""
92-
Purpose:
93-
Compute A(Lambda) for all possible emission lines
99+
Compute A(Lambda) for all possible emission lines
94100
95-
:param EBV: float value of E(B-V)
96-
Has not been configured to handle a large array. Some array handling would be needed
97-
:param verbose: bool to write verbose message to stdout. Default: file only
98-
:param log: LogClass or logging object
101+
:param EBV: E(B-V) value
102+
Has not been configured to handle a large array.
103+
Some array handling would be needed
99104
100-
:return A_dict: dict containing A(lambda) with keys identical to k_dict
101-
"""
105+
:param verbose: Write verbose message to stdout.
106+
Default: file only
107+
:param log: logging.Logger object
102108
103-
if log is None:
104-
log = log_stdout()
109+
:return: A(lambda) with keys identical to ``k_dict``
110+
"""
105111

106112
log_verbose(log, "starting ...", verbose=verbose)
107113

108-
k_arr = np.array(list(k_dict.values()))
114+
k_arr = np.array(list(k_dict.values()))
109115

110-
A_arr = k_arr * EBV
116+
A_arr = k_arr * EBV
111117
A_dict = dict(zip(list(k_dict.keys()), A_arr))
112118

113119
log_verbose(log, "finished.", verbose=verbose)
114120
return A_dict
115121

116122

117-
def line_ratio_atten(ratio, EBV, wave_top, wave_bottom, verbose=False,
118-
log=None):
123+
def line_ratio_atten(ratio: Union[float, np.ndarray],
124+
EBV: Union[float, np.ndarray],
125+
wave_top: str, wave_bottom: str,
126+
verbose: bool = False,
127+
log: Logger = log_stdout()) -> \
128+
Union[float, np.ndarray]:
129+
"""
130+
Determine dust-corrected emission-line ratios
119131
120-
if log is None:
121-
log = log_stdout()
132+
:param ratio: Float or array of observed flux ratios
133+
:param EBV: E(B-V) value(s)
134+
:param wave_top: Emission-line name for flux ratio numerator
135+
:param wave_bottom: Emission-line name for flux ratio denominator
136+
:param verbose: Write verbose message to stdout.
137+
Default: file only
138+
:param log: logging.Logger object
139+
140+
:return: Float or array of dust-corrected flux ratios
141+
"""
122142

123143
log_verbose(log, "starting ...", verbose=verbose)
124144

125-
k_top = k_dict[wave_top]
145+
k_top = k_dict[wave_top]
126146
k_bottom = k_dict[wave_bottom]
127147

128148
ratio_atten = ratio * 10**(0.4*EBV*(k_top - k_bottom))
@@ -131,28 +151,26 @@ def line_ratio_atten(ratio, EBV, wave_top, wave_bottom, verbose=False,
131151
return ratio_atten
132152

133153

134-
def Hb_SFR(log_LHb, EBV, verbose=False, log=None):
154+
def Hb_SFR(log_LHb: Union[float, np.ndarray],
155+
EBV: Union[float, np.ndarray],
156+
verbose: bool = False,
157+
log: Logger = log_stdout()) -> \
158+
Union[float, np.ndarray]:
135159
"""
136-
Purpose:
137-
Determine dust-corrected SFR using the H-beta luminosity and a
138-
measurement for nebular attenuation
160+
Determine dust-corrected SFR using the H-beta luminosity and a
161+
measurement for nebular attenuation
139162
140163
Equation below is based on Eq. 2 in Ly et al. (2015), ApJ, 805, 45
141164
DOI: https://doi.org/10.1088/0004-637X/805/1/45
142165
143-
:param log_LHb: numpy array or float containing logarithm of H-beta
144-
luminosity in units of erg/s
145-
:param EBV: numpy array or float providing E(B-V)
146-
:param verbose: bool to write verbose message to stdout. Default: file only
147-
:param log: LogClass or logging object
166+
:param log_LHb: Logarithm of H-beta luminosity in units of erg/s
167+
:param EBV: E(B-V) value(s)
168+
:param verbose: Write verbose message to stdout. Default: file only
169+
:param log: logging.Logger object
148170
149-
:return logSFR: numpy array or float containing the SFR in
150-
logarithmic units of M_sun/yr
171+
:return: SFRs in logarithmic units of M_sun/yr
151172
"""
152173

153-
if log is None:
154-
log = log_stdout()
155-
156174
log_verbose(log, "starting ...", verbose=verbose)
157175

158176
logSFR = np.log10(4.4e-42 * HaHb_CaseB) + 0.4*EBV*k_HBETA + log_LHb

Metallicity_Stack_Commons/analysis/composite_indv_detect.py

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from logging import Logger
2+
13
from os.path import join
24
from os.path import exists
35

@@ -21,40 +23,41 @@
2123
three_beta_name = indv_names0[6]
2224

2325

24-
def main(fitspath, dataset, revised=False, det3=True, verbose=False, log=None):
26+
def main(fitspath: str, dataset: str, revised: bool = False,
27+
det3: bool = True, verbose: bool = False,
28+
log: Logger = log_stdout()):
2529
"""
26-
Purpose:
27-
Reads in composite table(s) containing bin information to
28-
determine temperature-based metallicity from composite average
29-
T_e and individual line ratios ([OII]/H-beta, [OIII]/H-beta)
30-
31-
:param fitspath: str containing folder path
32-
:param dataset: str containing sub-folder (specific to stacking approach)
33-
:param revised: Bool indicates whether to use revised bin properties
34-
(e.g., *.revised.tbl files)
35-
:param det3: Bool indicates whether individual galaxy files is limited to
30+
Reads in composite table(s) containing bin information to
31+
determine temperature-based metallicity from composite average
32+
T_e and individual line ratios ([OII]/H-beta, [OIII]/H-beta)
33+
34+
:param fitspath: Folder full path
35+
:param dataset: Sub-folder path (specific to stacking approach)
36+
:param revised: Indicates whether to use revised bin properties
37+
(e.g., revised.tbl files). Default: False
38+
:param det3: Indicates whether individual galaxy files is limited to
3639
those satisfying emission-line det3 requirement
3740
Default: True
38-
:param verbose: bool to write verbose message to stdout. Default: file only
39-
:param log: LogClass or logging object
40-
41-
Files identified by default
42-
composite_file: str containing filename of composite data
43-
e.g., '[dataset]/bin_derived_properties.tbl' or
44-
'[dataset]/bin_derived_properties.revised.tbl'
45-
indv_em_line_file: str containing filename that contains
46-
emission-line information for each galaxy
41+
:param verbose: Write verbose message to stdout. Default: file only
42+
:param log: logging.Logger object
43+
44+
Files identified by default:
45+
46+
composite_file: Filename of composite data
47+
e.g., '[dataset]/bin_derived_properties.tbl',
48+
'[dataset]/bin_derived_properties.revised.tbl'
49+
50+
indv_em_line_file: Filename that contains emission-line information
51+
for each galaxy
4752
e.g., 'individual_properties.tbl'
48-
indv_bin_file: str containing filename tha contains bin information
49-
for each galaxy
53+
54+
indv_bin_file: Filename that contains bin information for each galaxy
5055
e.g., '[dataset]/individual_bin_info.tbl'
51-
outfile: str containing filename of output file
56+
57+
outfile: Filename of output file
5258
e.g., '[dataset]/individual_derived_properties.tbl'
5359
"""
5460

55-
if log is None:
56-
log = log_stdout()
57-
5861
log_verbose(log, "starting ...", verbose=verbose)
5962

6063
# Define [composite_file]

0 commit comments

Comments
 (0)