Esempio n. 1
0
    def test_simple(self):
        p1 = self.write_field_data('v1', ncol=1, nrow=1)
        p2 = self.write_field_data('v2', ncol=1, nrow=1)
        p3 = self.write_field_data('v1', dir='b')
        p4 = self.write_field_data('v2', dir='b')

        ref_range = [dt.datetime(2000, 3, 1), dt.datetime(2000, 3, 31)]
        ref = [ocgis.RequestDataset(p, time_range=ref_range) for p in [p1, p2]]
        reference = ocgis.MultiRequestDataset(ref)
        reference = reference.get()

        cand_range = [dt.datetime(2000, 8, 1), dt.datetime(2000, 8, 31)]
        can = [
            ocgis.RequestDataset(p, time_range=cand_range) for p in [p3, p4]
        ]
        candidate = ocgis.MultiRequestDataset(can)

        calc = [{
            'func': 'dissimilarity',
            'name': 'output_mfpf',
            'kwds': {
                'target': reference,
                'candidate': ('v1', 'v2')
            }
        }]

        ops = OcgOperations(dataset=candidate, calc=calc)
        ret = ops.execute()
        actual_field = ret.get_element()
        actual_variables = get_variable_names(actual_field.data_variables)
        self.assertEqual(actual_variables[0], ('dissimilarity'))
        dist = actual_field['dissimilarity']
        self.assertEqual(dist.shape, (1, 1, 2, 2))
Esempio n. 2
0
    def test_full(self):
        """Compute the dissimilarity will all metrics."""
        from flyingpigeon import dissimilarity
        from matplotlib import pyplot as plt

        p1 = self.write_field_data('v1', ncol=1, nrow=1)
        p2 = self.write_field_data('v2', ncol=1, nrow=1)
        p3 = self.write_field_data('v1', ncol=11, nrow=10, dir='c')
        p4 = self.write_field_data('v2', ncol=11, nrow=10, dir='c')

        ref_range = [dt.datetime(2000, 3, 1), dt.datetime(2000, 3, 31)]
        ref = [ocgis.RequestDataset(p, time_range=ref_range) for p in [p1, p2]]
        reference = ocgis.MultiRequestDataset(ref)
        reference = reference.get()

        cand_range = [dt.datetime(2000, 8, 1), dt.datetime(2000, 8, 31)]
        can = [
            ocgis.RequestDataset(p, time_range=cand_range) for p in [p3, p4]
        ]
        candidate = ocgis.MultiRequestDataset(can)

        fig, axes = plt.subplots(2, 3)
        for i, dist in enumerate(dissimilarity.__all__):

            calc = [{
                'func': 'dissimilarity',
                'name': 'output_mfpf',
                'kwds': {
                    'target': reference,
                    'candidate': ('v1', 'v2'),
                    'dist': dist
                }
            }]

            ops = OcgOperations(dataset=candidate, calc=calc)
            ret = ops.execute()
            out_field = ret.get_element()
            var_name = get_variable_names(out_field.data_variables)[0]
            out = out_field[var_name].get_value()[0, 0]
            axes.flat[i].imshow(out)
            axes.flat[i].set_title(dist)

        path = os.path.join(test_output_path,
                            'test_spatial_analog_metrics.png')
        plt.savefig(path)
        plt.close()