From 6a7fdbdf99b3a37870880f7a65e173ea19453576 Mon Sep 17 00:00:00 2001 From: Jean Connelly Date: Mon, 10 Jul 2023 14:49:31 -0400 Subject: [PATCH 1/7] Add date of dark cal to debug imposter dict --- starcheck/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/starcheck/utils.py b/starcheck/utils.py index d9b5dd72..55bdf022 100644 --- a/starcheck/utils.py +++ b/starcheck/utils.py @@ -386,6 +386,7 @@ def imposter_offset(cand_mag, imposter_mag): "bad2_mag": float(imp_mags[0]), "offset": float(offset), "t_ccd": float(t_ccd), + "dark_date": dark_props["date"], } ) except Exception: From 82750bd3859e8a37fb89c825ff58241219b67890 Mon Sep 17 00:00:00 2001 From: Jean Connelly Date: Mon, 10 Jul 2023 14:50:09 -0400 Subject: [PATCH 2/7] Add a unit test for the dyn bgd hot pixel imposter calc --- setup.py | 20 +++++----- starcheck/__init__.py | 9 +++++ starcheck/tests/__init__.py | 0 starcheck/tests/test_utils.py | 70 +++++++++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 9 deletions(-) create mode 100644 starcheck/tests/__init__.py create mode 100644 starcheck/tests/test_utils.py diff --git a/setup.py b/setup.py index 81aaf7e7..a6da1bd1 100644 --- a/setup.py +++ b/setup.py @@ -2,12 +2,14 @@ from setuptools import setup -setup(name='starcheck', - use_scm_version=True, - setup_requires=['setuptools_scm', 'setuptools_scm_git_archive'], - author='Jean Connelly', - author_email='jconnelly@cfa.harvard.edu', - packages=['starcheck'], - include_package_data=True, - scripts=['starcheck/src/starcheck'], - ) +setup( + name="starcheck", + use_scm_version=True, + setup_requires=["setuptools_scm", "setuptools_scm_git_archive"], + author="Jean Connelly", + author_email="jconnelly@cfa.harvard.edu", + packages=["starcheck", "starcheck.tests"], + test_requires=["pytest"], + include_package_data=True, + scripts=["starcheck/src/starcheck"], +) diff --git a/starcheck/__init__.py b/starcheck/__init__.py index a5bd990f..c2481e71 100644 --- a/starcheck/__init__.py +++ b/starcheck/__init__.py @@ -3,3 +3,12 @@ import ska_helpers __version__ = ska_helpers.get_version(__package__) + + +def test(*args, **kwargs): + """ + Run py.test unit tests. + """ + import testr + + return testr.test(*args, **kwargs) diff --git a/starcheck/tests/__init__.py b/starcheck/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/starcheck/tests/test_utils.py b/starcheck/tests/test_utils.py new file mode 100644 index 00000000..3febc06e --- /dev/null +++ b/starcheck/tests/test_utils.py @@ -0,0 +1,70 @@ +from starcheck.utils import check_hot_pix + + +def test_check_dynamic_hot_pix(): + # Parameters of obsid 25274 from JUL0323A + idxs = [1, 2, 3, 4, 5, 6, 7, 8] + yags = [ + -773.135672595873, + 2140.37683262341, + -1826.2356726102, + -1380.0856717436, + -713.835673125859, + -1322.09192254126, + -2185.44191819395, + 101.314326039055, + ] + zags = [ + -1741.99192158156, + 166.726825875404, + 160.264325897248, + -2469.16691506774, + -436.641923465157, + -1728.21692250903, + -1033.99192330043, + 1259.22057376853, + ] + mags = [7, 7, 7, 8.217, 9.052, 9.75, 10.407, 10.503] + types = ["FID", "FID", "FID", "BOT", "BOT", "BOT", "BOT", "BOT"] + t_ccd = -11.2132562902057 + dither_y = 7.9989482672109 + dither_z = 7.9989482672109 + + # Use a date before the PEA patch uplink + date = "2023:138" + + imposters1 = check_hot_pix( + idxs, yags, zags, mags, types, t_ccd, date, dither_y, dither_z + ) + # There is no bonus or penalty applied so the temperatures should all be the same as the + # input t_ccd + for imposter in imposters1: + assert imposter["status"] == 0 + assert imposter["t_ccd"] == t_ccd + + # Use a date after the PEA patch uplink + date = "2023:140" + imposters2 = check_hot_pix( + idxs, yags, zags, mags, types, t_ccd, date, dither_y, dither_z + ) + + # These stars are in mag-sorted order so the bonus should be applied to the last two + # Stars with idx 7 and 8 should have bonus-applied t_ccd + dyn_bgd_dt_ccd = 4.0 + for imposter in imposters2: + assert imposter["status"] == 0 + if imposter["idx"] < 7: + assert imposter["t_ccd"] == t_ccd + else: + assert imposter["t_ccd"] == t_ccd - dyn_bgd_dt_ccd + + # The imposters should be the same except for t_ccd, offset, mag + # as these dates were selected to have matching dark cal files + for imposter1, imposter2 in zip(imposters1, imposters2): + assert imposter["dark_date"] == imposter2["dark_date"] + assert imposter1["idx"] == imposter2["idx"] + assert imposter1["bad2_row"] == imposter2["bad2_row"] + assert imposter1["bad2_col"] == imposter2["bad2_col"] + assert imposter1["bad2_mag"] <= imposter2["bad2_mag"] + assert imposter1["status"] == imposter2["status"] + assert imposter1["offset"] >= imposter2["offset"] From 8a1c97df5c4361c8356c628477eedebbdb92d225 Mon Sep 17 00:00:00 2001 From: Jean Connelly Date: Tue, 11 Jul 2023 07:46:04 -0400 Subject: [PATCH 3/7] Fix typo on comparison of dark_date in test Co-authored-by: Tom Aldcroft --- starcheck/tests/test_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/starcheck/tests/test_utils.py b/starcheck/tests/test_utils.py index 3febc06e..07223ade 100644 --- a/starcheck/tests/test_utils.py +++ b/starcheck/tests/test_utils.py @@ -61,7 +61,7 @@ def test_check_dynamic_hot_pix(): # The imposters should be the same except for t_ccd, offset, mag # as these dates were selected to have matching dark cal files for imposter1, imposter2 in zip(imposters1, imposters2): - assert imposter["dark_date"] == imposter2["dark_date"] + assert imposter1["dark_date"] == imposter2["dark_date"] assert imposter1["idx"] == imposter2["idx"] assert imposter1["bad2_row"] == imposter2["bad2_row"] assert imposter1["bad2_col"] == imposter2["bad2_col"] From 0274bd397f6c1d2cb848d76577db843f64b5d2ec Mon Sep 17 00:00:00 2001 From: Jean Connelly Date: Tue, 11 Jul 2023 07:48:45 -0400 Subject: [PATCH 4/7] Move more testing into the loop comparison Co-authored-by: Tom Aldcroft --- starcheck/tests/test_utils.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/starcheck/tests/test_utils.py b/starcheck/tests/test_utils.py index 07223ade..0672d1e1 100644 --- a/starcheck/tests/test_utils.py +++ b/starcheck/tests/test_utils.py @@ -65,6 +65,15 @@ def test_check_dynamic_hot_pix(): assert imposter1["idx"] == imposter2["idx"] assert imposter1["bad2_row"] == imposter2["bad2_row"] assert imposter1["bad2_col"] == imposter2["bad2_col"] - assert imposter1["bad2_mag"] <= imposter2["bad2_mag"] - assert imposter1["status"] == imposter2["status"] - assert imposter1["offset"] >= imposter2["offset"] + assert imposter1["t_ccd"] == t_ccd + assert imposter1["status"] == 0 + assert imposter2["status"] == 0 + if imposter1["idx"] < 7: + assert imposter2["t_ccd"] == imposter1["t_ccd"] + assert imposter1["bad2_mag"] == imposter2["bad2_mag"] + assert imposter1["offset"] == imposter2["offset"] + else: + assert imposter2["t_ccd"] == imposter1["t_ccd"] - dyn_bgd_dt_ccd + assert imposter1["bad2_mag"] < imposter2["bad2_mag"] + assert imposter1["offset"] > imposter2["offset"] + From 7213d24274c06c358d08f826c360f70953c47ba0 Mon Sep 17 00:00:00 2001 From: Jean Connelly Date: Tue, 11 Jul 2023 07:49:28 -0400 Subject: [PATCH 5/7] Cut comparisons done elsewhere Co-authored-by: Tom Aldcroft --- starcheck/tests/test_utils.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/starcheck/tests/test_utils.py b/starcheck/tests/test_utils.py index 0672d1e1..4d306ca3 100644 --- a/starcheck/tests/test_utils.py +++ b/starcheck/tests/test_utils.py @@ -36,11 +36,6 @@ def test_check_dynamic_hot_pix(): imposters1 = check_hot_pix( idxs, yags, zags, mags, types, t_ccd, date, dither_y, dither_z ) - # There is no bonus or penalty applied so the temperatures should all be the same as the - # input t_ccd - for imposter in imposters1: - assert imposter["status"] == 0 - assert imposter["t_ccd"] == t_ccd # Use a date after the PEA patch uplink date = "2023:140" From 21e00d8921b516fa23000dbbfe9a5d24b1d3c672 Mon Sep 17 00:00:00 2001 From: Jean Connelly Date: Tue, 11 Jul 2023 07:49:54 -0400 Subject: [PATCH 6/7] Cut comparison done in the main loop Co-authored-by: Tom Aldcroft --- starcheck/tests/test_utils.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/starcheck/tests/test_utils.py b/starcheck/tests/test_utils.py index 4d306ca3..719c1652 100644 --- a/starcheck/tests/test_utils.py +++ b/starcheck/tests/test_utils.py @@ -46,12 +46,6 @@ def test_check_dynamic_hot_pix(): # These stars are in mag-sorted order so the bonus should be applied to the last two # Stars with idx 7 and 8 should have bonus-applied t_ccd dyn_bgd_dt_ccd = 4.0 - for imposter in imposters2: - assert imposter["status"] == 0 - if imposter["idx"] < 7: - assert imposter["t_ccd"] == t_ccd - else: - assert imposter["t_ccd"] == t_ccd - dyn_bgd_dt_ccd # The imposters should be the same except for t_ccd, offset, mag # as these dates were selected to have matching dark cal files From 0ec8d7df8395a42d0804279b1832cdf1c513f00f Mon Sep 17 00:00:00 2001 From: Jean Connelly Date: Tue, 11 Jul 2023 11:03:23 -0400 Subject: [PATCH 7/7] Update regex to have 'r' --- starcheck/pcad_att_check.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/starcheck/pcad_att_check.py b/starcheck/pcad_att_check.py index 75b1dfbb..f438897a 100755 --- a/starcheck/pcad_att_check.py +++ b/starcheck/pcad_att_check.py @@ -48,7 +48,7 @@ def recent_sim_history(time, file): parsing and the int cast of the parsed data. """ for line in reversed(open(file).readlines()): - match = re.match('^(\d+\.\d+)\s+\|\s+(\S+)\s*$', + match = re.match(r'^(\d+\.\d+)\s+\|\s+(\S+)\s*$', line) if match: greta_time, value = match.groups() @@ -64,7 +64,7 @@ def recent_attitude_history(time, file): parsing. """ for line in reversed(open(file).readlines()): - match = re.match('^(\d+\.\d+)\s+\|\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s*', line) + match = re.match(r'^(\d+\.\d+)\s+\|\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s*', line) if match: greta_time, q1, q2, q3, q4 = match.groups() if (DateTime(greta_time, format='greta').secs < time):