Advertisement
Guest User

Untitled

a guest
Sep 11th, 2023
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.23 KB | None | 0 0
  1.     import numpy as np
  2.     import matplotlib.pyplot as plt
  3.     import glob
  4.  
  5.     def get_data(fname):
  6.         with open(fname, 'r') as infile:
  7.             lines = infile.readlines()
  8.         SOE = [i for (i, line) in enumerate(lines) if 'SOE' in line][0]
  9.         EOE = [i for (i, line) in enumerate(lines) if 'EOE' in line][0]
  10.         lines = lines[SOE+1:EOE]
  11.         data = np.array([[float(x) for x in line.split(',')[2:8]]
  12.                          for line in lines])
  13.         position, velocity = data.T.reshape(2, 3, -1)
  14.         distance, speed = [np.sqrt((thing**2).sum(axis=0))
  15.                            for thing in (position, velocity)]
  16.         JD = np.array([float(line.split(',')[0]) for line in lines])
  17.         return lines, JD, distance, speed
  18.  
  19.     fnames = sorted(glob.glob('* horizons_results.txt'))
  20.  
  21.     titles = 'SS Barycenter', 'Sun'
  22.  
  23.     fig, (ax_bary, ax_Sun) = plt.subplots(2, 1)
  24.  
  25.     d_bary, d_Sun = [], []
  26.  
  27.  
  28.     for fname in fnames:
  29.         name, observer = fname.split()[:2]
  30.         lines, JD, distance, speed = get_data(fname)
  31.         if 'barycenter' in observer.lower():
  32.             ax_bary.plot(JD-JD[0]+1, distance/1E+09, label=name)
  33.             d_bary.append(distance)
  34.         else:
  35.             ax_Sun.plot(JD-JD[0]+1, distance/1E+09, label=name)
  36.             d_Sun.append(distance)
  37.         ax_bary.set_title('SS Barycenter')
  38.         ax_bary.set_ylabel('distance (km×10⁹)')
  39.         ax_bary.legend()
  40.         ax_Sun.set_title('Sun')
  41.         ax_Sun.set_ylabel('distance (km×10⁹)')
  42.         ax_Sun.legend()
  43.         ax_Sun.set_xlabel('day in July 2023 (UTC)')
  44.     diff_bary = d_bary[1] - d_bary[0]
  45.     diff_Sun = d_Sun[1] - d_Sun[0]
  46.     i_bary = np.argmax(diff_bary > 0)
  47.     i_Sun = np.argmax(diff_Sun > 0)
  48.     ax_bary.plot(JD[i_bary:i_bary+1]-JD[0]+1, d_bary[0][i_bary:i_bary+1]/1E+09, 'ok')
  49.     ax_Sun.plot(JD[i_Sun:i_Sun+1]-JD[0]+1, d_Sun[0][i_Sun:i_Sun+1]/1E+09, 'ok')
  50.     xy = (JD[i_bary]-JD[0]+1, d_bary[0][i_bary]/1E+09)
  51.     print('bary: ', xy[1])
  52.     date = lines[i_bary].split(',')[1][:-8]
  53.     ax_bary.annotate(date, xy)
  54.     xy = (JD[i_Sun]-JD[0]+1, d_Sun[0][i_Sun]/1E+09)
  55.     print('Sun: ', xy[1])
  56.     date = lines[i_Sun].split(',')[1][:-8]
  57.     ax_Sun.annotate(date, xy)
  58.     plt.show()
  59.  
  60.  
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement