mirror_pattern.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import sys
  2. import os
  3. def reverse_theta(input_file, output_file):
  4. # Check if the input file exists
  5. if not os.path.isfile(input_file):
  6. print(f"Error: File '{input_file}' not found.")
  7. return
  8. # Read the input file and process
  9. with open(input_file, "r") as infile:
  10. lines = infile.readlines()
  11. with open(output_file, "w") as outfile:
  12. for line in lines:
  13. # Skip comment lines
  14. if line.startswith("#"):
  15. outfile.write(line)
  16. continue
  17. # Process lines with theta and rho values
  18. try:
  19. theta, rho = map(float, line.split())
  20. reversed_theta = -theta # Reverse the sign of theta
  21. outfile.write(f"{reversed_theta:.5f} {rho:.5f}\n")
  22. except ValueError:
  23. # Handle any lines that don't match the expected format
  24. outfile.write(line)
  25. print(f"Reversed file saved as: {output_file}")
  26. def main():
  27. if len(sys.argv) != 3:
  28. print("Usage: python reverse_theta.py <input_file.thr> <output_file.thr>")
  29. sys.exit(1)
  30. input_file = sys.argv[1]
  31. output_file = sys.argv[2]
  32. reverse_theta(input_file, output_file)
  33. if __name__ == "__main__":
  34. main()