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

iris.experimental.stratify.relevel interface is difficult to use #5298

Open
bouweandela opened this issue May 2, 2023 · 9 comments
Open

Comments

@bouweandela
Copy link
Member

✨ Feature Request

In the ESMValCore, we have a Python function extract_levels originally contributed by @bjlittle. It would be nice if we could replace this function by iris.experimental.stratify.relevel, but the current implementation of that function has a difficult to use interface.

For example, if I have a 4D cube with dimensions (time x air_pressure x latitude x longitude), providing the source levels is difficult, it's unclear why I need to provide the axis argument, and the target levels lack any information on the variable name and units so the operation is quite unsafe:

src_coord = cube.coord(axis='Z')
src_coord_cube = cube[:1, :, :1, :1].copy()
src_levels = src_coord.points.reshape(1, src_coord.points.shape[0], 1, 1)
src_coord_cube.data = src_levels
tgt_levels = [100.]
result = relevel(cube=cube, src_levels=src_coord_cube, tgt_levels=tgt_levels, axis=src_coord)

What I would like to be able to do is

levels = iris.coords.DimCoord([100], standard_name='air_pressure', units='Pa')
result = iris.experimental.stratify.relevel(cube=cube, target_levels=levels)

i.e. the axis is automatically determined from the target levels and the source coordinate is found based on matching the target coordinate in the input cube.

Are there any plans for iris.experimental.stratify.relevel? Or are you planning to remove it in favour of more advanced techniques such as 3D regridding?

Related to #5290 and previously discussed in ESMValGroup/ESMValCore#35 (comment) and https://github.com/orgs/SciTools/projects/16?pane=issue&itemId=20691829.

@trexfeathers
Copy link
Contributor

Are there any plans for iris.experimental.stratify.relevel? Or are you planning to remove it in favour of more advanced techniques such as 3D regridding?

Planning to remove it because no-one is using it

@bjlittle
Copy link
Member

bjlittle commented May 2, 2023

Personally, I've never liked the relevel functionality as it was written for a very specific use case, and for that reason I find it pretty useless.

I'd vote to deprecate and retire it 👍

(ping @HGWright)

@trexfeathers
Copy link
Contributor

From discussion in @SciTools/peloton: we can definitely see the merit in an Iris-to-stratify convenience, but it shouldn't look the way it does now (written to solve a very specific case)! So the way forward is probably to completely re-do relevel to be more effective. Would love to hear more about your use case.

@bouweandela
Copy link
Member Author

Can iris.cube.Cube.interpolate already work with stratify schemes?

Our use cases in ESMValCore would be subsetting or interpolating vertical levels. Ideally with some configurable tolerance to use subsetting instead of interpolation if the requested level is already very close to what is available in the cube.

However, for more complicated grids, full 3D regridding might be more appropriate as also mentioned by @zklaus in earlier discussions.

@bjlittle
Copy link
Member

bjlittle commented May 4, 2023

Can iris.cube.Cube.interpolate already work with stratify schemes?

Nope. They're not related, as far as I know i.e., we don't have that level of interoperability (yet)... but it does sound interesting as a concept 🤔

@trexfeathers
Copy link
Contributor

@hdyson also registered an interest in relevel yesterday, in whatever form is most appropriate.

@bjlittle
Copy link
Member

bjlittle commented May 5, 2023

@bouweandela It would be great to hangout with you to capture your use case. I suspect this will shape the relevel API rebrand.

Would you be interested in doing that sometime?

@pp-mo
Copy link
Member

pp-mo commented May 5, 2023

Can iris.cube.Cube.interpolate already work with stratify schemes?

Actually I think it is implicit that all the Iris cube interpolation + regridding schemes only operate with horizontal coordinates.

This could really do with explaining -- unfortunately the piecemeal history of the various schemes has left us with a lot of unstated detail and a lack of consistency in explaining their various properties and usage requirements.
I'm hoping that #4754 may offer an opportunity to radically improve on this !

@hdyson
Copy link
Contributor

hdyson commented May 12, 2023

@hdyson also registered an interest in relevel yesterday, in whatever form is most appropriate.

Yeah, that "whatever form" is the key from our perspective here. We currently use stratify directly, so have no attachment to the existing iris interface. But when there is an iris interface to stratify that people are happy with, we'd be happy to migrate our usage over to the iris interface.

There's no urgency on our part here: our current solution works for our use cases, so the motivating factor would be the usual benefits of moving over to library solutions (less duplication, less code for us to maintain, more chance of bugs being found and fixed, etc).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Status: No status
Development

No branches or pull requests

5 participants