Advertisement
Guest User

Untitled

a guest
Jun 27th, 2020
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.23 KB | None | 0 0
  1. from skyfield.api import Loader, Topos
  2. from skyfield import almanac
  3. import numpy as np
  4. import matplotlib.pyplot as plt
  5.  
  6. halfpi, pi, twopi = [f*np.pi for f in (0.5, 1, 2)]
  7. to_degs, to_rads = 180/pi, pi/180
  8. r_sun, r_moon =  695700., 1738. # kilometers
  9.  
  10. load = Loader('~/Documents/fishing/SkyData')  # avoids multiple copies of large files
  11.  
  12. ts = load.timescale() # include builtin=True if you want to use older files (you may miss some leap-seconds)
  13. eph = load('de421.bsp')
  14. earth, sun, moon = [eph[x] for x in ('earth', 'sun', 'moon')]
  15.  
  16. time = ts.utc(2017, 8, 21, 18, 50)  # puts the Sun, Earth and Moon in almost the same plane
  17. epos, spos, mpos = [thing.at(time).ecliptic_position().km for thing in (earth, sun, moon)]
  18.  
  19. dpos = np.array([ 1.283504916395889E+08, -7.695767366817768E+07, -1.657242113438845E+05]) #  Horizons DSCOVR: 2457987.284722222, A.D. 2017-Aug-21 18:50:00.0000
  20. # DSCOVR: 2457987.284722222, A.D. 2017-Aug-21 18:50:00.0000,  1.283504916395889E+08, -7.695767366817768E+07, -1.657242113438845E+05,  1.488346029647132E+01,  2.515585471355211E+01,  4.287686810002356E-02,
  21.  
  22. # move Sun to origin for shadow producing reasons
  23. epos, spos, mpos, dpos = [pos - spos for pos in (epos, spos, mpos, dpos)]
  24.  
  25. # rotate around z to xy-plane
  26. theta = np.arctan2(epos[1], epos[0])
  27. # c, s, z, o = [f(-theta) for f in (np.cos, np.sin, np.zeros_like, np.ones_like)]
  28. # R1 = np.array([[c, -s, z], [s, c, z], [z, z, o]])
  29. # epos1, spos1, mpos1 = [(pos*R1).sum(axis=1) for pos in (epos, spos, mpos)]
  30. c, s = [f(-theta) for f in (np.cos, np.sin)]
  31. R1 = np.array([[c, -s, 0], [s, c, 0], [0, 0, 1]])
  32. epos1, spos1, mpos1, dpos1 = [(pos*R1).sum(axis=1) for pos in (epos, spos, mpos, dpos)]
  33.  
  34. # rotate around y to x-axis
  35. phi = np.arctan2(epos1[2], epos1[0])
  36. # c, s, z, o = [f(-phi) for f in (np.cos, np.sin, np.zeros_like, np.ones_like)]
  37. # R2 = np.array([[c, z, -s], [z, o, z], [s, z, c]])
  38. # epos2, spos2, mpos2 = [(pos*R2).sum(axis=1) for pos in (epos1, spos1, mpos1)]
  39. c, s = [f(-phi) for f in (np.cos, np.sin)]
  40. R2 = np.array([[c, 0, -s], [0, 1, 0], [s, 0, c]])
  41. epos2, spos2, mpos2, dpos2 = [(pos*R2).sum(axis=1) for pos in (epos1, spos1, mpos1, dpos1)]
  42.  
  43. # move everything to the geocenter
  44.  
  45. epos3, spos3, mpos3, dpos3 = [pos-epos2 for pos in (epos2, spos2, mpos2, dpos2)]
  46.  
  47. Re, Rm = 6378., 1737.
  48. Rd = 500. # small but not too small
  49.  
  50. plt.figure()
  51. colors = 'blue', 'green', 'black'
  52. radii = Re, Rm, Rd
  53. positions = epos3, mpos3, dpos3
  54. th = np.linspace(0, twopi, 201)
  55.  
  56. plt.figure()
  57. for pos, r, color in zip(positions, radii, colors):
  58.     x = pos[1] + r * np.cos(th)
  59.     y = pos[2] + r * np.sin(th)
  60.     plt.plot(x, y, color)
  61.     plt.gca().set_aspect('equal')
  62.     plt.title('YZ projection; Sun is behind you')
  63. plt.show()
  64.  
  65. plt.figure()
  66. plt.subplot(2, 1, 1)
  67. for pos, r, color in zip(positions, radii, colors):
  68.     x = pos[0] + r * np.cos(th)
  69.     y = pos[2] + r * np.sin(th)
  70.     plt.plot(x, y, color)
  71.     plt.gca().set_aspect('equal')
  72.     plt.title('XZ projection; Sun is to the left')
  73.  
  74. plt.subplot(2, 1, 2)
  75. for pos, r, color in zip(positions, radii, colors):
  76.     x = pos[0] + r * np.cos(th)
  77.     y = pos[1] + r * np.sin(th)
  78.     plt.plot(x, y, color)
  79.     plt.gca().set_aspect('equal')
  80.     plt.title('XY projection (top-down); Sun is to the left')
  81. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement