Skip to content
Snippets Groups Projects
Commit b794c931 authored by kgao's avatar kgao
Browse files

Added qc variables

parent 83689402
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,24 @@ from datetime import timedelta as delta
LOG = logging.getLogger(__name__)
def filterArray(array, valid_min, valid_max):
qcControl = []
for value in array:
if value == float(-999):
qcControl.append(np.byte(0b1))
elif value < valid_min:
qcControl.append(np.byte(0b10))
elif value > valid_min:
qcControl.append(np.byte(0b100))
else:
qcControl.append(np.byte(0b0))
return np.array(qcControl)
# The purpose of this function is to write the dimensions
# for the nc file
# no parameters
......@@ -109,13 +127,31 @@ def createVariables(ncFile, firstStamp, chunksizes, zlib):
variable.valid_min = float(varTup[5])
variable.valid_max = float(varTup[6])
qcVariable = ncFile.createVariable('qc_' + entry, 'b',
dimensions=('time'), fill_value=0b0, zlib=zlib, chunksizes=chunksizes)
qcVariable.long_name = 'data quality'
qcVariable.valid_range = np.byte(0b1), np.byte(0b1111)
qcVariable.flag_masks = np.byte(0b1), np.byte(0b10), np.byte(0b100), np.byte(0b1000)
flagMeaning = ['value is equal to missing_value',
'value is less than the valid min',
'value is greater than the valid max',
'difference between current and previous values exceeds valid_delta.']
qcVariable.flag_meaning = ', '.join(flagMeaning)
#create global attributes
ncFile.source = 'surface observation'
ncFile.conventions = 'ARM-1.2 CF-1.6'
ncFile.institution = 'UW SSEC'
ncFile.featureType = 'timeSeries'
ncFile.data_level = 'a0'
ncFile.datastream = 'aoss.tower.nc.la0.v00'
ncFile.data_level = 'b1'
#monthly files end with .month.nc
#these end with .day.nc
ncFile.datastream = 'aoss.tower.y_nc.b1.v00'
ncFile.software_version = '00'
#generate history
......@@ -255,6 +291,13 @@ def writeVars(ncFile, frame):
dataArray = np.asarray(dataList)
fileVar[varName][:] = dataArray
if parser.database[varName][5] != '':
valid_min = float(parser.database[varName][5])
valid_max = float(parser.database[varName][6])
fileVar['qc_' + varName][:] = filterArray(dataArray, valid_min, valid_max)
return ncFile
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment