Gallery: update seasonal ensemble example#3933
Conversation
| # 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), |
There was a problem hiding this comment.
I don't actually understand the realization part of this constraint but removing it didn't make any difference to the plot.
There was a problem hiding this comment.
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 👀
There was a problem hiding this comment.
OK, because I hate not knowing, I had a play:
- If I don't use the callback or the realization constraint, I get a
MergeErrorbecause 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.
There was a problem hiding this comment.
@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? 🤔
There was a problem hiding this comment.
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 🙄 🤣
There was a problem hiding this comment.
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 🙏)
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Not really sure why this mattered...?
There was a problem hiding this comment.
Hmm I strongly suspect it is to do with how the plot was rendered around/over the dateline,
There was a problem hiding this comment.
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"))) |
There was a problem hiding this comment.
@rcomer Even better, use an f-string here? i.e.,
plt.suptitle(f"Surface temperature ensemble forecasts for {time.strftime('%B %Y')}")There was a problem hiding this comment.
Ooooo I've never used an f-string before 😁
There was a problem hiding this comment.
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.
| # 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), |
There was a problem hiding this comment.
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}") |
There was a problem hiding this comment.
I thought it might make it more obvious what's going on if the time_string is defined before creating the f-string.
5cbe12d to
060e82a
Compare
|
Thanks @bjlittle 🎉 |
* 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) ...
🚀 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