display_simulation_curves.py 2.5 KB

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