Skip to content

Commit

Permalink
Merge e772bf5 into 3363791
Browse files Browse the repository at this point in the history
  • Loading branch information
ntejos committed Dec 13, 2017
2 parents 3363791 + e772bf5 commit eadc2db
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
23 changes: 23 additions & 0 deletions linetools/spectra/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Module to run tests on spectra.utils

from __future__ import print_function, absolute_import, \
division, unicode_literals

import pytest
from astropy.time import Time

from linetools.spectra import utils as lsu


def test_get_COS_LP_from_date():
dates_good = ["2009-12-11", "2012-12-12", "2014-06-06",
"2017-12-12", Time("2017-12-12")]
dates_bad =["2008-10-10", "2012-07-23","2014-02-09", "2017-10-02", 1, None]

for date in dates_good:
lsu.get_COS_LP_from_date(date)

for date in dates_bad:
with pytest.raises(ValueError):
lsu.get_COS_LP_from_date(date)

45 changes: 45 additions & 0 deletions linetools/spectra/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,3 +448,48 @@ def smash_spectra(spec, method='average', debug=False):
# Return
return new_spec

def get_COS_LP_from_date(date):
"""Given a date, it returns the corresponding
HST/COS Life-time Position (LP)
Parameters
----------
date : string or astropy.time.Time() object
Examples:
"1983-10-09"
Returns
-------
LP : string
Either `LP1`, `LP2`, `LP3`, `LP4`
"""
from astropy.time import Time
if isinstance(date, (basestring, str)):
time = Time(date)
elif isinstance(date, Time):
time = date
else:
raise ValueError("Wrong format for date, must be either string of astropy.time.Time() object.")

# LP changes
LP1_LP2 = Time("2012-07-23")
LP2_LP3 = Time("2014-02-09")
LP3_LP4 = Time("2017-10-02")

if time < Time("2009-08-01"):
raise ValueError("Date is before HST/COS launch year.")
elif (time < LP1_LP2):
return "LP1"
elif (time == LP1_LP2):
raise ValueError("Date equal to change from LP1 to LP2, LP uncertain. You better check your database.")
elif (time < LP2_LP3):
return "LP2"
elif (time == LP2_LP3):
raise ValueError("Date equal to change from LP2 to LP3, LP uncertain. You better check your database.")
elif (time < LP3_LP4):
return "LP3"
elif (time == LP3_LP4):
raise ValueError("Date equal to change from LP3 to LP4, LP uncertain. You better check your database.")
else:
return "LP4"

0 comments on commit eadc2db

Please sign in to comment.