NCAR / NCAR/wrf-python

Cartopy Plot is Very Slow compare to Basemap.

Open
#92 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question support
Dominant language
Python
Stars
498
Forks
178
PR merge metrics
No merged PRs in 30d

Description

Hi,
When i increase the lat long range for plotting in Cartopy with zoom level 10 or more than this cartopy plot is taking several hours to plot a single image. I want to increase the zoom level so that states should visible nicely and i want to add zoom features also in this plot .
How to reduce the time of this cartopy plot .

My Cartopy Plot code is given below .

`
import matplotlib.pyplot as plt
from scipy.io import loadmat
import datetime
import pandas as pd
from dateutil.parser import parse
import numpy as np
from scipy.spatial import Delaunay
import mpl_toolkits.mplot3d.axes3d
from datetime import timedelta
import matplotlib.tri as mtri
from mpl_toolkits.basemap import Basemap
%matplotlib inline
import folium
from folium.features import CustomIcon
import os

      %matplotlib inline
      import matplotlib.pyplot as plt

     from matplotlib.pyplot import figure, show

      import cartopy.crs as ccrs
       from cartopy.io import shapereader
       from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER

       import cartopy.io.img_tiles as cimgt

        datamat = loadmat('IOEC_ECM2017_BC.mat')
         Xp = datamat['Xp']
          Yp = datamat['Yp']
          strt = datetime.datetime(2017, 1, 11, 0, 0)
         end = datetime.datetime(2017, 1, 21, 0, 0)
         numdays = 3


        def perdelta(strt, end, delta):
                curr = strt
               while curr < end:
                yield curr
               curr += delta


          # Read element file
          # data = pd.read_table('fort.ele',delim_whitespace=True,names=
           #('A','B','C','D'))
             tri_new = pd.read_csv('fort.ele', delim_whitespace=True, names=('A',
               'B', 'C', 'D'), usecols=[1, 2, 3], skiprows=1,
                 dtype={'D': np.int})

                 dateList = []


             for result in perdelta(strt, strt + timedelta(days=2), timedelta(hours=3)):
                     dat = result
                     # print(result)
                     dt = parse(str(dat))
                     yr = dt.year
                     mn = dt.month
                      d = dt.day
                       hr = dt.hour
                      mi = dt.minute
                # print(y,mn,d,hr,mi)
                   if hr < 10:
                      # d='0'+str(d)
                        hr = '0' + str(hr)
                 else:
                       d = str(d)
                       hr = str(hr)
                   if int(d) < 10:
                        d = '0' + str(d)
                 else:
                          d = str(d)
                      varname = 'Hsig_' + str(yr) + '0' + str(mn) + str(d) + '_' + hr + '0000'
                        print(varname)

x = Xp.flatten()
y = Yp.flatten()
z = datamat[varname]
z1 = z.flatten()

tri_sub = tri_new.apply(lambda x: x - 1)
triang = mtri.Triangulation(x, y, triangles=tri_sub)

def make_map(projection=ccrs.PlateCarree()):
    fig, ax = plt.subplots(figsize=(13, 13),subplot_kw=dict(projection=projection))
    #gl = ax.gridlines(draw_labels=True,linestyle='--',linewidth=2)
    gl = ax.gridlines(draw_labels=False)
    ax.grid(False)
    gl.xlabels_top = gl.ylabels_right = False
    gl.xformatter = LONGITUDE_FORMATTER
    gl.yformatter = LATITUDE_FORMATTER
    return fig, ax

extent = [70, 93, 0, 26]
request = cimgt.GoogleTiles(url = 'https://cartodb-basemaps-4.global.ssl.fastly.net/rastertiles/voyager/{Z}/{X}/{Y}.png')
fig, ax = make_map()
tpc = ax.tripcolor(triang,z1,vmin = 0, vmax = 2)
ax.set_extent(extent)
ax.add_image(request, 9,interpolation='spline36')
ax.coastlines('50m')
fig.colorbar(tpc,extend='both')

plt.show()
break`

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided plotting code and profile ax.add_image(request, 9), ax.tripcolor, and ax.coastlines to identify which operation dominates the several-hour render. Compare the Cartopy and Basemap paths at the requested extent and zoom, then verify that the plot renders substantially faster while retaining visible states and the requested zoom behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.