Skip to content

Commit

Permalink
ready for review
Browse files Browse the repository at this point in the history
  • Loading branch information
profxj committed Jul 31, 2016
1 parent 8299207 commit 91bc493
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 35 deletions.
64 changes: 33 additions & 31 deletions linetools/analysis/linelimits.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class LineLimits(object):
Structured array containing all of the data
This can be a set of 1D spectra
meta : `dict`-like object, optional
_data : `dict`-like object, optional
Metadata for this object. "Metadata" here means all information that
is included with this object but not part of any other attribute
of this particular object. e.g., creation date, unique identifier,
Expand All @@ -35,22 +35,6 @@ class LineLimits(object):
wvlim : Quantity
vlim : Quantity
"""

@classmethod
def from_file(cls, ifile, **kwargs):
""" From file
Parameters
----------
ifile : str
Filename
"""
# put import here to avoid circular import with io.py
#from .io import readspec
from linetools.spectra import io as tio
slf = tio.readspec(ifile, **kwargs)
return slf

def __init__(self, wrest, z, zlim):
"""
Parameters
Expand All @@ -68,24 +52,40 @@ def __init__(self, wrest, z, zlim):
raise IOError("Input zlim must be a tuple or list")
if not isinstance(wrest, Quantity):
raise IOError("Input wrest must be a quantity")
# Data
self._data = {}
# Set
self.z = z
self.zlim = zlim
self.wrest = wrest
# Dict (for updating and pointing to)
self.data = {}
self.reset() # Sets dict values
self._z = z
self._wrest = wrest
self.set(zlim)

@property
def zlim(self):
""" Return zlim
"""
return self._data['zlim']

@property
def wvlim(self):
""" Return wvlim
"""
return self._data['wvlim']

@property
def vlim(self):
""" Return vlim
"""
return self._data['vlim']

def reset(self):
""" Update all the values
"""
self.data['zlim'] = self.zlim
self.data['wvlim'] = self.wrest*(1+np.array(self.zlim))
self.data['vlim'] = ckms*((self.data['wvlim']-self.wrest*(1+self.z))/(
self.wrest*(1+self.z))).decompose()
pdb.set_trace()
self._data['zlim'] = self.zlim
self._data['wvlim'] = self._wrest*(1+np.array(self.zlim))
self._data['vlim'] = ckms*((self._data['wvlim']-self._wrest*(1+self._z))/(
self._wrest*(1+self._z))).decompose()

def __eq__(self, inp, itype='zlim'):
def set(self, inp, itype='zlim'):
""" Over-ride = to re-init values
Parameters
Expand All @@ -104,10 +104,12 @@ def __eq__(self, inp, itype='zlim'):
if not isinstance(inp, (tuple, list, Quantity)):
raise IOError("Input must be tuple, list or Quantity")
if itype == 'zlim':
self.zlim = inp
self._data['zlim'] = inp
else:
raise IOError("Input type must be zlim, vlim, or wvlim")
#
# Reset
self.reset()

def __repr__(self):
txt = '<{:s}'.format(self.__class__.__name__)
# wrest
Expand Down
15 changes: 11 additions & 4 deletions linetools/analysis/tests/test_linelimits.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@
from linetools.analysis.linelimits import LineLimits

def test_init():
# Make fake spectrum
# Init
llim = LineLimits(1215.67*u.AA, 1., (0.999, 1.001))
# Test
#np.testing.assert_allclose((N.value, sig_N.value),
# (96652191688169.72, 194151305045168.12))
#assert N.unit == u.cm**-2
with pytest.raises(AttributeError):
llim.zlim=3

def test_use():
# Init
llim = LineLimits(1215.67*u.AA, 1., (0.999, 1.001))
# Use
np.testing.assert_allclose(llim.zlim, (0.999, 1.001))
np.testing.assert_allclose(llim.wvlim.value, [2430.12433, 2432.55567])
np.testing.assert_allclose(llim.vlim.value, [-149.896229, 149.896229])
assert llim.vlim.unit == u.km/u.s
3 changes: 3 additions & 0 deletions linetools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
except NameError: # For Python 3
basestring = str


def between(a, vmin, vmax):
""" Return a boolean array True where vmin <= a < vmax.
Expand All @@ -42,6 +43,7 @@ def between(a, vmin, vmax):
c &= a >= vmin
return c


def convert_quantity_in_dict(idict):
""" Return a dict where Quantities (usually from a JSON file)
have been converted from unit/value
Expand Down Expand Up @@ -122,6 +124,7 @@ def radec_to_coord(radec):
# Return
return coord


def scipy_rebin(a, *args):
""" Simple script to rebin an input array to a new shape.
Expand Down

0 comments on commit 91bc493

Please sign in to comment.