def apply_primary_qc(self, ncvariable): ''' Applies the primary QC array which is an aggregate of all the other QC tests. :param netCDF4.Variable ncvariable: NCVariable ''' primary_qc_name = 'qartod_%s_primary_flag' % ncvariable.name if primary_qc_name not in self.ncfile.variables: return qcvar = self.ncfile.variables[primary_qc_name] # Only perform primary QC on variables created by DAC if getattr(qcvar, 'dac_comment', '') != 'ioos_qartod_primary': return qc_variables = self.find_qc_flags(ncvariable) vectors = [] for qc_variable in qc_variables: ncvar = self.ncfile.variables[qc_variable] if getattr(ncvar, 'dac_comment', '') != 'ioos_qartod': continue log.info("Using %s in primary QC for %s", qc_variable, primary_qc_name) vectors.append(ma.getdata(ncvar[:])) log.info("Applying QC for %s", primary_qc_name) flags = qc.qc_compare(vectors) qcvar[:] = flags
def test_qc_compare(self): """ Tests that the compare function works as intended. """ range_flags = np.array([1, 1, 1, 9, 1, 1, 9, 9]) spike_flags = np.array([2, 1, 1, 1, 1, 1, 9, 9]) grdtn_flags = np.array([1, 3, 3, 4, 3, 1, 2, 9]) primary_flags = qc.qc_compare([range_flags, spike_flags, grdtn_flags]) np.testing.assert_array_equal(primary_flags, np.array([1, 3, 3, 4, 3, 1, 2, 9]))
def apply_primary_qc(self, ncvariable): ''' Applies the primary QC array which is an aggregate of all the other QC tests. :param netCDF4.Variable ncvariable: NCVariable ''' primary_qc_name = 'qartod_%s_primary_flag' % ncvariable.name if primary_qc_name not in self.ncfile.variables: return qcvar = self.ncfile.variables[primary_qc_name] ancillary_variables = self.find_ancillary_variables(ncvariable) vectors = [] for qc_variable in ancillary_variables: ncvar = self.ncfile.variables[qc_variable] vectors.append(ma.getdata(ncvar[:])) flags = qc.qc_compare(vectors) qcvar[:] = flags