-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_completeness_purity.py
More file actions
executable file
·134 lines (106 loc) · 4.07 KB
/
Copy pathtest_completeness_purity.py
File metadata and controls
executable file
·134 lines (106 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env python3
"""
Test script for completeness and purity plotting on existing experimental results.
Usage:
python test_completeness_purity.py <experiment_dir>
Example:
python test_completeness_purity.py ./trained_models/candidate_classifier_color_uq_run_20251027_120000/
"""
import sys
import os
from plot_completeness_purity import plot_completeness_purity
def find_evaluation_csv(experiment_dir):
"""Find evaluation_results.csv in experiment directory."""
# Common locations for evaluation_results.csv
possible_paths = [
os.path.join(experiment_dir, "evaluation_results", "evaluation_results.csv"),
os.path.join(experiment_dir, "evaluation_results.csv"),
os.path.join(experiment_dir, "test_results", "evaluation_results.csv"),
]
for path in possible_paths:
if os.path.exists(path):
return path
return None
def find_bcg_csv(experiment_dir):
"""Try to infer BCG CSV path from experiment directory."""
# Common BCG CSV locations on the cluster
base_dir = '/lcrc/project/cosmo_ai/nramachandra/Projects/BCGs_swing/data/lbleem/bcgs'
# Try to infer from experiment name
if '2p2arcmin' in experiment_dir or '2.2' in experiment_dir:
bcg_csv = f'{base_dir}/bcgs_2p2arcmin_clean_matched.csv'
elif '3p8arcmin' in experiment_dir or '3.8' in experiment_dir:
bcg_csv = f'{base_dir}/bcgs_3p8arcmin_clean_matched.csv'
else:
# Default to 3.8 arcmin
bcg_csv = f'{base_dir}/bcgs_3p8arcmin_clean_matched.csv'
if os.path.exists(bcg_csv):
return bcg_csv
# Try alternative path without '_clean_matched'
bcg_csv_alt = bcg_csv.replace('_clean_matched', '_with_coordinates')
if os.path.exists(bcg_csv_alt):
return bcg_csv_alt
return None
def main():
"""Main function to run completeness/purity analysis on existing results."""
if len(sys.argv) < 2:
print("Usage: python test_completeness_purity.py <experiment_dir>")
print("\nExample:")
print(" python test_completeness_purity.py ./trained_models/candidate_classifier_color_uq_run_20251027_120000/")
sys.exit(1)
experiment_dir = sys.argv[1]
if not os.path.exists(experiment_dir):
print(f"Error: Experiment directory not found: {experiment_dir}")
sys.exit(1)
print("="*80)
print("COMPLETENESS AND PURITY ANALYSIS")
print("="*80)
print(f"Experiment directory: {experiment_dir}")
print()
# Find evaluation_results.csv
evaluation_csv = find_evaluation_csv(experiment_dir)
if evaluation_csv is None:
print("Error: Could not find evaluation_results.csv in experiment directory")
print("Searched in:")
print(" - <experiment_dir>/evaluation_results/evaluation_results.csv")
print(" - <experiment_dir>/evaluation_results.csv")
print(" - <experiment_dir>/test_results/evaluation_results.csv")
sys.exit(1)
print(f"Found evaluation results: {evaluation_csv}")
# Find BCG CSV
bcg_csv = find_bcg_csv(experiment_dir)
if bcg_csv:
print(f"Found BCG catalog: {bcg_csv}")
else:
print("Warning: Could not find BCG catalog CSV. Delta M* z plots may not be available.")
# Set output directory to experiment root
output_dir = experiment_dir
print()
print("Generating completeness and purity plots...")
print()
try:
plot_completeness_purity(
evaluation_csv,
output_dir=output_dir,
bcg_csv=bcg_csv,
distance_threshold=10.0,
n_bins=10
)
print()
print("="*80)
print("SUCCESS!")
print("="*80)
print(f"Plots saved to:")
print(f" - {output_dir}/completeness_purity_plots.png")
print(f" - {output_dir}/completeness_purity_plots.pdf")
print()
except Exception as e:
print()
print("="*80)
print("ERROR!")
print("="*80)
print(f"Failed to generate plots: {e}")
import traceback
traceback.print_exc()
sys.exit(1)
if __name__ == "__main__":
main()