-
Notifications
You must be signed in to change notification settings - Fork 39
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
Use dask to reduce memory consumption of extract_levels for masked data #776
Conversation
can one of you @bouweandela @jvegasbsc @schlunma pls review this, it'd be useful to have it in the release 👍 🍺 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a test like this one, but with lazy input and output data?
def test_interpolation__linear(self): | |
levels = [0.5, 1.5] | |
scheme = 'linear' | |
result = extract_levels(self.cube, levels, scheme) | |
expected = np.array([[[[2., 3.], [4., 5.]], [[6., 7.], [8., 9.]]], | |
[[[14., 15.], [16., 17.]], [[18., 19.], | |
[20., 21.]]]]) | |
self.assert_array_equal(result.data, expected) | |
self.shape[self.z_dim] = len(levels) | |
self.assertEqual(result.shape, tuple(self.shape)) |
Oh wait, that won't work, because this doesn't make the process completely lazy, right? |
yer, it's a half-mule process due to vinterp not returning a lazy object |
@bouweandela 👍 or 👎 |
Please see #776 (comment) |
Co-authored-by: Bouwe Andela <b.andela@esciencecenter.nl>
with mock.patch( | ||
'stratify.interpolate', return_value=new_data) as mocker: | ||
# first test lazy | ||
loaded_cube = iris.load_cube(self.filename) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make a cube with realized data lazy, you can do
cube.data = cube.lazy_data()
or
cube.data = da.asarray(cube.data, chunks=(1, 2, 3, 4))
if you want more control over how the lazy array is created. There is no need to first save to file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool! I didn't know that, but I wanted to replicate the actual conditions the function runs in anyway
Before you start, please read our contribution guidelines.
Tasks
If you need help with any of the tasks above, please do not hesitate to ask by commenting in the issue or pull request.
partially addressing #775
Mostly appreciated by ocean people, I noticed a memory consumption reduction by about 30% for level selection.