From 8aa91d0e257a1842f5e28995c6d48ebc2757f40f Mon Sep 17 00:00:00 2001 From: Nicolas Tejos Date: Wed, 13 Dec 2017 16:01:50 -0300 Subject: [PATCH 1/3] Added utility function to get HST/COS Life- and test. --- linetools/spectra/tests/test_utils.py | 23 ++++++++++++++ linetools/spectra/utils.py | 45 +++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 linetools/spectra/tests/test_utils.py diff --git a/linetools/spectra/tests/test_utils.py b/linetools/spectra/tests/test_utils.py new file mode 100644 index 00000000..020ac36f --- /dev/null +++ b/linetools/spectra/tests/test_utils.py @@ -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"] + + 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) + diff --git a/linetools/spectra/utils.py b/linetools/spectra/utils.py index fc4daf22..3cee1bc9 100644 --- a/linetools/spectra/utils.py +++ b/linetools/spectra/utils.py @@ -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-06-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" From a19fa6d5c0524cf6009ddd50a66215c44477d757 Mon Sep 17 00:00:00 2001 From: Nicolas Tejos Date: Wed, 13 Dec 2017 16:52:18 -0300 Subject: [PATCH 2/3] Added utility function to get HST/COS Life- and test. --- linetools/spectra/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linetools/spectra/utils.py b/linetools/spectra/utils.py index 3cee1bc9..7a07bb3a 100644 --- a/linetools/spectra/utils.py +++ b/linetools/spectra/utils.py @@ -477,7 +477,7 @@ def get_COS_LP_from_date(date): LP2_LP3 = Time("2014-02-09") LP3_LP4 = Time("2017-10-02") - if time < Time("2009-06-01"): + if time < Time("2009-08-01"): raise ValueError("Date is before HST/COS launch year.") elif (time < LP1_LP2): return "LP1" From e772bf5d783f7cb8a9c4692a0a5d6455ead6dc21 Mon Sep 17 00:00:00 2001 From: Nicolas Tejos Date: Wed, 13 Dec 2017 18:23:46 -0300 Subject: [PATCH 3/3] more bad dates --- linetools/spectra/tests/test_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linetools/spectra/tests/test_utils.py b/linetools/spectra/tests/test_utils.py index 020ac36f..eb158c51 100644 --- a/linetools/spectra/tests/test_utils.py +++ b/linetools/spectra/tests/test_utils.py @@ -12,7 +12,7 @@ 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"] + 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)