Skip to content

Commit 375f4a4

Browse files
author
David Turner
committed
Added a new test_products sub-directory to the tests, and the test_profile file as the first entry. Added a couple of tests checking that profile view methods work with default settings
Signed-off-by: David Turner <djturner@umbc.edu>
1 parent d9d6e67 commit 375f4a4

3 files changed

Lines changed: 55 additions & 4 deletions

File tree

tests/test_products/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# This code is part of X-ray: Generate and Analyse (XGA), a module designed for the XMM Cluster Survey (XCS).
2+
# Last modified by David J Turner (djturner@umbc.edu) 5/20/26, 12:35 PM. Copyright (c) The Contributors.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# This code is part of X-ray: Generate and Analyse (XGA), a module designed for the XMM Cluster Survey (XCS).
2+
# Last modified by David J Turner (djturner@umbc.edu) 5/20/26, 12:46 PM. Copyright (c) The Contributors.
3+
4+
import os
5+
import unittest
6+
7+
from astropy.units import Quantity
8+
9+
from xga.products.profile import ProjectedGasTemperature1D
10+
from xga.sourcetools.misc import rad_to_ang
11+
from .. import MISC_OUTPUT_TESTS
12+
13+
14+
class TestProfileView(unittest.TestCase):
15+
16+
@classmethod
17+
def setUpClass(cls):
18+
radii = Quantity([100, 200, 300, 400], 'kpc')
19+
deg_radii = rad_to_ang(radii, z=0.16)
20+
21+
cls.tp_one = ProjectedGasTemperature1D(radii,
22+
Quantity([1, 3, 4, 3.4], 'keV'),
23+
Quantity([0, 0], 'deg'),
24+
"magic-galaxy-cluster",
25+
"an-obsid",
26+
"an-inst",
27+
deg_radii=deg_radii)
28+
29+
cls.tp_two = ProjectedGasTemperature1D(radii,
30+
Quantity([10, 8, 7.1, 3.4], 'keV'),
31+
Quantity([1, 1], 'deg'),
32+
"another-magic-galaxy-cluster",
33+
"an-obsid",
34+
"an-inst",
35+
deg_radii=deg_radii)
36+
37+
def test_default_view(self):
38+
test_out_path = os.path.join(MISC_OUTPUT_TESTS, self.id())
39+
os.makedirs(test_out_path, exist_ok=True)
40+
41+
self.tp_one.save_view(os.path.join(test_out_path, "tp_one_default.png"))
42+
43+
def test_default_aggregate_view(self):
44+
test_out_path = os.path.join(MISC_OUTPUT_TESTS, self.id())
45+
os.makedirs(test_out_path, exist_ok=True)
46+
47+
agg_prof = self.tp_one + self.tp_two
48+
49+
agg_prof.view(save_path=os.path.join(test_out_path, "tp_one_two_agg_default.png"))

xga/products/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This code is part of X-ray: Generate and Analyse (XGA), a module designed for the XMM Cluster Survey (XCS).
2-
# Last modified by David J Turner (djturner@umbc.edu) 5/20/26, 11:13 AM. Copyright (c) The Contributors.
2+
# Last modified by David J Turner (djturner@umbc.edu) 5/20/26, 12:51 PM. Copyright (c) The Contributors.
33

44
import inspect
55
import os
@@ -3481,9 +3481,9 @@ def view(self, figsize: Tuple = (10, 7), xscale: str = "log", yscale: str = "log
34813481
# If the user passed a save_path value, then we assume they want to save the figure
34823482
if save_path is not None:
34833483
fig.savefig(save_path, bbox_inches='tight')
3484-
3485-
# And of course actually showing it
3486-
plt.show()
3484+
else:
3485+
# Showing the figure
3486+
plt.show()
34873487

34883488
def __add__(self, other):
34893489
to_combine = self.profiles

0 commit comments

Comments
 (0)