Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a unit test for dyn bgd hotpix imposter calc #418

Merged
merged 7 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)
9 changes: 9 additions & 0 deletions starcheck/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions starcheck/pcad_att_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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):
Expand Down
Empty file added starcheck/tests/__init__.py
Empty file.
68 changes: 68 additions & 0 deletions starcheck/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
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
)

# 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

# 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 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"]
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"]

1 change: 1 addition & 0 deletions starcheck/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down