diff --git a/modules/deeplearning/cnn_cld_frac.py b/modules/deeplearning/cnn_cld_frac.py index 951d8c0bf2f370e5161449851ad5314405f8adaa..7a3271bb0ced600f6bc97fef01e8891202ea21f6 100644 --- a/modules/deeplearning/cnn_cld_frac.py +++ b/modules/deeplearning/cnn_cld_frac.py @@ -175,27 +175,47 @@ def upsample(tmp): return tmp +def upsample_mean(grd): + bsize, ylen, xlen = grd.shape + grd = get_grid_cell_mean(grd) + up = np.zeros((bsize, ylen, xlen)) + + up[:, ::2, ::2] = grd[:, :, :] + up[:, 1::2, ::2] = grd[:, :, :] + up[:, ::2, 1::2] = grd[:, :, :] + up[:, 1::2, 1::2] = grd[:, :, :] + + return up + + +def get_grid_cell_mean(grd_k): + grd_k = np.where(np.isnan(grd_k), 0, grd_k) + + a = grd_k[:, 0::2, 0::2] + b = grd_k[:, 1::2, 0::2] + c = grd_k[:, 0::2, 1::2] + d = grd_k[:, 1::2, 1::2] + s = a + b + c + d + s /= 4.0 + + return s + + def get_label_data(grd_k): grd_k = np.where(np.isnan(grd_k), 0, grd_k) - # grd_k = np.where(grd_k < 0.5, 0, 1) a = grd_k[:, 0::2, 0::2] b = grd_k[:, 1::2, 0::2] c = grd_k[:, 0::2, 1::2] d = grd_k[:, 1::2, 1::2] s_t = a + b + c + d - # s_t = np.where(s_t == 0, 0, s_t) - # s_t = np.where(s_t == 1, 1, s_t) - # s_t = np.where(s_t == 2, 1, s_t) - # s_t = np.where(s_t == 3, 1, s_t) - # s_t = np.where(s_t == 4, 2, s_t) s_t /= 4.0 blen, ylen, xlen = s_t.shape s_t = s_t.flatten() cat_0 = np.logical_and(s_t >= 0.0, s_t < 0.2) - cat_1 = np.logical_and(s_t >= 0.2, s_t < 0.8) - cat_2 = np.logical_and(s_t >= 0.8, s_t <= 1.0) + cat_1 = np.logical_and(s_t >= 0.2, s_t < 0.7) + cat_2 = np.logical_and(s_t >= 0.7, s_t <= 1.0) s_t[cat_0] = 0 s_t[cat_1] = 1