radar_chart.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import numpy as np
  2. import random
  3. import math
  4. import copy
  5. import os
  6. import sys
  7. sys.path.append("/home/vangogh/software/FuzzScene/code/")
  8. from generate_radar import *
  9. import Constants
  10. domain = [[0, 255], [0, 255], [0, 255], [1, 12], [8, 16], [30, 100], [0, 100], [0, 200]]
  11. ori_data = [[0, 0, 255], [3, 12], 85, 0, 200]
  12. def radar_sim(color1, color2, color3, time1, time2, sun, rain, fog, seed_name): # generate seed files, run simulations and collect data
  13. mutation_name = seed_name.split("_")
  14. complete_mutation_name = "seed_0_0_" + mutation_name[3]
  15. parse_path = "radar_seed_pool/" + complete_mutation_name
  16. DOMTree = xml.dom.minidom.parse(parse_path)
  17. ele = DOMTree.documentElement
  18. e = ele.getElementsByTagName("Entities")[0]
  19. s = ele.getElementsByTagName("Storyboard")[0]
  20. xml_path = 'radar_seed_pool/' + seed_name
  21. variable = {"name": "origin & random parameters"}
  22. rand_para = [color1, color2, color3, time1, time2, sun, rain, fog]
  23. Simulation(rand_para, variable, e, s)
  24. # print(variable)
  25. writeBack(xml_path, DOMTree)
  26. os.system("bash ./ga_sim.sh " + seed_name)
  27. # data_collection_para = str(data_collection_para[0]) + ',' + str(data_collection_para[1]) + ',' + str(
  28. # data_collection_para[2])
  29. # os.system("python radar_error_test.py " + model_name + " 1 " + seed_name + " " + data_collection_para)
  30. def rand_para(operator_num): # get random value of specified operator
  31. if operator_num == 0:
  32. color = []
  33. for i in range(0, 3):
  34. color.append(random.randint(0, 255))
  35. return color
  36. if operator_num == 1:
  37. date = []
  38. date.append(random.randint(1, 12))
  39. date.append(random.randint(8, 16))
  40. return date
  41. else:
  42. return random.randint(domain[operator_num + 3][0], domain[operator_num + 3][1])
  43. for operator in range(0, 5):
  44. if Constants.OPERATOR_FLAG[operator] is True:
  45. print("[" + os.path.basename(__file__) + ", Line " + str(sys._getframe().f_lineno) + ", " + sys._getframe().f_code.co_name + "] ", "# operator: ", operator)
  46. for random_time in range(1, Constants.RADAR_RAND_TIME + 1):
  47. print("[" + os.path.basename(__file__) + ", Line " + str(sys._getframe().f_lineno) + ", " + sys._getframe().f_code.co_name + "] ", "# random_time: ", random_time)
  48. for scene in range(1, Constants.SEED_NUM + 1):
  49. print("[" + os.path.basename(__file__) + ", Line " + str(sys._getframe().f_lineno) + ", " + sys._getframe().f_code.co_name + "] ", "# scene: ", scene)
  50. pop_seed_name = 'seed_' + str(operator) + '_' + str(random_time) + '_' + str(scene) + '.xosc'
  51. rand_data = copy.deepcopy(ori_data)
  52. rand_data[operator] = rand_para(operator)
  53. print("[" + os.path.basename(__file__) + ", Line " + str(sys._getframe().f_lineno) + ", " + sys._getframe().f_code.co_name + "] ", "pop_seed_name: ", pop_seed_name)
  54. print("[" + os.path.basename(__file__) + ", Line " + str(sys._getframe().f_lineno) + ", " + sys._getframe().f_code.co_name + "] ", "rand_data", rand_data)
  55. radar_sim(rand_data[0][0], rand_data[0][1], rand_data[0][2], rand_data[1][0], rand_data[1][1], rand_data[2], rand_data[3],
  56. rand_data[4], pop_seed_name)