act.qc.QCFilter.get_qc_test_mask#

QCFilter.get_qc_test_mask(var_name=None, test_number=None, qc_var_name=None, flag_value=False, return_index=False)[source]#

Returns a numpy array of False or True where a particular flag or bit is set in a numpy array. Must set var_name or qc_var_name when calling.

Parameters:
  • var_name (str or None) – Data variable name.

  • test_number (int) – Test number to return array where test is set.

  • qc_var_name (str or None) – Quality control variable name. Ignored if var_name is set.

  • flag_value (boolean) – Switch to use flag_values integer quality control.

  • return_index (boolean) – Return a numpy array of index numbers into QC array where the test is set instead of False or True mask.

Returns:

test_mask (numpy bool array or numpy integer array) – A numpy boolean array with False or True where the test number or bit was set, or numpy integer array of indexes where test is True.

Examples

from act.io.arm import read_arm_netcdf
from act.tests import EXAMPLE_IRT25m20s

ds = read_arm_netcdf(EXAMPLE_IRT25m20s)
var_name = "inst_up_long_dome_resist"
result = ds.qcfilter.add_test(
    var_name, index=[0, 1, 2], test_meaning="Birds!"
)
qc_var_name = result["qc_variable_name"]
mask = ds.qcfilter.get_qc_test_mask(
    var_name, result["test_number"], return_index=True
)
print(mask)
array([0, 1, 2])

mask = ds.qcfilter.get_qc_test_mask(var_name, result["test_number"])
print(mask)
array([True, True, True, ..., False, False, False])

data = ds[var_name].values
print(data[mask])
array([7.84, 7.8777, 7.8965], dtype=float32)

import numpy as np

data[mask] = np.nan
print(data)
array([nan, nan, nan, ..., 7.6705, 7.6892, 7.6892], dtype=float32)