display_simulation_curves.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import numpy as np
  2. import pandas as pd
  3. import matplotlib.pyplot as plt
  4. import os, sys, getopt
  5. from modules.utils.data_type import get_svd_data
  6. label_freq = 6
  7. folder_path = "Curve_simulations"
  8. def display_curves(folder_path):
  9. data_files = os.listdir(folder_path)
  10. scene_names = [f.split('_')[3] for f in data_files]
  11. for id, f in enumerate(data_files):
  12. print(scene_names[id])
  13. path_file = os.path.join(folder_path, f)
  14. df = pd.read_csv(path_file, header=None, sep=";")
  15. fig=plt.figure(figsize=(8, 8))
  16. fig.suptitle("Detection simulation for " + scene_names[id] + " scene", fontsize=20)
  17. for index, row in df.iterrows():
  18. row = np.asarray(row)
  19. threshold = row[2]
  20. start_index = row[3]
  21. step_value = row[4]
  22. counter_index = 0
  23. current_value = start_index
  24. while(current_value < threshold):
  25. counter_index += 1
  26. current_value += step_value
  27. fig.add_subplot(4, 4, (index + 1))
  28. plt.plot(row[5:])
  29. # draw vertical line from (70,100) to (70, 250)
  30. plt.plot([counter_index, counter_index], [-2, 2], 'k-', lw=2, color='red')
  31. plt.ylabel('Not noisy / Noisy', fontsize=18)
  32. plt.xlabel('Time in minutes / Samples per pixel', fontsize=16)
  33. x_labels = [id * step_value + start_index for id, val in enumerate(row[5:]) if id % label_freq == 0]
  34. x = [v for v in np.arange(0, len(row[5:])+1) if v % label_freq == 0]
  35. plt.xticks(x, x_labels, rotation=45)
  36. plt.ylim(-1, 2)
  37. plt.show()
  38. def main():
  39. if len(sys.argv) <= 1:
  40. print('Run with default parameters...')
  41. print('python display_simulation_curves.py --folder "path"')
  42. sys.exit(2)
  43. try:
  44. opts, args = getopt.getopt(sys.argv[1:], "hm:s:k", ["help=", "folder="])
  45. except getopt.GetoptError:
  46. # print help information and exit:
  47. print('python display_simulation_curves.py --folder "path"')
  48. sys.exit(2)
  49. for o, a in opts:
  50. if o == "-h":
  51. print('python display_simulation_curves.py --folder "path"')
  52. sys.exit()
  53. elif o in ("-f", "--folder"):
  54. p_folder = a
  55. else:
  56. assert False, "unhandled option"
  57. display_curves(p_folder)
  58. if __name__== "__main__":
  59. main()