From c1cec67ed117c07f449f2fed6d00dd0a48869a94 Mon Sep 17 00:00:00 2001 From: Rachel Date: Mon, 1 Dec 2025 14:46:19 +0000 Subject: [PATCH 1/7] Edited conftest.py --- sunkit_spex/conftest.py | 64 ++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 40 deletions(-) diff --git a/sunkit_spex/conftest.py b/sunkit_spex/conftest.py index 44d984ab..25da7751 100644 --- a/sunkit_spex/conftest.py +++ b/sunkit_spex/conftest.py @@ -1,44 +1,28 @@ -# This file is used to configure the behavior of pytest when using the Astropy -# test infrastructure. +import numpy as np +import astropy.units as u +from astropy.wcs import WCS -# Uncomment the following line to treat all DeprecationWarnings as -# exceptions. For Astropy v2.0 or later, there are 2 additional keywords, -# as follow (although default should work for most cases). -# To ignore some packages that produce deprecation warnings on import -# (in addition to 'compiler', 'scipy', 'pygments', 'ipykernel', and -# 'setuptools'), add: -# modules_to_ignore_on_import=['module_1', 'module_2'] -# To ignore some specific deprecation warning messages for Python version -# MAJOR.MINOR or later, add: -# warnings_to_ignore_by_pyver={(MAJOR, MINOR): ['Message to ignore']} -# enable_deprecations_as_exceptions() +from sunkit_spex.spectrum import Spectrum -# Uncomment and customize the following lines to add/remove entries from -# the list of packages for which version numbers are displayed when running -# the tests. Making it pass for KeyError is essential in some cases when -# the package uses other astropy affiliated packages. -# try: -# PYTEST_HEADER_MODULES['Astropy'] = 'astropy' -# PYTEST_HEADER_MODULES['scikit-image'] = 'skimage' -# del PYTEST_HEADER_MODULES['h5py'] -# except (NameError, KeyError): # NameError is needed to support Astropy < 1.0 -# pass -# Uncomment the following lines to display the version number of the -# package rather than the version number of Astropy in the top line when -# running the tests. -# import os -# -# This is to figure out the package version, rather than -# using Astropy's -# try: -# from .version import version -# except ImportError: -# version = 'dev' -# -# try: -# packagename = os.path.basename(os.path.dirname(__file__)) -# TESTED_VERSIONS[packagename] = version -# except NameError: # Needed to support Astropy <= 1.0.0 -# pass +def wcs_et(): + header = { + "CTYPE1": "TIME ", # data type + "CUNIT1": "min", # data unit + "CDELT1": 0.4, # interval + "CRPIX1": 0, # home pixel (units = pixels) + "CRVAL1": 0, # home coordinate (units = data unit) eg here the home coordinate is time = 0 min + "CTYPE2": "ENERGY ", + "CUNIT2": "keV", + "CDELT2": 0.2, + "CRPIX2": 0, + "CRVAL2": 0, + "DATEREF": "2020-01-01T00:00:00", + } + return WCS(header=header) + + +timeenergy = wcs_et() +data = np.arange(1, 11) * u.watt +spec = Spectrum(data, wcs=timeenergy) From 70a3f7465316e96bf9c8e1a71225cb57e6c59594 Mon Sep 17 00:00:00 2001 From: rh2082 Date: Mon, 1 Dec 2025 15:37:27 +0000 Subject: [PATCH 2/7] Update sunkit_spex/conftest.py Co-authored-by: DanRyanIrish --- sunkit_spex/conftest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sunkit_spex/conftest.py b/sunkit_spex/conftest.py index 25da7751..c94700fa 100644 --- a/sunkit_spex/conftest.py +++ b/sunkit_spex/conftest.py @@ -6,6 +6,7 @@ from sunkit_spex.spectrum import Spectrum +@pytest.fixture def wcs_et(): header = { "CTYPE1": "TIME ", # data type From ac7f1846936cd5e40b819555f8220596626ad162 Mon Sep 17 00:00:00 2001 From: Rachel Date: Mon, 1 Dec 2025 15:47:31 +0000 Subject: [PATCH 3/7] Edit from code review --- sunkit_spex/conftest.py | 54 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/sunkit_spex/conftest.py b/sunkit_spex/conftest.py index c94700fa..412f31f0 100644 --- a/sunkit_spex/conftest.py +++ b/sunkit_spex/conftest.py @@ -1,4 +1,50 @@ +# This file is used to configure the behavior of pytest when using the Astropy +# test infrastructure. + + +# Uncomment the following line to treat all DeprecationWarnings as +# exceptions. For Astropy v2.0 or later, there are 2 additional keywords, +# as follow (although default should work for most cases). +# To ignore some packages that produce deprecation warnings on import +# (in addition to 'compiler', 'scipy', 'pygments', 'ipykernel', and +# 'setuptools'), add: +# modules_to_ignore_on_import=['module_1', 'module_2'] +# To ignore some specific deprecation warning messages for Python version +# MAJOR.MINOR or later, add: +# warnings_to_ignore_by_pyver={(MAJOR, MINOR): ['Message to ignore']} +# enable_deprecations_as_exceptions() + +# Uncomment and customize the following lines to add/remove entries from +# the list of packages for which version numbers are displayed when running +# the tests. Making it pass for KeyError is essential in some cases when +# the package uses other astropy affiliated packages. +# try: +# PYTEST_HEADER_MODULES['Astropy'] = 'astropy' +# PYTEST_HEADER_MODULES['scikit-image'] = 'skimage' +# del PYTEST_HEADER_MODULES['h5py'] +# except (NameError, KeyError): # NameError is needed to support Astropy < 1.0 +# pass + +# Uncomment the following lines to display the version number of the +# package rather than the version number of Astropy in the top line when +# running the tests. +# import os +# +# This is to figure out the package version, rather than +# using Astropy's +# try: +# from .version import version +# except ImportError: +# version = 'dev' +# +# try: +# packagename = os.path.basename(os.path.dirname(__file__)) +# TESTED_VERSIONS[packagename] = version +# except NameError: # Needed to support Astropy <= 1.0.0 +# pass + import numpy as np +import pytest import astropy.units as u from astropy.wcs import WCS @@ -24,6 +70,8 @@ def wcs_et(): return WCS(header=header) -timeenergy = wcs_et() -data = np.arange(1, 11) * u.watt -spec = Spectrum(data, wcs=timeenergy) +@pytest.fixture +def spec(): + timeenergy = wcs_et() + data = np.arange(1, 11) * u.watt + return Spectrum(data, wcs=timeenergy) From c4243fdf212ed21574f4a6efeb4d3eb011a5be29 Mon Sep 17 00:00:00 2001 From: rh2082 Date: Mon, 1 Dec 2025 16:15:10 +0000 Subject: [PATCH 4/7] Update sunkit_spex/conftest.py Co-authored-by: DanRyanIrish --- sunkit_spex/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sunkit_spex/conftest.py b/sunkit_spex/conftest.py index 412f31f0..d19b3b22 100644 --- a/sunkit_spex/conftest.py +++ b/sunkit_spex/conftest.py @@ -71,7 +71,7 @@ def wcs_et(): @pytest.fixture -def spec(): - timeenergy = wcs_et() +def spec(wcs_et): + timeenergy = wcs_et data = np.arange(1, 11) * u.watt return Spectrum(data, wcs=timeenergy) From 87cae11d6be499cf8ee63aba01b8c7ddf57043c6 Mon Sep 17 00:00:00 2001 From: Rachel Date: Mon, 1 Dec 2025 16:46:10 +0000 Subject: [PATCH 5/7] Added further testing fixtures --- sunkit_spex/conftest.py | 135 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 130 insertions(+), 5 deletions(-) diff --git a/sunkit_spex/conftest.py b/sunkit_spex/conftest.py index 412f31f0..1ca1b3a4 100644 --- a/sunkit_spex/conftest.py +++ b/sunkit_spex/conftest.py @@ -55,11 +55,11 @@ @pytest.fixture def wcs_et(): header = { - "CTYPE1": "TIME ", # data type - "CUNIT1": "min", # data unit - "CDELT1": 0.4, # interval - "CRPIX1": 0, # home pixel (units = pixels) - "CRVAL1": 0, # home coordinate (units = data unit) eg here the home coordinate is time = 0 min + "CTYPE1": "TIME ", + "CUNIT1": "min", + "CDELT1": 0.4, + "CRPIX1": 0, + "CRVAL1": 0, "CTYPE2": "ENERGY ", "CUNIT2": "keV", "CDELT2": 0.2, @@ -75,3 +75,128 @@ def spec(): timeenergy = wcs_et() data = np.arange(1, 11) * u.watt return Spectrum(data, wcs=timeenergy) + + +@pytest.fixture +def wcs_dt(): + header = { + "CTYPE1": "DETECTOR", + "CUNIT1": "", + "CDELT1": 0, + "CRPIX1": 0, + "CRVAL1": 0, + "CTYPE2": "ENERGY ", + "CUNIT2": "keV", + "CDELT2": 0.2, + "CRPIX2": 0, + "CRVAL2": 0, + "DATEREF": "2020-01-01T00:00:00", + } + return WCS(header=header) + + +@pytest.fixture +def dve(): + detectorenergy = wcs_dt() + data = np.arange(1, 11) * u.watt + return Spectrum(data, wcs=detectorenergy) + + +@pytest.fixture +def wcs_ess(): + header = { + "CTYPE1": "ENERGY ", + "CUNIT1": "keV", + "CDELT1": 0.2, + "CRPIX1": 0, + "CRVAL1": 0, + "CTYPE2": "HPLT-TAN", + "CUNIT2": "deg", + "CDELT2": 0.5, + "CRPIX2": 2, + "CRVAL2": 0.5, + "CTYPE3": "HPLN-TAN", + "CUNIT3": "deg", + "CDELT3": 0.4, + "CRPIX3": 2, + "CRVAL3": 1, + "DATEREF": "2020-01-01T00:00:00", + } + return WCS(header=header) + + +@pytest.fixture +def evsvs(): + energyspacespace = wcs_ess() + data = np.arange(1, 11) * u.watt + return Spectrum(data, wcs=energyspacespace) + + +@pytest.fixture +def wcs_etd(): + header = { + "CTYPE1": "ENERGY ", + "CUNIT1": "keV", + "CDELT1": 0.2, + "CRPIX1": 0, + "CRVAL1": 0, + "CTYPE2": "TIME", + "CUNIT2": "min", + "CDELT2": 0.4, + "CRPIX2": 0, + "CRVAL2": 0, + "CTYPE3": "DETECTOR", + "CUNIT3": "", + "CDELT3": 0, + "CRPIX3": 0, + "CRVAL3": 0, + "DATEREF": "2020-01-01T00:00:00", + } + return WCS(header=header) + + +@pytest.fixture +def evtvd(): + energytimedetector = wcs_etd() + data = np.arange(1, 11) * u.watt + return Spectrum(data, wcs=energytimedetector) + + +@pytest.fixture +def wcs_esstp(): + header = { + "CTYPE1": "ENERGY ", + "CUNIT1": "keV", + "CDELT1": 0.2, + "CRPIX1": 0, + "CRVAL1": 0, + "CTYPE2": "HPLT-TAN", + "CUNIT2": "deg", + "CDELT2": 0.5, + "CRPIX2": 2, + "CRVAL2": 0.5, + "CTYPE3": "HPLN-TAN", + "CUNIT3": "deg", + "CDELT3": 0.4, + "CRPIX3": 2, + "CRVAL3": 1, + "CTYPE4": "TIME", + "CUNIT4": "min", + "CDELT4": 0.4, + "CRPIX4": 0, + "CRVAL4": 0, + "CTYPE5": "POLARISATION", + "CUNIT5": "C/m2", + "CDELT5": 0.4, + "CRPIX5": 0, + "CRVAL5": 0, + "DATEREF": "2020-01-01T00:00:00", + } + return WCS(header=header) + + +@pytest.fixture +def evsvsvtvp(): + esstp = wcs_esstp() + data = np.arange(1, 11) * u.watt + return Spectrum(data, wcs=esstp) From f2ca7ef599987c31e53fd4a03806d4da94f2b777 Mon Sep 17 00:00:00 2001 From: rh2082 Date: Thu, 4 Dec 2025 11:48:58 +0000 Subject: [PATCH 6/7] Update sunkit_spex/conftest.py Co-authored-by: DanRyanIrish --- sunkit_spex/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sunkit_spex/conftest.py b/sunkit_spex/conftest.py index a4cb50aa..0228c7e1 100644 --- a/sunkit_spex/conftest.py +++ b/sunkit_spex/conftest.py @@ -185,7 +185,7 @@ def wcs_esstp(): "CDELT4": 0.4, "CRPIX4": 0, "CRVAL4": 0, - "CTYPE5": "POLARISATION", + "CTYPE5": "STOKES", "CUNIT5": "C/m2", "CDELT5": 0.4, "CRPIX5": 0, From 60ca9ca57582f023070abfdf7f22abf724b26e77 Mon Sep 17 00:00:00 2001 From: Rachel Date: Thu, 4 Dec 2025 13:48:17 +0000 Subject: [PATCH 7/7] Added docstrings --- sunkit_spex/conftest.py | 62 ++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/sunkit_spex/conftest.py b/sunkit_spex/conftest.py index 0228c7e1..2f9adde4 100644 --- a/sunkit_spex/conftest.py +++ b/sunkit_spex/conftest.py @@ -53,14 +53,15 @@ @pytest.fixture -def wcs_et(): +def wcs_energy_time(): + """Return WCS object with time and energy axes.""" header = { - "CTYPE1": "TIME ", + "CTYPE1": "TIME", "CUNIT1": "min", "CDELT1": 0.4, "CRPIX1": 0, "CRVAL1": 0, - "CTYPE2": "ENERGY ", + "CTYPE2": "ENERGY", "CUNIT2": "keV", "CDELT2": 0.2, "CRPIX2": 0, @@ -71,21 +72,23 @@ def wcs_et(): @pytest.fixture -def spec(wcs_et): - timeenergy = wcs_et +def spectrum_energy_time(): + """Return Spectrum Object with linear data, and time and energy spectral axes.""" + timeenergy = wcs_energy_time data = np.arange(1, 11) * u.watt return Spectrum(data, wcs=timeenergy) @pytest.fixture -def wcs_dt(): +def wcs_detector_energy(): + """Return WCS object with detector and energy axes.""" header = { "CTYPE1": "DETECTOR", "CUNIT1": "", - "CDELT1": 0, - "CRPIX1": 0, - "CRVAL1": 0, - "CTYPE2": "ENERGY ", + "CDELT1": 1, + "CRPIX1": 1, + "CRVAL1": 1, + "CTYPE2": "ENERGY", "CUNIT2": "keV", "CDELT2": 0.2, "CRPIX2": 0, @@ -96,16 +99,18 @@ def wcs_dt(): @pytest.fixture -def dve(): - detectorenergy = wcs_dt() +def spectrum_detector_energy(): + """Return Spectrum object with linear data, and detector and energy spectral axes.""" + detectorenergy = wcs_detector_energy() data = np.arange(1, 11) * u.watt return Spectrum(data, wcs=detectorenergy) @pytest.fixture -def wcs_ess(): +def wcs_energy_space_space(): + """Return WCS object with energy and two spatial axes.""" header = { - "CTYPE1": "ENERGY ", + "CTYPE1": "ENERGY", "CUNIT1": "keV", "CDELT1": 0.2, "CRPIX1": 0, @@ -126,14 +131,16 @@ def wcs_ess(): @pytest.fixture -def evsvs(): - energyspacespace = wcs_ess() +def spectrum_energy_space_space(): + """Return Spectrum object with linear data, and energy and two spatial spectral axes.""" + energyspacespace = wcs_energy_space_space() data = np.arange(1, 11) * u.watt return Spectrum(data, wcs=energyspacespace) @pytest.fixture -def wcs_etd(): +def wcs_energy_time_detector(): + """Return WCS object with energy and time and detector axes.""" header = { "CTYPE1": "ENERGY ", "CUNIT1": "keV", @@ -147,25 +154,27 @@ def wcs_etd(): "CRVAL2": 0, "CTYPE3": "DETECTOR", "CUNIT3": "", - "CDELT3": 0, - "CRPIX3": 0, - "CRVAL3": 0, + "CDELT3": 1, + "CRPIX3": 1, + "CRVAL3": 1, "DATEREF": "2020-01-01T00:00:00", } return WCS(header=header) @pytest.fixture -def evtvd(): - energytimedetector = wcs_etd() +def spectrum_energy_time_detector(): + """Return Spectrum object with linear data, and energy, time and detector spectral axes.""" + energytimedetector = wcs_energy_time_detector() data = np.arange(1, 11) * u.watt return Spectrum(data, wcs=energytimedetector) @pytest.fixture -def wcs_esstp(): +def wcs_energy_2space_time_stokes(): + """Return WCS object with energy, 2 spatial, time and Stokes axes.""" header = { - "CTYPE1": "ENERGY ", + "CTYPE1": "ENERGY", "CUNIT1": "keV", "CDELT1": 0.2, "CRPIX1": 0, @@ -196,7 +205,8 @@ def wcs_esstp(): @pytest.fixture -def evsvsvtvp(): - esstp = wcs_esstp() +def spectrum_energy_2space_time_stokes(): + """Return Spectrum object with linear data, and energy, two spatial, time and Stokes spectral axes.""" + esstp = wcs_energy_2space_time_stokes() data = np.arange(1, 11) * u.watt return Spectrum(data, wcs=esstp)