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

Added new Extract surface preprocessor #1048

Draft
wants to merge 65 commits into
base: main
Choose a base branch
from
Draft

Added new Extract surface preprocessor #1048

wants to merge 65 commits into from

Conversation

ledm
Copy link
Contributor

@ledm ledm commented Mar 16, 2021

Description

This PR adds the extract_surface preprocessor, this is necessary because of the issues described in #1039.

Basically, when we're looking at a 3D dataset, but only want to keep the surface layer. Extract_layer can be used to do this, but it actually regrids the entire dataset along the z axis, so this is incredibly slow and memory intensive.


Before you get started

Checklist

If you make backwards incompatible changes to the recipe format:

  • Update ESMValTool and link the pull request(s) in the description

To help with the number pull requests:

@ledm ledm added enhancement New feature or request preprocessor Related to the preprocessor labels Mar 17, 2021
@ledm ledm marked this pull request as ready for review March 19, 2021 15:33
Copy link
Contributor

@valeriupredoi valeriupredoi left a comment

Choose a reason for hiding this comment

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

@ledm cheers dude! See a couple comments from me 👍 🍺

doc/recipe/preprocessor.rst Outdated Show resolved Hide resolved
doc/recipe/preprocessor.rst Outdated Show resolved Hide resolved
esmvalcore/preprocessor/_volume.py Outdated Show resolved Hide resolved
esmvalcore/preprocessor/_volume.py Outdated Show resolved Hide resolved
elif zcoord.points.ndim == 3:
points = zcoord.points.mean(axis=[1, 2])
elif zcoord.points.ndim == 4:
points = zcoord.points.mean(axis=[0, 2, 3])
Copy link
Contributor

Choose a reason for hiding this comment

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

could zcoord.points.ndim == 2?

Copy link
Contributor

Choose a reason for hiding this comment

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

either way, maybe add an exception if any of the dims are not the ones you analyze

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right.

The problem with that (and this method as a whole) is that it makes assumptions about the z-axis position. For instance, what if you have a cube with dimensions (time, depth, latitude) ie a meridional transect? The preprocessor would fail.

Maybe instead of that, we could replace this if-else loop with something more generic?

    zcoord_dim = cube.coord_dims(zcoord)[0]
    axes = np.arrange(zcoord.points.ndim).pop(zcoord_dim)
    points = zcoord.points.mean(axis=axes)

return cube[:, surf]

logger.error('Condition not recognised: postive: %s , zcoord_dim: %s, '
'surface level: %s', positive, zcoord_dim, surf)
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a very cryptic exception, could you reformulate for the user to understand what actually is wrong pls?

result = extract_surface(self.grid_3d)
self.assert_array_equal(result.data, self.grid_2d.data)
result2 = extract_surface(self.grid_4d)
self.assert_array_equal(self.grid_4d[:, 0, :, :].data, result2.data)
Copy link
Contributor

Choose a reason for hiding this comment

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

do you have a case for 1D as well?

@valeriupredoi
Copy link
Contributor

@ledm a couple linting issues and a couple of me comments still to be looked at, nice progress BTW 👍 🍺

@ledm ledm requested a review from jvegreg as a code owner May 25, 2021 12:31
@zklaus
Copy link

zklaus commented May 25, 2021

This seems to contain an awful lot of code that has nothing to do with the preprocessor. Could you please put the fixes in their own PR?

@ledm
Copy link
Contributor Author

ledm commented Jun 7, 2021

Hi @zklaus, sorry about that.

This branch has somehow become the working branch I'm using to do science. You'll see from the commits how ridiculous it is and how many fixes are needed just to look at model SST!

@zklaus zklaus marked this pull request as draft June 7, 2021 12:59
@zklaus zklaus added this to the v2.4.0 milestone Jun 7, 2021
@zklaus
Copy link

zklaus commented Jun 7, 2021

Ok, let's focus on other stuff for the upcoming release then.

@zklaus
Copy link

zklaus commented Sep 14, 2021

This still contains very many fixes. @ledm, I'd love to see this preprocessor go in, but there are just too many unrelated things here. Could you please separate out the fixes so we can move forward? Let me know if you need git help or something.

Conflicts:
	esmvalcore/_data_finder.py
	esmvalcore/_recipe.py
@zklaus
Copy link

zklaus commented Oct 5, 2021

I'll bump this to the next version. If we can't make any progress by then (Feb 2022), I'll suggest dropping this.

@zklaus zklaus modified the milestones: v2.4.0, v2.5.0 Oct 5, 2021
@schlunma
Copy link
Contributor

@ledm do you have any intentions to further work on this for v2.5?

@ledm
Copy link
Contributor Author

ledm commented Jan 21, 2022

I have a conceptual problem with this. I think it shouldn't be it's own thing, but rather should be a special case of the extract_levels preprocessor. I don't think users should have to know the difference...

@schlunma
Copy link
Contributor

I agree with that!

Do you think this is something you can do for v2.5? If not I will remove the milestone label so that we have a nice overview of what needs to be done before the release. 👍

@zklaus
Copy link

zklaus commented Jan 21, 2022

I agree and I think probably we won't make it for 2.5.0. I would move it to 2.6.0 instead of just removing the milestone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request preprocessor Related to the preprocessor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Extract_surface preprocessor
6 participants