Posted By

shrad on 09/11/08


Tagged


Versions (?)

map plotting python code (temporary)


 / Published in: Python
 

  1. from mpl_toolkits.basemap import Basemap
  2. from scipy.io.numpyio import fread
  3. import matplotlib.pyplot as plt
  4. import matplotlib.numerix.ma as M
  5. import matplotlib.colors as C
  6. from pylab import *
  7. import numpy as np
  8. import scipy as sc
  9. import os, fnmatch
  10. import array
  11. import sys
  12. import datetime
  13.  
  14. d=str(datetime.date.today())
  15. d=d.replace('-', '')
  16.  
  17. path='c:/' #sys.argv[1]
  18. for fn in os.listdir(path):
  19. if fnmatch.fnmatch(fn, d + '*.b*'):
  20. fileName=path + fn
  21. break
  22.  
  23. masking=True
  24. treshold=0
  25. savename=d + '_SO2.png'
  26. dpi=120
  27. smoothness=1
  28. projection='mill'
  29. titre='SO2'
  30. legende='Delta Brightness Temperature (K)'
  31. centre=[-90,0]
  32.  
  33. print('reading binary data')
  34. Lat=[]
  35. Lon=[]
  36. Val=[]
  37.  
  38. nbreligne=long(os.stat(fileName)[6])/(8*int(fileName[-2:]))
  39. rawfile=np.fromfile(open(fileName,'rb'),'d',-1)
  40. Lat=rawfile[0:nbreligne]
  41. Lon=rawfile[nbreligne:nbreligne*2]
  42. Val=rawfile[nbreligne*21:nbreligne*22]
  43.  
  44. if(masking==True):
  45. i=0
  46. while(i<nbreligne):
  47. if(Val[i]>-1.1):
  48. Val[i]=-1.1
  49. i+=1
  50.  
  51. print('plotting data')
  52. map=Basemap(projection='mill',lat_0=-90,lon_0=0,llcrnrlat=-90,urcrnrlat=90,\
  53. urcrnrlon=180,llcrnrlon=-180,resolution='i',area_thresh=30000.)
  54.  
  55. xi=np.linspace(-180,180,360*smoothness) #1440
  56. yi=np.linspace(-90,90,180*smoothness) #720
  57. zi=griddata(Lon,Lat,Val,xi,yi)
  58.  
  59. topodat=map.transform_scalar(zi,xi,yi,720,1440)
  60. map.imshow(topodat,cm.winter, interpolation='bilinear',aspect='auto',norm = C.Normalize(vmin = -5., vmax = -1.2, clip = True),extent=[-180,180,-90,90],filternorm=1)
  61.  
  62. cb=plt.colorbar(shrink=0.7)
  63. cb.ax.set_ylabel(legende,fontsize=11)
  64. for t in cb.ax.get_yticklabels():
  65. t.set_fontsize(7)
  66.  
  67. meridians = arange(-180,180,60)
  68. parallels = arange(-90,90,30)
  69. map.drawparallels(parallels,labels=[1,0,0,0],fontsize=7,linewidth=0.25)
  70. map.drawmeridians(meridians,labels=[0,0,0,1],fontsize=7,linewidth=0.25)
  71.  
  72. title(titre)
  73.  
  74. print('saving map')
  75. map.drawcoastlines(0.25,antialiased=1)
  76. plt.savefig(savename,dpi=dpi)
  77. print('done')

Report this snippet  

You need to login to post a comment.