-
Notifications
You must be signed in to change notification settings - Fork 370
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
Add inline grid meridian/parallel labeling #1089
Conversation
Maybe shouldn't remove that |
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.
In general, I like the idea, but it needs a little bit of clarification in some places, and it definitely needs tests.
lib/cartopy/mpl/gridliner.py
Outdated
alpha = 1 | ||
else: | ||
label_transform = cartopy.crs.PlateCarree() | ||
alpha = 0.7 |
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'm not sure if we want to be changing transparency. Best would be if the line were cut under the label, like contour lines, but this is somewhat more difficult to do. But maybe using the contour machinery would help.
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.
Will have to revisit.
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.
Thanks all for the review! I'll have to revisit some of the comments sometime later, so if anyone is interested in making their own PR based on this one, feel free!
lib/cartopy/mpl/gridliner.py
Outdated
alpha = 1 | ||
else: | ||
label_transform = cartopy.crs.PlateCarree() | ||
alpha = 0.7 |
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.
Will have to revisit.
Thank you for the contribution @ahuang11! Could you please also sign a CLA agreement, following the guidance in the SciTools documentation. |
Hi @ahuang11, this PR is really valuable and I'd like to move it forward if you're still in a position to work on it. If you could fill out this CLA form and return it to us at [email protected] then we can get this PR moving again, and I'd be very happy. |
Hmm I screwed up the pull... Can anyone advise on how to rebase / remove all the commits from others? Edit: Nevermind; I think I fixed it. |
…th v/h_align, better auto prevention of overlap and cramping, added more outer grid line projections
…ding documentation)
Thanks for the commands @stefraynaud; that seemed to work. I might have been using conda-forge earlier so it wasn't working. |
Conflicts: lib/cartopy/mpl/geoaxes.py lib/cartopy/mpl/gridliner.py lib/cartopy/tests/mpl/baseline_images/mpl/test_gridliner/gridliner_labels.png lib/cartopy/tests/mpl/baseline_images/mpl/test_gridliner/gridliner_labels_1.5.png lib/cartopy/tests/mpl/test_gridliner.py
lib/cartopy/mpl/gridliner.py
Outdated
lq = 25 | ||
uq = 75 | ||
midpoints = (self._round(np.percentile(lim, lq), cent), | ||
self._round(np.percentile(lim, uq), cent)) |
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.
E127 continuation line over-indented for visual indent
lib/cartopy/mpl/gridliner.py
Outdated
@@ -504,55 +526,125 @@ def _draw_gridliner(self, nx=None, ny=None, background_patch=None, | |||
|
|||
# Loop on head and tail and plot label by extrapolation | |||
for tail, head in zip(tails, heads): | |||
for pt0, pt1 in [tail, head]: | |||
for i ,(pt0, pt1) in enumerate([tail, head]): |
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.
E203 whitespace before ','
E231 missing whitespace after ','
lib/cartopy/mpl/gridliner.py
Outdated
return kw, angle, loc | ||
|
||
def _segment_angle_to_text_specs(self, angle): | ||
def _text_angle_to_specs_(self, angle, lonlat): | ||
"""Get appropriate kwargs for a rotated label from its angle in degrees""" |
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.
E501 line too long (82 > 79 characters)
lib/cartopy/mpl/gridliner.py
Outdated
angle -= 360 | ||
|
||
if ((self.x_inline and lonlat == 'lon') or | ||
(self.y_inline and lonlat == 'lat')): |
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.
E129 visually indented line with same indent as next logical line
lib/cartopy/mpl/gridliner.py
Outdated
x=dx, y=dy, units='dots') | ||
kw.update(transform=transform) | ||
if ((self.x_inline and lonlat == 'lon') or | ||
(self.y_inline and lonlat == 'lat')): |
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.
E129 visually indented line with same indent as next logical line
ax = plt.subplot(3, 2, 4, projection=crs_pc) | ||
>>>>>>> 45d0479abed27f73c5bb8bac35036772a3faa773 |
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.
E225 missing whitespace around operator
@@ -186,5 +240,46 @@ def test_grid_labels(): | |||
gl.xlabel_style = gl.ylabel_style = {'size': 9} | |||
|
|||
# Increase margins between plots to stop them bumping into one another. | |||
<<<<<<< HEAD |
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.
E227 missing whitespace around bitwise or shift operator
E225 missing whitespace around operator
ax.set_title(proj, y=1.08) | ||
ax.gridlines(draw_labels=True, auto_inline=True, clip_on=True) | ||
ax.coastlines() | ||
======= |
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.
E305 expected 2 blank lines after class or function definition, found 0
E225 missing whitespace around operator
plt.subplots_adjust(wspace=0.25, hspace=0.25, top=.98, left=.07, | ||
bottom=0.02, right=0.93) | ||
>>>>>>> 45d0479abed27f73c5bb8bac35036772a3faa773 |
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.
E225 missing whitespace around operator
That's really nice with the addition of inline labels! |
Hi @ahuang11, I'm still looking into the travis errors that are occurring at build time here, but it's bothering me that the SciTools CLA-checker isn't recognising you any more, despite the fact that I remember CLAing you myself. I think what's happened is that one of my more knowledgeable and capable colleagues has moved elsewhere in the business, but not before making a whole load of modifications to SciTools which has broken a lot of links in chains. You should be able to re-add yourself to the CLA list by filling in this form: https://docs.google.com/forms/d/e/1FAIpQLSfd0tdE-DcJOXh8ej_7T93IizwJFYBFyRWYQOi2A8QRaKwykA/viewform Please ping me once you've done that, I'll need to think about what to do next. |
@corinnebosley Done. |
Thanks @ahuang11, unfortunately it looks like the form isn't working. I'll continue to investigate both issues and tell you when I've found something. |
@ahuang11 My mistake, apparently the form is working and you are now on two whole lists (I'm not sure why we now have two or where they live, but you are on them both). I will continue to look into the test fails. I'm still pretty confused. I'll keep you posted. |
Any headway here? This would be such a great capability to have and it's one of the few missing features keeping my group from switching from basemap to cartopy for all our plotting. |
@ahuang11 @xylar I'm so sorry for dragging this on; we're very short-staffed at the moment but I'm trying to squeeze this in where I can. I am a bit concerned that this test failure has several causes, but it may be possible to get it passing by adding the new image to the cartopy image repository. Or by running idiff and accepting the image differences. Before we do that though (and by 'we' I think I mean 'you' (@ahuang11)), I need to really dig into this error to make sure this is the right action to take. It's possible that the tests that pass might be supposed to fail and actually our tests just aren't working; in which case it would be wrong to just add an image to the repo. I will post updates when I know more. |
@corinnebosley, thanks so much for the update. I know we're all volunteers here and I appreciate this work and the time you all put into it. |
Okay, I think this time, the test isn't failing because the images are different, but rather it's failing to build cartopy.
|
@ahuang11 You're quite right, the cartopy build itself is now failing due to updates to proj4. My colleague is looking into this and either she or I will put up a fix when we understand what cython's going to do with it a little better. For now though, all your tests are now passing (thanks for that!) and I want to give this another review before going ahead. |
Hey @ahuang11! I'm mostly very happy, but I'm slightly concerned by the images produced by your inline grid label machine for the USA. What worries me is the difference in text angles for labels which look like they should be at the same angle, shown on the Geostationary and Orthographic projections. I know it's even more work, but could you please add some tests to check that the text angle is being calculated correctly? It principle, it doesn't really matter if some plots just look ugly when constructed in a certain way (i.e. with inline grid labels); you just wouldn't make your plot with that argument. However, if there genuinely is something being calculated incorrectly that's a different matter and I shouldn't merge it yet. A few basic tests for the numbers themselves as opposed to images should do it I reckon. |
If I'm understanding correctly, you're saying that the 80W should be the same angle? I have checked out the current master branch of Cartopy and was able to replicate it because those aren't actually "inline" grid labels for Geostationary and Orthographic projections for the USA--those are labels from #1117 I have the default set to This is what it would look like if it's forced to be inline (the angle will be set to 0). Unfortunately, I did not write the angling logic and I don't have much of a clue about it (not sure if it's actually being calculated correctly or not). |
Thanks @ahuang11, nice work! |
Hi all, thanks for putting this in! Do you have a rough idea of when the next release will be, with this feature in? Thanks! |
This will be in the next release, 0.18. I'm hoping start pushing on that in a week or so, but I'm hesitant to give a firm timeline on when the release will be out. |
Work in progress after the newest merge; I know I haven't fully updated the tests! (Ignore the red s, I was using that as a reference)