Skip to content

Commit

Permalink
trans table
Browse files Browse the repository at this point in the history
  • Loading branch information
profxj committed Jun 3, 2016
1 parent fad216a commit 6aaf603
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 84 deletions.
164 changes: 91 additions & 73 deletions docs/examples/AbsLine_examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Examples for AbsLine class (v1.2)"
"# Examples for AbsLine class (v1.3)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 2,
"metadata": {
"collapsed": false
},
Expand All @@ -23,6 +23,7 @@
"import astropy.units as u\n",
"from linetools.spectralline import AbsLine, SpectralLine\n",
"from linetools import spectralline as ltsp\n",
"from linetools import line_utils as ltlu\n",
"from linetools.spectra.xspectrum1d import XSpectrum1D"
]
},
Expand All @@ -35,36 +36,18 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"linetools.lists.parse: Reading linelist --- \n",
" /Users/ncrighton/Code/Repo/linetools/build/lib.macosx-10.5-x86_64-3.4/linetools/data/lines/morton03_table2.fits.gz\n",
"linetools.lists.parse: Reading linelist --- \n",
" /Users/ncrighton/Code/Repo/linetools/build/lib.macosx-10.5-x86_64-3.4/linetools/data/lines/morton00_table2.fits.gz\n",
"linetools.lists.parse: Reading linelist --- \n",
" /Users/ncrighton/Code/Repo/linetools/build/lib.macosx-10.5-x86_64-3.4/linetools/data/lines/verner96_tab1.fits.gz\n",
"linetools.lists.parse: Reading linelist --- \n",
" /Users/ncrighton/Code/Repo/linetools/build/lib.macosx-10.5-x86_64-3.4/linetools/data/lines/verner94_tab6.fits\n",
"linetools.lists.parse: Reading linelist --- \n",
" /Users/ncrighton/Code/Repo/linetools/build/lib.macosx-10.5-x86_64-3.4/linetools/data/lines/EUV_lines.ascii\n",
"read_sets: Using set file -- \n",
" /Users/ncrighton/Code/Repo/linetools/build/lib.macosx-10.5-x86_64-3.4/linetools/lists/sets/llist_v1.0.ascii\n"
]
},
{
"data": {
"text/plain": [
"<AbsLine: CIV 1548, wrest=1548.1950 Angstrom>"
]
},
"execution_count": 5,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -83,7 +66,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 4,
"metadata": {
"collapsed": false
},
Expand All @@ -109,14 +92,17 @@
" 'gk': 4,\n",
" 'group': 1,\n",
" 'ion': 4,\n",
" 'is_EUV': False,\n",
" 'is_HI': False,\n",
" 'is_Strong': True,\n",
" 'mol': '',\n",
" 'name': 'CIV 1548',\n",
" 'nj': 0,\n",
" 'nk': 0,\n",
" 'wrest': <Quantity 1548.195 Angstrom>}"
]
},
"execution_count": 6,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -134,63 +120,66 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"{'analy': {'datafile': '',\n",
" 'do_analysis': 1,\n",
" 'flag_kin': 0,\n",
" 'flg_eye': 0,\n",
" 'flg_limit': 0,\n",
" 'name': 'CIV 1548',\n",
" 'vlim': {'unit': 'km / s', 'value': [0.0, 0.0]},\n",
" 'wvlim': {'unit': 'Angstrom', 'value': [0.0, 0.0]}},\n",
" 'attrib': {'DEC': 0.0,\n",
" 'EW': {'unit': 'Angstrom', 'value': 0.0},\n",
" 'N': {'unit': '1 / cm2', 'value': 0.0},\n",
" 'RA': 0.0,\n",
" 'b': {'unit': 'km / s', 'value': 0.0},\n",
" 'flag_EW': 0,\n",
" 'flag_N': 0,\n",
" 'sig_EW': {'unit': 'Angstrom', 'value': 0.0},\n",
" 'sig_N': {'unit': '1 / cm2', 'value': 0.0},\n",
" 'sig_b': {'unit': 'km / s', 'value': 0.0},\n",
" 'sig_v': {'unit': 'km / s', 'value': 0.0},\n",
" 'sig_z': 0.0,\n",
" 'v': {'unit': 'km / s', 'value': 0.0},\n",
" 'z': 0.0},\n",
" 'data': {'A': {'unit': '1 / s', 'value': 0.0},\n",
"{'analy': {u'datafile': u'',\n",
" u'do_analysis': 1,\n",
" u'flag_kin': 0,\n",
" u'flg_eye': 0,\n",
" u'flg_limit': 0,\n",
" u'name': 'CIV 1548',\n",
" u'vlim': {'unit': u'km / s', 'value': [0.0, 0.0]},\n",
" u'wvlim': {'unit': u'Angstrom', 'value': [0.0, 0.0]}},\n",
" 'attrib': {u'DEC': 0.0,\n",
" u'EW': {'unit': u'Angstrom', 'value': 0.0},\n",
" u'N': {'unit': u'1 / cm2', 'value': 0.0},\n",
" u'RA': 0.0,\n",
" u'b': {'unit': u'km / s', 'value': 0.0},\n",
" u'flag_EW': 0,\n",
" u'flag_N': 0,\n",
" u'sig_EW': {'unit': u'Angstrom', 'value': 0.0},\n",
" u'sig_N': {'unit': u'1 / cm2', 'value': 0.0},\n",
" u'sig_b': {'unit': u'km / s', 'value': 0.0},\n",
" u'sig_v': {'unit': u'km / s', 'value': 0.0},\n",
" u'sig_z': 0.0,\n",
" u'v': {'unit': u'km / s', 'value': 0.0},\n",
" u'z': 0.0},\n",
" 'data': {'A': {'unit': u'1 / s', 'value': 0.0},\n",
" 'Am': 0,\n",
" 'Ej': {'unit': '1 / cm', 'value': 0.0},\n",
" 'Ek': {'unit': '1 / cm', 'value': 0.0},\n",
" 'Ex': {'unit': '1 / cm', 'value': 0.0},\n",
" 'Ej': {'unit': u'1 / cm', 'value': 0.0},\n",
" 'Ek': {'unit': u'1 / cm', 'value': 0.0},\n",
" 'Ex': {'unit': u'1 / cm', 'value': 0.0},\n",
" 'Jj': 0.0,\n",
" 'Jk': 0.0,\n",
" 'Ref': 'Verner1994',\n",
" 'Z': 6,\n",
" 'el': 0,\n",
" 'f': 0.18999999761581421,\n",
" 'gamma': {'unit': '1 / s', 'value': 0.0},\n",
" 'f': 0.1899999976158142,\n",
" 'gamma': {'unit': u'1 / s', 'value': 0.0},\n",
" 'gj': 2,\n",
" 'gk': 4,\n",
" 'group': 1,\n",
" 'ion': 4,\n",
" 'is_EUV': False,\n",
" 'is_HI': False,\n",
" 'is_Strong': True,\n",
" 'mol': '',\n",
" 'name': 'CIV 1548',\n",
" 'nj': 0,\n",
" 'nk': 0,\n",
" 'wrest': {'unit': 'Angstrom', 'value': 1548.195}},\n",
" 'ltype': 'Abs',\n",
" 'wrest': {'unit': u'Angstrom', 'value': 1548.195}},\n",
" 'ltype': u'Abs',\n",
" 'name': 'CIV 1548',\n",
" 'wrest': {'unit': 'Angstrom', 'value': 1548.195}}"
" 'wrest': {'unit': u'Angstrom', 'value': 1548.195}}"
]
},
"execution_count": 7,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -210,7 +199,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 6,
"metadata": {
"collapsed": false
},
Expand All @@ -221,7 +210,7 @@
"<AbsLine: CIV 1548, wrest=1548.1950 Angstrom>"
]
},
"execution_count": 8,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -231,6 +220,47 @@
"tmp2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## List of AbsLines"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"abslines = [abslin, AbsLine('HI 1215')]"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[<Quantity 1548.195 Angstrom>, <Quantity 1215.67 Angstrom>]"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"wrest_values = ltlu.parse_abslines(abslines, 'wrest')\n",
"wrest_values"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -338,21 +368,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 2",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.4"
"name": "python2"
}
},
"nbformat": 4,
Expand Down
11 changes: 0 additions & 11 deletions linetools/isgm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,18 +171,7 @@ def build_components_from_dict(idict, coord=None, **kwargs):
return components


