Skip to content

Commit

Permalink
emiss -> em
Browse files Browse the repository at this point in the history
  • Loading branch information
profxj committed Oct 28, 2016
1 parent f7b8e87 commit e1bf278
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 69 deletions.
72 changes: 23 additions & 49 deletions docs/examples/EmissLine_examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Examples for EmissLine class [v1.0]"
"# Examples for EmissLine class [v1.1]"
]
},
{
Expand Down Expand Up @@ -55,7 +55,7 @@
{
"data": {
"text/plain": [
"<EmissLine: Halpha, wrest=6564.61 Angstrom>"
"<EmLine: Halpha, wrest=6564.61 Angstrom>"
]
},
"execution_count": 2,
Expand All @@ -65,7 +65,7 @@
],
"source": [
"reload(lsp)\n",
"emisslin = lsp.EmissLine('Halpha')\n",
"emisslin = lsp.EmLine('Halpha')\n",
"emisslin"
]
},
Expand Down Expand Up @@ -171,7 +171,7 @@
" 'limits': {u'vlim': {'unit': u'km / s', 'value': [0.0, 0.0]},\n",
" u'wvlim': {'unit': u'Angstrom', 'value': [6564.613, 6564.613]},\n",
" u'zlim': [0.0, 0.0]},\n",
" 'ltype': u'Emiss',\n",
" 'ltype': u'Em',\n",
" 'name': u'Halpha',\n",
" 'wrest': {'unit': u'Angstrom', 'value': 6564.613}}"
]
Expand Down Expand Up @@ -203,7 +203,7 @@
{
"data": {
"text/plain": [
"<EmissLine: Halpha, wrest=6564.61 Angstrom>"
"<EmLine: Halpha, wrest=6564.61 Angstrom>"
]
},
"execution_count": 5,
Expand All @@ -228,9 +228,21 @@
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
"collapsed": false
},
"outputs": [],
"outputs": [
{
"ename": "AttributeError",
"evalue": "'module' object has no attribute 'EmissLine'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-6-30b2da4480ad>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0memisslines\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0memisslin\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlsp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mEmissLine\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'Hbeta'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m: 'module' object has no attribute 'EmissLine'"
]
}
],
"source": [
"emisslines = [emisslin, lsp.EmissLine('Hbeta')]"
]
Expand All @@ -244,22 +256,11 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[<Quantity 6564.613 Angstrom>, <Quantity 4862.683 Angstrom>]"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"wrest_values = ltlu.parse_speclines(emisslines, 'wrest')\n",
"wrest_values"
Expand All @@ -274,38 +275,11 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"&lt;Table length=2&gt;\n",
"<table id=\"table4601425424\">\n",
"<thead><tr><th>wrest</th><th>name</th><th>Z</th><th>ion</th><th>Ej</th><th>z</th><th>EW</th><th>sig_EW</th><th>flag_flux</th><th>flux</th><th>sig_flux</th></tr></thead>\n",
"<thead><tr><th>Angstrom</th><th></th><th></th><th></th><th>1 / cm</th><th></th><th>Angstrom</th><th>Angstrom</th><th></th><th>erg / s</th><th>erg / s</th></tr></thead>\n",
"<thead><tr><th>float64</th><th>unicode6</th><th>int64</th><th>int64</th><th>float64</th><th>float64</th><th>float64</th><th>float64</th><th>int64</th><th>float64</th><th>float64</th></tr></thead>\n",
"<tr><td>4862.683</td><td>Hbeta</td><td>1</td><td>1</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0</td><td>0.0</td><td>0.0</td></tr>\n",
"<tr><td>6564.613</td><td>Halpha</td><td>1</td><td>1</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0</td><td>0.0</td><td>0.0</td></tr>\n",
"</table>"
],
"text/plain": [
"<Table length=2>\n",
" wrest name Z ion Ej ... sig_EW flag_flux flux sig_flux\n",
"Angstrom 1 / cm ... Angstrom erg / s erg / s \n",
"float64 unicode6 int64 int64 float64 ... float64 int64 float64 float64 \n",
"-------- -------- ----- ----- ------- ... -------- --------- ------- --------\n",
"4862.683 Hbeta 1 1 0.0 ... 0.0 0 0.0 0.0\n",
"6564.613 Halpha 1 1 0.0 ... 0.0 0 0.0 0.0"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"reload(ltlu)\n",
"tbl = ltlu.transtable_from_speclines(emisslines)\n",
Expand Down
8 changes: 4 additions & 4 deletions linetools/analysis/linelimits.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ class LineLimits(object):
"""
@classmethod
def from_specline(cls, aline, zlim):
""" From AbsLine or Emissline
""" From AbsLine or Emline
Parameters
----------
aline : AbsLine
"""
from ..spectralline import AbsLine, EmissLine
if not isinstance(aline, (AbsLine, EmissLine)):
raise IOError("Input aline must be AbsLine or EmissLine")
from ..spectralline import AbsLine, EmLine
if not isinstance(aline, (AbsLine, EmLine)):
raise IOError("Input aline must be AbsLine or EmLine")
#
slf = cls(aline.wrest, aline.attrib['z'], zlim)
return slf
Expand Down
4 changes: 2 additions & 2 deletions linetools/line_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from astropy.table import Table
from astropy.units import Quantity

from linetools.spectralline import AbsLine, EmissLine
from linetools.spectralline import AbsLine, EmLine

def parse_speclines(speclines, key, mk_array=False):
""" Generate a list or array of items from a list of SpectralLines
Expand Down Expand Up @@ -70,7 +70,7 @@ def transtable_from_speclines(speclines, add_keys=None):
keys = ['wrest','name','Z', 'ion', 'Ej', 'z', 'EW', 'sig_EW']
if speclines[0].ltype == 'Abs':
keys += ['flag_N', 'logN', 'sig_logN']
if speclines[0].ltype == 'Emiss':
if speclines[0].ltype == 'Em':
keys += ['flag_flux', 'flux', 'sig_flux']
if add_keys is not None:
keys += add_keys
Expand Down
16 changes: 8 additions & 8 deletions linetools/spectralline.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class SpectralLine(object):
Attributes
----------
ltype : str
Type of line, either 'Abs' or 'Emiss' (not currently implemented though)
Type of line, either 'Abs' or 'Em' (not currently implemented though)
wrest : Quantity
Rest wavelength
z : float
Expand Down Expand Up @@ -111,8 +111,8 @@ def from_dict(cls, idict, coord=None, warn_only=False, chk_data=True, **kwargs):
sline = AbsLine(idict['name'], **kwargs)
except KeyError: # This is to be compatible JSON files already written with old notation (e.g. DLA H100)
sline = AbsLine(idict['trans'], **kwargs)
elif idict['ltype'] == 'Emiss':
sline = EmissLine(idict['name'], **kwargs)
elif idict['ltype'] == 'Em':
sline = EmLine(idict['name'], **kwargs)
else:
raise ValueError("Not prepared for type {:s}.".format(idict['ltype']))
# Check data
Expand Down Expand Up @@ -182,7 +182,7 @@ def __init__(self, ltype, trans, linelist=None, closest=False, z=0.,

# Required
self.ltype = ltype
if ltype not in ['Abs', 'Emiss']:
if ltype not in ['Abs', 'Em']:
raise ValueError('spec/lines: Not ready for type {:s}'.format(ltype))

# Init
Expand All @@ -202,7 +202,7 @@ def __init__(self, ltype, trans, linelist=None, closest=False, z=0.,
zlim = kwargs['zlim']
except KeyError:
zlim = [z,z]
if ltype in ['Abs', 'Emiss']:
if ltype in ['Abs', 'Em']:
self.limits = LineLimits.from_specline(self, zlim)
else:
raise ValueError('Not ready to set limits for this type')
Expand All @@ -226,7 +226,7 @@ def fill_data(self, trans, linelist=None, closest=False, verbose=True):
if linelist is None:
if self.ltype == 'Abs':
llist = LineList('ISM')
elif self.ltype == 'Emiss':
elif self.ltype == 'Em':
llist = LineList('Galaxy')
else:
raise ValueError("Not ready for ltype = {:s}".format(self.ltype))
Expand Down Expand Up @@ -678,7 +678,7 @@ def __repr__(self):
txt = txt + '>'
return (txt)

class EmissLine(SpectralLine):
class EmLine(SpectralLine):
"""Class representing a spectral emission line.
Parameters
Expand All @@ -690,7 +690,7 @@ class EmissLine(SpectralLine):
"""
def __init__(self, trans, **kwargs):
# Generate with type
super(EmissLine, self).__init__('Emiss', trans, **kwargs)
super(EmLine, self).__init__('Em', trans, **kwargs)

def update(self):
""" Fill in a few additional dicts
Expand Down
12 changes: 6 additions & 6 deletions linetools/tests/test_init_emissline.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Module to run tests on initializing EmissLine
# Module to run tests on initializing EmLine

# TEST_UNICODE_LITERALS
from __future__ import print_function, absolute_import, division, unicode_literals
Expand All @@ -7,7 +7,7 @@
import pytest
from astropy import units as u

from linetools.spectralline import EmissLine, SpectralLine
from linetools.spectralline import EmLine, SpectralLine
from linetools import utils as ltu

'''
Expand All @@ -18,17 +18,17 @@ def data_path(filename):

def test_mk_emissline():
# Init Halpha
emisslin = EmissLine(6564.613*u.AA)
emisslin = EmLine(6564.613*u.AA)
assert emisslin.name == 'Halpha'

# Init Halpha by name
emisslin2 = EmissLine('Halpha')
emisslin2 = EmLine('Halpha')
np.testing.assert_allclose(emisslin2.data['wrest'], 6564.613*u.AA)


def test_dicts():
# Init Halpha
emisslin = EmissLine(6564.613*u.AA)
emisslin = EmLine(6564.613*u.AA)
emisslin.analy['spec'] = 'tmp.fits'
edict = emisslin.to_dict()
assert isinstance(edict, dict)
Expand All @@ -38,4 +38,4 @@ def test_dicts():
newdict = ltu.loadjson('tmp.json')
newlin = SpectralLine.from_dict(newdict)
assert newlin.name == 'Halpha'
assert newlin.ltype == 'Emiss'
assert newlin.ltype == 'Em'

0 comments on commit e1bf278

Please sign in to comment.