Sun_processing1.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import pandas as pd
  2. import matplotlib
  3. import matplotlib.pyplot as plt
  4. import matplotlib.ticker as ticker
  5. from mpl_toolkits.mplot3d import Axes3D
  6. import matplotlib.animation as animation
  7. from tftb.processing.cohen import WignerVilleDistribution, PageRepresentation, MargenauHillDistribution
  8. from scipy.signal import hilbert, spectrogram, get_window
  9. import numpy as np
  10. from numpy import log as ln
  11. def one_3d_pick(x,y,z,len_step):
  12. fig = plt.figure(figsize=(10, 10))
  13. ax = plt.axes(projection='3d')
  14. ax.scatter(x[:len_step], y[:len_step], z[:len_step], marker=">", c='black')
  15. plt.show()
  16. def Anime(x, y, z, len_step):
  17. from matplotlib.animation import PillowWriter
  18. metadata = dict(title="Movie")
  19. writer = PillowWriter(fps=2, metadata=metadata)
  20. fig = plt.figure(figsize=(12, 12), dpi=100)
  21. ax = fig.add_subplot(projection='3d')
  22. def update(i):
  23. ax.clear()
  24. ax.scatter(x[i * len_step:i * len_step + len_step], y[i * len_step:i * len_step + len_step], z[i * len_step:i * len_step + len_step], s=0.5)
  25. plt.title(str(i * len_step))
  26. plt.xlabel('$Bx$', color='g')
  27. plt.ylabel('$By$', color='g')
  28. ax.set_zlabel('$Bz$')
  29. ani = animation.FuncAnimation(fig, update, np.arange(100), interval=1000, repeat=False)
  30. with writer.saving(fig, "Banimate-fix.gif", 100):
  31. for i in range(100):
  32. ax.clear()
  33. ax.scatter(x[i * len_step:i * len_step + len_step], y[i * len_step:i * len_step + len_step], z[i * len_step:i * len_step + len_step])
  34. plt.title(str(i * len_step))
  35. plt.xlabel('$Bx$', color='g')
  36. plt.ylabel('$By$', color='g')
  37. ax.set_zlabel('$Bz$')
  38. writer.grab_frame()
  39. plt.show()
  40. def Video(x, y, z, len_step):
  41. from matplotlib.animation import FFMpegWriter
  42. metadata = dict(title="Movie")
  43. writer2 = FFMpegWriter(fps=2, metadata=metadata)
  44. fig = plt.figure(figsize=(12, 12), dpi=100)
  45. ax = fig.add_subplot(projection='3d')
  46. with writer2.saving(fig, "Banimate.mp4", 100):
  47. for i in range(100):
  48. ax.clear()
  49. ax.scatter(x[i * len_step:i * len_step + len_step], y[i * len_step:i * len_step + len_step], z[i * len_step:i * len_step + len_step])
  50. plt.title(str(i*len_step))
  51. plt.xlabel('$Bx$', color='g')
  52. plt.ylabel('$By$', color='g')
  53. ax.set_zlabel('$Bz$')
  54. # ax.set_xlim(min(X), max(X))
  55. # ax.set_ylim(min(Y), max(Y))
  56. # ax.set_zlim(min(Z), max(Z))
  57. writer2.grab_frame()
  58. plt.show()
  59. fig = plt.figure(figsize=plt.figaspect(0.5))
  60. amoung = 3
  61. j = 1
  62. for i in range(24, 33):
  63. ax = fig.add_subplot(amoung, amoung, j, projection='3d')
  64. ax.scatter(x[i * len_step:i * len_step + len_step], y[i * len_step:i * len_step + len_step], z[i * len_step:i * len_step + len_step], s=0.01)
  65. ax.set_yticklabels([])
  66. ax.set_xticklabels([])
  67. ax.set_zticklabels([])
  68. j += 1
  69. plt.show()
  70. def Diagrams():
  71. X = df["Bx_GSE"]
  72. Y = df["By_GSE"]
  73. Z = df["Bz_GSE"]
  74. step = 5000
  75. one_3d_pick(X,Y,Z,step)
  76. #Anime(X, Y, Z, step)
  77. def ReadTable(file):
  78. arr = ["Year", "Day", "Hour", "Minute", "Sec", "Bx_GSE", "By_GSE", "Bz_GSE"]
  79. df = pd.read_table(file, names=arr, sep="\s+")
  80. for i in arr:
  81. df.loc[(df[i] > 9999)] = 0
  82. return df
  83. df = ReadTable('sun.lst')
  84. Diagrams()