Advertisement
Guest User

Untitled

a guest
Jul 30th, 2019
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1.     import numpy as np
  2.     import matplotlib.pyplot as plt
  3.  
  4.     halfpi, pi, twopi = [f*np.pi for f in (0.5, 1, 2)]
  5.     degs, rads = 180/pi, pi/180
  6.  
  7.     normals = np.vstack((np.eye(3), -np.eye(3)))
  8.  
  9.     theta = np.linspace(0, pi, 181)
  10.     phi   = np.linspace(-pi, pi, 361)
  11.  
  12.     Phi, Theta = np.meshgrid(phi, theta)
  13.  
  14.     (cp, sp), (ct, st) = [[f(thing) for f in (np.cos, np.sin)] for thing in (Phi, Theta)]
  15.  
  16.     directions = np.stack([cp*st, sp*st, ct])
  17.  
  18.     cos_thetas = [np.maximum((directions * normal[:, None, None]).sum(axis=0), 0) for normal in normals]
  19.  
  20.     if True:
  21.         plt.figure()
  22.         for i, (cth, normal) in enumerate(zip(cos_thetas, normals)):
  23.             plt.subplot(4, 3, i+1)
  24.             plt.imshow(cth)
  25.             # plt.colorbar()
  26.             plt.title(str(normal.astype(int)), fontsize=14)
  27.         cth = sum(cos_thetas)
  28.         plt.subplot(2, 1, 2)
  29.         plt.imshow(cth/cth.max(), vmin=0)
  30.         plt.colorbar()
  31.         plt.xlabel('phi (longitude)', fontsize=14)
  32.         plt.ylabel('theta (latitude)', fontsize=14)
  33.         plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement