Пример #1
0
    def setUp(self):
        """Set up the test tree."""
        self.dependency_tree = DependencyTree(None, None, None)

        composite_1 = make_cid(name="comp19")
        dependency_1 = make_dataid(name="ds5",
                                   resolution=250,
                                   modifiers=("res_change", ))
        dependency_1_1 = make_dataid(name="ds5",
                                     resolution=250,
                                     modifiers=tuple())
        node_composite_1 = self.dependency_tree.add_leaf(composite_1)
        node_dependency_1 = self.dependency_tree.add_leaf(
            dependency_1, node_composite_1)
        self.dependency_tree.add_leaf(dependency_1_1, node_dependency_1)
        # ToDo: do we really want then empty node to be at the same level as the unmodified data?
        node_dependency_1.add_child(self.dependency_tree.empty_node)

        dependency_2 = make_cid(name="comp13")
        dependency_2_1 = dependency_1
        node_dependency_2 = self.dependency_tree.add_leaf(
            dependency_2, node_composite_1)
        self.dependency_tree.add_leaf(dependency_2_1, node_dependency_2)
        # We don't need to add the unmodified dependency a second time.

        dependency_3 = make_dataid(name='ds2',
                                   resolution=250,
                                   calibration="reflectance",
                                   modifiers=tuple())
        self.dependency_tree.add_leaf(dependency_3, node_composite_1)
Пример #2
0
    def test_id_filtering(self):
        """Check did filtering."""
        dq = DataQuery(modifiers=tuple(), name='cheese_shops')
        did = DataID(self.default_id_keys_config, name='cheese_shops')
        did2 = DataID(self.default_id_keys_config, name='ni')
        res = dq.filter_dataids([did2, did])
        assert len(res) == 1
        assert res[0] == did

        dataid_container = [
            DataID(self.default_id_keys_config,
                   name='ds1',
                   resolution=250,
                   calibration='reflectance',
                   modifiers=tuple())
        ]
        dq = DataQuery(wavelength=0.22, modifiers=tuple())
        assert len(dq.filter_dataids(dataid_container)) == 0
        dataid_container = [
            DataID(minimal_default_keys_config, name='natural_color')
        ]
        dq = DataQuery(name='natural_color', resolution=250)
        assert len(dq.filter_dataids(dataid_container)) == 1

        dq = make_dsq(wavelength=0.22, modifiers=('mod1', ))
        did = make_cid(name='static_image')
        assert len(dq.filter_dataids([did])) == 0
Пример #3
0
    def setUp(self):
        """Set up the test tree."""
        from satpy.composites import CompositeBase
        from satpy.modifiers import ModifierBase
        from satpy.dataset.data_dict import DatasetDict

        class _FakeCompositor(CompositeBase):
            def __init__(self, ret_val, *args, **kwargs):
                self.ret_val = ret_val
                super().__init__(*args, **kwargs)

            def __call__(self, *args, **kwargs):
                return self.ret_val

        class _FakeModifier(ModifierBase):
            def __init__(self, ret_val, *args, **kwargs):
                self.ret_val = ret_val
                super().__init__(*args, **kwargs)

            def __call__(self, *args, **kwargs):
                return self.ret_val

        comp1_sensor1 = _FakeCompositor(1, "comp1")
        comp1_sensor2 = _FakeCompositor(2, "comp1")
        # create the dictionary one element at a time to force "incorrect" order
        # (sensor2 comes before sensor1, but results should be alphabetical order)
        compositors = {}
        compositors['sensor2'] = s2_comps = DatasetDict()
        compositors['sensor1'] = s1_comps = DatasetDict()
        c1_s2_id = make_cid(name='comp1', resolution=1000)
        c1_s1_id = make_cid(name='comp1', resolution=500)
        s2_comps[c1_s2_id] = comp1_sensor2
        s1_comps[c1_s1_id] = comp1_sensor1

        modifiers = {}
        modifiers['sensor2'] = s2_mods = {}
        modifiers['sensor1'] = s1_mods = {}
        s2_mods['mod1'] = (_FakeModifier, {'ret_val': 2})
        s1_mods['mod1'] = (_FakeModifier, {'ret_val': 1})

        self.dependency_tree = DependencyTree({}, compositors, modifiers)
        # manually add a leaf so we don't have to mock a reader
        ds5 = make_dataid(name="ds5", resolution=250, modifiers=tuple())
        self.dependency_tree.add_leaf(ds5)
