From be5253c95f01ff9c58c547c661d74737a843c241 Mon Sep 17 00:00:00 2001 From: Kaleb Phipps Date: Thu, 5 Sep 2024 15:15:34 +0200 Subject: [PATCH] switch to pathlib instead of os.path --- .../stj_data/stj-tower-measurements.json | 1 - .../test_focal_spot_detection.py | 39 +++++++++++++++---- .../test_focal_spot_detection_from_dict.py | 31 +++++++++++---- 3 files changed, 54 insertions(+), 17 deletions(-) delete mode 100644 tests/target_cropper/stj_data/stj-tower-measurements.json diff --git a/tests/target_cropper/stj_data/stj-tower-measurements.json b/tests/target_cropper/stj_data/stj-tower-measurements.json deleted file mode 100644 index 242122f..0000000 --- a/tests/target_cropper/stj_data/stj-tower-measurements.json +++ /dev/null @@ -1 +0,0 @@ -{"solar_tower_juelich_upper": {"center": [50.91338911716799, 6.387794544159513, 130.09766666666667], "upper_left": [50.913389074925156, 6.38785596334749, 133.684], "upper_middle": [50.913389018219576, 6.387794564665748, 133.71], "upper_right": [50.91338922182834, 6.3877332676815515, 133.719], "lower_left": [50.9133889758114, 6.387856033619185, 126.476], "lower_right": [50.913389266158724, 6.3877334528986855, 126.506]}, "solar_tower_juelich_lower": {"center": [50.91338911716799, 6.387794544159513, 122.8815], "upper_left": [50.9133889758114, 6.387856033619185, 126.476], "upper_right": [50.913389266158724, 6.3877334528986855, 126.506], "lower_left": [50.91338894889202, 6.387856019176259, 119.268], "lower_middle": [50.91338921611639, 6.3877945236532705, 119.269], "lower_right": [50.91338944678619, 6.3877331984554475, 119.279]}, "multi_functions_tower": {"center": [50.91339355918569, 6.3875444167659845, 138.97975], "upper_left": [50.91339339750286, 6.387582963492142, 142.175], "upper_right": [50.91339372487825, 6.387506012264232, 142.172], "lower_left": [50.91339345190814, 6.387582821752781, 135.789], "lower_right": [50.913393662428156, 6.387505869554209, 135.783]}, "receiver": {"center": [50.91341371314919, 6.387794691724733, 142.22674999999998], "receiver_outer_upper_left": [50.91342438206257, 6.387826837461327, 144.805], "receiver_outer_upper_right": [50.913424848806365, 6.387762101585306, 144.82], "receiver_outer_lower_left": [50.91340258533124, 6.387826272355175, 139.596], "receiver_outer_lower_right": [50.91340281604982, 6.38776223128536, 139.592], "receiver_inner_lower_left": [50.913403653906435, 6.387823906642166, 139.86], "receiver_inner_lower_right": [50.91340375876268, 6.387765282015661, 139.862], "receiver_inner_upper_left": [50.913423563872826, 6.387824185899528, 144.592], "receiver_inner_upper_right": [50.91342387604005, 6.387765392341336, 144.593]}} diff --git a/tests/target_cropper/test_focal_spot_detection.py b/tests/target_cropper/test_focal_spot_detection.py index eb2f579..274b045 100644 --- a/tests/target_cropper/test_focal_spot_detection.py +++ b/tests/target_cropper/test_focal_spot_detection.py @@ -1,9 +1,10 @@ import os +import pathlib import sys import torch -from paint import target_cropper +from paint import PAINT_ROOT, target_cropper lib_dir = os.path.abspath(os.path.join(__file__, os.pardir, os.pardir, os.pardir)) sys.path.append(lib_dir) @@ -15,9 +16,16 @@ def test_focal_spot_detection() -> None: applied_k_means = 5 warped_image = target_cropper.util.load_image( - os.path.join(__file__, os.pardir, "focal_spot_image.png") + pathlib.Path(PAINT_ROOT) + / "tests" + / "target_cropper" + / "test_data" + / "focal_spot_image.png" + ) + + mask = target_cropper.util.load_image( + pathlib.Path(PAINT_ROOT) / "tests" / "target_cropper" / "test_data" / "mask.png" ) - mask = target_cropper.util.load_image(os.path.join(__file__, os.pardir, "mask.png")) mask = torch.where(mask != 0, torch.tensor(1.0), mask) target = target_cropper.dataclasses.Target( @@ -26,7 +34,11 @@ def test_focal_spot_detection() -> None: template_offset=torch.tensor([0, 0.5]), enu_position=torch.tensor([-1, 0, 1]), template_image=target_cropper.util.load_image( - os.path.join(__file__, os.pardir, "stj_data", "stj_center_left.png") + pathlib.Path(PAINT_ROOT) + / "tests" + / "target_cropper" + / "test_data" + / "stj_center_left.png" ), ), marker_2=target_cropper.dataclasses.Marker( @@ -34,7 +46,11 @@ def test_focal_spot_detection() -> None: template_offset=torch.tensor([0.5, 1.0]), enu_position=torch.tensor([1, 0, 1]), template_image=target_cropper.util.load_image( - os.path.join(__file__, os.pardir, "stj_data", "stj_center_right.png") + pathlib.Path(PAINT_ROOT) + / "tests" + / "target_cropper" + / "test_data" + / "stj_center_right.png" ), ), marker_3=target_cropper.dataclasses.Marker( @@ -42,7 +58,11 @@ def test_focal_spot_detection() -> None: template_offset=torch.tensor([1.0, 0.5]), enu_position=torch.tensor([-1, 0, -1]), template_image=target_cropper.util.load_image( - os.path.join(__file__, os.pardir, "stj_data", "stj_lower_left.png") + pathlib.Path(PAINT_ROOT) + / "tests" + / "target_cropper" + / "test_data" + / "stj_lower_left.png" ), ), marker_4=target_cropper.dataclasses.Marker( @@ -50,7 +70,11 @@ def test_focal_spot_detection() -> None: template_offset=torch.tensor([0.5, 0]), enu_position=torch.tensor([1, 0, -1]), template_image=target_cropper.util.load_image( - os.path.join(__file__, os.pardir, "stj_data", "stj_lower_right.png") + pathlib.Path(PAINT_ROOT) + / "tests" + / "target_cropper" + / "test_data" + / "stj_lower_right.png" ), ), output_shape=torch.Size([400, 400]), @@ -60,7 +84,6 @@ def test_focal_spot_detection() -> None: focal_spot = target_cropper.detect_focal_spot( image=warped_image, num_k_means=num_k_means, - applied_k_means=applied_k_means, target=target, ) diff --git a/tests/target_cropper/test_focal_spot_detection_from_dict.py b/tests/target_cropper/test_focal_spot_detection_from_dict.py index 2bb7dd2..76309a2 100644 --- a/tests/target_cropper/test_focal_spot_detection_from_dict.py +++ b/tests/target_cropper/test_focal_spot_detection_from_dict.py @@ -1,11 +1,12 @@ import json import os +import pathlib import sys import matplotlib.pyplot as plt import torch -from paint import target_cropper +from paint import PAINT_ROOT, target_cropper lib_dir = os.path.abspath(os.path.join(__file__, os.pardir, os.pardir, os.pardir)) sys.path.append(lib_dir) @@ -17,14 +18,24 @@ def test_focal_spot_detection_from_dict(): applied_k_means = 5 image = target_cropper.util.load_image( - os.path.join(__file__, os.pardir, "stj_data", "stj_target.png") + pathlib.Path(PAINT_ROOT) + / "tests" + / "target_cropper" + / "test_data" + / "stj_target.png" + ) + mask = target_cropper.util.load_image( + pathlib.Path(PAINT_ROOT) / "tests" / "target_cropper" / "test_data" / "mask.png" ) - mask = target_cropper.util.load_image(os.path.join(__file__, os.pardir, "mask.png")) # mask = torch.where(mask != 0, torch.tensor(1.0), mask) mask = None with open( - os.path.join(__file__, os.pardir, "stj_data", "stj-tower-measurements.json"), + pathlib.Path(PAINT_ROOT) + / "tests" + / "target_cropper" + / "test_data" + / "stj-tower-measurements.json", "r", ) as file: data_dict = json.load(file) @@ -37,7 +48,11 @@ def test_focal_spot_detection_from_dict(): data_dict["solar_tower_juelich_lower"]["upper_left"] ), template_image=target_cropper.util.load_image( - os.path.join(__file__, os.pardir, "stj_data", "stj_center_left.png") + pathlib.Path(PAINT_ROOT) + / "tests" + / "target_cropper" + / "test_data" + / "stj_center_left.png" ), ), marker_2=target_cropper.dataclasses.Marker( @@ -47,7 +62,7 @@ def test_focal_spot_detection_from_dict(): data_dict["solar_tower_juelich_lower"]["upper_right"] ), template_image=target_cropper.util.load_image( - os.path.join(__file__, os.pardir, "stj_data", "stj_center_right.png") + os.path.join(__file__, os.pardir, "test_data", "stj_center_right.png") ), ), marker_3=target_cropper.dataclasses.Marker( @@ -57,7 +72,7 @@ def test_focal_spot_detection_from_dict(): data_dict["solar_tower_juelich_lower"]["lower_left"] ), template_image=target_cropper.util.load_image( - os.path.join(__file__, os.pardir, "stj_data", "stj_lower_left.png") + os.path.join(__file__, os.pardir, "test_data", "stj_lower_left.png") ), ), marker_4=target_cropper.dataclasses.Marker( @@ -67,7 +82,7 @@ def test_focal_spot_detection_from_dict(): data_dict["solar_tower_juelich_lower"]["lower_right"] ), template_image=target_cropper.util.load_image( - os.path.join(__file__, os.pardir, "stj_data", "stj_lower_right.png") + os.path.join(__file__, os.pardir, "test_data", "stj_lower_right.png") ), ), output_shape=torch.Size([400, 400]),