Advertisement
Guest User

Untitled

a guest
Mar 4th, 2019
567
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1.  
  2. from netCDF4 import Dataset
  3. import matplotlib.pyplot as plt
  4. import numpy as np
  5.  
  6.  
  7. # Rebin function from https://stackoverflow.com/questions/8090229/resize-with-averaging-or-rebin-a-numpy-2d-array
  8. def rebin(a, shape):
  9. sh = shape[0],a.shape[0]//shape[0],shape[1],a.shape[1]//shape[1]
  10. return a.reshape(sh).mean(-1).mean(1)
  11.  
  12. print("Converting, Please wait...")
  13.  
  14. g16nc = Dataset('GOES_16_CH02.nc', 'r')
  15.  
  16. g16nc.close()
  17. g16nc = None
  18.  
  19.  
  20. # Define some constants needed for the conversion. From the pdf linked above
  21. Esun_Ch_01 = 726.721072
  22. Esun_Ch_02 = 663.274497
  23. Esun_Ch_03 = 441.868715
  24. d2 = 0.3
  25.  
  26. # Apply the formula to convert radiance to reflectance
  27. ref = (radiance * np.pi * d2) / Esun_Ch_02
  28.  
  29. # Make sure all data is in the valid data range
  30. ref = np.maximum(ref, 0.0)
  31. ref = np.minimum(ref, 1.0)
  32.  
  33. # Apply the formula to adjust reflectance gamma
  34. ref_gamma = np.sqrt(ref)
  35.  
  36. # Load Channel 1 - Blue Visible
  37. g16nc = Dataset('GOES_16_CH01.nc', 'r')
  38. radiance_1 = g16nc.variables['Rad'][:]
  39. g16nc.close()
  40. g16nc = None
  41. ref_1 = (radiance_1 * np.pi * d2) / Esun_Ch_01
  42. # Make sure all data is in the valid data range
  43. ref_1 = np.maximum(ref_1, 0.0)
  44. ref_1 = np.minimum(ref_1, 1.0)
  45. ref_gamma_1 = np.sqrt(ref_1)
  46.  
  47. # Load Channel 3 - Veggie Near IR
  48. g16nc = Dataset('GOES_16_CH03.nc', 'r')
  49. radiance_3 = g16nc.variables['Rad'][:]
  50. g16nc.close()
  51. g16nc = None
  52. ref_3 = (radiance_3 * np.pi * d2) / Esun_Ch_03
  53. # Make sure all data is in the valid data range
  54. ref_3 = np.maximum(ref_3, 0.0)
  55. ref_3 = np.minimum(ref_3, 1.0)
  56. ref_gamma_3 = np.sqrt(ref_3)
  57.  
  58. ref_gamma_2 = rebin(ref_gamma, [3000, 5000])
  59.  
  60. geocolor = np.stack([ref_gamma_2, ref_gamma_3, ref_gamma_1], axis=2)
  61.  
  62. # Derived from Planet Labs data, CC > 0.9
  63. ref_gamma_true_green = 0.48358168 * ref_gamma_2 + 0.45706946 * ref_gamma_1 + 0.06038137 * ref_gamma_3
  64.  
  65. truecolor = np.stack([ref_gamma_2, ref_gamma_true_green, ref_gamma_1], axis=2)
  66. fig = plt.figure(figsize=(6,6),dpi=200)
  67. im = plt.imshow(truecolor)
  68. finalimag= np.array(truecolor)
  69. plt.title('TrueColor - Red - Psuedo-Green - Blue')
  70. plt.imsave("True-Color-Final.jpg",finalimag)
  71. print("Finished. File is saved as True-Color-Final.jpg")
  72. # plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement