Delete scripts
Browse files- scripts/cleanup.py +0 -33
- scripts/generate_scenes.py +0 -315
- scripts/run_raytracing.py +0 -169
scripts/cleanup.py
DELETED
|
@@ -1,33 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import shutil
|
| 3 |
-
|
| 4 |
-
def cleanup_generated_files():
|
| 5 |
-
"""Cleans up generated scene files and datasets."""
|
| 6 |
-
# Define directories to clean up
|
| 7 |
-
scenes_dir = os.path.join("data", "scenes")
|
| 8 |
-
datasets_dir = os.path.join("data", "datasets")
|
| 9 |
-
logs_dir = "logs"
|
| 10 |
-
|
| 11 |
-
# Remove scenes directory if it exists
|
| 12 |
-
if os.path.exists(scenes_dir):
|
| 13 |
-
shutil.rmtree(scenes_dir)
|
| 14 |
-
print(f"Removed directory: {scenes_dir}")
|
| 15 |
-
|
| 16 |
-
# Remove datasets directory if it exists
|
| 17 |
-
if os.path.exists(datasets_dir):
|
| 18 |
-
shutil.rmtree(datasets_dir)
|
| 19 |
-
print(f"Removed directory: {datasets_dir}")
|
| 20 |
-
|
| 21 |
-
# Remove logs directory if it exists
|
| 22 |
-
if os.path.exists(logs_dir):
|
| 23 |
-
shutil.rmtree(logs_dir)
|
| 24 |
-
print(f"Removed directory: {logs_dir}")
|
| 25 |
-
|
| 26 |
-
# Optionally, create the directories again for fresh use
|
| 27 |
-
os.makedirs(scenes_dir, exist_ok=True)
|
| 28 |
-
os.makedirs(datasets_dir, exist_ok=True)
|
| 29 |
-
os.makedirs(logs_dir, exist_ok=True)
|
| 30 |
-
print("Cleanup complete. Directories have been recreated.")
|
| 31 |
-
|
| 32 |
-
if __name__ == "__main__":
|
| 33 |
-
cleanup_generated_files()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scripts/generate_scenes.py
DELETED
|
@@ -1,315 +0,0 @@
|
|
| 1 |
-
import sys
|
| 2 |
-
import os
|
| 3 |
-
import argparse
|
| 4 |
-
import shutil
|
| 5 |
-
|
| 6 |
-
# Add project root to Python path
|
| 7 |
-
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 8 |
-
sys.path.insert(0, project_root)
|
| 9 |
-
|
| 10 |
-
from src.coordinate_generator import generate_random_coordinates
|
| 11 |
-
from src.scene_manager import SceneManager
|
| 12 |
-
from src.config_manager import ConfigManager
|
| 13 |
-
from src.utils.logging_utils import log_info, set_log_file
|
| 14 |
-
from src.utils.file_utils import ensure_directory_exists
|
| 15 |
-
|
| 16 |
-
def parse_arguments():
|
| 17 |
-
"""Parse command-line arguments (supports config overrides)"""
|
| 18 |
-
parser = argparse.ArgumentParser(description='Batch generate ray-tracing scenes')
|
| 19 |
-
|
| 20 |
-
# Config file arguments
|
| 21 |
-
parser.add_argument('--config', type=str,
|
| 22 |
-
help='Path to config file (default: configs/regions_config.yaml)')
|
| 23 |
-
parser.add_argument('--region', type=str,
|
| 24 |
-
help='Use a predefined region (e.g., hefei, beijing, shanghai)')
|
| 25 |
-
|
| 26 |
-
# Basic parameters (override config file)
|
| 27 |
-
parser.add_argument('--num-scenes', type=int,
|
| 28 |
-
help='Number of scenes to generate')
|
| 29 |
-
parser.add_argument('--center-lat', type=float,
|
| 30 |
-
help='Center latitude')
|
| 31 |
-
parser.add_argument('--center-lon', type=float,
|
| 32 |
-
help='Center longitude')
|
| 33 |
-
parser.add_argument('--radius-km', type=float,
|
| 34 |
-
help='Generation radius (km)')
|
| 35 |
-
parser.add_argument('--data-dir', type=str,
|
| 36 |
-
help='Data storage directory')
|
| 37 |
-
parser.add_argument('--log-file', type=str,
|
| 38 |
-
help='Log file path')
|
| 39 |
-
parser.add_argument('--size-x', type=int,
|
| 40 |
-
help='Scene size X (meters)')
|
| 41 |
-
parser.add_argument('--size-y', type=int,
|
| 42 |
-
help='Scene size Y (meters)')
|
| 43 |
-
|
| 44 |
-
# Generation mode parameters
|
| 45 |
-
parser.add_argument('--generation-mode', type=str,
|
| 46 |
-
choices=['fallback', 'osm_retry'],
|
| 47 |
-
help='Scene generation mode')
|
| 48 |
-
parser.add_argument('--max-osm-attempts', type=int,
|
| 49 |
-
help='Max attempts in OSM retry mode')
|
| 50 |
-
parser.add_argument('--search-radius-km', type=float,
|
| 51 |
-
help='Search radius in OSM retry mode (km)')
|
| 52 |
-
|
| 53 |
-
# Other parameters
|
| 54 |
-
parser.add_argument('--list-regions', action='store_true',
|
| 55 |
-
help='List all available regions and exit')
|
| 56 |
-
parser.add_argument('--show-config', action='store_true',
|
| 57 |
-
help='Show current configuration and exit')
|
| 58 |
-
|
| 59 |
-
return parser.parse_args()
|
| 60 |
-
|
| 61 |
-
def main():
|
| 62 |
-
"""Main function"""
|
| 63 |
-
args = parse_arguments()
|
| 64 |
-
|
| 65 |
-
# Initialize config manager
|
| 66 |
-
config_manager = ConfigManager(args.config)
|
| 67 |
-
|
| 68 |
-
# Handle special commands
|
| 69 |
-
if args.list_regions:
|
| 70 |
-
regions = config_manager.list_available_regions()
|
| 71 |
-
print("Available regions:")
|
| 72 |
-
for region in regions:
|
| 73 |
-
region_config = config_manager.get_region_config(region)
|
| 74 |
-
print(f" {region}: {region_config.get('name', 'Unnamed')} - "
|
| 75 |
-
f"({region_config.get('center_lat')}, {region_config.get('center_lon')})")
|
| 76 |
-
return True
|
| 77 |
-
|
| 78 |
-
if args.show_config:
|
| 79 |
-
print("Current configuration:")
|
| 80 |
-
print(f" Config file: {config_manager.config_file_path}")
|
| 81 |
-
print(f" Default region: {config_manager.get('default_region.name', 'Not set')}")
|
| 82 |
-
print(f" Generation mode: {config_manager.get('scene_generation.generation_mode', 'Not set')}")
|
| 83 |
-
print(f" Data directory: {config_manager.get('data_storage.base_data_dir', 'Not set')}")
|
| 84 |
-
return True
|
| 85 |
-
|
| 86 |
-
# Merge config file and CLI args
|
| 87 |
-
config = config_manager.merge_with_args(args)
|
| 88 |
-
|
| 89 |
-
# If a region is specified, use its config
|
| 90 |
-
if args.region:
|
| 91 |
-
region_config = config_manager.get_region_config(args.region)
|
| 92 |
-
if region_config:
|
| 93 |
-
config.update(region_config)
|
| 94 |
-
log_info(f"Using region config: {args.region} - {region_config.get('name', 'Unnamed')}")
|
| 95 |
-
|
| 96 |
-
# Set up logging
|
| 97 |
-
ensure_directory_exists('logs')
|
| 98 |
-
set_log_file(config['log_file'])
|
| 99 |
-
|
| 100 |
-
# Ensure data directory exists
|
| 101 |
-
data_dir_abs = os.path.abspath(config['data_dir'])
|
| 102 |
-
if not ensure_directory_exists(data_dir_abs):
|
| 103 |
-
log_info(f"Failed to create data directory: {data_dir_abs}")
|
| 104 |
-
return False
|
| 105 |
-
|
| 106 |
-
# Show configuration info
|
| 107 |
-
log_info(f"Start generating {config['num_scenes']} scenes")
|
| 108 |
-
log_info(f"Center coordinates: ({config['center_lat']}, {config['center_lon']})")
|
| 109 |
-
log_info(f"Generation radius: {config['radius_km']} km")
|
| 110 |
-
log_info(f"Scene size: {config['size_x']}x{config['size_y']} meters")
|
| 111 |
-
log_info(f"Data directory: {data_dir_abs}")
|
| 112 |
-
log_info(f"Generation mode: {config['generation_mode']}")
|
| 113 |
-
|
| 114 |
-
if config['generation_mode'] == 'fallback':
|
| 115 |
-
log_info("Strategy: Prefer OSM data; if it fails, automatically generate random building scenes")
|
| 116 |
-
elif config['generation_mode'] == 'osm_retry':
|
| 117 |
-
log_info("Strategy: Prefer OSM data; if it fails, re-sample within search radius and retry OSM")
|
| 118 |
-
log_info(f"OSM retry params - Max attempts: {config['max_osm_attempts']}, "
|
| 119 |
-
f"Search radius: {config['search_radius_km']}km")
|
| 120 |
-
|
| 121 |
-
# Generate random coordinates
|
| 122 |
-
coordinates = generate_random_coordinates(
|
| 123 |
-
center_lat=config['center_lat'],
|
| 124 |
-
center_lon=config['center_lon'],
|
| 125 |
-
radius_km=config['radius_km'],
|
| 126 |
-
num_points=config['num_scenes']
|
| 127 |
-
)
|
| 128 |
-
|
| 129 |
-
log_info(f"Generated {len(coordinates)} coordinate points")
|
| 130 |
-
|
| 131 |
-
# Initialize scene manager
|
| 132 |
-
scene_manager = SceneManager(config_manager)
|
| 133 |
-
|
| 134 |
-
# Batch generate scenes
|
| 135 |
-
successful_scenes = scene_manager.batch_generate_scenes(
|
| 136 |
-
coordinates,
|
| 137 |
-
generation_mode=config['generation_mode'],
|
| 138 |
-
max_osm_attempts=config['max_osm_attempts'],
|
| 139 |
-
search_radius_km=config['search_radius_km']
|
| 140 |
-
)
|
| 141 |
-
|
| 142 |
-
log_info(f"Scene generation completed! Success: {len(successful_scenes)}/{len(coordinates)}")
|
| 143 |
-
|
| 144 |
-
# Show details of generated scenes
|
| 145 |
-
if successful_scenes:
|
| 146 |
-
log_info("Details of successfully generated scenes:")
|
| 147 |
-
osm_scenes = []
|
| 148 |
-
random_scenes = []
|
| 149 |
-
|
| 150 |
-
for i, scene_result in enumerate(successful_scenes, 1):
|
| 151 |
-
scene_file = scene_result['scene_file']
|
| 152 |
-
generation_type = scene_result['generation_type']
|
| 153 |
-
attempts = scene_result['attempts']
|
| 154 |
-
original_coords = scene_result['original_coordinates']
|
| 155 |
-
actual_coords = scene_result['coordinates']
|
| 156 |
-
|
| 157 |
-
log_info(f" {i}. {os.path.basename(os.path.dirname(scene_file))} - "
|
| 158 |
-
f"Type: {generation_type} - Attempts: {attempts} times")
|
| 159 |
-
log_info(f" Original coordinates: ({original_coords[0]:.6f}, {original_coords[1]:.6f})")
|
| 160 |
-
|
| 161 |
-
if generation_type == 'OSM':
|
| 162 |
-
osm_scenes.append(scene_result)
|
| 163 |
-
if 'distance_from_original' in scene_result:
|
| 164 |
-
distance = scene_result['distance_from_original']
|
| 165 |
-
log_info(f" Actual coordinates: ({actual_coords[0]:.6f}, {actual_coords[1]:.6f}) "
|
| 166 |
-
f"Offset: {distance:.2f}km")
|
| 167 |
-
else:
|
| 168 |
-
log_info(f" Actual coordinates: ({actual_coords[0]:.6f}, {actual_coords[1]:.6f}) "
|
| 169 |
-
f"Offset: 0.00km")
|
| 170 |
-
else:
|
| 171 |
-
random_scenes.append(scene_result)
|
| 172 |
-
log_info(f" Actual coordinates: ({actual_coords[0]:.6f}, {actual_coords[1]:.6f})")
|
| 173 |
-
|
| 174 |
-
# Statistics
|
| 175 |
-
log_info(f"\nScene type statistics:")
|
| 176 |
-
log_info(f" OSM scenes: {len(osm_scenes)}")
|
| 177 |
-
log_info(f" Random scenes: {len(random_scenes)}")
|
| 178 |
-
|
| 179 |
-
if config['generation_mode'] == 'osm_retry' and osm_scenes:
|
| 180 |
-
total_attempts = sum(s['attempts'] for s in osm_scenes)
|
| 181 |
-
avg_attempts = total_attempts / len(osm_scenes)
|
| 182 |
-
total_distance = sum(s.get('distance_from_original', 0) for s in osm_scenes)
|
| 183 |
-
avg_distance = total_distance / len(osm_scenes)
|
| 184 |
-
log_info(f" Average attempts for OSM scenes: {avg_attempts:.1f}")
|
| 185 |
-
log_info(f" Average offset distance for OSM scenes: {avg_distance:.2f}km")
|
| 186 |
-
|
| 187 |
-
# Adjust scene directory names by removing _attempt/_random suffixes
|
| 188 |
-
successful_scenes = sanitize_scene_directories(successful_scenes)
|
| 189 |
-
|
| 190 |
-
# Save generation results
|
| 191 |
-
save_generation_results(successful_scenes, coordinates, config, data_dir_abs)
|
| 192 |
-
|
| 193 |
-
return len(successful_scenes) > 0
|
| 194 |
-
|
| 195 |
-
def sanitize_scene_directories(scenes):
|
| 196 |
-
"""Remove _attempt/_random suffix from scene directory names"""
|
| 197 |
-
sanitized = []
|
| 198 |
-
for scene in scenes:
|
| 199 |
-
scene_file = scene.get('scene_file')
|
| 200 |
-
if not scene_file:
|
| 201 |
-
sanitized.append(scene)
|
| 202 |
-
continue
|
| 203 |
-
scene_dir = os.path.dirname(scene_file)
|
| 204 |
-
original_name = os.path.basename(scene_dir)
|
| 205 |
-
stripped_name = _strip_scene_suffix(original_name)
|
| 206 |
-
if stripped_name == original_name:
|
| 207 |
-
sanitized.append(scene)
|
| 208 |
-
continue
|
| 209 |
-
parent_dir = os.path.dirname(scene_dir)
|
| 210 |
-
new_dir = os.path.join(parent_dir, stripped_name)
|
| 211 |
-
if os.path.exists(new_dir):
|
| 212 |
-
shutil.rmtree(new_dir)
|
| 213 |
-
os.rename(scene_dir, new_dir)
|
| 214 |
-
updated_scene = dict(scene)
|
| 215 |
-
updated_scene['scene_file'] = os.path.join(new_dir, os.path.basename(scene_file))
|
| 216 |
-
if 'scene_directory' in updated_scene:
|
| 217 |
-
updated_scene['scene_directory'] = new_dir
|
| 218 |
-
sanitized.append(updated_scene)
|
| 219 |
-
return sanitized
|
| 220 |
-
|
| 221 |
-
def _strip_scene_suffix(name: str) -> str:
|
| 222 |
-
"""Remove suffixes like _attempt/_random from scene directory names"""
|
| 223 |
-
if '_attempt_' in name:
|
| 224 |
-
return name.split('_attempt_')[0]
|
| 225 |
-
if name.endswith('_random'):
|
| 226 |
-
return name[:-7]
|
| 227 |
-
return name
|
| 228 |
-
|
| 229 |
-
def save_generation_results(successful_scenes, coordinates, config, data_dir_abs):
|
| 230 |
-
"""Save generation results to files"""
|
| 231 |
-
# Save list of successful scenes
|
| 232 |
-
scenes_list_file = os.path.join(data_dir_abs, 'generated_scenes.txt')
|
| 233 |
-
try:
|
| 234 |
-
with open(scenes_list_file, 'w', encoding='utf-8') as f:
|
| 235 |
-
f.write(f"# Generated scene list\n")
|
| 236 |
-
f.write(f"# Total: {len(successful_scenes)}/{len(coordinates)}\n")
|
| 237 |
-
f.write(f"# Generation time: {os.popen('date').read().strip()}\n")
|
| 238 |
-
f.write(f"# Center coordinates: ({config['center_lat']}, {config['center_lon']})\n")
|
| 239 |
-
f.write(f"# Generation radius: {config['radius_km']} km\n")
|
| 240 |
-
f.write(f"# Scene size: {config['size_x']}x{config['size_y']} meters\n")
|
| 241 |
-
f.write(f"# Generation mode: {config['generation_mode']}\n")
|
| 242 |
-
if config['generation_mode'] == 'osm_retry':
|
| 243 |
-
f.write(f"# OSM retry params: max attempts {config['max_osm_attempts']}, search radius {config['search_radius_km']}km\n")
|
| 244 |
-
f.write(f"\n")
|
| 245 |
-
f.write(f"# Format: scene_file_path\toriginal_lat\toriginal_lon\tactual_lat\tactual_lon\tgeneration_type\tattempts\toffset_distance(km)\n")
|
| 246 |
-
|
| 247 |
-
for scene_result in successful_scenes:
|
| 248 |
-
scene_file = scene_result['scene_file']
|
| 249 |
-
original_coords = scene_result['original_coordinates']
|
| 250 |
-
actual_coords = scene_result['coordinates']
|
| 251 |
-
generation_type = scene_result['generation_type']
|
| 252 |
-
attempts = scene_result['attempts']
|
| 253 |
-
distance = scene_result.get('distance_from_original', 0.0)
|
| 254 |
-
|
| 255 |
-
f.write(f"{scene_file}\t{original_coords[0]:.6f}\t{original_coords[1]:.6f}\t"
|
| 256 |
-
f"{actual_coords[0]:.6f}\t{actual_coords[1]:.6f}\t{generation_type}\t"
|
| 257 |
-
f"{attempts}\t{distance:.2f}\n")
|
| 258 |
-
|
| 259 |
-
log_info(f"Scene list saved to: {scenes_list_file}")
|
| 260 |
-
except Exception as e:
|
| 261 |
-
log_info(f"Failed to save scene list: {e}")
|
| 262 |
-
|
| 263 |
-
# Generate scene statistics report
|
| 264 |
-
try:
|
| 265 |
-
stats_file = os.path.join(data_dir_abs, 'generation_stats.txt')
|
| 266 |
-
osm_scenes = [s for s in successful_scenes if s['generation_type'] == 'OSM']
|
| 267 |
-
random_scenes = [s for s in successful_scenes if s['generation_type'] == 'Random']
|
| 268 |
-
|
| 269 |
-
with open(stats_file, 'w', encoding='utf-8') as f:
|
| 270 |
-
f.write("Scene generation statistics report\n")
|
| 271 |
-
f.write("=" * 50 + "\n")
|
| 272 |
-
f.write(f"Requested scene count: {len(coordinates)}\n")
|
| 273 |
-
f.write(f"Successfully generated scenes: {len(successful_scenes)}\n")
|
| 274 |
-
f.write(f"Failed scene count: {len(coordinates) - len(successful_scenes)}\n")
|
| 275 |
-
f.write(f"Success rate: {len(successful_scenes)/len(coordinates)*100:.1f}%\n")
|
| 276 |
-
f.write(f"Center coordinates: ({config['center_lat']}, {config['center_lon']})\n")
|
| 277 |
-
f.write(f"Generation radius: {config['radius_km']} km\n")
|
| 278 |
-
f.write(f"Scene size: {config['size_x']}x{config['size_y']} meters\n")
|
| 279 |
-
f.write(f"Generation mode: {config['generation_mode']}\n")
|
| 280 |
-
|
| 281 |
-
f.write(f"\nScene type statistics:\n")
|
| 282 |
-
f.write(f"OSM scenes: {len(osm_scenes)} ({len(osm_scenes)/len(successful_scenes)*100:.1f}%)\n")
|
| 283 |
-
f.write(f"Random scenes: {len(random_scenes)} ({len(random_scenes)/len(successful_scenes)*100:.1f}%)\n")
|
| 284 |
-
|
| 285 |
-
if config['generation_mode'] == 'osm_retry' and osm_scenes:
|
| 286 |
-
total_attempts = sum(s['attempts'] for s in osm_scenes)
|
| 287 |
-
avg_attempts = total_attempts / len(osm_scenes)
|
| 288 |
-
total_distance = sum(s.get('distance_from_original', 0) for s in osm_scenes)
|
| 289 |
-
avg_distance = total_distance / len(osm_scenes)
|
| 290 |
-
|
| 291 |
-
f.write(f"\nOSM retry statistics:\n")
|
| 292 |
-
f.write(f"Configured max attempts: {config['max_osm_attempts']}\n")
|
| 293 |
-
f.write(f"Configured search radius: {config['search_radius_km']} km\n")
|
| 294 |
-
f.write(f"Average attempts: {avg_attempts:.1f}\n")
|
| 295 |
-
f.write(f"Average offset distance: {avg_distance:.2f} km\n")
|
| 296 |
-
f.write(f"Total attempts: {total_attempts}\n")
|
| 297 |
-
|
| 298 |
-
# Attempt count distribution
|
| 299 |
-
attempt_counts = {}
|
| 300 |
-
for s in osm_scenes:
|
| 301 |
-
attempts = s['attempts']
|
| 302 |
-
attempt_counts[attempts] = attempt_counts.get(attempts, 0) + 1
|
| 303 |
-
|
| 304 |
-
f.write(f"\nAttempts distribution:\n")
|
| 305 |
-
for attempts in sorted(attempt_counts.keys()):
|
| 306 |
-
count = attempt_counts[attempts]
|
| 307 |
-
f.write(f" {attempts} times: {count} scenes\n")
|
| 308 |
-
|
| 309 |
-
log_info(f"Statistics report saved to: {stats_file}")
|
| 310 |
-
except Exception as e:
|
| 311 |
-
log_info(f"Failed to save statistics report: {e}")
|
| 312 |
-
|
| 313 |
-
if __name__ == "__main__":
|
| 314 |
-
success = main()
|
| 315 |
-
exit(0 if success else 1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scripts/run_raytracing.py
DELETED
|
@@ -1,169 +0,0 @@
|
|
| 1 |
-
import sys
|
| 2 |
-
import os
|
| 3 |
-
import argparse
|
| 4 |
-
|
| 5 |
-
# Add project root to Python path
|
| 6 |
-
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 7 |
-
sys.path.insert(0, project_root)
|
| 8 |
-
|
| 9 |
-
from src.raytracer.raytracing_manager import RaytracingManager
|
| 10 |
-
from src.config_manager import ConfigManager
|
| 11 |
-
from src.utils.logging_utils import log_info, set_log_file
|
| 12 |
-
from src.utils.file_utils import ensure_directory_exists
|
| 13 |
-
|
| 14 |
-
def parse_arguments():
|
| 15 |
-
"""Parse command-line arguments"""
|
| 16 |
-
parser = argparse.ArgumentParser(description='Batch execute ray tracing')
|
| 17 |
-
|
| 18 |
-
# Config file arguments
|
| 19 |
-
parser.add_argument('--config', type=str,
|
| 20 |
-
help='Config file path (default: configs/regions_config.yaml)')
|
| 21 |
-
|
| 22 |
-
# Ray tracing parameters
|
| 23 |
-
parser.add_argument('--scenes-dir', type=str,
|
| 24 |
-
help='Scenes directory path')
|
| 25 |
-
parser.add_argument('--results-dir', type=str,
|
| 26 |
-
help='Results output directory')
|
| 27 |
-
parser.add_argument('--max-workers', type=int, default=None,
|
| 28 |
-
help='Maximum parallel workers (default uses config file)')
|
| 29 |
-
parser.add_argument('--gpu-mode', type=str,
|
| 30 |
-
choices=['auto', 'all', 'cpu_only'],
|
| 31 |
-
help='GPU usage mode')
|
| 32 |
-
|
| 33 |
-
# Scene selection parameters
|
| 34 |
-
parser.add_argument('--scene-pattern', type=str,
|
| 35 |
-
help='Scene name matching pattern')
|
| 36 |
-
parser.add_argument('--max-scenes', type=int,
|
| 37 |
-
help='Maximum number of scenes to process')
|
| 38 |
-
|
| 39 |
-
# Other parameters
|
| 40 |
-
parser.add_argument('--log-file', type=str,
|
| 41 |
-
help='Log file path')
|
| 42 |
-
parser.add_argument('--show-config', action='store_true',
|
| 43 |
-
help='Show current configuration and exit')
|
| 44 |
-
parser.add_argument('--list-scenes', action='store_true',
|
| 45 |
-
help='List available scenes and exit')
|
| 46 |
-
|
| 47 |
-
return parser.parse_args()
|
| 48 |
-
|
| 49 |
-
def safe_get_frequency(raytracing_config, default=3.66e9):
|
| 50 |
-
"""Safely get frequency value, handling string and numeric types"""
|
| 51 |
-
try:
|
| 52 |
-
frequency = raytracing_config.get('simulation', {}).get('frequency', default)
|
| 53 |
-
# If it is a string, try to convert to float
|
| 54 |
-
if isinstance(frequency, str):
|
| 55 |
-
frequency = float(frequency)
|
| 56 |
-
return frequency
|
| 57 |
-
except (ValueError, TypeError):
|
| 58 |
-
log_info(f"Warning: Failed to parse frequency value, using default {default/1e9:.2f} GHz")
|
| 59 |
-
return default
|
| 60 |
-
|
| 61 |
-
def main():
|
| 62 |
-
"""Main function"""
|
| 63 |
-
args = parse_arguments()
|
| 64 |
-
|
| 65 |
-
# Initialize config manager
|
| 66 |
-
config_manager = ConfigManager(args.config)
|
| 67 |
-
|
| 68 |
-
# Handle special commands
|
| 69 |
-
if args.show_config:
|
| 70 |
-
print("Current ray tracing configuration:")
|
| 71 |
-
raytracing_config = config_manager.get('raytracing', {})
|
| 72 |
-
print(f" Engine: {raytracing_config.get('engine', 'Not set')}")
|
| 73 |
-
print(f" GPU mode: {raytracing_config.get('gpu_config', {}).get('gpu_mode', 'Not set')}")
|
| 74 |
-
print(f" Max parallel jobs: {raytracing_config.get('max_parallel_jobs', 'Not set')}")
|
| 75 |
-
|
| 76 |
-
# Safely get frequency
|
| 77 |
-
frequency = safe_get_frequency(raytracing_config)
|
| 78 |
-
print(f" Frequency: {frequency/1e9:.2f} GHz")
|
| 79 |
-
|
| 80 |
-
# Show visualization configuration
|
| 81 |
-
viz_config = config_manager.get('visualization', {})
|
| 82 |
-
print(f" Heatmap generation: {'Enabled' if viz_config.get('enabled', False) else 'Disabled'}")
|
| 83 |
-
return True
|
| 84 |
-
|
| 85 |
-
# Merge config file and CLI args
|
| 86 |
-
effective_workers = args.max_workers if args.max_workers is not None else config_manager.get(
|
| 87 |
-
'raytracing.max_parallel_jobs', 1
|
| 88 |
-
) or 1
|
| 89 |
-
if args.gpu_mode:
|
| 90 |
-
config_manager.config.setdefault('raytracing', {}).setdefault('gpu_config', {})['gpu_mode'] = args.gpu_mode
|
| 91 |
-
config_manager.config.setdefault('raytracing', {}).setdefault('gpu_config', {})
|
| 92 |
-
config_manager.config['raytracing']['max_parallel_jobs'] = effective_workers
|
| 93 |
-
|
| 94 |
-
# Ensure visualization config exists
|
| 95 |
-
if 'visualization' not in config_manager.config:
|
| 96 |
-
config_manager.config['visualization'] = {
|
| 97 |
-
'enabled': True,
|
| 98 |
-
'point_size': 50,
|
| 99 |
-
'dpi': 300
|
| 100 |
-
}
|
| 101 |
-
|
| 102 |
-
# Fill in minimum samples ratio default
|
| 103 |
-
sim_cfg = config_manager.config.setdefault('raytracing', {}).setdefault('simulation', {})
|
| 104 |
-
sim_cfg.setdefault('min_samples_ratio', 0.5)
|
| 105 |
-
|
| 106 |
-
# Set up logging
|
| 107 |
-
log_file = args.log_file or 'logs/raytracing.log'
|
| 108 |
-
ensure_directory_exists('logs')
|
| 109 |
-
set_log_file(log_file)
|
| 110 |
-
|
| 111 |
-
# Initialize ray tracing manager
|
| 112 |
-
raytracing_manager = RaytracingManager(config_manager)
|
| 113 |
-
|
| 114 |
-
# Discover scenes
|
| 115 |
-
scenes = raytracing_manager.discover_scenes()
|
| 116 |
-
|
| 117 |
-
if args.list_scenes:
|
| 118 |
-
print(f"Found {len(scenes)} available scenes:")
|
| 119 |
-
for scene in scenes:
|
| 120 |
-
print(f" {scene['scene_name']} - ({scene['latitude']:.6f}, {scene['longitude']:.6f})")
|
| 121 |
-
return True
|
| 122 |
-
|
| 123 |
-
if not scenes:
|
| 124 |
-
log_info("No available scene files found")
|
| 125 |
-
return False
|
| 126 |
-
|
| 127 |
-
# Filter scenes
|
| 128 |
-
if args.scene_pattern:
|
| 129 |
-
scenes = [s for s in scenes if args.scene_pattern in s['scene_name']]
|
| 130 |
-
log_info(f"After filtering by pattern '{args.scene_pattern}', {len(scenes)} scenes remain")
|
| 131 |
-
|
| 132 |
-
if args.max_scenes and len(scenes) > args.max_scenes:
|
| 133 |
-
scenes = scenes[:args.max_scenes]
|
| 134 |
-
log_info(f"Limiting number of scenes to process to {args.max_scenes}")
|
| 135 |
-
|
| 136 |
-
# Display configuration info
|
| 137 |
-
raytracing_config = config_manager.get('raytracing', {})
|
| 138 |
-
log_info(f"Starting ray tracing, scene count: {len(scenes)}")
|
| 139 |
-
log_info(f"Engine: {raytracing_config.get('engine', 'sionna')}")
|
| 140 |
-
log_info(f"GPU mode: {raytracing_config.get('gpu_config', {}).get('gpu_mode', 'auto')}")
|
| 141 |
-
|
| 142 |
-
# Safely get and display frequency
|
| 143 |
-
frequency = safe_get_frequency(raytracing_config)
|
| 144 |
-
log_info(f"Frequency: {frequency/1e9:.2f} GHz")
|
| 145 |
-
log_info(f"Max parallel jobs: {raytracing_config.get('max_parallel_jobs', 1)}")
|
| 146 |
-
|
| 147 |
-
# Execute ray tracing
|
| 148 |
-
results = raytracing_manager.run_batch_raytracing(scenes, max_workers=effective_workers)
|
| 149 |
-
|
| 150 |
-
# Display results
|
| 151 |
-
successful_results = [r for r in results if r['success']]
|
| 152 |
-
log_info(f"Ray tracing completed! Success: {len(successful_results)}/{len(scenes)}")
|
| 153 |
-
|
| 154 |
-
if successful_results:
|
| 155 |
-
log_info("Successfully processed scenes:")
|
| 156 |
-
for result in successful_results:
|
| 157 |
-
scene_name = result['scene_info']['scene_name']
|
| 158 |
-
execution_time = result['execution_time']
|
| 159 |
-
num_paths = result.get('num_paths', 0)
|
| 160 |
-
num_receivers = result.get('num_receivers', 0)
|
| 161 |
-
|
| 162 |
-
log_info(f" {scene_name}: {execution_time:.1f}s, "
|
| 163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