|
2 | 2 | import logging
|
3 | 3 | import os
|
4 | 4 |
|
5 |
| -import numpy as np |
6 | 5 | import pytest
|
7 | 6 | from rasterio.windows import Window
|
8 | 7 | from sertit import ci
|
9 | 8 |
|
| 9 | +from CI.scripts_utils import READER, dask_env, get_db_dir, others_path, s3_env |
10 | 10 | from eoreader import EOREADER_NAME
|
11 |
| -from eoreader.bands import ( |
12 |
| - BLUE, |
13 |
| - CA, |
14 |
| - CLOUDS, |
15 |
| - GREEN, |
16 |
| - HH, |
17 |
| - HILLSHADE, |
18 |
| - NDVI, |
19 |
| - NIR, |
20 |
| - RED, |
21 |
| - RH, |
22 |
| - SWIR_1, |
23 |
| - VV, |
24 |
| - VV_DSPK, |
25 |
| - YELLOW, |
26 |
| -) |
| 11 | +from eoreader.bands import BLUE, CA, GREEN, HILLSHADE, NDVI, NIR, RED, SWIR_1 |
27 | 12 | from eoreader.env_vars import DEM_PATH
|
28 |
| -from eoreader.exceptions import InvalidProductError, InvalidTypeError |
| 13 | +from eoreader.exceptions import InvalidTypeError |
29 | 14 | from eoreader.products import SensorType
|
30 | 15 |
|
31 |
| -from .scripts_utils import READER, dask_env, get_db_dir, others_path, s3_env |
32 |
| - |
33 | 16 | LOGGER = logging.getLogger(EOREADER_NAME)
|
34 | 17 |
|
35 | 18 | ci.reduce_verbosity()
|
@@ -156,133 +139,6 @@ def test_custom_optical():
|
156 | 139 | )
|
157 | 140 |
|
158 | 141 |
|
159 |
| -def test_custom_sar(): |
160 |
| - # SAR |
161 |
| - sar_stack = others_path() / "20210827T162210_ICEYE_SC_GRD_STK.tif" |
162 |
| - |
163 |
| - # Load with all info |
164 |
| - prod_sar = READER.open( |
165 |
| - sar_stack, |
166 |
| - custom=True, |
167 |
| - sensor_type=SensorType.SAR, |
168 |
| - name="20210827T162210_ICEYE_SC_GRD", |
169 |
| - datetime="20210827T162210", |
170 |
| - constellation="ICEYE", |
171 |
| - instrument="SAR X-band", |
172 |
| - pixel_size=6.0, |
173 |
| - product_type="GRD", |
174 |
| - band_map={VV: 1, VV_DSPK: 2}, |
175 |
| - ) |
176 |
| - LOGGER.info(prod_sar) |
177 |
| - extent_sar = prod_sar.extent() |
178 |
| - footprint_sar = prod_sar.footprint() |
179 |
| - crs_sar = prod_sar.crs() |
180 |
| - stack_sar = prod_sar.stack([VV, VV_DSPK], prod_sar.pixel_size * 10) |
181 |
| - |
182 |
| - # Errors |
183 |
| - with pytest.raises(AssertionError): |
184 |
| - prod_sar.load(NDVI) |
185 |
| - |
186 |
| - # Check attributes |
187 |
| - assert stack_sar.attrs["long_name"] == "VV VV_DSPK" |
188 |
| - assert stack_sar.attrs["constellation"] == "ICEYE" |
189 |
| - assert stack_sar.attrs["constellation_id"] == "ICEYE" |
190 |
| - assert stack_sar.attrs["product_type"] == "GRD" |
191 |
| - assert stack_sar.attrs["instrument"] == "SAR X-band" |
192 |
| - assert stack_sar.attrs["acquisition_date"] == "20210827T162210" |
193 |
| - assert stack_sar.attrs["condensed_name"] == "20210827T162210_ICEYE_GRD" |
194 |
| - assert stack_sar.attrs["product_path"] == str(sar_stack) |
195 |
| - |
196 |
| - # MIX |
197 |
| - sar_stack = others_path() / "20210827T162210_ICEYE_SC_GRD_STK.tif" |
198 |
| - prod_wtf = READER.open( |
199 |
| - sar_stack, |
200 |
| - custom=True, |
201 |
| - sensor_type=SensorType.SAR, |
202 |
| - band_map={HH: 1, RH: 2}, |
203 |
| - name=None, |
204 |
| - product_type=None, |
205 |
| - instrument=None, |
206 |
| - datetime=None, |
207 |
| - pixel_size=6.0, |
208 |
| - ) |
209 |
| - LOGGER.info(prod_wtf) |
210 |
| - extent_wtf = prod_wtf.extent() |
211 |
| - footprint_wtf = prod_wtf.footprint() |
212 |
| - crs_wtf = prod_wtf.crs() |
213 |
| - stack_wtf = prod_wtf.stack([HH, RH], prod_wtf.pixel_size * 10) |
214 |
| - |
215 |
| - ci.assert_geom_equal(extent_sar, extent_wtf) |
216 |
| - ci.assert_geom_equal(footprint_sar, footprint_wtf) |
217 |
| - assert crs_sar == crs_wtf |
218 |
| - assert prod_wtf.name is not None |
219 |
| - assert prod_wtf.product_type is not None |
220 |
| - assert prod_wtf.instrument is not None |
221 |
| - |
222 |
| - np.testing.assert_array_equal(stack_sar.data, stack_wtf.data) |
223 |
| - |
224 |
| - |
225 |
| -def test_custom_wgs84(): |
226 |
| - # WGS84 |
227 |
| - wgs84_stack = others_path() / "SPOT6_WGS84.tif" |
228 |
| - prod_wgs84 = READER.open( |
229 |
| - wgs84_stack, |
230 |
| - custom=True, |
231 |
| - sensor_type=SensorType.OPTICAL, |
232 |
| - name="SPOT6_WGS84", |
233 |
| - datetime="20181218T090308", |
234 |
| - constellation="SPOT6", |
235 |
| - pixel_size=1.5 * 15, |
236 |
| - instrument="NAOMI", |
237 |
| - product_type="ORT", |
238 |
| - band_map={RED: 1, GREEN: 2, BLUE: 3, NIR: 4}, |
239 |
| - ) |
240 |
| - LOGGER.info(prod_wgs84) |
241 |
| - |
242 |
| - # Check geometries -> assert projected |
243 |
| - with pytest.raises(InvalidProductError): |
244 |
| - prod_wgs84.extent() # noqa |
245 |
| - |
246 |
| - with pytest.raises(InvalidProductError): |
247 |
| - prod_wgs84.footprint() # noqa |
248 |
| - |
249 |
| - with pytest.raises(InvalidProductError): |
250 |
| - prod_wgs84.crs() # noqa |
251 |
| - |
252 |
| - # Read mtd |
253 |
| - root, nsp = prod_wgs84.read_mtd() |
254 |
| - assert nsp == {} |
255 |
| - assert root.findtext("name") == "SPOT6_WGS84" |
256 |
| - assert root.findtext("datetime") == "2018-12-18T09:03:08" |
257 |
| - assert root.findtext("sensor_type") == "Optical" |
258 |
| - assert root.findtext("constellation") == "Spot-6" |
259 |
| - assert root.findtext("pixel_size") == str(1.5 * 15) |
260 |
| - assert root.findtext("product_type") == "ORT" |
261 |
| - assert root.findtext("band_map") == "{'BLUE': 3, 'GREEN': 2, 'RED': 1, 'NIR': 4}" |
262 |
| - assert root.findtext("sun_azimuth") == "None" |
263 |
| - assert root.findtext("sun_zenith") == "None" |
264 |
| - assert root.findtext("orbit_direction") == "None" |
265 |
| - assert root.findtext("cloud_cover") == "None" |
266 |
| - assert root.findtext("instrument") == "NAOMI" |
267 |
| - |
268 |
| - # Band paths |
269 |
| - assert prod_wgs84.get_existing_bands() == [BLUE, GREEN, RED, NIR] |
270 |
| - assert prod_wgs84.get_default_band() == BLUE |
271 |
| - for key, ppath in prod_wgs84.get_existing_band_paths().items(): |
272 |
| - assert key in [BLUE, GREEN, RED, NIR] |
273 |
| - assert str(ppath) == str(wgs84_stack) |
274 |
| - |
275 |
| - # Load without a list and nothing |
276 |
| - with pytest.raises(InvalidProductError): |
277 |
| - prod_wgs84.load(BLUE, size=[3863, 1049])[BLUE] # noqa |
278 |
| - |
279 |
| - # Try non-available clouds and bands |
280 |
| - assert len(prod_wgs84.load([])) == 0 |
281 |
| - assert not prod_wgs84.has_bands(CLOUDS) |
282 |
| - with pytest.raises(AssertionError): |
283 |
| - prod_wgs84.load(CLOUDS, YELLOW) |
284 |
| - |
285 |
| - |
286 | 142 | def test_custom_invalid():
|
287 | 143 | # Invalid tests
|
288 | 144 | opt_stack = others_path() / "20200310T030415_WV02_Ortho_BGRN_STK.tif"
|
|
0 commit comments