entropy_get_results / clean_script.py
DanielSc4's picture
cleaned leftover from previous fix
1067020
#!/usr/bin/env python3
"""
Script to recursively find JSON files and replace 'np.float64' with 'np.float32'
"""
import os
import json
from pathlib import Path
def process_json_files(root_directory):
"""
Recursively scan directories for JSON files and replace np.float64 with np.float32
Args:
root_directory (str): The root directory to start scanning from
"""
root_path = Path(root_directory)
if not root_path.exists():
print(f"Error: Directory '{root_directory}' does not exist")
return
json_files_found = 0
json_files_modified = 0
# Recursively find all JSON files
for json_file in root_path.rglob("*.json"):
json_files_found += 1
print(f"Processing: {json_file}")
try:
# Read the file as text
with open(json_file, 'r', encoding='utf-8') as f:
content = f.read()
# Check if replacement is needed
string_to_replace = "_threshold': ("
if string_to_replace in content:
# "_threshold': ("
modified_content = content.replace(string_to_replace, "_threshold': " )
# modified_content = content.replace("np.float64", "")
# modified_content = modified_content.replace("), 'man", ", 'man")
# Write back to the same file
with open(json_file, 'w', encoding='utf-8') as f:
f.write(modified_content)
json_files_modified += 1
print(f" ✓ Modified: {json_file}")
else:
print(f" - No changes needed: {json_file}")
except Exception as e:
print(f" ✗ Error processing {json_file}: {e}")
print(f"\nSummary:")
print(f"JSON files found: {json_files_found}")
print(f"JSON files modified: {json_files_modified}")
def main():
"""Main function"""
# Get the current directory or specify your target directory
current_dir = "."
# You can change this to your specific directory path
# current_dir = "/path/to/your/directory"
print(f"Scanning directory: {os.path.abspath(current_dir)}")
print("Looking for JSON files to process...")
print("-" * 50)
process_json_files(current_dir)
if __name__ == "__main__":
main()