-
Notifications
You must be signed in to change notification settings - Fork 394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix for Basemap.pcolormesh 'ortho' projection #476
Conversation
@@ -3426,6 +3426,27 @@ def pcolormesh(self,x,y,data,**kwargs): | |||
if the dimensions are the same, then the last row and column of data will be ignored. | |||
""" | |||
ax, plt = self._ax_plt_from_kw(kwargs) | |||
# fix for invalid grid points | |||
if ((np.any(x > 1e20) or np.any (y > 1e20)) and | |||
len(x.shape) == 2 and len(y.shape) == 2): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of len(x.shape) == 2
, do x.ndim == 2
.
@@ -3426,6 +3426,27 @@ def pcolormesh(self,x,y,data,**kwargs): | |||
if the dimensions are the same, then the last row and column of data will be ignored. | |||
""" | |||
ax, plt = self._ax_plt_from_kw(kwargs) | |||
# fix for invalid grid points | |||
if ((np.any(x > 1e20) or np.any (y > 1e20)) and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extraneous space
# fix for invalid grid points | ||
if ((np.any(x > 1e20) or np.any (y > 1e20)) and | ||
len(x.shape) == 2 and len(y.shape) == 2): | ||
if not x.shape == y.shape: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or clearer would be if x.shape != y.shape:
if ((np.any(x > 1e20) or np.any (y > 1e20)) and | ||
len(x.shape) == 2 and len(y.shape) == 2): | ||
if not x.shape == y.shape: | ||
raise Exception('pcolormesh: x and y need same dimension') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a ValueError
, which is typically used when there are problems with input arguments.
) | ||
# we do not want to overwrite original array | ||
data = data[:nx-1,:ny-1].copy() | ||
data[mask] = np.nan |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to do some testing with this. I am pretty sure some numpy rules changed recently regarding boolean indexing using masks that don't exactly match the shape of the array being indexed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is why I make a copy of slice of data with the correct dimensions: data = data[:nx-1,:ny-1].copy()
*It seems to be working with current numpy; irrespective, the aim of the
code as written is that the dimensions match.*
*Thanks for all the suggestions. Do I need to do a new pull request you
you will integrate a version with your modifications?*
…On Tue, 27 Aug 2019 at 03:52, Benjamin Root ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In lib/mpl_toolkits/basemap/__init__.py
<#476 (comment)>:
> + nx,ny = x.shape
+ if nx < data.shape[0] or ny < data.shape[1]:
+ raise Exception('pcolormesh: data dimension needs to be at least that of x and y.')
+ mask = (
+ (x[:-1,:-1] > 1e20) |
+ (x[1:,:-1] > 1e20) |
+ (x[:-1,1:] > 1e20) |
+ (x[1:,1:] > 1e20) |
+ (y[:-1,:-1] > 1e20) |
+ (y[1:,:-1] > 1e20) |
+ (y[:-1,1:] > 1e20) |
+ (y[1:,1:] > 1e20)
+ )
+ # we do not want to overwrite original array
+ data = data[:nx-1,:ny-1].copy()
+ data[mask] = np.nan
I need to do some testing with this. I am pretty sure some numpy rules
changed recently regarding boolean indexing using masks that don't exactly
match the shape of the array being indexed.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#476?email_source=notifications&email_token=AAJW2FUM5YLKB6AEVGJ77XLQGQJ7NA5CNFSM4IPGEWB2YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCCWHNTQ#pullrequestreview-279738062>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAJW2FWIFGNTKURXGRCY5WTQGQJ7NANCNFSM4IPGEWBQ>
.
|
Is it still possible to merge this fix? |
Hi @2sn, you do not need to create a new pull request, you can just create a new commit in your |
@molinav thanks for your follow-up My apologies, I have since transitioned my code to |
No worries @2sn, then I will just merge the pull request as it is and I will apply the review changes afterwards in |
fix for #470 as discussed in comment there