From c96f19591455f25114605580a25d72ed62f3c395 Mon Sep 17 00:00:00 2001 From: tobiasmarke Date: Fri, 1 Dec 2023 14:34:15 +0100 Subject: [PATCH] Extract quality flag bits for lev2 products --- mwrpy/level2/write_lev2_nc.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mwrpy/level2/write_lev2_nc.py b/mwrpy/level2/write_lev2_nc.py index 19320d0..446e96b 100644 --- a/mwrpy/level2/write_lev2_nc.py +++ b/mwrpy/level2/write_lev2_nc.py @@ -19,6 +19,8 @@ interpol_2d, interpolate_2d, read_config, + setbit, + isbit, ) Fill_Value_Float = -999.0 @@ -497,9 +499,13 @@ def _get_qf( assume_unique=False, return_indices=True, ) - rpg_dat[product + "_quality_flag"] = np.max( - lev1["quality_flag"][index, freq_ind], axis=1 - ) + rpg_dat[product + "_quality_flag"] = np.zeros(len(index), np.int32) + for bit in range(8): + bit_set = np.any(isbit(lev1["quality_flag"][index, freq_ind], bit), axis=1) + if np.any(bit_set): + rpg_dat[product + "_quality_flag"][bit_set] = setbit( + rpg_dat[product + "_quality_flag"][bit_set], bit + ) rpg_dat[product + "_quality_flag_status"] = lev1["quality_flag_status"][ index, freq_ind[0] ]