Skip to content

Plotting on map projection much slower on v0.6.1 than 0.6.0 #657

Closed
@fmaussion

Description

@fmaussion

The following code snippet produces an average of ERA-Interim temperature on a map:

import matplotlib.pyplot as plt 
import xray
import cartopy.crs as ccrs 
import time

netcdf = xray.open_dataset('ERA-Int-Monthly-2mTemp.nc')
t2_avg = netcdf.t2m.mean(dim='time')

start_time = time.time()
ax = plt.axes(projection=ccrs.Robinson())
if xray.__version__ == '0.6.0':
    t2_avg.plot(ax=ax, origin='upper', aspect='equal', transform=ccrs.PlateCarree()) 
else:
    t2_avg.plot(ax=ax, transform=ccrs.PlateCarree()) 
ax.coastlines()
plt.savefig('t_xray.png')
print("xray V{}: {:.2f} s".format(xray.__version__, time.time() - start_time))

t

I've been very careful to check that my environments are exact same (mpl 1.4.3, numpy 1.10.1, cartopy 0.13.0).

See the output for V0.6.0 and 0.6.1 (output from the latest master is similar to 0.6.1):

0.6.0:

python test_xray.py
/home/mowglie/.bin/conda/envs/climate/lib/python3.4/site-packages/matplotlib/collections.py:590: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
  if self._edgecolors == str('face'):
xray V0.6.0: 3.21 s

0.6.1:

 python test_xray.py 
/home/mowglie/.bin/conda/envs/upclim/lib/python3.4/site-packages/numpy/lib/shape_base.py:431: FutureWarning: in the future np.array_split will retain the shape of arrays with a zero size, instead of replacing them by `array([])`, which always has a shape of (0,).
  FutureWarning)
/home/mowglie/.bin/conda/envs/upclim/lib/python3.4/site-packages/matplotlib/collections.py:590: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
  if self._edgecolors == str('face'):
xray V0.6.1: 28.52 s

The first warning seems related to recent numpy. Note that a second warning appeared with xray V0.6.1.

It's interesting to mention that the bottleneck clearly is in the rendering (plt.savefig('t_xray.png')). Removing this line will make xray V0.6.1 faster than xray V0.6.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions