From 3e54a49218d716ced507e9adfea75d7985f1abb1 Mon Sep 17 00:00:00 2001 From: "J. Xavier Prochaska" Date: Fri, 3 Feb 2017 10:34:26 -0800 Subject: [PATCH 1/5] various bug fixes and improvements --- linetools/analysis/plots.py | 6 +++++- linetools/isgm/abssystem.py | 11 ++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/linetools/analysis/plots.py b/linetools/analysis/plots.py index 4ae8d0ea..f4af9565 100644 --- a/linetools/analysis/plots.py +++ b/linetools/analysis/plots.py @@ -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. @@ -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']") diff --git a/linetools/isgm/abssystem.py b/linetools/isgm/abssystem.py index 73b9091f..6c4754f2 100644 --- a/linetools/isgm/abssystem.py +++ b/linetools/isgm/abssystem.py @@ -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 @@ -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] @@ -437,8 +438,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)) + else: + # Measure + iline.measure_restew(**kwargs) def measure_aodm(self, spec=None, **kwargs): """ Measure ADOM columns for the list of lines From a53e0fafa0a57feee764a558874889fd83ea6685 Mon Sep 17 00:00:00 2001 From: "J. Xavier Prochaska" Date: Fri, 3 Feb 2017 17:31:58 -0800 Subject: [PATCH 2/5] test --- linetools/isgm/tests/test_use_abssys.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/linetools/isgm/tests/test_use_abssys.py b/linetools/isgm/tests/test_use_abssys.py index 8f7baa4c..4995cd2b 100644 --- a/linetools/isgm/tests/test_use_abssys.py +++ b/linetools/isgm/tests/test_use_abssys.py @@ -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) @@ -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 @@ -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() From 8a12d44de59f3df2e3e5098872d5f6a8b4563b91 Mon Sep 17 00:00:00 2001 From: "J. Xavier Prochaska" Date: Fri, 3 Feb 2017 17:51:51 -0800 Subject: [PATCH 3/5] more docs --- docs/absline.rst | 1 + docs/abssys.rst | 33 ++++++++++++++++++++++++++++++++- docs/specline.rst | 16 ++++++++++------ linetools/isgm/abssystem.py | 2 ++ 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/docs/absline.rst b/docs/absline.rst index 012f3b76..8160d161 100644 --- a/docs/absline.rst +++ b/docs/absline.rst @@ -109,5 +109,6 @@ generate_voigt measure_aodm ------------ + Output ====== diff --git a/docs/abssys.rst b/docs/abssys.rst index 7a88f1c2..94a45a02 100644 --- a/docs/abssys.rst +++ b/docs/abssys.rst @@ -85,11 +85,20 @@ 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. :: @@ -97,6 +106,26 @@ or rest-wavelength of a transition, e.g. :: # 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 ---------- @@ -122,6 +151,8 @@ These are derived from the components :: abssys.fill_ionN() print(abssys._ionN) + + Output ====== diff --git a/docs/specline.rst b/docs/specline.rst index 9f410299..746740d3 100644 --- a/docs/specline.rst +++ b/docs/specline.rst @@ -50,7 +50,7 @@ within its own object. It is also accessible as a property, e.g.:: z = sline.z -.. _specanalysis +.. _spec-analysis: Analysis ======== @@ -91,6 +91,8 @@ and whether they are from the same ion:: print specline.ismatch(another_line) +.. _measure-ew: + measure_ew ---------- @@ -99,11 +101,13 @@ 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 @@ -111,7 +115,7 @@ 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:: @@ -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 ------- diff --git a/linetools/isgm/abssystem.py b/linetools/isgm/abssystem.py index 6c4754f2..1e0382c5 100644 --- a/linetools/isgm/abssystem.py +++ b/linetools/isgm/abssystem.py @@ -422,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 From 64031eb374eb8092c3d032a29da6b0b3e07724d4 Mon Sep 17 00:00:00 2001 From: "J. Xavier Prochaska" Date: Fri, 3 Feb 2017 17:53:41 -0800 Subject: [PATCH 4/5] fix test --- linetools/isgm/abssystem.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linetools/isgm/abssystem.py b/linetools/isgm/abssystem.py index 1e0382c5..45a3e1c2 100644 --- a/linetools/isgm/abssystem.py +++ b/linetools/isgm/abssystem.py @@ -442,7 +442,7 @@ def measure_restew(self, spec=None, **kwargs): iline.analy['spec'] = spec # Check for analysis if iline.analy['do_analysis'] == 0: - warnings.warn("Skipping {:s} because do_analysis=0".format(iline)) + warnings.warn("Skipping {:s} because do_analysis=0".format(iline.__repr__)) else: # Measure iline.measure_restew(**kwargs) From cf0bbe14eaa3492bc8f5a3739caeac7c2173f20b Mon Sep 17 00:00:00 2001 From: "J. Xavier Prochaska" Date: Sat, 4 Feb 2017 08:01:01 -0800 Subject: [PATCH 5/5] try again --- linetools/isgm/abssystem.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linetools/isgm/abssystem.py b/linetools/isgm/abssystem.py index 45a3e1c2..17f66fb1 100644 --- a/linetools/isgm/abssystem.py +++ b/linetools/isgm/abssystem.py @@ -442,7 +442,7 @@ def measure_restew(self, spec=None, **kwargs): iline.analy['spec'] = spec # Check for analysis if iline.analy['do_analysis'] == 0: - warnings.warn("Skipping {:s} because do_analysis=0".format(iline.__repr__)) + warnings.warn("Skipping {:s} because do_analysis=0".format(iline.name)) else: # Measure iline.measure_restew(**kwargs)