爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
楼主: MeteoInfo

MeteoInfoLab脚本示例:同时加载多个文件

[复制链接]

新浪微博达人勋

发表于 2017-2-15 11:23:29 | 显示全部楼层
MeteoInfo 发表于 2017-2-15 10:56
数据文件可以加载很多,不过读取的数组太大的话可能会有内存不够的问题。

我刚才读取了10个数据文件可以正常运行,所以跨月的问题解决了。目前还是相对湿度的维数好像有问题。没有解决。
错误提示是:Traceback (most recent call last):
  File "<iostream>", line 147, in <module>
AttributeError: 'float' object has no attribute 'interpn'
147行是rh行。
  1.         v = vort.interpn([t,pres,lat,lon])
  2. #       d = divg.interpn([t,pres,lat,lon])
  3.         ww = mpv.interpn([t,press,lat,lon])
  4.         temp = t0.interpn([t,pres,lat,lon])
  5.         rh = rh.interpn([t,pres,lat,lon])
复制代码
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2017-2-15 11:41:06 | 显示全部楼层
良辰 发表于 2017-2-15 11:23
我刚才读取了10个数据文件可以正常运行,所以跨月的问题解决了。目前还是相对湿度的维数好像有问题。没有 ...

可能是rh并非多维数组的缘故。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2017-2-15 13:00:22 | 显示全部楼层
MeteoInfo 发表于 2017-2-15 11:41
可能是rh并非多维数组的缘故。

好的,我再研究研究!谢谢王老师
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2017-2-17 16:21:50 | 显示全部楼层
本帖最后由 良辰 于 2017-2-17 16:23 编辑
MeteoInfo 发表于 2017-2-15 11:41
可能是rh并非多维数组的缘故。


王老师,学生又有一个问题。想在tdump写入的时候,将气压一列替换为湿位涡。使用replace好像没有这个函数。想咨询一下王老师,怎么能实现。就是不改变原轨迹数据格式,只是替换一下气压列。错误行为39行。
  1. # Get meteorological data along trajectory
  2. print 'Get meteorological data along trajectory...'
  3. # Open trjactory data file
  4. print 'Open trajectory data file ...'
  5. trajfn = os.path.join(trajDir, 'tdump42.5122.5500_2009070312')
  6. print 'Trajectory file: ' + trajfn
  7. trajf = addfile_hytraj(trajfn)
  8. # Create trajectory layer
  9. trajLayer = trajf.trajlayer()
  10. # Get meteorological data along trajectory
  11. print 'Get meteorological data along trajectory...'
  12. outfn = os.path.join(trajDir, 'tdump42.5122.5500_2009070312.txt')
  13. inf = open(trajfn, 'r')
  14. outf = open(outfn, 'w')
  15. lnum = 0
  16. for line in inf:
  17.     lnum += 1;
  18.     if (lnum >= 1) & (lnum <= 16):
  19.        print line  
  20.        outf.write(line)
  21. idx = 0
  22. for tline in trajLayer.shapes():   
  23.     t = trajLayer.cellvalue('Date', idx)
  24.     h = trajLayer.cellvalue('Hour', idx)
  25.     t.replace(hour=h)
  26.     for ps in tline.getPoints():  
  27.         lon = ps.X
  28.         lat = ps.Y
  29.         z = ps.M
  30.         pres = ps.Z
  31. #if pressure below 975,mpv nan
  32.         if pres > 975:
  33.            press=975
  34.         else:
  35.            press=ps.Z
  36.         v = vort.interpn([t,pres,lat,lon])
  37.         ww = mpv.interpn([t,press,lat,lon])
  38.         temp = t0.interpn([t,pres,lat,lon])
  39.         line = tline.replace(pres,ww)
  40.         outf.write(line + '\n')
  41.         t = t + datetime.timedelta(hours=-1)
  42.     idx += 1
  43. outf.close()
  44. inf.close()
  45. print 'Finish...'
复制代码

密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2017-3-23 19:32:43 | 显示全部楼层
功能很强大,出图效果还需要改进些
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2017-8-22 10:39:24 | 显示全部楼层
不错不错,学习了
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2017-10-10 18:36:59 | 显示全部楼层
王老师,您好,我使用最新的V1.4.6R13版本运行了主贴的脚本,结果出现了问题,报错如下,请老师指导

  1. <P> >>> run script...
  2. E:/test/linshi\fnl_20140816_00_00.grib2
  3. E:/test/linshi\fnl_20140816_06_00.grib2
  4. E:/test/linshi\fnl_20140816_12_00.grib2
  5. E:/test/linshi\fnl_20140816_18_00.grib2
  6. E:/test/linshi\fnl_20140817_00_00.grib2
  7. E:/test/linshi\fnl_20140817_06_00.grib2
  8. E:/test/linshi\fnl_20140817_12_00.grib2
  9. 十月 11, 2017 9:53:04 下午 org.meteoinfo.data.meteodata.netcdf.NetCDFDataInfo read
  10. 严重: null
  11. ucar.ma2.InvalidRangeException: Illegal Range for dimension 0: last requested 6 > max 0
  12. at ucar.ma2.Section.fill(Section.java:179)
  13. at ucar.nc2.Variable.read(Variable.java:709)
  14. at org.meteoinfo.data.meteodata.netcdf.NetCDFDataInfo.read(NetCDFDataInfo.java:3318)
  15. at org.meteoinfo.data.meteodata.MeteoDataInfo.read(MeteoDataInfo.java:865)
  16. at org.meteoinfo.data.meteodata.MeteoDataInfo.read(MeteoDataInfo.java:885)
  17. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  18. at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  19. at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  20. at java.lang.reflect.Method.invoke(Unknown Source)
  21. at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:188)
  22. at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:206)
  23. at org.python.core.PyObject.__call__(PyObject.java:515)
  24. at org.python.core.PyObject.__call__(PyObject.java:519)
  25. at org.python.core.PyMethod.__call__(PyMethod.java:156)
  26. at mipylib.dataset.dimvariable$py.__getitem__$6(D:/MyProgram/Java/MeteoInfoDev/MeteoInfoLab/pylib/mipylib/dataset/dimvariable.py:262)
  27. at mipylib.dataset.dimvariable$py.call_function(D:/MyProgram/Java/MeteoInfoDev/MeteoInfoLab/pylib/mipylib/dataset/dimvariable.py)
  28. at org.python.core.PyTableCode.call(PyTableCode.java:171)
  29. at org.python.core.PyBaseCode.call(PyBaseCode.java:154)
  30. at org.python.core.PyFunction.__call__(PyFunction.java:423)
  31. at org.python.core.PyMethod.__call__(PyMethod.java:141)
  32. at mipylib.dataset.dimvariable$py.__getitem__$21(D:/MyProgram/Java/MeteoInfoDev/MeteoInfoLab/pylib/mipylib/dataset/dimvariable.py:458)
  33. at mipylib.dataset.dimvariable$py.call_function(D:/MyProgram/Java/MeteoInfoDev/MeteoInfoLab/pylib/mipylib/dataset/dimvariable.py)
  34. at org.python.core.PyTableCode.call(PyTableCode.java:171)
  35. at org.python.core.PyBaseCode.call(PyBaseCode.java:154)
  36. at org.python.core.PyFunction.__call__(PyFunction.java:423)
  37. at org.python.core.PyFunction.__call__(PyFunction.java:418)
  38. at org.python.core.PyInstance.invoke(PyInstance.java:242)
  39. at org.python.core.PyInstance.instance___getitem__(PyInstance.java:663)
  40. at org.python.core.PyInstance.__getitem__(PyInstance.java:658)
  41. at org.python.pycode._pyx62.f$0(<iostream>:19)
  42. at org.python.pycode._pyx62.call_function(<iostream>)
  43. at org.python.core.PyTableCode.call(PyTableCode.java:171)
  44. at org.python.core.PyCode.call(PyCode.java:18)
  45. at org.python.core.Py.runCode(Py.java:1614)
  46. at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:296)
  47. at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:291)
  48. at org.meteoinfo.laboratory.gui.PythonInteractiveInterpreter.execfile(PythonInteractiveInterpreter.java:123)
  49. at org.meteoinfo.laboratory.gui.ConsoleDockable$1.doInBackground(ConsoleDockable.java:296)
  50. at org.meteoinfo.laboratory.gui.ConsoleDockable$1.doInBackground(ConsoleDockable.java:272)
  51. at javax.swing.SwingWorker$1.call(Unknown Source)
  52. at java.util.concurrent.FutureTask.run(Unknown Source)
  53. at javax.swing.SwingWorker.run(Unknown Source)
  54. at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
  55. at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
  56. at java.lang.Thread.run(Unknown Source)</P>
  57. <P>Traceback (most recent call last):
  58.   File "<iostream>", line 13, in <module>
  59.   File "E:\MeteoInfo\pylib\mipylib\dataset\dimvariable.py", line 412, in __getitem__
  60.     aa = var.__getitem__(nindices)
  61.   File "E:\MeteoInfo\pylib\mipylib\dataset\dimvariable.py", line 251, in __getitem__
  62.     if rr.getSize() == 1:
  63. AttributeError: 'NoneType' object has no attribute 'getSize'</P>
复制代码

密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2018-2-14 23:41:01 | 显示全部楼层
王老师,这个功能不支持micaps类型的数据么?
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2018-3-30 13:11:05 | 显示全部楼层
王老师您好,我想问一下,meteoinfo怎么读取文件夹下所有的文件名,能调用os的ls指令么?因为我的数据是雷达资料,后面部分分钟时间不好确定!Z_RADR_I_Z9250_20170610072700_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610073300_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610073900_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610074500_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610075100_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610075700_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610080400_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610081000_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610081600_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610082200_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610082800_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610083400_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610084000_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610084600_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610085300_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610085900_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610090500_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610091100_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610091700_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610092300_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610092900_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610093600_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610094200_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610094800_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610095400_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610100000_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610100600_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610101200_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610101900_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610102500_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610103100_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610103700_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610104300_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610104900_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610105500_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610110100_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610110800_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610111400_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610112000_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610112600_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610113200_O_DOR_SA_CAP.bin
Z_RADR_I_Z9250_20170610113800_O_DOR_SA_CAP.bin

密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2018-3-30 14:17:41 | 显示全部楼层
chongzika 发表于 2018-3-30 13:11
王老师您好,我想问一下,meteoinfo怎么读取文件夹下所有的文件名,能调用os的ls指令么?因为我的数据是雷 ...

同时加载太多文件读取大数组可能会存在内存问题,建议尽量用循环。Python的语法,可以度娘去查。
密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

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

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

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