Skip to content

Conversation

@pp-mo
Copy link
Member

@pp-mo pp-mo commented Oct 26, 2020

Now with no specific reference to ugrid.

This is now an extensive refactor of the Iris Cube summary and _repr_html_ methods.
Including changes needed to enable the forthcoming iris-ugrid UCubes to produce "extended" cube summmaries.

I have added testing for the new factored-out helper methods. But I haven't provided any test of how modifying these can produce extended cube summaries, as its not really an "API" + the requirement is hard to generalise.
That usage will eventually get tested by the specifics in iris-ugrid.

Meanwhile, you should see that all the existing tests simply pass. 🏹

Proposals for the specific use of this in iris-ugrid are here : SciTools-incubator/iris-ugrid#26

@pp-mo pp-mo force-pushed the cube_print_respin branch from 564a746 to f40aadc Compare October 27, 2020 16:39
@pp-mo pp-mo marked this pull request as ready for review October 27, 2020 16:39
@pp-mo
Copy link
Member Author

pp-mo commented Oct 27, 2020

Hi @trexfeathers
Hoping you can do this ? It's a bit of a big lump to swallow in one, but I've tried to make the individual commit changes intelligible.

@trexfeathers
Copy link
Contributor

Hi @trexfeathers
Hoping you can do this ?

@pp-mo I'm on it now 👀 sorry for the delay.

@trexfeathers
Copy link
Contributor

Note to self: have so far reviewed up to and including: 988710c

Copy link
Contributor

@trexfeathers trexfeathers left a comment

Choose a reason for hiding this comment

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

@pp-mo this looks like a huge improvement! 💐

A few things for you to address/answer, mainly on test coverage. Thanks!

lib/iris/cube.py Outdated
scalar_coords.sort(key=lambda coord: coord.name())
# Sort vector coordinates by data dimension and name.
vector_dim_coords.sort(
key=lambda coord: (self.coord_dims(coord), coord.name())
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
key=lambda coord: (self.coord_dims(coord), coord.name())
key=lambda coord: (self.coord_dims(coord))

Isn't this redundant, since it's not possible to have multiple DimCoords against a single dimension?

Copy link
Member Author

@pp-mo pp-mo Oct 29, 2020

Choose a reason for hiding this comment

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

Another good one!

I think, like the former code to select dim-names from multiple dim-coords, which I already removed, this is really an ancient legacy of a time when we hadn't yet sorted out what was and was not allowed for dim-coords.

It goes back to the initial commit on GitHub
(!)

Copy link
Contributor

Choose a reason for hiding this comment

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

@pp-mo has modified but not certain we're there yet. See: #3914 (comment)

@pp-mo
Copy link
Member Author

pp-mo commented Oct 29, 2020

Many thanks @trexfeathers . You seem to have done a very thorough job here ! 🚀
Hoping the latest addresses your comments.

@pp-mo
Copy link
Member Author

pp-mo commented Oct 29, 2020

@trexfeathers
Just to note, some of the points you raised I was originally side-stepping, because I was rather focussed on "pure refactoring".
I.E. I was sticking to "no functional change, even to fix things" , so as not to possibly break backwards-compatibility.

But in retrospect, that may be a useful reference idea, but it is over-strict :
We don't really expect anyone's code to be undermined by a slightly different cube-summary output, especially if it is "better".
We can take the opportunity to improve some things, just as we do to add some missing testing.

lib/iris/cube.py Outdated
Comment on lines 2352 to 2353
vector_aux_coords.sort(key=self.coord_dims)
vector_derived_coords.sort(key=self.coord_dims)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't actually know about derived_coords, but I was fairly certain that you are allowed to have multiple aux_coords against a single dimension, so it's still appropriate to keep the second sort by coord.name(). Am I wrong?

Copy link
Contributor

@trexfeathers trexfeathers Oct 29, 2020

Choose a reason for hiding this comment

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

We have now discovered that all 5 of the components in section_specs are intrinsically sorted since that's the way they come out of the Cube! @pp-mo is going to remove the sort lines.

],
)

def test_aux_coords_ordering(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you need the same for derived_coords?

Copy link
Contributor

Choose a reason for hiding this comment

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

Having discussed with @pp-mo, we've agreed that all we need to do is convert this test into a general confirmation of correct sorting, by:

  • Changing the test name
  • Adding a few dim_coords

@pp-mo
Copy link
Member Author

pp-mo commented Oct 29, 2020

Since @trexfeathers prompting above, I have realised that none of the element sorting is actually needed, as all the relevant cube access methods already provide the results ready-sorted by (cube-dims, name), which is exactly what we wanted.
E.G. cube.aux_coords.

So, I have now removed all that sorting code.

Also I have now rationalised all the scalar-element testing : "Scalar" elements are now consistently those with an empty ".cube_dims(cube)" -- any testing for a shape of (1,) I think was legacy which is now doing simply nothing.

ALSO, I've added a possible "scalar ancillary variables" section, which was previously missing.

@trexfeathers
Copy link
Contributor

So long as the tests pass, I will be happy with this..!

@trexfeathers trexfeathers merged commit 2a77c94 into SciTools:ugrid Oct 30, 2020
@pp-mo pp-mo deleted the cube_print_respin branch February 9, 2021 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants