|
4 | 4 | from hypothesis import given |
5 | 5 | from hypothesis.strategies import lists |
6 | 6 |
|
7 | | -from tests.storage_data import ers_granules, s5p_granules, umbra_granules |
8 | | -from tilebox.storage.granule import ASFStorageGranule, CopernicusStorageGranule, UmbraStorageGranule, _asf_download_urls |
| 7 | +from tests.storage_data import ers_granules, landsat_granules, s5p_granules, umbra_granules |
| 8 | +from tilebox.storage.granule import ( |
| 9 | + ASFStorageGranule, |
| 10 | + CopernicusStorageGranule, |
| 11 | + UmbraStorageGranule, |
| 12 | + USGSLandsatStorageGranule, |
| 13 | + _asf_download_urls, |
| 14 | +) |
9 | 15 |
|
10 | 16 |
|
11 | 17 | def _asf_granule_to_datapoint(granule: ASFStorageGranule) -> xr.Dataset: |
@@ -101,3 +107,31 @@ def test_granule_from_copernicus_datapoints(granules: list[CopernicusStorageGran |
101 | 107 |
|
102 | 108 | for i in range(len(granules)): # converting a dataset with a time dimension of 1 should still work though |
103 | 109 | assert CopernicusStorageGranule.from_data(dataset.isel(time=i)) == granules[i] |
| 110 | + |
| 111 | + |
| 112 | +def _landsat_granule_to_datapoint(granule: USGSLandsatStorageGranule) -> xr.Dataset: |
| 113 | + datapoint = xr.Dataset() |
| 114 | + datapoint.coords["time"] = np.array(granule.time).astype("datetime64[ns]") |
| 115 | + datapoint["granule_name"] = granule.granule_name |
| 116 | + datapoint["location"] = granule.location |
| 117 | + if granule.thumbnail is not None: |
| 118 | + datapoint["thumbnail"] = f"{granule.location}/{granule.thumbnail}" |
| 119 | + return datapoint |
| 120 | + |
| 121 | + |
| 122 | +@given(landsat_granules()) |
| 123 | +def test_granule_from_landsat_datapoint(granule: USGSLandsatStorageGranule) -> None: |
| 124 | + datapoint = _landsat_granule_to_datapoint(granule) |
| 125 | + assert USGSLandsatStorageGranule.from_data(datapoint) == granule |
| 126 | + assert USGSLandsatStorageGranule.from_data(USGSLandsatStorageGranule.from_data(datapoint)) == granule |
| 127 | + |
| 128 | + |
| 129 | +@given(lists(landsat_granules(), min_size=2, max_size=5)) |
| 130 | +def test_granule_from_landsat_datapoints(granules: list[USGSLandsatStorageGranule]) -> None: |
| 131 | + datapoints = [_landsat_granule_to_datapoint(granule) for granule in granules] |
| 132 | + dataset = xr.concat(datapoints, dim="time") |
| 133 | + with pytest.raises(ValueError, match=".*more than one granule.*"): |
| 134 | + USGSLandsatStorageGranule.from_data(dataset) |
| 135 | + |
| 136 | + for i in range(len(granules)): # converting a dataset with a time dimension of 1 should still work though |
| 137 | + assert USGSLandsatStorageGranule.from_data(dataset.isel(time=i)) == granules[i] |
0 commit comments