map plotting python code (temporary)


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  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. d=str(datetime.date.today())
  14. d=d.replace('-', '')
  15. path='c:/' #sys.argv[1]
  16. for fn in os.listdir(path):
  17. if fnmatch.fnmatch(fn, d + '*.b*'):
  18. fileName=path + fn
  19. break
  20. masking=True
  21. treshold=0
  22. savename=d + '_SO2.png'
  23. dpi=120
  24. smoothness=1
  25. projection='mill'
  26. titre='SO2'
  27. legende='Delta Brightness Temperature (K)'
  28. centre=[-90,0]
  29. print('reading binary data')
  30. Lat=[]
  31. Lon=[]
  32. Val=[]
  33. nbreligne=long(os.stat(fileName)[6])/(8*int(fileName[-2:]))
  34. rawfile=np.fromfile(open(fileName,'rb'),'d',-1)
  35. Lat=rawfile[0:nbreligne]
  36. Lon=rawfile[nbreligne:nbreligne*2]
  37. Val=rawfile[nbreligne*21:nbreligne*22]
  38. if(masking==True):
  39. i=0
  40. while(i<nbreligne):
  41. if(Val[i]>-1.1):
  42. Val[i]=-1.1
  43. i+=1
  44. print('plotting data')
  45. map=Basemap(projection='mill',lat_0=-90,lon_0=0,llcrnrlat=-90,urcrnrlat=90,\
  46. urcrnrlon=180,llcrnrlon=-180,resolution='i',area_thresh=30000.)
  47. xi=np.linspace(-180,180,360*smoothness) #1440
  48. yi=np.linspace(-90,90,180*smoothness) #720
  49. zi=griddata(Lon,Lat,Val,xi,yi)
  50. topodat=map.transform_scalar(zi,xi,yi,720,1440)
  51. 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)
  52. cb=plt.colorbar(shrink=0.7)
  53. cb.ax.set_ylabel(legende,fontsize=11)
  54. for t in cb.ax.get_yticklabels():
  55. t.set_fontsize(7)
  56. meridians = arange(-180,180,60)
  57. parallels = arange(-90,90,30)
  58. map.drawparallels(parallels,labels=[1,0,0,0],fontsize=7,linewidth=0.25)
  59. map.drawmeridians(meridians,labels=[0,0,0,1],fontsize=7,linewidth=0.25)
  60. title(titre)
  61. print('saving map')
  62. map.drawcoastlines(0.25,antialiased=1)
  63. plt.savefig(savename,dpi=dpi)
  64. print('done')

Report this snippet Tweet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.

AltStyle によって変換されたページ (->オリジナル) /