2
votes

I've installed cartopy using miniconda2. When running a small sample, the code never gets past the image transform on the plt.imshow line, it just hangs there using 100% CPU. Here's the code:

#!~/miniconda2/bin/python
import cartopy.crs as ccrs
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
import datetime
import time
import sys

print datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')

fname = '2016_2_24_1200_MTSAT3_10_S1_grid.jpeg'

img = plt.imread(fname)

print datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')

img_proj = ccrs.Geostationary(satellite_height=35786000)
img_extent = (-5500000, 5500000, -5500000, 5500000)

ax = plt.axes(projection=ccrs.Miller())
ax.coastlines()
ax.set_global()
origin = 'upper'

print datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')

plt.imshow(img, transform=img_proj, extent=img_extent, origin=origin, cmap='gray')
fig.savefig('html/test.jpg')

Any clue anyone?

1
Is the image itself public domain? Can this be reproduced by exchanging the image for a numpy.arange(12).reshape(3, 4)? - pelson
I've in the meantime figured out that it's only the Geostationary transform that is causing this issue. It usually fails after several hours with an error 11, whatever that means. All other transforms are reasonably quick and behave as expected. - Balthasar

1 Answers

1
votes

So I had a similar problem with image transforms in Cartopy, I've fixed the issue by adding a keyword to a Cartopy script. In your Python installation directory go to Lib\site-packages\cartopy. The file you need to edit is img_transform.py and you also need to delete img_transform.pyc to make it recompile with the change you make.

Within img_transform.pyc the line you need to edit is:

kdtree = scipy.spatial.cKDTree(xyz)

which is line 288 in Cartopy v0.14.2 (latest at time of writing).

change this line to:

kdtree = scipy.spatial.cKDTree(xyz, balanced_tree=False)

This switches off a new default that was introduced in SciPy v0.16 (see scipy.spatial.ckdtree running slowly).

For me this made something which took >24 hours return to taking ~3 minutes-hope it works for you!