1

我在风速 pcolormesh 图上添加风箭。这些看起来不错,几乎正是我希望它们看起来的样子。不幸的是,当我遍历多个级别、预测时间等时,内存使用量会累积到机器崩溃的程度。

当我不计算风箭时,不会发生这种情况。问题出现在以下代码中:

#!/usr/local/sci/bin/python

'''
Created on Jul 18, 2014

@author: freb
'''

import numpy as np

import cartopy
from cartopy.vector_transform import vector_scalar_to_grid

input_coord_system = cartopy.crs.PlateCarree()

this_plot_projection =  cartopy.crs.PlateCarree()

x_start = -180.0
x_end = 180.0
n_x = 500
d_x = (x_end - x_start) / n_x

y_start = -90.0
y_end = 90.0
n_y = 400
d_y = (y_end - y_start) / n_y



n_runs = 10

for i_run in range(n_runs):

    print 'vector_scalar_to_grid call number %s' % i_run
    random_u_data = np.random.randn(n_y, n_x)
    random_v_data = np.random.randn(n_y, n_x)
    random_spd_data = np.sqrt( random_u_data**2 + random_v_data**2)             

    source_lon = np.arange(x_start, x_end, d_x)
    source_lat = np.arange(y_start, y_end, d_y)

    regrid_shape = (60, 40)

    #import pdb #@@@
    #pdb.set_trace() #@@@
    #print 'stop here' #@@@

    (vt_lon, vt_lat, vt_u, vt_v, vt_spd) = vector_scalar_to_grid(input_coord_system,     \
                            this_plot_projection, \
                            regrid_shape, \
                            source_lon, source_lat, \
                            random_u_data, \
                            random_v_data, \
                            random_spd_data )

    print vt_lon.shape, vt_lat.shape, vt_u.shape, vt_v.shape, vt_spd.shape

我做错什么了吗?或者这是一个cartopy错误?

谢谢,

马尔科姆

4

1 回答 1

0

我无法在我的环境中重现内存问题。我使用:

  • numpy v1.8.1
  • scipy v0.14.0
  • 赛通 v0.20.1
  • cartopy(主)

转换代码使用来自 scipy 的 griddata 例程,我在过去看到过这种遭受内存泄漏的报告(例如,Scipy griddata 在循环/内存泄漏中不起作用)。我怀疑这是问题所在,但我不知道它是否已在 scipy、cython 或两者中修复...您使用的是哪些软件包版本?

(编辑:我忘了提,我正在使用来自 conda 包管理器的 scipy/cython 等)

于 2014-07-18T14:20:59.320 回答