爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 7482|回复: 3

循环画风玫瑰图报错求助,windows可正常使用 linux系统下报错

[复制链接]

新浪微博达人勋

发表于 2021-4-1 10:06:22 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
本帖最后由 flyed 于 2021-4-1 10:07 编辑
  1. import time
  2. def windrose2polar(a):
  3.     r = 360 - a + 90
  4.     r[r>360] = r - 360
  5.     return r

  6. def plotWindRole(fn, imageName, polType):
  7.     #Read data (wind speed, weed direction, pm10)
  8.     table = readtable(fn,delimiter=",",format='%3f')
  9.     ws = table['WS']
  10.     wd = table['WD']
  11.     pm10 = table['VAL']
  12.     N = len(ws)

  13.     vmaxArray = []
  14.     for row in pm10:
  15.         vmaxArray.append(row)
  16.     vmaxArray.sort()
  17.     vmax = vmaxArray[int(len(vmaxArray)*0.99)]
  18.    
  19.     #Convert from windrose coordinate to polar coordinate
  20.     rwd = windrose2polar(wd)
  21.    
  22.     #Degree to radians
  23.     rwd = radians(rwd)
  24.    
  25.     #Calculate frequency of each wind direction bin
  26.     wdbins = linspace(0.0, pi * 2, 9)
  27.     dwdbins = degrees(wdbins)
  28.     dwdbins = windrose2polar(dwdbins)
  29.     rwdbins = radians(dwdbins)
  30.     wdN = len(wdbins) - 1
  31.     theta = ones(wdN + 1)
  32.     for j in range(wdN):
  33.         theta[j] = rwdbins[j]
  34.     theta[wdN] = theta[0]
  35.     wd = wd + 360./wdN/2
  36.     wd[wd>360] = wd - 360
  37.     wdhist = histogram(radians(wd), wdbins)[0].astype('float')
  38.     wdhist = wdhist / N
  39.     nwdhist = wdhist.aslist()
  40.     nwdhist.append(nwdhist[0])
  41.     nwdhist = array(nwdhist)
  42.    
  43.     #Polar coordinate to Cartesian coordinate
  44.     rwdc, wsc = pol2cart(rwd, ws)
  45.    
  46.     #Get convexhull (minimum outer polygon of the wind points)
  47.     poly = topo.convexhull(rwdc, wsc)
  48.    
  49.     #Get grid data
  50.     dd = 0.5
  51.     x = linspace(rwdc.min() - dd, rwdc.max() + dd, 5)
  52.     y = linspace(wsc.min() - dd, wsc.max() + dd, 5)
  53.     data = griddata((rwdc, wsc), pm10, xi=(x, y), method='idw', pointnum=5, convexhull=False)[0]
  54.     #---------------------------------------
  55.     #Plot figure
  56.     pos = [0.13, 0.1, 0.775, 0.775]
  57.    
  58.     #Cartesian axes
  59.     ax = axes(position=pos, aspect='equal')
  60.     xaxis(visible=False)
  61.     yaxis(location='right', visible=False)
  62.     yaxis(location='left', shift = 50)
  63.     ylabel('Wind speed (m/s)')
  64.     levs = arange(0, vmax, vmax/7).astype(int)
  65.     cg = contourf(x, y, data, levs, cmap='BlAqGrYeOrRe', visible=False)
  66.     cg = cg.clip([poly])
  67.     ax.add_graphic(cg)
  68.     #ss = scatter(rwdc, wsc, s=6, fill=False, edgecolor='b', edgesize=1)
  69.     #patch(poly)
  70.     # xshift:离图的距离 shrink:colorBar的高度
  71.     colorbar(cg, shrink=0.8, xshift=30, label=r'$\mu g/m^3'
  72. , labelloc='bottom')
  73.     maxv = ws.max()+1
  74.     xlim(-maxv, maxv)
  75.     ylim(-maxv, maxv)
  76.     ticks = ax.get_yticks()
  77.     ax.set_yticklabels([abs(yy) for yy in ticks])
  78.    
  79.     #Polar axes
  80.     axp = axes(position=pos, polar=True)
  81.     plot(theta, nwdhist, color='k', linewidth=2)
  82.     axp.set_rmax(1)
  83.     axp.set_rlabel_position(25.)
  84.     axp.set_rtick_locations([0.2,0.4,0.6,0.8])
  85.     #axp.set_rticks(['2','4','6','8','10 m/s'])
  86.     axp.set_rticks(['20%','40%','60%','80%'])
  87.     axp.set_xtick_font(size=14)
  88.     axp.set_xtick_locations(arange(0,360,22.5))
  89.     axp.set_xticks(['E','NEE','NE','NNE','N','NNW','NW','NWW','W','SWW',
  90.         'SW','SSW','S','SSE','SE','SEE'])
  91.     title(r'$Windrose \ with \ '+polType+r' \ concentrations, fontsize=18)
  92.     savefig(imageName,640, 524)
  93. clf()
  94.     time.sleep(2)

  95. baseDir = r"/mnt/d/pythonWorkspace/try/windrose/"
  96. targetDir = r"/mnt/f/tmp/windRoseImages/"

  97. for file in (os.listdir(baseDir)):
  98.     if file.endswith(".txt"):
  99.         imgName = file.replace(".txt", ".png")
  100.         polType = imgName[imgName.rindex('-')+1:imgName.index('.')]
  101.         if polType == 'pm25':
  102.             polType = 'PM_{25}'
  103.         if polType == 'o3':
  104.             polType = 'O_{3}'
  105.         if polType == 'pm10':
  106.             polType = 'PM_{10}'
  107.         polType = polType.upper()
  108.         print(polType, baseDir, targetDir, imgName, file)
  109.         plotWindRole(baseDir + file, targetDir + imgName, polType)
  110.         print imgName
  111.    
复制代码
如程序需求需要循环画风玫瑰图当在 clf()是否发生错误,此程序在windows下可正常运行,但在Linux中不行  linux中的报错信息为:AttributeError: 'NoneType' object has no attribute 'getFigureDock'
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2021-4-1 10:50:13 | 显示全部楼层
你是在MeteoInfolab界面里运行脚本,还是在命令行中运行的?Linux系统你是远程登录进去的吗?是否启动了图形环境?
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

 楼主| 发表于 2021-4-1 10:51:00 | 显示全部楼层
MeteoInfo 发表于 2021-4-1 10:50
你是在MeteoInfolab界面里运行脚本,还是在命令行中运行的?Linux系统你是远程登录进去的吗?是否启动了图 ...

linux是远程进去的,没有启动图形界面
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2021-4-1 10:55:06 | 显示全部楼层
flyed 发表于 2021-4-1 10:51
linux是远程进去的,没有启动图形界面

可以尝试加上 -b 参数:  milab.sh -b test.py
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表