请选择 进入手机版 | 继续访问电脑版
爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 14944|回复: 8

[求助] python scipy interp2d 运行太慢问题

[复制链接]

新浪微博达人勋

发表于 2013-9-27 15:03:31 | 显示全部楼层 |阅读模式

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

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

x
我用interp2d把一个(181 * 360)的场插值成(361 * 719)的场,运算怎么那么慢啊!!!!!求大神解释和帮助!

####脚本如下

import numpy as np

import pygrib

from scipy import interpolate

grbs=pygrib.open('perturbation_1220300000120.grib2')

grb=grbs.select(shortName='gh',level=500)[0]

lat,lon=grb.latlons() ###lat,lon 是两维坐标量(181*360)

z=grb.values

latnew,lonnew=np.mgrid[90:-90:361j,0:359:719j]

f=interpolate.interp2d(lat,lon,z)  ##########这一步真的太太慢了。。。。

znew=f(latnew,lonnew)

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

新浪微博达人勋

发表于 2013-9-27 18:13:01 | 显示全部楼层
。。。。。。
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2013-9-28 10:25:25 | 显示全部楼层
Interp2d 主要针对不规则的散点资料,对于格点资料用scipy.ndimage或map_coordinates
ndimage的zoom可以放大一个数组:
“Zooming" an array (scipy.ndimage.zoom)

As a quick example (This will use cubic interpolation. Use order=1 for bilinear, order=0 for nearest, etc.):

import numpy as np
import scipy.ndimage as ndimage

data = np.arange(9).reshape(3,3)

print 'Original:\n', data
print 'Zoomed by 2x:\n', ndimage.zoom(data, 2)

This yields:

Original:
[[0 1 2]
[3 4 5]
[6 7 8]]
Zoomed by 2x:
[[0 0 1 1 2 2]
[1 1 1 2 2 3]
[2 2 3 3 4 4]
[4 4 5 5 6 6]
[5 6 6 7 7 7]
[6 6 7 7 8 8]]

基于这两个函数,JohannesBuchner做了一个regulargrid包,用于插值规则格点资料(下载地址见regulargrid
用法:
插值函数一:
Cartesian grid regulargrid.cartesiangrid.CartesianGrid (equal spacing between points)

    Uses very fast implementation based on scipy.ndimage.map_coordinates

    Example:
  1. # create a 3-dimensional cartesian grid:
  2. limits = [(0, 1), (0, 1), (0, 1)]
  3. x = numpy.linspace(0, 1, 8)
  4. y = numpy.linspace(0, 1, 9)
  5. z = numpy.linspace(0, 1, 10)

  6. Z, Y = numpy.meshgrid(z, y)
  7. X = numpy.array([[x]]).transpose()

  8. # our grid values
  9. values = X**2 + Y - Z

  10. from regulargrid.cartesiangrid import CartesianGrid
  11. # does linear interpolation
  12. grid = CartesianGrid(limits, values)

  13. # interpolate for one point
  14. print grid([0.1], [0.5], [0.3])
  15. # interpolate many
  16. print grid([0.1, 0.3], [0.5, 0.5], [0.3, 0.2])


插值函数二:
Regular grid regulargrid.regulargrid.RegularGrid (unequal spacing between points)
该函数作者没给例程,估计用法跟上述用法一致
密码修改失败请联系微信:mofangbao

新浪微博达人勋

 楼主| 发表于 2013-10-4 14:16:20 | 显示全部楼层
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-9-28 21:48:19 | 显示全部楼层
压哈 居然在这能找到你
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2015-9-29 23:34:31 | 显示全部楼层
python需要关注优化程序,提升程序的速度,学习了
{:eb502:}{:eb502:}
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2016-5-8 21:14:56 | 显示全部楼层
学习了
密码修改失败请联系微信:mofangbao
回复

使用道具 举报

新浪微博达人勋

发表于 2019-8-5 08:45:06 | 显示全部楼层
请问lat 和lon都是二维的,用什么插值函数
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2019-8-5 08:59:09 | 显示全部楼层
学到了,不错不错,python用起来
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

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