#! /usr/bin/env python
"""Tests for the ``bias_monitor`` module.
Authors
-------
- Ben Sunnquist
Use
---
These tests can be run via the command line (omit the ``-s`` to
suppress verbose output to stdout):
::
pytest -s test_bias_monitor.py
"""
import os
import pytest
import shutil
from astropy.io import fits
import numpy as np
from jwql.database.database_interface import NIRCamBiasQueryHistory, NIRCamBiasStats
from jwql.instrument_monitors.common_monitors import bias_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_collapse_image():
"""Test that the image is collapsed correctly along its axes"""
monitor = bias_monitor.Bias()
# Create test data and its corresponding collapsed arrays
image = np.arange(100).reshape(10, 10)
collapsed_rows_truth = np.arange(4.5, 95, 10)
collapsed_columns_truth = np.arange(45, 55)
# Find the collapsed arrays using the bias monitor
collapsed_rows, collapsed_columns = monitor.collapse_image(image)
assert np.all(collapsed_rows == collapsed_rows_truth)
assert np.all(collapsed_columns == collapsed_columns_truth)
[docs]def test_identify_tables():
"""Be sure the correct database tables are identified"""
monitor = bias_monitor.Bias()
monitor.instrument = 'nircam'
monitor.identify_tables()
assert monitor.query_table == eval('NIRCamBiasQueryHistory')
assert monitor.stats_table == eval('NIRCamBiasStats')
[docs]def test_make_histogram():
"""Test histogram creation"""
monitor = bias_monitor.Bias()
# Create test data and its corresponding histogram stats
data = np.zeros((100, 100))
counts_truth = [10000]
bin_centers_truth = [0.0]
# Find the histogram stats of the test data using the bias monitor
counts, bin_centers = monitor.make_histogram(data)
counts, bin_centers = list(counts), list(bin_centers)
assert counts == counts_truth
assert bin_centers == bin_centers_truth