display_simulation_curves.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import numpy as np
  2. import pandas as pd
  3. import matplotlib.pyplot as plt
  4. import os, sys, argparse
  5. from modules.utils.data import get_svd_data
  6. from modules.utils import config as cfg
  7. learned_zones_folder = cfg.learned_zones_folder
  8. models_name = cfg.models_names_list
  9. label_freq = 6
  10. def display_curves(folder_path, model_name):
  11. """
  12. @brief Method used to display simulation given .csv files
  13. @param folder_path, folder which contains all .csv files obtained during simulation
  14. @param model_name, current name of model
  15. @return nothing
  16. """
  17. for name in models_name:
  18. print(name in model_name)
  19. if name in model_name:
  20. data_filename = model_name
  21. learned_zones_folder_path = os.path.join(learned_zones_folder, data_filename)
  22. print(learned_zones_folder_path)
  23. data_files = [x for x in os.listdir(folder_path) if '.png' not in x]
  24. scene_names = [f.split('_')[3] for f in data_files]
  25. print(scene_names)
  26. for id, f in enumerate(data_files):
  27. print(scene_names[id])
  28. path_file = os.path.join(folder_path, f)
  29. scenes_zones_used_file_path = os.path.join(learned_zones_folder_path, scene_names[id] + '.csv')
  30. zones_used = []
  31. with open(scenes_zones_used_file_path, 'r') as f:
  32. zones_used = [int(x) for x in f.readline().split(';') if x != '']
  33. print(zones_used)
  34. df = pd.read_csv(path_file, header=None, sep=";")
  35. fig=plt.figure(figsize=(35, 22))
  36. fig.suptitle("Detection simulation for " + scene_names[id] + " scene", fontsize=20)
  37. for index, row in df.iterrows():
  38. row = np.asarray(row)
  39. threshold = row[2]
  40. start_index = row[3]
  41. step_value = row[4]
  42. counter_index = 0
  43. current_value = start_index
  44. while(current_value < threshold):
  45. counter_index += 1
  46. current_value += step_value
  47. fig.add_subplot(4, 4, (index + 1))
  48. plt.plot(row[5:])
  49. if index in zones_used:
  50. ax = plt.gca()
  51. ax.set_facecolor((0.9, 0.95, 0.95))
  52. # draw vertical line from (70,100) to (70, 250)
  53. plt.plot([counter_index, counter_index], [-2, 2], 'k-', lw=2, color='red')
  54. plt.ylabel('Not noisy / Noisy', fontsize=18)
  55. plt.xlabel('Time in minutes / Samples per pixel', fontsize=16)
  56. x_labels = [id * step_value + start_index for id, val in enumerate(row[5:]) if id % label_freq == 0]
  57. x = [v for v in np.arange(0, len(row[5:])+1) if v % label_freq == 0]
  58. plt.xticks(x, x_labels, rotation=45)
  59. plt.ylim(-1, 2)
  60. plt.savefig(os.path.join(folder_path, scene_names[id] + '_simulation_curve.png'))
  61. #plt.show()
  62. def main():
  63. parser = argparse.ArgumentParser(description="Display simulations curves from simulation data")
  64. parser.add_argument('--folder', type=str, help='Folder which contains simulations data for scenes')
  65. parser.add_argument('--model', type=str, help='Name of the model used for simulations')
  66. args = parser.parse_args()
  67. p_folder = args.folder
  68. p_model = args.model
  69. display_curves(p_folder, p_model)
  70. if __name__== "__main__":
  71. main()