#! /usr/bin/env python
"""Tests for the ``dark_monitor`` module.
Authors
-------
- Bryan Hilbert
Use
---
These tests can be run via the command line (omit the ``-s`` to
suppress verbose output to stdout):
::
pytest -s test_dark_monitor.py
"""
import os
import pytest
from astropy.time import Time
import numpy as np
from jwql.instrument_monitors.common_monitors import dark_monitor
from jwql.utils.utils import get_config
ON_GITHUB_ACTIONS = '/home/runner' in os.path.expanduser('~') or '/Users/runner' in os.path.expanduser('~')
[docs]def test_find_hot_dead_pixels():
"""Test hot and dead pixel searches"""
monitor = dark_monitor.Dark()
# Create "baseline" image
comparison_image = np.zeros((10, 10)) + 1.
# Create mean slope image to compare
mean_image = np.zeros((10, 10)) + 1.
mean_image[0, 0] = 1.7
mean_image[1, 1] = 2.2
mean_image[7, 7] = 4.5
mean_image[5, 5] = 0.12
mean_image[6, 6] = 0.06
mean_image[7, 3] = 0.09
hot, dead = monitor.find_hot_dead_pixels(mean_image, comparison_image, hot_threshold=2., dead_threshold=0.1)
assert len(hot) == 2
assert np.all(hot[0] == np.array([1, 7]))
assert np.all(hot[1] == np.array([1, 7]))
assert len(dead) == 2
assert np.all(dead[0] == np.array([6, 7]))
assert np.all(dead[1] == np.array([6, 3]))
[docs]def test_mast_query_darks():
"""Test that the MAST query for darks is functional"""
instrument = 'NIRCAM'
aperture = 'NRCA1_FULL'
readpatt = 'BRIGHT2'
start_date = Time("2016-01-01T00:00:00").mjd
end_date = Time("2018-01-01T00:00:00").mjd
query = dark_monitor.mast_query_darks(instrument, aperture, readpatt, start_date, end_date)
apernames = [entry['apername'] for entry in query]
filenames = [entry['filename'] for entry in query]
truth_filenames = ['jw82600013001_02103_00003_nrca1_dark.fits',
'jw82600013001_02103_00001_nrca1_dark.fits',
'jw82600013001_02103_00002_nrca1_dark.fits',
'jw82600016001_02103_00002_nrca1_dark.fits',
'jw82600016001_02103_00001_nrca1_dark.fits',
'jw82600016001_02103_00004_nrca1_dark.fits',
'jw82600016001_02103_00003_nrca1_dark.fits']
assert len(query) >= 7
for truth_filename in truth_filenames:
assert truth_filename in filenames
[docs]def test_noise_check():
"""Test the search for noisier than average pixels"""
noise_image = np.zeros((10, 10)) + 0.5
baseline = np.zeros((10, 10)) + 0.5
noise_image[3, 3] = 0.8
noise_image[6, 6] = 0.6
noise_image[9, 9] = 1.0
baseline[5, 5] = 1.0
noise_image[5, 5] = 1.25
monitor = dark_monitor.Dark()
noisy = monitor.noise_check(noise_image, baseline, threshold=1.5)
assert len(noisy[0]) == 2
assert np.all(noisy[0] == np.array([3, 9]))
assert np.all(noisy[1] == np.array([3, 9]))
[docs]def test_shift_to_full_frame():
"""Test pixel coordinate shifting to be in full frame coords"""
monitor = dark_monitor.Dark()
monitor.x0 = 512
monitor.y0 = 512
coordinates = (np.array([6, 7]), np.array([6, 3]))
new_coords = monitor.shift_to_full_frame(coordinates)
assert np.all(new_coords[0] == np.array([518, 519]))
assert np.all(new_coords[1] == np.array([518, 515]))