... | ... | @@ -14,31 +14,32 @@ Create a single integer summarizing all the tests of interest from the 'tests' a |
|
|
|
|
|
mask_test = np.sum(np.left_shift(1, tests-1)) # mask_test = 23 for tests 1,2,3,5
|
|
|
print(np.binary_repr(mask_test,width=16)) # Print the binary representation of the number
|
|
|
0000000000010111
|
|
|
# 0000000000010111
|
|
|
|
|
|
Search the companion QC field for at least one of the tests to be tripped. The result of the search is an array of true-false values.
|
|
|
|
|
|
mask = qc_direct_normal_broadband & mask_test > 0
|
|
|
print(mask)
|
|
|
[ True True True True False False False False True False]
|
|
|
# [ True True True True False False False False True False]
|
|
|
|
|
|
Then use the mask to replace values failing QC test with IEEE Not A Number to remove the data value from analysis
|
|
|
|
|
|
direct_normal_broadband[mask] = np.nan
|
|
|
print(direct_normal_broadband)
|
|
|
[ nan nan nan nan 11. 20. 50. 110. nan 134.]
|
|
|
# [ nan nan nan nan 11. 20. 50. 110. nan 134.]
|
|
|
|
|
|
direct_normal_broadband_mean = np.nanmean(direct_normal_broadband)
|
|
|
print(direct_normal_broadband_mean)
|
|
|
# 65.0
|
|
|
|
|
|
If you prefer you can also use [Numpy Masked Array](https://docs.scipy.org/doc/numpy/reference/maskedarray.html) to remove data from analysis.
|
|
|
|
|
|
direct_normal_broadband = np.ma.array(direct_normal_broadband, mask=mask)
|
|
|
print(direct_normal_broadband)
|
|
|
[-- -- -- -- 11.0 20.0 50.0 110.0 -- 134.0]
|
|
|
# [-- -- -- -- 11.0 20.0 50.0 110.0 -- 134.0]
|
|
|
|
|
|
direct_normal_broadband_mean = np.mean(direct_normal_broadband)
|
|
|
print(direct_normal_broadband_mean)
|
|
|
65.0
|
|
|
# 65.0
|
|
|
|
|
|
If a different set of tests were desired the only part that needs to change is 'tests', the rest of the code is independent of datastream or analysis. This will also work with multi-dimensional data. |
|
|
\ No newline at end of file |