Пример #4
0
    def test_copy_preserves_all_nodes(self):
        """Test that dependency tree copy preserves all nodes."""
        new_dependency_tree = self.dependency_tree.copy()
        assert self.dependency_tree.empty_node is new_dependency_tree.empty_node
        assert self._nodes_equal(self.dependency_tree.leaves(),
                                 new_dependency_tree.leaves())
        assert self._nodes_equal(self.dependency_tree.trunk(),
                                 new_dependency_tree.trunk())

        # make sure that we can get access to sub-nodes
        c13_id = make_cid(name='comp13')
        assert self._nodes_equal(self.dependency_tree.trunk(limit_nodes_to=[c13_id]),
                                 new_dependency_tree.trunk(limit_nodes_to=[c13_id]))
Пример #5
0
def test_id_query_interactions():
    """Test interactions between DataIDs and DataQuery's."""
    from satpy.dataset.dataid import DataQuery, DataID, WavelengthRange, ModifierTuple, minimal_default_keys_config

    default_id_keys_config = {
        'name': {
            'required': True,
        },
        'wavelength': {
            'type': WavelengthRange,
        },
        'resolution': None,
        'calibration': {
            'enum':
            ['reflectance', 'brightness_temperature', 'radiance', 'counts']
        },
        'modifiers': {
            'default': ModifierTuple(),
            'type': ModifierTuple,
        },
    }

    # Check hash equality
    dq = DataQuery(modifiers=tuple(), name='cheese_shops')
    did = DataID(default_id_keys_config, name='cheese_shops')
    assert hash(dq) == hash(did)

    # Check did filtering
    did2 = DataID(default_id_keys_config, name='ni')
    res = dq.filter_dataids([did2, did])
    assert len(res) == 1
    assert res[0] == did

    dataid_container = [
        DataID(default_id_keys_config,
               name='ds1',
               resolution=250,
               calibration='reflectance',
               modifiers=tuple())
    ]
    dq = DataQuery(wavelength=0.22, modifiers=tuple())
    assert len(dq.filter_dataids(dataid_container)) == 0
    dataid_container = [
        DataID(minimal_default_keys_config, name='natural_color')
    ]
    dq = DataQuery(name='natural_color', resolution=250)
    assert len(dq.filter_dataids(dataid_container)) == 1

    dq = make_dsq(wavelength=0.22, modifiers=('mod1', ))
    did = make_cid(name='static_image')
    assert len(dq.filter_dataids([did])) == 0

    # Check did sorting
    dq = DataQuery(name='cheese_shops', wavelength=2, modifiers='*')
    did = DataID(default_id_keys_config,
                 name='cheese_shops',
                 wavelength=(1, 2, 3))
    did2 = DataID(default_id_keys_config,
                  name='cheese_shops',
                  wavelength=(1.1, 2.1, 3.1))
    dsids, distances = dq.sort_dataids([did2, did])
    assert list(dsids) == [did, did2]
    assert np.allclose(distances, [0, 0.1])

    dq = DataQuery(name='cheese_shops')
    did = DataID(default_id_keys_config, name='cheese_shops', resolution=200)
    did2 = DataID(default_id_keys_config, name='cheese_shops', resolution=400)
    dsids, distances = dq.sort_dataids([did2, did])
    assert list(dsids) == [did, did2]
    assert distances[0] < distances[1]

    did = DataID(default_id_keys_config,
                 name='cheese_shops',
                 calibration='counts')
    did2 = DataID(default_id_keys_config,
                  name='cheese_shops',
                  calibration='reflectance')
    dsids, distances = dq.sort_dataids([did2, did])
    assert list(dsids) == [did2, did]
    assert distances[0] < distances[1]

    did = DataID(default_id_keys_config,
                 name='cheese_shops',
                 modifiers=tuple())
    did2 = DataID(default_id_keys_config,
                  name='cheese_shops',
                  modifiers=tuple(['out_of_stock']))
    dsids, distances = dq.sort_dataids([did2, did])
    assert list(dsids) == [did, did2]
    assert distances[0] < distances[1]

    # Check (in)equality
    assert DataQuery(wavelength=10) != DataID(default_id_keys_config,
                                              name="VIS006")