Skip to content

Commit

Permalink
Merge f5fe7ca into 0df35cb
Browse files Browse the repository at this point in the history
  • Loading branch information
jnburchett committed Oct 3, 2017
2 parents 0df35cb + f5fe7ca commit 9ffb8f6
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 94 deletions.
128 changes: 36 additions & 92 deletions docs/examples/AbsLine_examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# suppress warnings for these examples\n",
Expand All @@ -38,9 +36,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand All @@ -57,8 +53,8 @@
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
"output_type": "execute_result",
"metadata": {}
}
],
"source": [
Expand All @@ -76,9 +72,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -117,8 +111,8 @@
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
"output_type": "execute_result",
"metadata": {}
}
],
"source": [
Expand All @@ -135,9 +129,7 @@
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -200,8 +192,8 @@
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
"output_type": "execute_result",
"metadata": {}
}
],
"source": [
Expand All @@ -220,9 +212,7 @@
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
Expand All @@ -231,8 +221,8 @@
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
"output_type": "execute_result",
"metadata": {}
}
],
"source": [
Expand All @@ -250,9 +240,7 @@
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
Expand All @@ -265,8 +253,8 @@
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
"output_type": "execute_result",
"metadata": {}
}
],
"source": [
Expand All @@ -276,9 +264,7 @@
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"tmp['analy']['vlim'] = [-150,150]*u.km/u.s\n",
Expand All @@ -288,9 +274,7 @@
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"tmp3 = SpectralLine.from_dict(tmp)"
Expand All @@ -306,9 +290,7 @@
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"abslines = [abslin, AbsLine('HI 1215')]"
Expand All @@ -324,9 +306,7 @@
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
Expand All @@ -335,8 +315,8 @@
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
"output_type": "execute_result",
"metadata": {}
}
],
"source": [
Expand All @@ -354,9 +334,7 @@
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
Expand All @@ -369,20 +347,10 @@
"<tr><td>1215.67</td><td>HI 1215</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>1548.195</td><td>CIV 1548</td><td>6</td><td>4</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_N logN sig_logN\n",
"Angstrom 1 / cm ... Angstrom \n",
"float64 str8 int64 int64 float64 ... float64 int64 float64 float64 \n",
"-------- -------- ----- ----- ------- ... -------- ------ ------- --------\n",
" 1215.67 HI 1215 1 1 0.0 ... 0.0 0 0.0 0.0\n",
"1548.195 CIV 1548 6 4 0.0 ... 0.0 0 0.0 0.0"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
"output_type": "execute_result",
"metadata": {}
}
],
"source": [
Expand All @@ -400,9 +368,7 @@
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"# Set spectrum\n",
Expand All @@ -412,9 +378,7 @@
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# Set analysis range\n",
Expand All @@ -424,9 +388,7 @@
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand All @@ -452,9 +414,7 @@
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"#\n",
Expand All @@ -466,9 +426,7 @@
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand All @@ -486,19 +444,15 @@
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"metadata": {},
"source": [
"### Another Table"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
Expand All @@ -511,20 +465,10 @@
"<tr><td>1215.67</td><td>HI 1215</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>1548.195</td><td>CIV 1548</td><td>6</td><td>4</td><td>0.0</td><td>2.92929</td><td>0.993502101206</td><td>0.0527114204241</td><td>1</td><td>13.9050897399</td><td>0.0207026007539</td></tr>\n",
"</table>"
],
"text/plain": [
"<Table length=2>\n",
" wrest name Z ion ... flag_N logN sig_logN \n",
"Angstrom ... \n",
"float64 str8 int64 int64 ... int64 float64 float64 \n",
"-------- -------- ----- ----- ... ------ ------------- ---------------\n",
" 1215.67 HI 1215 1 1 ... 0 0.0 0.0\n",
"1548.195 CIV 1548 6 4 ... 1 13.9050897399 0.0207026007539"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
"output_type": "execute_result",
"metadata": {}
}
],
"source": [
Expand All @@ -542,7 +486,7 @@
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 2.0
},
"file_extension": ".py",
"mimetype": "text/x-python",
Expand All @@ -554,4 +498,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}
23 changes: 23 additions & 0 deletions linetools/isgm/abssightline.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from linetools.spectralline import AbsLine, SpectralLine
from linetools import utils as ltu
from linetools.isgm.abscomponent import AbsComponent
from linetools.isgm.abssystem import AbsSystem

# Global import for speed
c_kms = const.c.to('km/s').value
Expand Down Expand Up @@ -98,6 +99,28 @@ def from_components(cls, components, **kwargs):
# Return
return slf

@classmethod
def from_systems(cls,systems, **kwargs):
""" Instantiate from a list of AbsSystem objects
Parameters
----------
systems : list
list of AbsComponent objects
"""
if not isinstance(systems, list):
raise IOError("Need a list of AbsSystem objects")
if not isinstance(systems[0], AbsSystem):
raise IOError('Need an AbsSystem object')

# Instantiate with coordinates of first system
slf = cls(systems[0].coord)
slf._abssystems = systems
# Return
return slf


def __init__(self, radec, sl_type=None, em_type=None, comment=None, name=None, **kwargs):
""" Initiator
Expand Down
16 changes: 16 additions & 0 deletions linetools/isgm/tests/test_init_abssightline.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,29 @@
from astropy.coordinates import SkyCoord

from linetools.isgm.abssightline import GenericAbsSightline
from linetools.isgm.abssystem import GenericAbsSystem
from .utils import lyman_comp, si2_comp


def data_path(filename):
data_dir = os.path.join(os.path.dirname(__file__), 'files')
return os.path.join(data_dir, filename)

def test_from_systems():
radec = SkyCoord(ra=123.1143*u.deg, dec=-12.4321*u.deg)
# HI
lyacomp1 = lyman_comp(radec, z=0.45)
lyacomp2 = lyman_comp(radec, z=0.25)
# SiII
SiII_comp1 = si2_comp(radec, z=0.45)
SiII_comp2 = si2_comp(radec, z=0.25)
# Instantiate systems
sys1 = GenericAbsSystem.from_components([lyacomp1,SiII_comp1])
sys2 = GenericAbsSystem.from_components([lyacomp2, SiII_comp2])
# Instantiate sightline
sl = GenericAbsSightline.from_systems([sys1,sys2])
# Test
assert len(sl._abssystems) == 2

def test_from_components():
radec = SkyCoord(ra=123.1143*u.deg, dec=-12.4321*u.deg)
Expand Down
Loading

0 comments on commit 9ffb8f6

Please sign in to comment.