NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/raw2proc/trunk/raw2proc/qcutil.py

Revision 451 (checked in by cbc, 13 years ago)

Add various proc and config files not already under SVN.

Line 
1 #!/usr/bin/env python
2 # Last modified:  Time-stamp: <2011-05-11 15:59:31 haines>
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 # **** pack and unpack go in ncutil.py
42 def nc_pack_qcflags(qcflag, rtype='int8'):
43     """ Pack boolean numpy.array and cast for netcdf
44     padding where necessary
45     """
46     # check if boolean
47
48     # convert bool to int (0,1)
49     q1=qcflag.astype(int)
50     # pack 1s and 0s into a uint8 array
51     # (other dtype in this step not optional with numpy.packbits)
52     q2=numpy.packbits(q1,axis=1)
53     # cast uint8 to int8 (NC_BYTE)
54     qcflag=numpy.cast['int8'](q2)
55
56     return (qcflag)
57
58 def nc_unpack_qcflags(qcflag):
59     """
60     """
61
62     # check if uint8 (?)
63
64     # cast int8 (NC_BYTE) to uint8
65     q1=numpy.cast['uint8'](qcflag)
66     # unpack uint8 to 1s and 0s
67     q2=numpy.unpackbits(q1, axis=1)
68     #
69     qcflags=q2.astype(bool)
Note: See TracBrowser for help on using the browser.