Guest User

Untitled

a guest
May 25th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. import xarray
  2. from scipy.stats import norm
  3. import numpy as np
  4. import matplotlib.mlab as mlab
  5. import matplotlib.pyplot as plt
  6.  
  7. list_indices = ['tasmax']
  8. indices = list_indices[0]
  9.  
  10. exp = ['CTL_E0', '121GPsc_E0']
  11. exp1 = '121GPsc_E0'
  12.  
  13. for i,ind in enumerate(exp):
  14. #print ind
  15.  
  16. #files = sorted(glob.glob('/g/data3/w97/dc8106/AMZ_def_EXPs/'+exp+'/tasmax_sc-only_1978-2011_'+exp+'.nc', chunks={'time':1000})
  17. #analysis/ensmean/'+indices+'/'+indices+'**_*diff_to_CTL.nc'))
  18. data = xarray.open_dataset('/g/data3/w97/dc8106/AMZ_def_EXPs/'+exp[i]+'/tasmax_sc-only_1978-2011_'+exp[i]+'.nc', chunks={'time':1000})
  19. #data1 = xarray.open_dataset('/g/data3/w97/dc8106/AMZ_def_EXPs/'+exp1+'/tasmax_sc-only_1978-2011_'+exp1+'.nc', chunks={'time':1000})
  20. tasmax = data.tasmax - 272.15
  21. #tasmax1 = data1.tasmax - 272.15
  22. #tasmin = data.tasmin
  23.  
  24. lat = data.lat
  25. lon = data.lon
  26. lons,lats = np.meshgrid(lon,lat)
  27.  
  28. ind_label = indices
  29.  
  30. print(tasmax)
  31. print("tasmax")
  32. print(tasmax.stack(dim=["lat","lon","time"]))
  33.  
  34. mu, sigma = tasmax.mean().values, tasmax.std().values
  35.  
  36. # Print the values of mu and sigma which forces them to be evaluated so I can see how long it takes to do this, then I can tune the time chunking
  37. print(mu,sigma)
  38.  
  39. # the histogram of the data \
  40.  
  41. n, bins, patches = plt.hist(tasmax.stack(dim=["lat","lon","time"]), bins = 1000, normed=1, facecolor='green', alpha=0.75)
  42. plt.xticks(np.arange(20, 50, 2.0))
  43. print(n)
  44. print(bins)
  45. print(patches)
  46.  
  47. # add a 'best fit' line \
  48.  
  49. y = mlab.normpdf( bins, mu, sigma)
  50. print(y)
  51.  
  52. l = plt.plot(bins, y, 'r--', label=ind, linewidth=10
  53. l_legend = plt.legend(handles=[l], loc=1)
  54.  
  55. l1 = plt.plot(bins, y, 'b--', label=ind, linewidth=1)
  56. l1_legend = plt.legend(handles=[l1], loc=1
  57.  
  58. units = 'Celsius'
  59.  
  60. plt.axis([20, 50, 0, 0.15])
  61. plt.xlabel(indices+' in '+units)
  62.  
  63. plt.suptitle(ind_label+ ' in ' +ind, fontsize=16)
  64.  
  65. #plt.savefig('/g/data3/w97/dc8106/images/'+ind_label+'_'+exp1, format='png')
  66.  
  67. # plt.ylabel('Probability')
  68. # plt.title(r'$\mathrm{Histogram of '+indices+'\ \mu='+mu+',\ \sigma='+sigma+')')
  69. #plt.axis([25, 45, 0, 0.03]) \
  70.  
  71. #plt.grid(True) \
  72.  
  73.  
  74. plt.show()
Add Comment
Please, Sign In to add comment