Skip to content

Commit

Permalink
Merge branches 'abssys_speedup' and 'master' of https://github.com/li…
Browse files Browse the repository at this point in the history
…netools/linetools into abssys_speedup
  • Loading branch information
profxj committed May 16, 2016
2 parents f50f0c7 + ebcbf94 commit 98eda3e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
9 changes: 8 additions & 1 deletion linetools/isgm/abscomponent.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,10 @@ def synthesize_colm(self, overwrite=False, redo_aodm=False, **kwargs):
# Collate
self.flag_N = 0
for aline in self._abslines:
if aline.attrib['flag_N'] == 0: # No value
warnings.warn("Absline {} has flag=0. Hopefully you expected that".format(str(aline)))
continue
# Check N is filled
if np.allclose(aline.attrib['N'].value, 0.):
raise ValueError("Need to set N in attrib. \n Consider linear_clm in linetools.analysis.absline")
if aline.attrib['flag_N'] == 1: # Good value?
Expand Down Expand Up @@ -445,10 +449,13 @@ def synthesize_colm(self, overwrite=False, redo_aodm=False, **kwargs):
if aline.attrib['N'] < self.N:
self.N = aline.attrib['N']
self.sig_N = aline.attrib['sig_N']
elif aline.attrib['flag_N'] == 0: # No value
warnings.warn("Absline {} has flag=0. Hopefully you expected that")
else:
raise ValueError("Bad flag_N value")
# Log values
self.logN, self.sig_logN = ltaa.log_clm(self)
if self.flag_N > 0:
self.logN, self.sig_logN = ltaa.log_clm(self)

def repr_vpfit(self, b=10.*u.km/u.s, tie_strs=('', '', ''), fix_strs=('', '', '')):
"""
Expand Down
13 changes: 10 additions & 3 deletions linetools/isgm/tests/test_use_abscomp.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
#pdb.set_trace()
# Set of Input lines

def mk_comp(ctype,vlim=[-300.,300]*u.km/u.s,add_spec=False, use_rand=True):
def mk_comp(ctype,vlim=[-300.,300]*u.km/u.s,add_spec=False, use_rand=True,
add_trans=False):
# Read a spectrum Spec
if add_spec:
xspec = lsio.readspec(lt_path+'/spectra/tests/files/UM184_nF.fits')
Expand All @@ -37,6 +38,8 @@ def mk_comp(ctype,vlim=[-300.,300]*u.km/u.s,add_spec=False, use_rand=True):
all_trans = ['HI 1215', 'HI 1025']
elif ctype == 'SiII':
all_trans = ['SiII 1260', 'SiII 1304', 'SiII 1526', 'SiII 1808']
if add_trans:
all_trans += ['SiII 1193']
abslines = []
for trans in all_trans:
iline = AbsLine(trans)
Expand Down Expand Up @@ -75,18 +78,22 @@ def test_build_table():
assert isinstance(comp_tbl,QTable)

def test_synthesize_colm():
abscomp,_ = mk_comp('SiII', vlim=[-250,80.]*u.km/u.s, add_spec=True)
abscomp,_ = mk_comp('SiII', vlim=[-250,80.]*u.km/u.s, add_spec=True,
add_trans=True)
# Column
abscomp.synthesize_colm(redo_aodm=True)
# Test
np.testing.assert_allclose(abscomp.logN, 13.594445560856554)
# Reset flags (for testing)
abscomp2,_ = mk_comp('SiII', vlim=[-250,80.]*u.km/u.s, add_spec=True, use_rand=False)
abscomp2,_ = mk_comp('SiII', vlim=[-250,80.]*u.km/u.s, add_spec=True, use_rand=False,
add_trans=True)
for iline in abscomp2._abslines:
if iline.data['name'] == 'SiII 1260':
iline.attrib['flag_N'] = 2
elif iline.data['name'] == 'SiII 1808':
iline.attrib['flag_N'] = 3
elif iline.data['name'] == 'SiII 1193':
iline.attrib['flag_N'] = 0
else:
iline.attrib['flag_N'] = 1
abscomp2.synthesize_colm()
Expand Down

0 comments on commit 98eda3e

Please sign in to comment.