- 积分
- 5344
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2012-8-28
- 最后登录
- 1970-1-1
|
发表于 2020-5-27 23:28:25
|
显示全部楼层
本帖最后由 Masterpiece 于 2020-5-27 23:29 编辑
- import numpy as np
- from dateutil.parser import *
- import scipy.ndimage as sn
- import matplotlib.pyplot as plt
- from mpl_toolkits.basemap import Basemap
- file_name='17033020.000'
- raw=np.loadtxt(file_name,dtype=np.str,delimiter='/n')
- raw=' '.join(raw.tolist())
- raw=raw.split()
- title=raw[:3]
- time_str='20'+'-'.join(raw[3:3+4])
- file_time=parse(time_str)
- duration,level=int(raw[7]),int(raw[8])
- xint,yint=float(raw[9]),float(raw[10])
- start_lon,end_lon=float(raw[11]),float(raw[12])
- start_lat,end_lat=float(raw[13]),float(raw[14])
- xsize,ysize=int(raw[15]),int(raw[16])
- lineint,start_level,end_level=int(raw[17]),int(raw[18]),int(raw[19])
- smooth,boldlevel=int(raw[20]),raw[21]
- data=np.array(raw[22:],dtype=float).reshape(ysize,xsize)
- fig, ax = plt.subplots(figsize=(14,9))
- m = Basemap(projection='cyl',
- llcrnrlat=end_lat, urcrnrlat=start_lat,
- llcrnrlon=start_lon, urcrnrlon=end_lon,
- resolution='l')
- m.drawcoastlines(linewidth=0.3, color='black')
- lon=np.linspace(start_lon,end_lon,xsize)
- lat=np.linspace(end_lat,start_lat,ysize)[::-1]
- if smooth:
- factor=6
- else:
- factor=1
- lons, lats = np.meshgrid(sn.zoom(lon, factor), sn.zoom(lat, factor))
- x, y = m(lons, lats)
- c1=m.contour(x,y,sn.zoom(data, factor),
- levels=np.arange(start_level,end_level+lineint,lineint),colors='k',zorder=1)
- ax.clabel(c1, fmt='%d', inline=True, fontsize=12, inline_spacing=8)
- m.readshapefile('D:/pyproj/shp/CHN_2019/province', 'province', color='r',linewidth=0.6,zorder=0)
- plt.title('%s Level:%d'%(file_time.strftime('%Y-%m-%d %H:%M'),level),size=14, loc='left')
- plt.savefig(file_name+'.png',dpi=300,bbox_inches='tight')
- plt.show()
复制代码 |
|