matplotlib / matplotlib/basemap

drawlsmask not working for rotpole

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

Nobody has claimed this yet.

Dominant language
Python
Stars
817
Forks
395
PR merge metrics
No merged PRs in 30d

Description

Now that I played with 'rotpole' a bit... I also found that dralsmask fails with ZeroDivisionError. This is the full traceback:

---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
<ipython-input-79-0ba416c748fa> in <module>()
----> 1 m.drawlsmask(resolution='c')

/home/razvan/.local/lib/python3.4/site-packages/mpl_toolkits/basemap/__init__.py in drawlsmask(self, land_color, ocean_color, lsmask, lsmask_lons, lsmask_lats, lakes, resolution, grid, **kwargs)
   3934         # to a rectangular map projection grid.
   3935             mask,x,y = self.transform_scalar(lsmask,lsmask_lons,-> 3936                        lsmask_lats,nx,ny,returnxy=True,order=0,masked=255)
   3937             lsmask_lats.dtype
   3938             # for these projections, points outside the projection

/home/razvan/.local/lib/python3.4/site-packages/mpl_toolkits/basemap/__init__.py in transform_scalar(self, datin, lons, lats, nx, ny, returnxy, checkbounds, order, masked)
   2961                 raise ValueError('grid must be shifted so that lons are monotonically increasing and fit in range -180,+180 (see shiftgrid function)')
   2962         if returnxy:
-> 2963             lonsout, latsout, x, y = self.makegrid(nx,ny,returnxy=True)
   2964         else:
   2965             lonsout, latsout = self.makegrid(nx,ny)

/home/razvan/.local/lib/python3.4/site-packages/mpl_toolkits/basemap/__init__.py in makegrid(self, nx, ny, returnxy)
   1172         If ``returnxy = True``, the x,y values of the grid are returned also.
   1173         """
-> 1174         return self.projtran.makegrid(nx,ny,returnxy=returnxy)
   1175 
   1176     def _readboundarydata(self,name,as_polygons=False):

/home/razvan/.local/lib/python3.4/site-packages/mpl_toolkits/basemap/proj.py in makegrid(self, nx, ny, returnxy)
    332         if returnxy=True, the x,y values of the grid are returned also.
    333         """
--> 334         dx = (self.urcrnrx-self.llcrnrx)/(nx-1)
    335         dy = (self.urcrnry-self.llcrnry)/(ny-1)
    336         x = self.llcrnrx+dx*np.indices((ny,nx),np.float32)[1,:,:]

ZeroDivisionError: float division by zero

I figured it's because of this:

nx = int((self.xmax-self.xmin)/dx)+1; ny = int((self.ymax-self.ymin)/dx)+1

here self.xmax, self.xmin, ... are used incorrectly for 'rotpole' giving nx == ny == 1.

I tried changing line 3928:

if self.projection == 'cyl':

to

if self.projection == 'cyl' or self.projection == 'rotpole':

with the effect of producing a nice pattern :) but no land sea mask unfortunately... so the issue is a bit dipper, but I don't have time to investigate now...

Edit: on version 1.0.7

Contributor guide

No contributing guide indexed for this repository

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 in mpl_toolkits/basemap/init.py at drawlsmask and follow its transform_scalar call into mpl_toolkits/basemap/proj.py makegrid, where the traceback shows division by nx-1. Reproduce m.drawlsmask(resolution='c') with a rotpole projection and determine the projection-specific handling needed. Done means drawlsmask completes without ZeroDivisionError and renders the land-sea mask.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.