1 |
|
---|
2 |
|
---|
3 |
""" |
---|
4 |
Quality Control Tests and Utilities |
---|
5 |
""" |
---|
6 |
|
---|
7 |
def range_test(val, lower_limit, upper_limit): |
---|
8 |
""" QC Range Test |
---|
9 |
|
---|
10 |
Test whether value is inclusively within established upper and lower limit |
---|
11 |
|
---|
12 |
:Parameters: |
---|
13 |
val : scalar, list, or numpy.array |
---|
14 |
value(s) to be tested |
---|
15 |
lower_limit : scalar |
---|
16 |
Any value less than lower limit fails |
---|
17 |
upper_limit : scalar |
---|
18 |
Any value more than upper limit fails |
---|
19 |
|
---|
20 |
:Returns: |
---|
21 |
flag : boolean, list, numpy.array |
---|
22 |
True = Pass |
---|
23 |
False = Fail |
---|
24 |
|
---|
25 |
""" |
---|
26 |
flag = (val > lower_limit) & (val < upper_limit) |
---|
27 |
return (flag) |
---|
28 |
|
---|
29 |
def time_continuity_test(val, factor, v1, v2, t1, t2): |
---|
30 |
""" QC Time-Continuity Test |
---|
31 |
|
---|
32 |
Checks the amount of change in each measurment's value over the |
---|
33 |
given time period. If same or less than empirical form or constant |
---|
34 |
maximum of allowable change for a given time difference, then the |
---|
35 |
test passes. |
---|
36 |
|
---|
37 |
""" |
---|
38 |
flag = abs((v2-v1)/(t2-t1)) <= factor |
---|
39 |
return (flag) |
---|
40 |
|
---|
41 |
|
---|
42 |
def nc_pack_qcflags(qcflag, rtype='int8'): |
---|
43 |
""" Pack boolean numpy.array and cast for netcdf |
---|
44 |
padding where necessary |
---|
45 |
""" |
---|
46 |
|
---|
47 |
|
---|
48 |
|
---|
49 |
q1=qcflag.astype(int) |
---|
50 |
|
---|
51 |
|
---|
52 |
q2=numpy.packbits(q1,axis=1) |
---|
53 |
|
---|
54 |
qcflag=numpy.cast['int8'](q2) |
---|
55 |
|
---|
56 |
return (qcflag) |
---|
57 |
|
---|
58 |
def nc_unpack_qcflags(qcflag): |
---|
59 |
""" |
---|
60 |
""" |
---|
61 |
|
---|
62 |
|
---|
63 |
|
---|
64 |
|
---|
65 |
q1=numpy.cast['uint8'](qcflag) |
---|
66 |
|
---|
67 |
q2=numpy.unpackbits(q1, axis=1) |
---|
68 |
|
---|
69 |
qcflags=q2.astype(bool) |
---|