def transtable_from_components(components, ztbl=None, NHI_obj=None):
"""Generate a QTable summarizing the transitions from a list of components
Parameters
----------
components
ztbl
NHI_obj
Returns
-------

"""

def iontable_from_components(components, ztbl=None, NHI_obj=None):
"""Generate a QTable from a list of components
Expand Down
74 changes: 74 additions & 0 deletions linetools/line_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
""" Module for utilities related to spectral line or lines(s)
"""
from __future__ import print_function, absolute_import, division, unicode_literals

import pdb
import numpy as np

from astropy.table import QTable, Column
from astropy import units as u
from astropy.units import Quantity

def parse_abslines(abslines, key, mk_array=False):
""" Generate a list or array of items from a list of AbsLines
Parameters
----------
abslines : list of AbsLine objects
key : str
Returns
-------
items : list
"""
out_list = []
# Ugly loop
for iline in abslines:
try:
out_list.append(getattr(iline,key))
except AttributeError:
try:
out_list.append(iline.attrib[key])
except KeyError:
try:
out_list.append(iline.analy[key])
except KeyError:
try:
out_list.append(iline.data[key])
except KeyError:
out_list.append(None)
# Return
if mk_array:
if isinstance(out_list[0], Quantity):
return Quantity(out_list)
else:
return np.array(out_list)
else:
return out_list


def transtable_from_abslines(abslines, add_keys=None):
"""Generate a QTable summarizing the transitions from a list of AbsLines
Parameters
----------
abslines : list of AbsLine objects
Returns
-------
tbl : QTable
"""
keys = ['wrest','name','z','flag_EW', 'EW', 'flag_N', 'logN']
if add_keys is not None:
keys += add_keys

# Get started
tbl = QTable()

# Loop to my loop
for key in keys:
tbl[key] = parse_abslines(abslines, key, mk_array=True)

# Return
return tbl
1 change: 1 addition & 0 deletions linetools/spectralline.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ def fill_data(self, trans, linelist=None, closest=False, verbose=True):

# Additional fundamental attributes for Absorption Line
self.attrib.update({'N': 0./u.cm**2, 'sig_N': 0./u.cm**2, 'flag_N': 0, # Column
'logN': 0., 'sig_logN': 0.,
'b': 0.*u.km/u.s, 'sig_b': 0.*u.km/u.s # Doppler
} )

Expand Down
Loading

0 comments on commit 6aaf603

Please sign in to comment.