Skip to content

Commit

Permalink
Merge pull request #351 from linetools/chk_z
Browse files Browse the repository at this point in the history
EW using do_analysis
  • Loading branch information
profxj committed Feb 20, 2017
2 parents 5ce8a7d + cf0bbe1 commit 6fc02b7
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 19 deletions.
1 change: 1 addition & 0 deletions docs/absline.rst
Expand Up @@ -109,5 +109,6 @@ generate_voigt
measure_aodm
------------


Output
======
33 changes: 32 additions & 1 deletion docs/abssys.rst
Expand Up @@ -85,18 +85,47 @@ AbsLines
--------

There are a few methods related to the AbsLine objects within
an AbsSystem. One can generate a list of all the AbsLine objects
an AbsSystem.

List
++++

One can generate a list of all the AbsLine objects
with::

lines = abssys.list_of_abslines()


get absline
+++++++++++

One can retrieve one or more AbsLine objects matching the name
or rest-wavelength of a transition, e.g. ::

lyb = abssys.get_absline('HI 1025')
# or
lyb = abssys.get_absline(1025.72*u.AA) # Nearest 0.01 A is required

measure_restew
++++++++++++++

Measure the rest-frame equivalent widths for all AbsLine objects
in the system.
In addition to the inputs described in :ref:`measure-ew`,
each line to be measured must have line.analy['do_anlaysis']=1.
Here is an example::

abssys.measure_restew(spec=xspec_object)


fill transitions
++++++++++++++++

Generate an astropy.Table of information on the absorption lines
in the system. This is stored in the ._trans attribute::

abssys.fill_trans()
print(abssys._trans)

Components
----------
Expand All @@ -122,6 +151,8 @@ These are derived from the components ::
abssys.fill_ionN()
print(abssys._ionN)



Output
======

Expand Down
16 changes: 10 additions & 6 deletions docs/specline.rst
Expand Up @@ -50,7 +50,7 @@ within its own object. It is also accessible as a property, e.g.::

z = sline.z

.. _specanalysis
.. _spec-analysis:

Analysis
========
Expand Down Expand Up @@ -91,6 +91,8 @@ and whether they are from the same ion::
print specline.ismatch(another_line)


.. _measure-ew:

measure_ew
----------

Expand All @@ -99,19 +101,21 @@ Following absorption-line convention, absorption will
have a positive value and emission will have a negative value.

To perform the calculation, the line must be associated to
a spectrum (see `Analysis_`) and either wvlim or vlim must
be specified. When executed, the EW and sig_EW attibutes
are filled::
a spectrum (see `Analysis`_ above) and the LineLimits of the line
must have previously been specified.

When executed, the EW and sig_EW attibutes are filled::

specline.measure_ew()
print(specline.attrib['EW'])


measure_kin
-----------

Measure kinematic characteristics of an AbsLine.
To perform the calculation, the line must be associated to
a spectrum (see `Analysis_`) and vlim must
a spectrum (see `Analysis`_) and vlim must
be specified. When executed, the 'kin' attribute is filled
with a dict of measurements. Default set of measurements
are the v90, fedg, and fmm statistics of Prochaska & Wolfe 1997::
Expand All @@ -123,7 +127,7 @@ measure_restew
--------------

Measure the rest-frame Equivalent width of a SpectralLine.
See `measure_ew`_ for details.
See :ref:`measure-ew` for other details.

to_dict
-------
Expand Down
6 changes: 5 additions & 1 deletion linetools/analysis/plots.py
Expand Up @@ -13,7 +13,7 @@
import matplotlib.gridspec as gridspec
import matplotlib as mpl

def stack_plot(abslines, vlim=[-300,300.]*u.km/u.s, nrow=6, show=True,
def stack_plot(abslines, vlim=[-300,300.]*u.km/u.s, nrow=6, show=True, spec=None,
ymnx=(-0.1,1.1), figsz=(18,11), return_fig=False, tight_layout=False):
"""Show a stack plot of the input lines
Assumes the data are normalized.
Expand Down Expand Up @@ -49,6 +49,10 @@ def stack_plot(abslines, vlim=[-300,300.]*u.km/u.s, nrow=6, show=True,
for iline in abslines:
if isinstance(iline.analy['spec'], XSpectrum1D):
gdiline.append(iline)
else:
if spec is not None:
iline.analy['spec'] = spec
gdiline.append(iline)
nplt = len(gdiline)
if nplt == 0:
print("Load spectra into the absline.analy['spec']")
Expand Down
13 changes: 10 additions & 3 deletions linetools/isgm/abssystem.py
Expand Up @@ -260,6 +260,7 @@ def add_component(self, abscomp, tol=0.2*u.arcsec,
else:
testcoord = True
# Now redshift/velocity
testz = True
if chk_z:
# Will avoid Quantity for speed
comp_vlim_mks = abscomp.vlim.to('km/s').value
Expand Down Expand Up @@ -348,7 +349,7 @@ def get_absline(self, inp):
warnings.warn("No absline with input={}".format(inp))
return None
elif len(mt) == 1:
return abslines[mt]
return abslines[mt[0]]
else:
return [abslines[ii] for ii in mt]

Expand Down Expand Up @@ -421,6 +422,8 @@ def list_of_abslines(self):

def measure_restew(self, spec=None, **kwargs):
""" Measure rest-frame EWs for lines in the AbsSystem
Analysis is only performed on lines with analy['do_analysis'] != 0
Parameters
----------
spec : XSpectrum1D, optional
Expand All @@ -437,8 +440,12 @@ def measure_restew(self, spec=None, **kwargs):
# Fill in spec?
if spec is not None:
iline.analy['spec'] = spec
# Measure
iline.measure_restew(**kwargs)
# Check for analysis
if iline.analy['do_analysis'] == 0:
warnings.warn("Skipping {:s} because do_analysis=0".format(iline.name))
else:
# Measure
iline.measure_restew(**kwargs)

def measure_aodm(self, spec=None, **kwargs):
""" Measure ADOM columns for the list of lines
Expand Down
24 changes: 16 additions & 8 deletions linetools/isgm/tests/test_use_abssys.py
Expand Up @@ -31,21 +31,18 @@ def data_path(filename):
def init_system():
radec = SkyCoord(ra=123.1143*u.deg, dec=-12.4321*u.deg)
# HI Lya, Lyb
lya = AbsLine(1215.670*u.AA)
lya = AbsLine(1215.670*u.AA, z=2.92939)
lya.limits.set([-300.,300.]*u.km/u.s)
lya.attrib['z'] = 2.92939
lya.attrib['coord'] = radec
lyb = AbsLine(1025.7222*u.AA)
lyb = AbsLine(1025.7222*u.AA, z=lya.z)
lyb.limits.set([-300.,300.]*u.km/u.s)
lyb.attrib['z'] = lya.attrib['z']
lyb.attrib['coord'] = radec
abscomp = AbsComponent.from_abslines([lya,lyb])
# SiII
SiIItrans = ['SiII 1260', 'SiII 1304', 'SiII 1526', 'SiII 1808']
abslines = []
for trans in SiIItrans:
iline = AbsLine(trans)
iline.attrib['z'] = 2.92939
iline = AbsLine(trans, z=2.92939)
iline.attrib['coord'] = radec
iline.limits.set([-250.,80.]*u.km/u.s)
abslines.append(iline)
Expand All @@ -64,8 +61,6 @@ def test_list_of_abslines():
abslines = gensys.list_of_abslines()
# Test
assert len(abslines) == 6
# Measure EWs
gensys.measure_restew(spec=spec)
# Measure AODM
gensys.measure_aodm(spec=spec)
# trans table
Expand All @@ -77,6 +72,19 @@ def test_list_of_abslines():
lyb = gensys.get_absline(1025.72*u.AA)
np.testing.assert_allclose(lyb.wrest.value, 1025.7222)

def test_measure_ew():
spec = io.readspec(data_path('UM184_nF.fits'))
gensys = init_system()
# Measure EWs
gensys.measure_restew(spec=spec)
for aline in gensys.list_of_abslines():
assert aline.attrib['flag_EW'] == 1
# Skip do_analysis = 0
gensys2 = init_system()
lyb = gensys2.get_absline('HI 1025')
lyb.analy['do_analysis'] = 0
gensys2.measure_restew(spec=spec)
assert lyb.attrib['flag_EW'] == 0

def test_ionn():
gensys = init_system()
Expand Down

0 comments on commit 6fc02b7

Please sign in to comment.