Advertisement
Guest User

Untitled

a guest
Aug 7th, 2019
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.34 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import re
  4.  
  5. halfpi, pi, twopi = [f*np.pi for f in (0.5, 1, 2)]
  6. degs, rads        = 180/pi, pi/180.
  7.  
  8. fnames = ('horizons_results Sun from Apollo 14.txt',
  9.           'horizons_results Earth from Apollo 14.txt',
  10.           'horizons_results Sun from Apollo 12.txt',
  11.           'horizons_results Earth from Apollo 12.txt')
  12.  
  13. linez = []
  14. for fname in fnames:
  15.     with open(fname, 'r') as infile:
  16.         lines = infile.read().splitlines()
  17.     linez.append(lines)
  18.  
  19. data = []
  20. sun_angles = []
  21. for lines in linez:
  22.     iSOE = [i for i, line in enumerate(lines) if "$$SOE" in line][0]
  23.     iEOE = [i for i, line in enumerate(lines) if "$$EOE" in line][0]
  24.     hours, azimuths, elevations = [], [], []
  25.     SOTs, STOs = [], []
  26.     first_day = None
  27.     d_day     = 0
  28.     for line in lines[iSOE+1:iEOE]:
  29.         line = list(filter(None, re.split("[, ]+", line)))
  30.         day  = float(line[0].split('-')[2])
  31.         if first_day is None:
  32.             first_day = day
  33.         hour, minute = [float(x) for x in line[1].split(':')]
  34.         hours.append(float(hour) + float(minute)/60. + 24.*(day-first_day))
  35.         RA, Dec, Az, El = [float(x) for x in line[4:8]]
  36.         SOT, STO = [float(line[i]) for i in (12, 14)]
  37.         azimuths.append(Az)
  38.         elevations.append(El)
  39.         SOTs.append(SOT)
  40.         STOs.append(STO)
  41.     data.append((hours, azimuths, elevations))
  42.     sun_angles.append((hours, SOTs, STOs))
  43.     print ('hours min, max: ', min(hours), max(hours))
  44.  
  45.  
  46. fnames = ('horizons_results Sun from Apollo 14.txt',
  47.           'horizons_results Earth from Apollo 14.txt',
  48.           'horizons_results Sun from Apollo 12.txt',
  49.           'horizons_results Earth from Apollo 12.txt')
  50. Apollo_14_Sun, Apollo_14_Earth, Apollo_12_Sun, Apollo_12_Earth = data
  51. Apollo_14_SOT_STO, Apollo_12_SOT_STO = sun_angles[1::2]
  52.  
  53. if True:
  54.     plt.figure()
  55.  
  56.     plt.subplot(2, 1, 1)
  57.     plt.title('Apollo 12 Sun Earth angle', fontsize=16)
  58.     hours, SOT, STO = Apollo_12_SOT_STO
  59.     plt.plot(hours, SOT, linewidth=2)
  60.     plt.ylim(0, 180)
  61.  
  62.     plt.subplot(2, 1, 2)
  63.     plt.title('Apollo 14 Sun Earth angle', fontsize=16)
  64.     hours, SOT, STO = Apollo_12_SOT_STO
  65.     plt.plot(hours, SOT, linewidth=2)
  66.     plt.ylim(0, 180)
  67.  
  68.     plt.show()
  69.  
  70. if True:
  71.     plt.figure()
  72.  
  73.     plt.subplot(4, 1, 1)
  74.     plt.title('Apollo 12 Azimuth', fontsize=16)
  75.     hours, Az, El = Apollo_12_Sun
  76.     plt.plot(hours, Az, '-r', linewidth=2)
  77.     hours, Az, El = Apollo_12_Earth
  78.     plt.plot(hours, Az, '--b', linewidth=2)
  79.     plt.ylim(45, 135)
  80.    
  81.     plt.subplot(4, 1, 2)
  82.     plt.title('Apollo 12 Elevation', fontsize=16)
  83.     hours, Az, El = Apollo_12_Sun
  84.     plt.plot(hours, El, '-r', linewidth=2)
  85.     hours, Az, El = Apollo_12_Earth
  86.     plt.plot(hours, El, '--b', linewidth=2)
  87.     plt.ylim(0, 90)
  88.    
  89.     plt.subplot(4, 1, 3)
  90.     plt.title('Apollo 14 Azimuth', fontsize=16)
  91.     hours, Az, El = Apollo_14_Sun
  92.     plt.plot(hours, Az, '-r', linewidth=2)
  93.     hours, Az, El = Apollo_14_Earth
  94.     plt.plot(hours, Az, '--b', linewidth=2)
  95.     plt.ylim(45, 135)
  96.    
  97.     plt.subplot(4, 1, 4)
  98.     plt.title('Apollo 14 Elevation', fontsize=16)
  99.     hours, Az, El = Apollo_14_Sun
  100.     plt.plot(hours, El, '-r', linewidth=2)
  101.     hours, Az, El = Apollo_14_Earth
  102.     plt.plot(hours, El, '--b', linewidth=2)
  103.     plt.ylim(0, 90)
  104.    
  105.     plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement