From 5ffa1c6411aa925b1032e1cfcdf78bc305ecac4c Mon Sep 17 00:00:00 2001 From: Saksham Gupta Date: Tue, 13 Aug 2024 09:45:50 +0530 Subject: [PATCH] Fix flagging logic for missing and unknown data in QARTOD spike test --- ioos_qc/qartod.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ioos_qc/qartod.py b/ioos_qc/qartod.py index d69772c..e1ac6fd 100644 --- a/ioos_qc/qartod.py +++ b/ioos_qc/qartod.py @@ -611,9 +611,17 @@ def spike_test( flag_arr[0] = QartodFlags.UNKNOWN flag_arr[-1] = QartodFlags.UNKNOWN - # If the value is masked or nan set the flag to MISSING - flag_arr[diff.mask] = QartodFlags.MISSING - + # Check if the original data was masked + for i in range(inp.size): + + # Check if both inp and diff are masked + if inp.mask[i] and diff.mask[i]: + flag_arr[i] = QartodFlags.MISSING + + # Check if either inp or diff is masked + elif inp.mask[i] or diff.mask[i]: + flag_arr[i] = QartodFlags.UNKNOWN + return flag_arr.reshape(original_shape)