display_simulation_curves.py 2.6 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 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=(35, 22))
  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.savefig(os.path.join(folder_path, scene_names[id] + '_simulation_curve.png'))
  42. #plt.show()
  43. def main():
  44. if len(sys.argv) <= 1:
  45. print('Run with default parameters...')
  46. print('python display_simulation_curves.py --folder "path"')
  47. sys.exit(2)
  48. try:
  49. opts, args = getopt.getopt(sys.argv[1:], "hm:s:k", ["help=", "folder="])
  50. except getopt.GetoptError:
  51. # print help information and exit:
  52. print('python display_simulation_curves.py --folder "path"')
  53. sys.exit(2)
  54. for o, a in opts:
  55. if o == "-h":
  56. print('python display_simulation_curves.py --folder "path"')
  57. sys.exit()
  58. elif o in ("-f", "--folder"):
  59. p_folder = a
  60. else:
  61. assert False, "unhandled option"
  62. display_curves(p_folder)
  63. if __name__== "__main__":
  64. main()