Skip to content

Commit 2d5bc85

Browse files
committed
adds qc variables
1 parent b6d6168 commit 2d5bc85

3 files changed

Lines changed: 48 additions & 1 deletion

File tree

ocean_dp/qc/add_qc_flags.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,7 @@ def add_qc(netCDFfile):
101101

102102

103103
if __name__ == "__main__":
104-
add_qc(sys.argv[1:])
104+
add_qc(sys.argv[1:])
105+
106+
107+

ocean_dp/qc/netcdf_gen.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import sys
1818
from datetime import datetime
1919
import numpy as np
20+
import shutil
2021

2122
# Provide the function with a filename (don't include .nc), a nominal depth,
2223
# and pairs of names and arrays containing the data to be included as variables.
@@ -26,6 +27,8 @@
2627
# For example, netcdf_gen('test',30,'PRES',pres_data,'TEMP',temp_data)
2728
# from the command line gen_test_data.py test 30 PRES 10,20,30 TEMP 11,12,NaN
2829

30+
31+
2932
def netcdf_gen(file_name, nominal_depth, *args):
3033
# Convert the args tuple to a list
3134
args = list(args)
@@ -93,10 +96,49 @@ def netcdf_gen(file_name, nominal_depth, *args):
9396
ds.createVariable(name_in, "f8", ("TIME"))
9497
ds.variables[name_in][:] = data_in
9598

99+
# read the variable names from the netCDF dataset
100+
vars = ds.variables
101+
102+
# create a list of variables, don't include the 'TIME' variable
103+
# TODO: detect 'TIME' variable using the standard name 'time'
104+
to_add = []
105+
106+
for v in vars:
107+
#print (vars[v].dimensions)
108+
if v != 'TIME':
109+
to_add.append(v)
110+
111+
# for each variable, add a new ancillary variable <VAR>_quality_control to each which has 'TIME' as a dimension
112+
for v in to_add:
113+
if "TIME" in vars[v].dimensions:
114+
# print("time dim ", v)
115+
116+
if v+"_quality_control" not in ds.variables:
117+
ncVarOut = ds.createVariable(v+"_quality_control", "i1", vars[v].dimensions, fill_value=99, zlib=True) # fill_value=99 otherwise defaults to max, imos-toolbox uses 99
118+
ncVarOut[:] = np.zeros(vars[v].shape)
119+
ncVarOut.long_name = "quality_code for " + v
120+
ncVarOut.flag_values = np.array([0, 1, 2, 3, 4, 6, 7, 9])
121+
ncVarOut.flag_meanings = 'unknown good_data probably_good_data probably_bad_data bad_data not_deployed interpolated missing_value'
122+
123+
124+
vars[v].ancillary_variables = v + "_quality_control"
125+
126+
# update the global attributes
127+
ds.file_version = "Level 1 - Quality Controlled Data"
128+
129+
ds.history = datetime.utcnow().strftime("%Y%m%d:") + ' converted to FV01 file, quality_control variables added.'
130+
131+
# ADD quality control attributes!!
132+
96133
ds.close()
134+
135+
#add_qc(file_name)
136+
97137
print("generated ", file_name)
98138

99139
return (file_name)
140+
141+
100142

101143
else:
102144
print('Data arrays not of equal length')

ocean_dp/qc/select_in_water.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
# Submit argument as a list
3131

32+
33+
3234
def select_in_water(netCDFfiles):
3335

3436
new_name = [] # list of new file names

0 commit comments

Comments
 (0)