Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
86a6e93
changing astropy FITSDiff for STFITSDiff
penaguerrero Apr 28, 2025
30378f6
Merge branch 'main' into jp3908
penaguerrero Apr 29, 2025
5a78952
Merge branch 'main' into jp3908
penaguerrero Apr 29, 2025
8eccde4
Merge branch 'main' into jp3908
penaguerrero Apr 30, 2025
5357784
Implementing STFITSDiff for our regression tests instead of FITSDiff …
penaguerrero Apr 30, 2025
b2d071d
Delete changes/9414.regression_testing.rst
penaguerrero Apr 30, 2025
da2aebc
Implementing STFITSDiff for our regression tests instead of FITSDiff …
penaguerrero Apr 30, 2025
b02fcee
Delete changes/9414.regtest.rst
penaguerrero Apr 30, 2025
0a1b546
Implementing STFITSDiff for our regression tests instead of FITSDiff …
penaguerrero Apr 30, 2025
29ee927
Merge branch 'main' into jp3908
penaguerrero Apr 30, 2025
22c26e0
Merge branch 'main' into jp3908
penaguerrero May 1, 2025
1104e62
Merge branch 'main' into jp3908
penaguerrero May 1, 2025
eb19846
Merge branch 'main' into jp3908
penaguerrero May 5, 2025
c6aa62d
Merge branch 'main' into jp3908
melanieclarke May 5, 2025
4ce7315
Merge branch 'main' into jp3908
penaguerrero May 5, 2025
22eeb5a
Merge branch 'main' into jp3908
penaguerrero May 6, 2025
7064754
fixing func isnan not supported for the input types
penaguerrero May 6, 2025
b0660ee
fixing func isnan not supported for the input types
penaguerrero May 7, 2025
7b14ed3
Merge branch 'main' into jp3908
penaguerrero May 8, 2025
09a8044
new attempt at fixing func isnan not supported for the input types
penaguerrero May 8, 2025
4e3e5eb
Merge branch 'main' into jp3908
melanieclarke May 8, 2025
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
1 change: 1 addition & 0 deletions changes/9414.general.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implementing STFITSDiff for our regression tests instead of FITSDiff to improve reports.
2 changes: 1 addition & 1 deletion jwst/regtest/regtestdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import sys

import asdf
from astropy.io.fits.diff import FITSDiff
from jwst.regtest.st_fitsdiff import STFITSDiff as FITSDiff
from ci_watson.artifactory_helpers import (
check_url,
get_bigdata_root,
Expand Down
161 changes: 111 additions & 50 deletions jwst/regtest/st_fitsdiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,7 @@ def __init__(
self.report_table = Table(
names=(
"col_name",
"dtype",
"abs_diffs",
"abs_max",
"abs_mean",
Expand All @@ -1212,12 +1213,13 @@ def __init__(
"rel_std",
),
dtype=(
"str",
"str",
"int32",
"float64",
"float64",
"float64",
"int32",
"float64",
"float64",
"float64",
"float64",
Expand Down Expand Up @@ -1404,49 +1406,102 @@ def _diff(self):
# it is not important where they come from

# Calculate the absolute and relative differences
nan_idx = np.isnan(arra) | np.isnan(arrb)
anonan = arra[~nan_idx]
bnonan = arrb[~nan_idx]
diffs = np.abs(anonan - bnonan)
abs_diffs = diffs[diffs > self.atol].size
nozeros = (diffs != 0.0) & (bnonan != 0.0)
rel_values = diffs[nozeros] / np.abs(bnonan[nozeros])
rel_diffs = rel_values[rel_values > self.rtol].size

sum_diffs = np.any(diffs > (self.atol + self.rtol * np.abs(bnonan)))
if sum_diffs:
# Report the total number of zeros, nans, and no-nan values
self.report_zeros_nan.add_row(
(
col.name,
arra[arra == 0.0].size,
arrb[arrb == 0.0].size,
arra[np.isnan(arra)].size,
arrb[np.isnan(arrb)].size,
arra[~np.isnan(arra)].size,
arrb[~np.isnan(arrb)].size,
np.mean(anonan),
np.mean(bnonan),
get_stats = False
if np.issubdtype(arra.dtype, np.floating) and np.issubdtype(
arrb.dtype, np.floating
):
nan_idx = np.isnan(arra) | np.isnan(arrb)
anonan = arra[~nan_idx]
bnonan = arrb[~nan_idx]
diffs = np.abs(anonan - bnonan)
abs_diffs = diffs[diffs > self.atol].size
nozeros = (diffs != 0.0) & (bnonan != 0.0)
rel_values = diffs[nozeros] / np.abs(bnonan[nozeros])
rel_diffs = rel_values[rel_values > self.rtol].size
get_stats = True

elif "P" in col.format or "Q" in col.format:
diffs = []
rel_values = []
zeros_idx = []
nan_idx = []
for idx in range(len(arra)):
if arra[idx] == 0 or arrb[idx] == 0:
zeros_idx.append(idx)
elif np.isnan(arra[idx]) or np.isnan(arrb[idx]):
nan_idx.append(idx)
else:
df = np.abs(arra[idx] - arrb[idx])
if not df <= self.atol:
diffs.append(df)
dfr = df / np.abs(arrb[idx])
if not dfr <= self.rtol:
rel_values.append(dfr)
get_stats = True
diffs = np.array(diffs)
abs_diffs = diffs.size
rel_values = np.array(rel_values)
rel_diffs = rel_values.size
anonan = arra[~np.array(nan_idx)]
bnonan = arrb[~np.array(nan_idx)]

if get_stats:
sum_diffs = np.any(diffs > (self.atol + self.rtol * np.abs(bnonan)))
if sum_diffs:
# Report the total number of zeros, nans, and no-nan values
self.report_zeros_nan.add_row(
(
col.name,
arra[arra == 0.0].size,
arrb[arrb == 0.0].size,
arra[np.isnan(arra)].size,
arrb[np.isnan(arrb)].size,
arra[~np.isnan(arra)].size,
arrb[~np.isnan(arrb)].size,
np.mean(anonan),
np.mean(bnonan),
)
)
)

# Report the differences per column
self.report_table.add_row(
(
col.name,
abs_diffs,
np.max(diffs),
np.mean(diffs),
np.std(diffs),
rel_diffs,
np.max(rel_values),
np.mean(rel_values),
np.std(rel_values),
# Report the differences per column
self.report_table.add_row(
(
col.name,
str(arra.dtype).replace(">", ""),
abs_diffs,
np.max(diffs),
np.mean(diffs),
np.std(diffs),
rel_diffs,
np.max(rel_values),
np.mean(rel_values),
np.std(rel_values),
)
)
)

self.diff_total += abs_diffs
self.rel_diffs += rel_diffs
self.diff_total += abs_diffs
self.rel_diffs += rel_diffs

else:
diffs = arra[arra != arrb].size
if diffs > 0:
# Report the differences per column
self.report_table.add_row(
(
col.name,
str(arra.dtype).replace(">", ""),
diffs,
0,
0,
0,
0,
0,
0,
0,
)
)
self.diff_total += diffs
self.rel_diffs = np.nan

# Calculate the absolute difference
total_values = len(self.a) * len(self.a.dtype.fields)
Expand Down Expand Up @@ -1537,23 +1592,29 @@ def _report(self):
f"Found {self.diff_total} different table data element(s). "
"Reporting percentages above respective tolerances: "
f"\n - absolute .... {self.diff_ratio:.4g}%"
f"\n - relative .... {self.diff_ratio_rel:.4g}%"
)
if np.isnan(self.diff_ratio_rel):
self._writeln(
"\n * Unable to calculate relative differences and stats due to data types"
)
else:
self._writeln(f" - relative .... {self.diff_ratio_rel:.4g}%")

# Print differences in zeros and nans per column
self._writeln("\nValues in a and b")
self.report_zeros_nan["mean_a"].format = ".4g"
self.report_zeros_nan["mean_b"].format = ".4g"
tlines = self.report_zeros_nan.pformat()
for tline in tlines:
self._writeln(tline)
# Print differences in zeros and nans per column
self._writeln("\nValues in a and b")
self.report_zeros_nan["mean_a"].format = ".4g"
self.report_zeros_nan["mean_b"].format = ".4g"
tlines = self.report_zeros_nan.pformat()
for tline in tlines:
self._writeln(tline)

# Print the difference (a-b) stats
self._writeln("\nDifference stats: abs(a - b) ")
# make sure the format is acceptable
for colname in self.report_table.columns:
if colname != "col_name":
self.report_table[colname].format = ".4g"
if colname in ["col_name", "dtype"]:
continue
self.report_table[colname].format = ".4g"
tlines = self.report_table.pformat()
for tline in tlines:
self._writeln(tline)
2 changes: 1 addition & 1 deletion jwst/regtest/test_fgs_image2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from astropy.io.fits.diff import FITSDiff
from jwst.regtest.st_fitsdiff import STFITSDiff as FITSDiff

from jwst.stpipe import Step

Expand Down
2 changes: 1 addition & 1 deletion jwst/regtest/test_fgs_image3.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from astropy.io.fits.diff import FITSDiff
from jwst.regtest.st_fitsdiff import STFITSDiff as FITSDiff

from jwst.stpipe import Step

Expand Down
2 changes: 1 addition & 1 deletion jwst/regtest/test_miri_coron3.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from astropy.io.fits.diff import FITSDiff
from jwst.regtest.st_fitsdiff import STFITSDiff as FITSDiff

from jwst.stpipe import Step

Expand Down
2 changes: 1 addition & 1 deletion jwst/regtest/test_miri_cubebuild.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Test CubeBuildStep on MIRI MRS"""
import pytest
from astropy.io.fits.diff import FITSDiff
from jwst.regtest.st_fitsdiff import STFITSDiff as FITSDiff
from jwst.stpipe import Step


Expand Down
2 changes: 1 addition & 1 deletion jwst/regtest/test_miri_dark.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from astropy.io.fits.diff import FITSDiff
from jwst.regtest.st_fitsdiff import STFITSDiff as FITSDiff

from jwst.stpipe import Step

Expand Down
2 changes: 1 addition & 1 deletion jwst/regtest/test_miri_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import numpy as np
import pytest
from astropy.io.fits.diff import FITSDiff
from jwst.regtest.st_fitsdiff import STFITSDiff as FITSDiff
from numpy.testing import assert_allclose
from gwcs.wcstools import grid_from_bounding_box
from stdatamodels.jwst import datamodels
Expand Down
2 changes: 1 addition & 1 deletion jwst/regtest/test_miri_lrs_dedicated_mbkg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import pytest
from astropy.io.fits.diff import FITSDiff
from jwst.regtest.st_fitsdiff import STFITSDiff as FITSDiff

from jwst.master_background import MasterBackgroundStep

Expand Down
2 changes: 1 addition & 1 deletion jwst/regtest/test_miri_lrs_masterbg_user.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import pytest
from astropy.io.fits.diff import FITSDiff
from jwst.regtest.st_fitsdiff import STFITSDiff as FITSDiff

from jwst.master_background import MasterBackgroundStep

Expand Down
2 changes: 1 addition & 1 deletion jwst/regtest/test_miri_lrs_nod_masterbg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import pytest
from astropy.io.fits.diff import FITSDiff
from jwst.regtest.st_fitsdiff import STFITSDiff as FITSDiff

from jwst.stpipe import Step

Expand Down
2 changes: 1 addition & 1 deletion jwst/regtest/test_miri_lrs_optimal_extraction.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from astropy.io.fits.diff import FITSDiff
from jwst.regtest.st_fitsdiff import STFITSDiff as FITSDiff
import pytest

from jwst.stpipe import Step
Expand Down
2 changes: 1 addition & 1 deletion jwst/regtest/test_miri_lrs_slit_spec2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from astropy.io.fits.diff import FITSDiff
from jwst.regtest.st_fitsdiff import STFITSDiff as FITSDiff
from gwcs.wcstools import grid_from_bounding_box
from numpy.testing import assert_allclose
import pytest
Expand Down
2 changes: 1 addition & 1 deletion jwst/regtest/test_miri_lrs_slit_spec3.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from gwcs import wcstools
import asdf
from astropy.io.fits.diff import FITSDiff
from jwst.regtest.st_fitsdiff import STFITSDiff as FITSDiff

from jwst.stpipe import Step
from jwst import datamodels
Expand Down
2 changes: 1 addition & 1 deletion jwst/regtest/test_miri_lrs_slitless.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

import pytest
from astropy.io.fits.diff import FITSDiff
from jwst.regtest.st_fitsdiff import STFITSDiff as FITSDiff
from numpy.testing import assert_allclose
from gwcs.wcstools import grid_from_bounding_box
from stdatamodels.jwst import datamodels
Expand Down
2 changes: 1 addition & 1 deletion jwst/regtest/test_miri_mrs_badpix_selfcal.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

import pytest
from astropy.io.fits.diff import FITSDiff
from jwst.regtest.st_fitsdiff import STFITSDiff as FITSDiff

from jwst.stpipe import Step

Expand Down
2 changes: 1 addition & 1 deletion jwst/regtest/test_miri_mrs_dedicated_mbkg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import pytest
from astropy.io.fits.diff import FITSDiff
from jwst.regtest.st_fitsdiff import STFITSDiff as FITSDiff

from jwst.master_background import MasterBackgroundStep

Expand Down
2 changes: 1 addition & 1 deletion jwst/regtest/test_miri_mrs_extract1d.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Test Extract1dStep on MIRI data running the step various ways
"""
import pytest
from astropy.io.fits.diff import FITSDiff
from jwst.regtest.st_fitsdiff import STFITSDiff as FITSDiff

from jwst.stpipe import Step

Expand Down
2 changes: 1 addition & 1 deletion jwst/regtest/test_miri_mrs_spec3.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os

import pytest
from astropy.io.fits.diff import FITSDiff
from jwst.regtest.st_fitsdiff import STFITSDiff as FITSDiff

from jwst.stpipe import Step

Expand Down
2 changes: 1 addition & 1 deletion jwst/regtest/test_miri_mrs_spec3_moving_target.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Regression tests for Moving Target MIRI MRS mode"""
import os
import pytest
from astropy.io.fits.diff import FITSDiff
from jwst.regtest.st_fitsdiff import STFITSDiff as FITSDiff
from jwst.stpipe import Step

# Define artifactory source and truth
Expand Down
2 changes: 1 addition & 1 deletion jwst/regtest/test_miri_mrs_straylight.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Regression tests for MIRI MRS straylight step"""
import pytest

from astropy.io.fits.diff import FITSDiff
from jwst.regtest.st_fitsdiff import STFITSDiff as FITSDiff
from jwst.stpipe import Step

# Define artifactory source and truth file paths
Expand Down
2 changes: 1 addition & 1 deletion jwst/regtest/test_miri_mrs_tso.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Regression test for MIRI MRS TSO mode"""
import pytest
from astropy.io.fits.diff import FITSDiff
from jwst.regtest.st_fitsdiff import STFITSDiff as FITSDiff

from jwst.stpipe import Step

Expand Down
2 changes: 1 addition & 1 deletion jwst/regtest/test_miri_residual_fringe.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Test ResidualFringeStep on MIRI MRS"""
import pytest
from astropy.io.fits.diff import FITSDiff
from jwst.regtest.st_fitsdiff import STFITSDiff as FITSDiff

from jwst.stpipe import Step

Expand Down
2 changes: 1 addition & 1 deletion jwst/regtest/test_miri_setpointing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from astropy.io.fits.diff import FITSDiff
from jwst.regtest.st_fitsdiff import STFITSDiff as FITSDiff
from jwst.lib.set_telescope_pointing import add_wcs


Expand Down
2 changes: 1 addition & 1 deletion jwst/regtest/test_miri_spectral_leak.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Test SpectralLeakStep on MIRI MRS"""
import pytest
from astropy.io.fits.diff import FITSDiff
from jwst.regtest.st_fitsdiff import STFITSDiff as FITSDiff
from jwst.stpipe import Step

@pytest.mark.bigdata
Expand Down
Loading