Skip to content

Commit 0d49296

Browse files
committed
Fix access to reference and results files in Python comparison scripts
1 parent 83399b1 commit 0d49296

15 files changed

Lines changed: 199 additions & 194 deletions
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/regression/f3of/compare.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,16 @@
1919
from compare_template import run_multi_column_comparison
2020

2121
def main():
22-
if len(sys.argv) == 1 or (len(sys.argv) == 3 and sys.argv[1] == 'default'):
23-
# Use default reference and result file locations
24-
ref_file = os.path.join(os.path.dirname(__file__), "..", "reference_data", "f3of", "dt3", "hc_ref_f3of_dt3_flap_pitch.txt")
25-
build_dir = os.environ.get('HYDROCHRONO_BUILD_DIR', os.path.join(os.path.dirname(__file__), '..', '..', '..', 'build'))
26-
test_file = os.path.join(build_dir, "bin", "tests", "regression", "f3of", "results", "CHRONO_F3OF_DT3_FLAP_PITCH.txt")
27-
elif len(sys.argv) == 3:
28-
ref_file = sys.argv[1]
29-
test_file = sys.argv[2]
30-
else:
22+
if len(sys.argv) != 3:
3123
print("Usage: python compare.py <reference_file> <test_file>")
32-
print(" or: python compare.py default")
3324
sys.exit(1)
34-
25+
26+
# Get reference and results files
27+
ref_file = sys.argv[1]
28+
test_file = sys.argv[2]
29+
print("Reference file: ", ref_file)
30+
print("Results file: ", test_file)
31+
3532
# F3OF DT3 specific configuration
3633
test_name = "F3OF DT3 Decay Test"
3734
executable_patterns = ["f3of_dt3_test", "f3of_dt3_test.exe"]

tests/regression/f3of/compare_f3of_dt1.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,36 @@ def main():
2020
test_name = "F3OF DT1 Surge Decay"
2121
executable_patterns = ["f3of_dt1_test", "f3of_dt1_test.exe"]
2222

23-
# Find the result file
24-
# C++ regression tests write under: <build>/bin/Release/results/tests/f3of/
25-
build_dir = os.environ.get('HYDROCHRONO_BUILD_DIR', os.path.join(os.path.dirname(__file__), '..', '..', '..', 'build'))
26-
hc_data_file = os.path.join(build_dir, "bin", "Release", "results", "tests", "f3of", "results_f3of_dt1.txt")
27-
# Reference data lives under: <project_root>/data/reference_data/f3of/
28-
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", ".."))
29-
ref_data_file = os.path.join(project_root, "data", "reference_data", "f3of", "hc_ref_f3of_dt1_surge.txt")
30-
23+
if len(sys.argv) != 3:
24+
print("Usage: python compare.py <reference_file> <test_file>")
25+
sys.exit(1)
26+
27+
# Get reference and results files
28+
ref_file = sys.argv[1]
29+
results_file = sys.argv[2]
30+
print("Reference file: ", ref_file)
31+
print("Results file: ", results_file)
32+
3133
# Check if files exist
32-
if not os.path.exists(hc_data_file):
33-
print(f"Error: Test data file not found: {hc_data_file}")
34+
if not os.path.exists(results_file):
35+
print(f"Error: Test data file not found: {results_file}")
3436
sys.exit(1)
3537

36-
if not os.path.exists(ref_data_file):
37-
print(f"Error: Reference data file not found: {ref_data_file}")
38+
if not os.path.exists(ref_file):
39+
print(f"Error: Reference data file not found: {ref_file}")
3840
sys.exit(1)
3941

4042
try:
4143
# Load data for validation
42-
ref_data = np.loadtxt(ref_data_file, skiprows=1)
43-
test_data = np.loadtxt(hc_data_file, skiprows=1)
44+
ref_data = np.loadtxt(ref_file, skiprows=1)
45+
test_data = np.loadtxt(results_file, skiprows=1)
4446

4547
# Extract surge column (column 1) for comparison
4648
ref_surge_data = np.column_stack((ref_data[:, 0], ref_data[:, 1])) # time, surge
4749
test_surge_data = np.column_stack((test_data[:, 0], test_data[:, 1])) # time, surge
4850

4951
# Show where the plots will be saved
50-
test_file_path = Path(hc_data_file)
52+
test_file_path = Path(results_file)
5153
plots_dir = test_file_path.parent / "plots"
5254
plots_dir.mkdir(parents=True, exist_ok=True)
5355
print(f"Plots will be saved to: {plots_dir}")
@@ -68,8 +70,8 @@ def rel_to_root(path):
6870

6971
n1, n2 = create_comparison_plot(
7072
ref_surge_data, test_surge_data, test_name, plots_dir,
71-
ref_file_path=rel_to_root(ref_data_file),
72-
test_file_path=rel_to_root(hc_data_file),
73+
ref_file_path=rel_to_root(ref_file),
74+
test_file_path=rel_to_root(results_file),
7375
executable_path=rel_to_root(str(executable_path)) if executable_path else None,
7476
y_label="Base Surge (m)",
7577
executable_patterns=executable_patterns

tests/regression/f3of/compare_f3of_dt2.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,36 @@ def main():
2020
test_name = "F3OF DT2 Pitch Decay"
2121
executable_patterns = ["f3of_dt2_test", "f3of_dt2_test.exe"]
2222

23-
# Find the result file
24-
# C++ regression tests write under: <build>/bin/Release/results/tests/f3of/
25-
build_dir = os.environ.get('HYDROCHRONO_BUILD_DIR', os.path.join(os.path.dirname(__file__), '..', '..', '..', 'build'))
26-
hc_data_file = os.path.join(build_dir, "bin", "Release", "results", "tests", "f3of", "results_f3of_dt2.txt")
27-
# Reference data lives under: <project_root>/data/reference_data/f3of/
28-
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", ".."))
29-
ref_data_file = os.path.join(project_root, "data", "reference_data", "f3of", "hc_ref_f3of_dt2_pitch.txt")
30-
23+
if len(sys.argv) != 3:
24+
print("Usage: python compare.py <reference_file> <test_file>")
25+
sys.exit(1)
26+
27+
# Get reference and results files
28+
ref_file = sys.argv[1]
29+
results_file = sys.argv[2]
30+
print("Reference file: ", ref_file)
31+
print("Results file: ", results_file)
32+
3133
# Check if files exist
32-
if not os.path.exists(hc_data_file):
33-
print(f"Error: Test data file not found: {hc_data_file}")
34+
if not os.path.exists(results_file):
35+
print(f"Error: Test data file not found: {results_file}")
3436
sys.exit(1)
3537

36-
if not os.path.exists(ref_data_file):
37-
print(f"Error: Reference data file not found: {ref_data_file}")
38+
if not os.path.exists(ref_file):
39+
print(f"Error: Reference data file not found: {ref_file}")
3840
sys.exit(1)
3941

4042
try:
4143
# Load data for validation
42-
ref_data = np.loadtxt(ref_data_file, skiprows=1)
43-
test_data = np.loadtxt(hc_data_file, skiprows=1)
44+
ref_data = np.loadtxt(ref_file, skiprows=1)
45+
test_data = np.loadtxt(results_file, skiprows=1)
4446

4547
# Extract pitch column (column 2) for comparison
4648
ref_pitch_data = np.column_stack((ref_data[:, 0], ref_data[:, 2])) # time, pitch
4749
test_pitch_data = np.column_stack((test_data[:, 0], test_data[:, 2])) # time, pitch
4850

4951
# Show where the plots will be saved
50-
test_file_path = Path(hc_data_file)
52+
test_file_path = Path(results_file)
5153
plots_dir = test_file_path.parent / "plots"
5254
plots_dir.mkdir(parents=True, exist_ok=True)
5355
print(f"Plots will be saved to: {plots_dir}")
@@ -68,8 +70,8 @@ def rel_to_root(path):
6870

6971
n1, n2 = create_comparison_plot(
7072
ref_pitch_data, test_pitch_data, test_name, plots_dir,
71-
ref_file_path=rel_to_root(ref_data_file),
72-
test_file_path=rel_to_root(hc_data_file),
73+
ref_file_path=rel_to_root(ref_file),
74+
test_file_path=rel_to_root(results_file),
7375
executable_path=rel_to_root(str(executable_path)) if executable_path else None,
7476
y_label="Base Pitch (rad)",
7577
executable_patterns=executable_patterns

tests/regression/f3of/compare_f3of_dt3.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,32 @@ def main():
2020
test_name = "F3OF DT3 Flap Pitch Decay"
2121
executable_patterns = ["f3of_dt3_test", "f3of_dt3_test.exe"]
2222

23-
# Find the result file
24-
# C++ regression tests write under: <build>/bin/Release/results/tests/f3of/
25-
build_dir = os.environ.get('HYDROCHRONO_BUILD_DIR', os.path.join(os.path.dirname(__file__), '..', '..', '..', 'build'))
26-
hc_data_file = os.path.join(build_dir, "bin", "Release", "results", "tests", "f3of", "results_f3of_dt3.txt")
23+
if len(sys.argv) != 3:
24+
print("Usage: python compare.py <reference_file> <test_file>")
25+
sys.exit(1)
2726

28-
# Reference data lives under: <project_root>/data/reference_data/f3of/
29-
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", ".."))
30-
ref_data_file = os.path.join(project_root, "data", "reference_data", "f3of", "hc_ref_f3of_dt3_flap_pitch.txt")
27+
# Get reference and results files
28+
ref_file = sys.argv[1]
29+
results_file = sys.argv[2]
30+
print("Reference file: ", ref_file)
31+
print("Results file: ", results_file)
3132

3233
# Check if files exist
33-
if not os.path.exists(hc_data_file):
34-
print(f"Error: Test data file not found: {hc_data_file}")
34+
if not os.path.exists(results_file):
35+
print(f"Error: Test data file not found: {results_file}")
3536
sys.exit(1)
3637

37-
if not os.path.exists(ref_data_file):
38-
print(f"Error: Reference data file not found: {ref_data_file}")
38+
if not os.path.exists(ref_file):
39+
print(f"Error: Reference data file not found: {ref_file}")
3940
sys.exit(1)
4041

4142
try:
4243
# Load data for validation
43-
ref_data = np.loadtxt(ref_data_file, skiprows=1)
44-
test_data = np.loadtxt(hc_data_file, skiprows=1)
44+
ref_data = np.loadtxt(ref_file, skiprows=1)
45+
test_data = np.loadtxt(results_file, skiprows=1)
4546

4647
# Show where the plots will be saved
47-
test_file_path = Path(hc_data_file)
48+
test_file_path = Path(results_file)
4849
plots_dir = test_file_path.parent / "plots"
4950
plots_dir.mkdir(parents=True, exist_ok=True)
5051
print(f"Plots will be saved to: {plots_dir}")
@@ -73,7 +74,7 @@ def main():
7374

7475
# Run the multi-column comparison using the template
7576
results = run_multi_column_comparison(
76-
ref_data_file, hc_data_file, test_configs,
77+
ref_file, results_file, test_configs,
7778
executable_patterns=executable_patterns
7879
)
7980

tests/regression/oswec/compare_oswec_decay.py

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
55
This script compares the OSWEC decay test results with reference data and generates
66
comparison plots using the standardized template.
7-
8-
Usage:
9-
python compare_decay.py <reference_file> <test_file>
107
"""
118

129
import sys
@@ -19,21 +16,16 @@
1916
from compare_template import run_multi_column_comparison
2017

2118
def main():
22-
if len(sys.argv) == 1 or (len(sys.argv) == 3 and sys.argv[1] == 'default'):
23-
# Use default reference and result file locations
24-
ref_file = os.path.join(os.path.dirname(__file__), "..", "reference_data", "oswec", "decay", "hc_ref_oswec_decay.txt")
25-
26-
# Find the result file
27-
build_dir = os.environ.get('HYDROCHRONO_BUILD_DIR', 'C:/code/HydroChrono/build')
28-
test_file = os.path.join(build_dir, "bin", "tests", "regression", "oswec", "results", "CHRONO_OSWEC_DECAY.txt")
29-
elif len(sys.argv) == 3:
30-
ref_file = sys.argv[1]
31-
test_file = sys.argv[2]
32-
else:
33-
print("Usage: python compare_decay.py <reference_file> <test_file>")
34-
print(" or: python compare_decay.py default")
19+
if len(sys.argv) != 3:
20+
print("Usage: python compare.py <reference_file> <test_file>")
3521
sys.exit(1)
36-
22+
23+
# Get reference and results files
24+
ref_file = sys.argv[1]
25+
results_file = sys.argv[2]
26+
print("Reference file: ", ref_file)
27+
print("Results file: ", results_file)
28+
3729
# OSWEC Decay specific configuration
3830
test_name = "OSWEC Decay Test"
3931
executable_patterns = ["oswec_decay_test", "oswec_decay_test.exe"]
@@ -51,10 +43,10 @@ def main():
5143
try:
5244
# Load data for additional OSWEC-specific validations
5345
ref_data = np.loadtxt(ref_file, skiprows=1)
54-
test_data = np.loadtxt(test_file, skiprows=1)
46+
test_data = np.loadtxt(results_file, skiprows=1)
5547

5648
# Show where the plots will be saved
57-
test_file_path = Path(test_file)
49+
test_file_path = Path(results_file)
5850
plots_dir = test_file_path.parent / "plots"
5951
plots_dir.mkdir(parents=True, exist_ok=True)
6052
print(f"Plots will be saved to: {plots_dir}")
@@ -102,7 +94,7 @@ def main():
10294
create_comparison_plot(
10395
ref_col_data, test_col_data, test_name, plots_dir,
10496
ref_file_path=format_path(ref_file),
105-
test_file_path=format_path(test_file),
97+
test_file_path=format_path(results_file),
10698
y_label=y_label,
10799
executable_patterns=executable_patterns
108100
)

tests/regression/oswec/compare_oswec_reg_waves.py

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,67 @@
2121
from compare_template import create_comparison_plot, format_path
2222

2323
def main():
24-
# Directories
25-
script_dir = Path(__file__).parent
26-
ref_dir = script_dir.parent / "reference_data" / "oswec" / "reg_waves"
27-
# Default build results dir
28-
build_dir = Path(os.environ.get('HYDROCHRONO_BUILD_DIR', 'C:/code/HydroChrono/build'))
29-
# New recommended layout
30-
results_dir = build_dir / "bin" / "tests" / "regression" / "oswec" / "results"
31-
if not results_dir.exists():
32-
# Fallback to older Release layout used previously
33-
results_dir = build_dir / "tests" / "regression" / "Release" / "oswec" / "results" / "oswec" / "regular_waves"
34-
if not results_dir.exists():
35-
print(f"Results directory not found: {results_dir}")
24+
if len(sys.argv) != 3:
25+
print("Usage: python compare.py <reference_file> <test_file>")
3626
sys.exit(1)
3727

38-
# Find all result files
39-
all_files = [p for p in results_dir.glob("CHRONO_OSWEC_REG_WAVES_*.txt") if not p.stem.endswith("DURATION")]
40-
def wave_num_from_stem(stem: str):
41-
m = re.search(r"_(\d+)$", stem)
42-
return int(m.group(1)) if m else -1
43-
result_files = sorted(all_files, key=lambda p: wave_num_from_stem(p.stem))
28+
# Get reference and results files
29+
ref_file = sys.argv[1]
30+
results_file = sys.argv[2]
31+
print("Reference file: ", ref_file)
32+
print("Results file: ", results_file)
33+
34+
# Get the reference data directory from the reference file
35+
ht = os.path.split(ref_file)
36+
ref_dir = Path(ht[0])
37+
38+
if not ref_dir.exists():
39+
print(f"Error: Reference directory not found: {ref_dir}")
40+
sys.exit(1)
41+
42+
# Get the results directory from the results file
43+
ht = os.path.split(results_file)
44+
results_dir = Path(ht[0])
45+
46+
if not results_dir.exists():
47+
print(f"Error: Results directory not found: {results_dir}")
48+
sys.exit(1)
49+
50+
# Find all result files produced by the C++ test
51+
# C++ writes files named: results_oswec_reg_waves_<N>.txt
52+
result_files = list(results_dir.glob("results_oswec_reg_waves_*.txt"))
53+
result_files.sort()
54+
4455
if not result_files:
45-
print(f"No result files found in {results_dir}")
56+
print(f"Error: No result files found in {results_dir}")
4657
sys.exit(1)
58+
59+
print(f"Found {len(result_files)} result files in {results_dir}")
60+
61+
62+
# # Directories
63+
# script_dir = Path(__file__).parent
64+
# ref_dir = script_dir.parent / "reference_data" / "oswec" / "reg_waves"
65+
# # Default build results dir
66+
# build_dir = Path(os.environ.get('HYDROCHRONO_BUILD_DIR', 'C:/code/HydroChrono/build'))
67+
# # New recommended layout
68+
# results_dir = build_dir / "bin" / "tests" / "regression" / "oswec" / "results"
69+
# if not results_dir.exists():
70+
# # Fallback to older Release layout used previously
71+
# results_dir = build_dir / "tests" / "regression" / "Release" / "oswec" / "results" / "oswec" / "regular_waves"
72+
# if not results_dir.exists():
73+
# print(f"Results directory not found: {results_dir}")
74+
# sys.exit(1)
75+
#
76+
# # Find all result files
77+
# all_files = [p for p in results_dir.glob("CHRONO_OSWEC_REG_WAVES_*.txt") if not p.stem.endswith("DURATION")]
78+
# def wave_num_from_stem(stem: str):
79+
# m = re.search(r"_(\d+)$", stem)
80+
# return int(m.group(1)) if m else -1
81+
# result_files = sorted(all_files, key=lambda p: wave_num_from_stem(p.stem))
82+
# if not result_files:
83+
# print(f"No result files found in {results_dir}")
84+
# sys.exit(1)
4785

4886
# Output directory for plots
4987
plots_dir = results_dir / "plots"

0 commit comments

Comments
 (0)