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
def test_sort_dataids(self): """Check dataid sorting.""" dq = DataQuery(name='cheese_shops', wavelength=2, modifiers='*') did = DataID(self.default_id_keys_config, name='cheese_shops', wavelength=(1, 2, 3)) did2 = DataID(self.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(self.default_id_keys_config, name='cheese_shops', resolution=200) did2 = DataID(self.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(self.default_id_keys_config, name='cheese_shops', calibration='counts') did2 = DataID(self.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(self.default_id_keys_config, name='cheese_shops', modifiers=tuple()) did2 = DataID(self.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]
def test_create_less_modified_query(self): """Test that modifications are popped correctly.""" from satpy.dataset import DataQuery d1 = DataQuery(name="a", wavelength=0.2, modifiers=('hej', )) d2 = DataQuery(name="a", wavelength=0.2, modifiers=tuple()) assert not d1.create_less_modified_query()['modifiers'] assert not d2.create_less_modified_query()['modifiers']
def test_is_modified(self): """Test that modifications are detected properly.""" from satpy.dataset import DataQuery d1 = DataQuery(name="a", wavelength=0.2, modifiers=('hej', )) d2 = DataQuery(name="a", wavelength=0.2, modifiers=tuple()) assert d1.is_modified() assert not d2.is_modified()
def test_dataquery(self): """Test DataQuery objects.""" from satpy.dataset import DataQuery DataQuery(name='cheese_shops') # Check repr did = DataQuery(name='VIS008', resolution=111) assert repr(did) == "DataQuery(name='VIS008', resolution=111)" # Check inequality assert DataQuery(wavelength=10) != DataQuery(name="VIS006")
def test_seviri_hrv_has_priority_over_vis008(self): """Check that the HRV channel has priority over VIS008 when querying 0.8µm.""" dids = [DataID(self.default_id_keys_config, name='HRV', wavelength=WavelengthRange(min=0.5, central=0.7, max=0.9, unit='µm'), resolution=1000.134348869, calibration="reflectance", modifiers=()), DataID(self.default_id_keys_config, name='HRV', wavelength=WavelengthRange(min=0.5, central=0.7, max=0.9, unit='µm'), resolution=1000.134348869, calibration="radiance", modifiers=()), DataID(self.default_id_keys_config, name='HRV', wavelength=WavelengthRange(min=0.5, central=0.7, max=0.9, unit='µm'), resolution=1000.134348869, calibration="counts", modifiers=()), DataID(self.default_id_keys_config, name='VIS006', wavelength=WavelengthRange(min=0.56, central=0.635, max=0.71, unit='µm'), resolution=3000.403165817, calibration="reflectance", modifiers=()), DataID(self.default_id_keys_config, name='VIS006', wavelength=WavelengthRange(min=0.56, central=0.635, max=0.71, unit='µm'), resolution=3000.403165817, calibration="radiance", modifiers=()), DataID(self.default_id_keys_config, name='VIS006', wavelength=WavelengthRange(min=0.56, central=0.635, max=0.71, unit='µm'), resolution=3000.403165817, calibration="counts", modifiers=()), DataID(self.default_id_keys_config, name='VIS008', wavelength=WavelengthRange(min=0.74, central=0.81, max=0.88, unit='µm'), resolution=3000.403165817, calibration="reflectance", modifiers=()), DataID(self.default_id_keys_config, name='VIS008', wavelength=WavelengthRange(min=0.74, central=0.81, max=0.88, unit='µm'), resolution=3000.403165817, calibration="radiance", modifiers=()), DataID(self.default_id_keys_config, name='VIS008', wavelength=WavelengthRange(min=0.74, central=0.81, max=0.88, unit='µm'), resolution=3000.403165817, calibration="counts", modifiers=())] dq = DataQuery(wavelength=0.8) res, distances = dq.sort_dataids(dids) assert res[0].name == "HRV"
def test_sort_dataids_with_different_set_of_keys(self): """Check sorting data ids when the query has a different set of keys.""" dq = DataQuery(name='solar_zenith_angle', calibration='reflectance') dids = [DataID(self.default_id_keys_config, name='solar_zenith_angle', resolution=1000, modifiers=()), DataID(self.default_id_keys_config, name='solar_zenith_angle', resolution=500, modifiers=()), DataID(self.default_id_keys_config, name='solar_zenith_angle', resolution=250, modifiers=())] dsids, distances = dq.sort_dataids(dids) assert distances[0] < distances[1] assert distances[1] < distances[2]
def test_inequality(self): """Check (in)equality.""" assert DataQuery(wavelength=10) != DataID(self.default_id_keys_config, name="VIS006")
def test_hash_equality(self): """Test hash equality.""" dq = DataQuery(modifiers=tuple(), name='cheese_shops') did = DataID(self.default_id_keys_config, name='cheese_shops') assert hash(dq) == hash(did)