From bc39b1ba74b2bfb49f929c6b007bbae3e8a15280 Mon Sep 17 00:00:00 2001 From: sloosvel Date: Fri, 23 Oct 2020 15:47:26 +0200 Subject: [PATCH 1/3] Adapt to dask and mask with nans --- diagonals/ohc.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/diagonals/ohc.py b/diagonals/ohc.py index e5cd6c6..c73298a 100644 --- a/diagonals/ohc.py +++ b/diagonals/ohc.py @@ -1,4 +1,5 @@ import numpy as np +import dask.array as da from numba import vectorize from numba import cuda @@ -162,7 +163,7 @@ def _compute_ohc_cpu(layers, thetao, weights, area): """ ohc = [] for layer in range(len(layers)): - ohc_layer = _sum_red.reduce( + ohc_layer = da.sum( _multiply_array(thetao, weights[layer]), axis=1 ) @@ -259,8 +260,6 @@ def _calculate_weight_numba_cuda(min_depth, max_depth, e3t, depth, mask): weight: float32 Masked array containing the weights for a given layer. """ - if not mask: - return 0 top = depth bottom = top + e3t if bottom < min_depth or top > max_depth: @@ -270,6 +269,8 @@ def _calculate_weight_numba_cuda(min_depth, max_depth, e3t, depth, mask): top = min_depth if bottom > max_depth: bottom = max_depth + if not mask: + return np.nan return (bottom - top) * 1020 * 4000 @@ -361,8 +362,6 @@ def _calculate_weight_numba(min_depth, max_depth, e3t, depth, mask): weight: float32 Masked array containing the weights for a given layer. """ - if not mask: - return 0 top = depth bottom = top + e3t if bottom < min_depth or top > max_depth: @@ -372,6 +371,8 @@ def _calculate_weight_numba(min_depth, max_depth, e3t, depth, mask): top = min_depth if bottom > max_depth: bottom = max_depth + if not mask: + return np.nan return (bottom - top) * 1020 * 4000 -- GitLab From 64324949af5848ac75fb1f375b3bbb3aeea491c8 Mon Sep 17 00:00:00 2001 From: sloosvel Date: Fri, 23 Oct 2020 17:10:02 +0200 Subject: [PATCH 2/3] Fix test --- test/unit/test_ohc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/test_ohc.py b/test/unit/test_ohc.py index a7641df..fd885cd 100644 --- a/test/unit/test_ohc.py +++ b/test/unit/test_ohc.py @@ -23,7 +23,7 @@ class TestOhc(unittest.TestCase): cell_height=np.array(((1., 2.), (4., 3.)), dtype=np.float32), cell_top_depth=np.array(((0., 0.), (1., 2.)), dtype=np.float32) ) - self.assertTrue(np.all(weights == np.zeros((2, 2), dtype=np.float32))) + self.assertTrue(np.all(np.isnan(weights))) def test_weights_mul_layers(self): weights = ohc.get_weights( -- GitLab From bd9a8fc08e1881692e13375aed33fdc8a27cbb9d Mon Sep 17 00:00:00 2001 From: sloosvel Date: Tue, 27 Oct 2020 10:58:26 +0100 Subject: [PATCH 3/3] Bump version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 2d08400..48cb8a4 100644 --- a/setup.py +++ b/setup.py @@ -36,7 +36,7 @@ REQUIREMENTS = { setup(name='diagonals', - version='0.3.1', + version='0.3.2', description='Compute diagnostics targeting the CPU or the GPU', url='https://earth.bsc.es/gitlab/es/diagonals', author='BSC-CNS Earth Sciences Department', -- GitLab