clean_bess_data.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import math
  2. counter = 0
  3. with open("./Development/data_toclean.txt", "r") as ins:
  4. tmp = []
  5. for line in ins:
  6. print "WOW: ", line
  7. if line.strip() == "":
  8. print counter
  9. # edit data
  10. line1 = tmp[0].split(" ")
  11. new_name = line1[0]+"a"
  12. line1[0] = new_name
  13. line11 = tmp[11].split(" ")
  14. print line11
  15. infos = line11[-1].split("_")
  16. elevation = int(infos[1])
  17. angle = int(infos[2][0:2])
  18. direction = infos[2][-1]
  19. line8 = tmp[8].split(",")
  20. x_cur = float(line8[0].split("(")[1])
  21. z_cur = float(line8[1])
  22. y_cur = float(line8[2].split(")")[0])
  23. angle = 90 - angle
  24. if direction == "e":
  25. x = x_cur - (math.cos(math.radians(angle)) * (0.5 * math.cos(math.radians(elevation))))
  26. else:
  27. x = x_cur + (math.cos(math.radians(angle)) * (0.5 * math.cos(math.radians(elevation))))
  28. y = y_cur - (math.sin(math.radians(angle)) * (0.5 * math.cos(math.radians(elevation))))
  29. z = (elevation / 15 * 0.1) + z_cur
  30. print x_cur, z_cur, y_cur
  31. print new_name, elevation, angle, direction
  32. tmp[0] = " ".join(line1)
  33. line8_string = tmp[8]
  34. line8_string = new_name + line8_string[5:19] + ("%.3f" % x) + "," + " " + ("%.1f" % z) + "," + " " + ("%.3f" % y) + ");"
  35. tmp[8] = line8_string
  36. tmp[9] = new_name + tmp[9][5:]
  37. tmp[10] = new_name + tmp[10][5:]
  38. tmp[11] = new_name + tmp[11][5:28] + '01";'
  39. tmp[12] = tmp[12][0:10] + new_name + ");"
  40. tmp.pop()
  41. tmp.pop()
  42. with open("./Development/cleaned.txt", "a") as myfile:
  43. for item in tmp:
  44. myfile.write(item+"\n")
  45. myfile.write("\n")
  46. tmp = []
  47. counter += 1
  48. #if counter > 1:
  49. #break
  50. else:
  51. tmp.append(line.strip())