def test_full(self):
     ca.classification_accuracy(self.data_fn, self.classifier_fn, 'k.csv',
         'e.csv', 'OBSERVED', 'PREDICTED')
     self.assertTrue(filecmp.cmp(self.k_ref, 'k.csv'))
     self.assertTrue(filecmp.cmp(self.e_ref, 'e.csv'))
     os.remove('k.csv')
     os.remove('e.csv')
    def run_diagnostic(self):

        # Read the observed and predicted files into numpy recarrays
        obs = utilities.csv2rec(self.observed_file)
        prd = utilities.csv2rec(self.predicted_file)

        # Subset the observed data just to the IDs that are in the
        # predicted file
        obs_keep = np.in1d(
            getattr(obs, self.id_field), getattr(prd, self.id_field))
        obs = obs[obs_keep]

        # Calculate VEGCLASS for both the observed and predicted data
        vc_dict = self.vegclass_aa(obs, prd, id_field=self.id_field)

        # Print out the vegclass file
        vc_fh = open(self.vegclass_file, 'w')
        vc_fh.write(','.join((self.id_field, 'OBSERVED', 'PREDICTED')) + '\n')

        # Print out the observed and predicted vegetation classes
        for id_val in sorted(vc_dict.keys()):
            obs_vc = vc_dict[id_val]['obs_vc']
            prd_vc = vc_dict[id_val]['prd_vc']
            out_list = ['%d' % x for x in (id_val, obs_vc, prd_vc)]
            vc_fh.write(','.join(out_list) + '\n')
        vc_fh.close()

        # Create the vegetation class kappa and error matrix files
        vc_xml = 'L:/resources/code/xml/vegclass.xml'
        ca.classification_accuracy(self.vegclass_file, vc_xml,
            kappa_file=self.vegclass_kappa_file,
            err_matrix_file=self.vegclass_errmatrix_file)
Пример #3
0
    def run_diagnostic(self):

        # Read the observed and predicted files into numpy recarrays
        obs = utilities.csv2rec(self.observed_file)
        prd = utilities.csv2rec(self.predicted_file)

        # Subset the observed data just to the IDs that are in the
        # predicted file
        obs_keep = np.in1d(getattr(obs, self.id_field),
                           getattr(prd, self.id_field))
        obs = obs[obs_keep]

        # Calculate VEGCLASS for both the observed and predicted data
        vc_dict = self.vegclass_aa(obs, prd, id_field=self.id_field)

        # Print out the vegclass file
        vc_fh = open(self.vegclass_file, 'w')
        vc_fh.write(','.join((self.id_field, 'OBSERVED', 'PREDICTED')) + '\n')

        # Print out the observed and predicted vegetation classes
        for id_val in sorted(vc_dict.keys()):
            obs_vc = vc_dict[id_val]['obs_vc']
            prd_vc = vc_dict[id_val]['prd_vc']
            out_list = ['%d' % x for x in (id_val, obs_vc, prd_vc)]
            vc_fh.write(','.join(out_list) + '\n')
        vc_fh.close()

        # Create the vegetation class kappa and error matrix files
        vc_xml = 'L:/resources/code/xml/vegclass.xml'
        ca.classification_accuracy(
            self.vegclass_file,
            vc_xml,
            kappa_file=self.vegclass_kappa_file,
            err_matrix_file=self.vegclass_errmatrix_file)