|
| 1 | +# Copyright (c) 2025 by EOPF Sample Service team and contributors |
| 2 | +# Permissions are hereby granted under the terms of the Apache 2.0 License: |
| 3 | +# https://opensource.org/license/apache-2-0. |
| 4 | + |
| 5 | +from collections.abc import Sequence |
| 6 | +from unittest import TestCase |
| 7 | + |
| 8 | +import xarray as xr |
| 9 | + |
| 10 | +from integration.helpers import assert_dataset_is_chunked |
| 11 | +from xarray_eopf.constants import DEFAULT_ENDPOINT_URL |
| 12 | +from xarray_eopf.utils import timeit |
| 13 | + |
| 14 | + |
| 15 | +allowed_open_time = 1000 # seconds |
| 16 | +show_chunking = False |
| 17 | + |
| 18 | +ol1efr_url = ( |
| 19 | + "https://objects.eodc.eu/e05ab01a9d56408d82ac32d69a5aae2a:202508-s03olcefr/19/" |
| 20 | + "products/cpm_v256/S3B_OL_1_EFR____20250819T074058_20250819T074358_" |
| 21 | + "20250819T092155_0179_110_106_3420_ESA_O_NR_004.zarr" |
| 22 | +) |
| 23 | + |
| 24 | +ol1err_url = ( |
| 25 | + "https://objects.eodc.eu/e05ab01a9d56408d82ac32d69a5aae2a:202510-s03olcerr-global/" |
| 26 | + "19/products/cpm_v256/S3A_OL_1_ERR____20251019T145533_20251019T153950_" |
| 27 | + "20251019T165332_2657_131_353______PS1_O_NR_004.zarr" |
| 28 | +) |
| 29 | + |
| 30 | +ol2lfr_url = ( |
| 31 | + "https://objects.eodc.eu/e05ab01a9d56408d82ac32d69a5aae2a:202510-s03olclfr-" |
| 32 | + "global/15/products/cpm_v256/S3A_OL_2_LFR____20251015T050206_20251015T050506_" |
| 33 | + "20251015T070316_0179_131_290_2340_PS1_O_NR_003.zarr" |
| 34 | +) |
| 35 | +sl1rbt_url = ( |
| 36 | + "https://objects.eodc.eu/e05ab01a9d56408d82ac32d69a5aae2a:202510-s03slsrbt-global/" |
| 37 | + "16/products/cpm_v256/S3B_SL_1_RBT____20251016T072510_20251016T072810_" |
| 38 | + "20251016T092049_0179_112_163_2700_ESA_O_NR_004.zarr" |
| 39 | +) |
| 40 | +sl2lst_url = ( |
| 41 | + "https://objects.eodc.eu/e05ab01a9d56408d82ac32d69a5aae2a:202510-s03slslst-eu/16/" |
| 42 | + "products/cpm_v256/S3B_SL_2_LST____20251016T215803_20251016T220103_20251017T004323_" |
| 43 | + "0179_112_172_0540_ESA_O_NR_004.zarr" |
| 44 | +) |
| 45 | + |
| 46 | + |
| 47 | +class Sentinel3AnalysisTest(TestCase): |
| 48 | + def test_open_dataset_sen3_olci_l1_efr(self): |
| 49 | + expected_vars = ["oa01_radiance", "oa02_radiance", "oa03_radiance"] |
| 50 | + expected_size = (5000, 5269) |
| 51 | + self._test_sen3(ol1efr_url, expected_vars, expected_size) |
| 52 | + |
| 53 | + def test_open_dataset_sen3_olci_l1_err(self): |
| 54 | + expected_vars = ["oa01_radiance", "oa02_radiance", "oa03_radiance"] |
| 55 | + expected_size = (14432, 11065) |
| 56 | + self._test_sen3(ol1err_url, expected_vars, expected_size) |
| 57 | + |
| 58 | + def test_open_dataset_sen3_olci_l2_lfr(self): |
| 59 | + expected_vars = ["gifapar", "iwv", "otci"] |
| 60 | + expected_size = (4790, 5125) |
| 61 | + self._test_sen3(ol2lfr_url, expected_vars, expected_size) |
| 62 | + |
| 63 | + def test_open_dataset_sen3_slstr_l1_rbt(self): |
| 64 | + expected_vars = ["s1_radiance_an", "s7_bt_in", "s7_bt_io"] |
| 65 | + expected_size = (2959, 3308) |
| 66 | + self._test_sen3(sl1rbt_url, expected_vars, expected_size) |
| 67 | + |
| 68 | + def test_open_dataset_sen3_slstr_l2_lst(self): |
| 69 | + expected_vars = ["lst"] |
| 70 | + expected_size = (1473, 1657) |
| 71 | + self._test_sen3(sl2lst_url, expected_vars, expected_size) |
| 72 | + |
| 73 | + def _test_sen3( |
| 74 | + self, path: str, expected_vars: Sequence[str], expected_size: tuple[int, int] |
| 75 | + ): |
| 76 | + with timeit("open " + path) as result: |
| 77 | + # noinspection PyTypeChecker |
| 78 | + ds = xr.open_dataset( |
| 79 | + path, |
| 80 | + engine="eopf-zarr", |
| 81 | + chunks={}, |
| 82 | + ) |
| 83 | + self.assertTrue(result.time_delta < allowed_open_time) |
| 84 | + |
| 85 | + for expected_var in expected_vars: |
| 86 | + self.assertIn(expected_var, ds) |
| 87 | + |
| 88 | + assert_dataset_is_chunked(self, ds, verbose=show_chunking) |
| 89 | + for var_name in ds.data_vars: |
| 90 | + self.assertEqual(expected_size, ds[var_name].shape[-2:], msg=var_name) |
0 commit comments