Skip to content
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

Gallery: update seasonal ensemble example #3933

Merged
merged 5 commits into from
Dec 7, 2020

Conversation

rcomer
Copy link
Member

@rcomer rcomer commented Nov 29, 2020

🚀 Pull Request

Description

Iris has moved on a lot since many of the gallery examples were added. This PR simplifies the seasonal forecast example as well as dropping the old school "%s" string formatting.


Consult Iris pull request check list

@@ -51,7 +52,7 @@ def main():
# coordinate, adding appropriate lagged ensemble metadata
surface_temp = iris.load_cube(
iris.sample_data_path("GloSea4", "ensemble_???.pp"),
iris.Constraint("surface_temperature", realization=lambda value: True),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't actually understand the realization part of this constraint but removing it didn't make any difference to the plot.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow. Okay, what the heck... hmmm without digging this seems like an ancient workaround for something.

The only thing I can think of is that it's ensuring that the realization coordinate is always present? Dunno... anyways if removing it makes no difference, then let's remove it. Great spot 👀

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, because I hate not knowing, I had a play:

  • If I don't use the callback or the realization constraint, I get a MergeError because of mismatched "realization" coordinates, as we might expect.
  • If I don't use the callback but reinstate the realization constraint, the plot works fine but more maps and lines are missing. So yeah, it seems this is a "coordinate exists" constraint, which actually seems quite useful, though I guess you could get the same effect using a cube_func.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rcomer Well at the very least it deserves a comment to explain what the heck it's doing.

It's a neat pattern to employ without cracking open the cube_func. So let's honour the original authors intent but with some clarification for the reader... what say ye? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely: if we're going to include it, it should be explained! But... if we advertise this behaviour, should there also be a test for this behaviour? Is there a test for this behaviour? If not, should I add one, and if so where?

And I thought a gallery update would be straightforward 🙄 🤣

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries. Let's conquer and divide here 💪

How's about you add a comment, if you're happy doing that and I'll add some appropriate test coverage, and target a pull-request on your rcomer:gallery-seasonal-ensemble branch.

Deal?

(Ode to a simple life 🙏)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sounds good to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured it's easier to explain the constraint if it's defined on its own line.


# Subsetting a circular longitude coordinate always results in a circular
# coordinate, so set the coordinate to be non-circular
nino_cube.coord("longitude").circular = False
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really sure why this mattered...?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I strongly suspect it is to do with how the plot was rendered around/over the dateline,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then we're taking an area mean before we plot it... 🤷

% (time.strftime("%B %Y"),)
)
title = "Surface temperature ensemble forecasts for {}"
plt.suptitle(title.format(time.strftime("%B %Y")))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rcomer Even better, use an f-string here? i.e.,

plt.suptitle(f"Surface temperature ensemble forecasts for {time.strftime('%B %Y')}")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooooo I've never used an f-string before 😁

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as format is a step-up from %, f-strings are a step-up from format IMHO

e.g., generally once you've tried them, you don't look back. I kinda love'em now.

@bjlittle bjlittle self-assigned this Dec 3, 2020
@bjlittle bjlittle added this to the v3.1.0 milestone Dec 3, 2020
Copy link
Member Author

@rcomer rcomer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @bjlittle, I think I've covered those points now. I also, somewhat belatedly, realised that the comments were a bit inconsistent. So have been through and enforced capital letters and full stops.

@@ -51,7 +52,7 @@ def main():
# coordinate, adding appropriate lagged ensemble metadata
surface_temp = iris.load_cube(
iris.sample_data_path("GloSea4", "ensemble_???.pp"),
iris.Constraint("surface_temperature", realization=lambda value: True),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured it's easier to explain the constraint if it's defined on its own line.

# Set a global title for the postage stamps with the date formated by
# "monthname year".
time_string = time.strftime("%B %Y")
plt.suptitle(f"Surface temperature ensemble forecasts for {time_string}")
Copy link
Member Author

@rcomer rcomer Dec 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it might make it more obvious what's going on if the time_string is defined before creating the f-string.

Copy link
Member

@bjlittle bjlittle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rcomer LGTM 👍

Thanks for sticking with it 😄

@bjlittle bjlittle merged commit 3483482 into SciTools:master Dec 7, 2020
@rcomer
Copy link
Member Author

rcomer commented Dec 7, 2020

Thanks @bjlittle 🎉

@rcomer rcomer deleted the gallery-seasonal-ensemble branch December 7, 2020 11:59
tkknight added a commit to tkknight/iris that referenced this pull request Feb 9, 2021
* master: (23 commits)
  Added text to state the Python version used to build the docs. (SciTools#3989)
  add nox session conda list (SciTools#3990)
  Add abstract cube summary (SciTools#3987)
  automate docs discovery of iris and python versions (SciTools#3981)
  corrected syntax (SciTools#3980)
  core dev whatsnew entry (SciTools#3978)
  moved docs dir and updated references to it (SciTools#3975)
  Fix test_incompatible_dimensions test (SciTools#3977)
  remove explicit URLs for core dev names from latest.rst (SciTools#3973)
  document that iris.coords.Coord is an ABC (SciTools#3971)
  reorganise docs common links + add core devs (SciTools#3972)
  Docs whatsnew add dropdowns to the template (SciTools#3969)
  Docs whatsnew enumerated lists (SciTools#3970)
  Merge back v3p0p1 (SciTools#3966)
  Captilise installation heading - align SciTools#3958 content with SciTools#3940. (SciTools#3963)
  Merge back v3p0p0 (SciTools#3960)
  Extended the installation description (SciTools#3958)
  Put cube data on the x axis if plotting just a cube against a vertical or y coordinate (SciTools#3906)
  remove stock_mdi_arrays.npz (SciTools#3913)
  Gallery: update seasonal ensemble example (SciTools#3933)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants