Skip to content

Commit d0638fa

Browse files
authored
Add emission and si-line (#18)
1 parent 4d567b5 commit d0638fa

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

sccala-env.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ george
55
emcee
66
astropy
77
specutils
8-
pystan==3.9.0
98
corner
109
cloudpickle
1110
itsdangerous

src/sccala/speclib/linefit.py

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,57 @@ def __reset_builtin_lines__(self):
148148
self.lines = {
149149
"halpha-ae": [6250, 6650, 6563, True],
150150
"hbeta": [4550, 4900, 4861, False],
151-
"si-ii": [5900, 6450, 6355, False],
151+
"si-ii": [5750, 6450, 6355, False],
152152
}
153153
return
154154

155+
def add_line(
156+
self, line, cr_low, cr_high, rest, ae_feature=False, overwrite=False
157+
) -> None:
158+
"""
159+
Adds a new line to the line dictionary so that it can be
160+
fitted later.
161+
162+
Parameters
163+
----------
164+
line : str
165+
Specifies the name of the line. Will not overwrite
166+
existing lines.
167+
cr_low : float
168+
Lower boundary of the line feature.
169+
cr_high : float
170+
Upper boundary of the line feature.
171+
rest : float
172+
Rest wavelength of the feature.
173+
ae_feature : bool
174+
Specifies if absorption to emission ratio is to be fit.
175+
Default: False
176+
overwrite : bool
177+
If set to True, existing lines will be overwritten.
178+
Default: False
179+
180+
Returns
181+
-------
182+
None
183+
"""
184+
185+
if overwrite:
186+
self.__modify_builtin_lines__(
187+
line, cr_low=cr_low, cr_high=cr_high, rest=rest, ae_feature=ae_feature
188+
)
189+
else:
190+
self.__set_builtin_lines__(line, cr_low, cr_high, rest, ae_feature)
191+
192+
return
193+
155194
def fit_line(
156195
self,
157196
line,
158197
cr_low=None,
159198
cr_high=None,
160199
rest=None,
161200
ae_feature=False,
201+
emission=False,
162202
noisefit=True,
163203
hodlrsolver=True,
164204
size=1000,
@@ -183,6 +223,9 @@ def fit_line(
183223
ae_feature : bool
184224
Specifies if absorption to emission ratio is to be fit.
185225
Default: False
226+
emission : bool
227+
Specifies if the line is an emission line. If ae_feature is
228+
set to True, this parameter is ignored. Default: False
186229
noisefit : bool
187230
Determines if correlated noise is to be fit. If false, only one
188231
kernel is used, otherwise two will be used. Default: True
@@ -230,7 +273,9 @@ def fit_line(
230273
else:
231274
error = None
232275
try:
233-
if wav[np.argmin(flux)] < rest:
276+
if emission and wav[np.argmax(flux)] > rest:
277+
break
278+
if not emission and wav[np.argmin(flux)] < rest:
234279
break
235280
except ValueError as e:
236281
warnings.warn(
@@ -343,7 +388,10 @@ def log_likelihood(params):
343388

344389
print("Predicting flux...")
345390
# Mask to ensure only minima in the middle region are selected
346-
mask = np.logical_and(x > min(wav) + lowcut, x < rest)
391+
if emission:
392+
mask = np.logical_and(x > rest, x < max(wav) - lowcut)
393+
else:
394+
mask = np.logical_and(x > min(wav) + lowcut, x < rest)
347395
xmin = x[mask]
348396
for s in tqdm(sampler.results["samples"][subsample]):
349397
gp.set_parameter_vector(s)
@@ -359,7 +407,10 @@ def log_likelihood(params):
359407
else:
360408
fits_noise.extend(np.zeros_like(fit))
361409
try:
362-
minind = np.argmin(fit[:, mask], axis=1)
410+
if emission:
411+
minind = np.argmax(fit[:, mask], axis=1)
412+
else:
413+
minind = np.argmin(fit[:, mask], axis=1)
363414
if len(minind) == 0:
364415
continue
365416
# Calculate absorption to emission line ratio

0 commit comments

Comments
 (0)