From 6972305d0a2483e776e79844a7711d82c086b3a6 Mon Sep 17 00:00:00 2001 From: Caitlin Adams <25995927+caitlinadams@users.noreply.github.com> Date: Tue, 7 Jan 2025 16:35:06 +1100 Subject: [PATCH 1/8] Update modules to import from installed pip package --- sar_antarctica/nci/preparation/find_scene.py | 4 ++-- sar_antarctica/nci/preparation/orbits.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sar_antarctica/nci/preparation/find_scene.py b/sar_antarctica/nci/preparation/find_scene.py index 3a86533..c6f8a71 100644 --- a/sar_antarctica/nci/preparation/find_scene.py +++ b/sar_antarctica/nci/preparation/find_scene.py @@ -1,8 +1,8 @@ import click from pathlib import Path -from scenes import find_scene_file_from_id -from orbits import find_latest_orbit_for_scene +from sar_antarctica.nci.preparation.scenes import find_scene_file_from_id +from sar_antarctica.nci.preparation.orbits import find_latest_orbit_for_scene @click.command() @click.argument("scene_id") diff --git a/sar_antarctica/nci/preparation/orbits.py b/sar_antarctica/nci/preparation/orbits.py index 1baaeb6..72f3563 100644 --- a/sar_antarctica/nci/preparation/orbits.py +++ b/sar_antarctica/nci/preparation/orbits.py @@ -2,7 +2,7 @@ from pathlib import Path import re -from scenes import parse_scene_file_dates +from sar_antarctica.nci.preparation.scenes import parse_scene_file_dates # Constants for NCI S1_DIR = Path("/g/data/fj7/Copernicus/Sentinel-1/") From c6ec8740a0f13a28b220063fda9374070203b248 Mon Sep 17 00:00:00 2001 From: Caitlin Adams <25995927+caitlinadams@users.noreply.github.com> Date: Wed, 8 Jan 2025 08:52:07 +1100 Subject: [PATCH 2/8] Rename test for dem to ensure discoverable by pytest --- tests/{dem.py => test_dem.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/{dem.py => test_dem.py} (100%) diff --git a/tests/dem.py b/tests/test_dem.py similarity index 100% rename from tests/dem.py rename to tests/test_dem.py From 27b80f036ace998614a6de9c82d3c82a63b7a8e2 Mon Sep 17 00:00:00 2001 From: Caitlin Adams <25995927+caitlinadams@users.noreply.github.com> Date: Wed, 8 Jan 2025 09:40:27 +1100 Subject: [PATCH 3/8] Add test for parse_orbit_file_dates --- tests/test_orbits.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/test_orbits.py diff --git a/tests/test_orbits.py b/tests/test_orbits.py new file mode 100644 index 0000000..16ec842 --- /dev/null +++ b/tests/test_orbits.py @@ -0,0 +1,35 @@ +from sar_antarctica.nci.preparation.orbits import ( + parse_orbit_file_dates, + find_latest_orbit_for_scene +) + +import pytest +import dataclasses +from datetime import datetime + +@dataclasses.dataclass +class Orbit: + file: str + published_date: datetime + start_date: datetime + stop_date: datetime + +orbit_1 = Orbit( + file="S1A_OPER_AUX_POEORB_OPOD_20141207T123431_V20141115T225944_20141117T005944.EOF", + published_date=datetime(2014, 12, 7,12,34,31), + start_date=datetime(2014,11,15,22,59,44), + stop_date=datetime(2014,11,17,0,59,44) +) +orbit_2 = Orbit( + file="S1A_OPER_AUX_POEORB_OPOD_20191220T120706_V20191129T225942_20191201T005942.EOF", + published_date=datetime(2019,12,20,12,7,6), + start_date=datetime(2019,11,29,22,59,42), + stop_date=datetime(2019,12,1,0,59,42) +) + +orbits = [orbit_1, orbit_2] + +@pytest.mark.parametrize("orbit", orbits) +def test_parse_orbit_file_dates(orbit: Orbit): + date_tuple = (orbit.published_date, orbit.start_date, orbit.stop_date) + assert parse_orbit_file_dates(orbit.file) == date_tuple From 8016828b4fc3129ebcf67b1f9a6fb8cd33f84ea6 Mon Sep 17 00:00:00 2001 From: Caitlin Adams <25995927+caitlinadams@users.noreply.github.com> Date: Wed, 8 Jan 2025 13:13:52 +1100 Subject: [PATCH 4/8] Add test for find_latest_orbit_for_scene --- sar_antarctica/nci/preparation/orbits.py | 85 ++++++++++++++++-------- sar_antarctica/nci/preparation/scenes.py | 71 ++++++++++++++++++-- tests/test_orbits.py | 32 ++++++++- 3 files changed, 157 insertions(+), 31 deletions(-) diff --git a/sar_antarctica/nci/preparation/orbits.py b/sar_antarctica/nci/preparation/orbits.py index 72f3563..69f7c43 100644 --- a/sar_antarctica/nci/preparation/orbits.py +++ b/sar_antarctica/nci/preparation/orbits.py @@ -1,29 +1,36 @@ from datetime import datetime from pathlib import Path import re +from typing import Optional -from sar_antarctica.nci.preparation.scenes import parse_scene_file_dates +from sar_antarctica.nci.preparation.scenes import parse_scene_file_dates, parse_scene_file_sensor # Constants for NCI S1_DIR = Path("/g/data/fj7/Copernicus/Sentinel-1/") POE_DIR = "POEORB" RES_DIR = "RESORB" -ORBIT_DIRS = [POE_DIR, RES_DIR] -SENSORS = ["S1A", "S1B"] def parse_orbit_file_dates(orbit_file_name: str) -> tuple[datetime, datetime, datetime]: - """ - Extracts published_date, start_date, and end_date from the given orbit file. + """Extracts published_date, start_date, and end_date from the given orbit file. Filename example: S1A_OPER_AUX_POEORB_OPOD_20141207T123431_V20141115T225944_20141117T005944.EOF - Published: 20141207T123431 - Start: 20141115T225944 - End: 20141117T005944 - Args: - file_name (str): The orbit file name as a string. + Parameters + ---------- + orbit_file_name : str + The orbit file name as a string. + + Returns + ------- + tuple[datetime, datetime, datetime] + a tuple of datetimes for published, start and end of the orbit file - Returns: - tuple(datetime): a tuple of datetimes for published, start and end of the orbit file + Raises + ------ + ValueError + Did not find a match to the expected date pattern of published_date followed by start_date and end_date """ # Regex pattern to match the dates pattern = (r"(?P\d{8}T\d{6})_V" @@ -43,34 +50,60 @@ def parse_orbit_file_dates(orbit_file_name: str) -> tuple[datetime, datetime, da return (published_date, start_date, stop_date) -def find_latest_orbit_for_scene(scene_id: str, poe_only: bool = True) -> Path: - """ - Identifies the most recent orbit file available for a given scene, based +def find_latest_orbit_for_scene(scene_id: str, orbit_type: Optional[str] = None) -> Path: + """Identifies the most recent orbit file available for a given scene, based on the scene's start and end date. + + Parameters + ---------- + scene_id : str + Sentinel-1 scene ID + e.g. S1A_EW_GRDM_1SDH_20220612T120348_20220612T120452_043629_053582_0F6 + orbit_type : Optional[str], optional + Any of "POE" for POE orbits, "RES" for RES orbits, or None, by default None + + Returns + ------- + Path + Full file path to latest orbit file on NCI + + Raises + ------ + ValueError + orbit_type must be one of "POE", "RES" or None + ValueError + No valid orbit file was found """ scene_start, scene_stop = parse_scene_file_dates(scene_id) + scene_sensor = parse_scene_file_sensor(scene_id) relevant_orbits = [] - for orbit_dir in ORBIT_DIRS: + if orbit_type == "POE": + orbit_directories = [POE_DIR] + elif orbit_type == "RES": + orbit_directories = [RES_DIR] + elif orbit_type is None: + orbit_directories = [RES_DIR, POE_DIR] + else: + raise ValueError("orbit_type must be one of 'POE', 'RES', or None") + + # Find all orbits for the sensor that fall within the date range of the scene + for orbit_dir in orbit_directories: orbit_dir_path = S1_DIR / orbit_dir - for sensor in SENSORS: - orbit_files_path = orbit_dir_path / sensor - orbit_files = orbit_files_path.glob("*.EOF") + orbit_files_path = orbit_dir_path / scene_sensor + orbit_files = orbit_files_path.glob("*.EOF") - for orbit_file in orbit_files: + for orbit_file in orbit_files: - orbit_published, orbit_start, orbit_stop = parse_orbit_file_dates(orbit_file) - - # Check if scene falls within orbit - if scene_start >= orbit_start and scene_stop <= orbit_stop: - orbit_metadata = (orbit_file, orbit_dir, orbit_published) - relevant_orbits.append(orbit_metadata) + orbit_published, orbit_start, orbit_stop = parse_orbit_file_dates(orbit_file) + + # Check if scene falls within orbit + if scene_start >= orbit_start and scene_stop <= orbit_stop: + orbit_metadata = (orbit_file, orbit_dir, orbit_published) + relevant_orbits.append(orbit_metadata) - if poe_only: - relevant_orbits = [item for item in relevant_orbits if item[1] == POE_DIR] - # If relevant_orbits is empty, set latest_orbit to None latest_orbit = max(relevant_orbits, key=lambda x: x[2]) if relevant_orbits else None diff --git a/sar_antarctica/nci/preparation/scenes.py b/sar_antarctica/nci/preparation/scenes.py index bb0783f..b629232 100644 --- a/sar_antarctica/nci/preparation/scenes.py +++ b/sar_antarctica/nci/preparation/scenes.py @@ -4,9 +4,55 @@ SCENE_DIR = Path("/g/data/fj7/Copernicus/Sentinel-1/C-SAR/GRD/") -def parse_scene_file_dates(scene_id: str) -> tuple[datetime, datetime]: +def parse_scene_file_sensor(scene_id: str) -> str: + """Extract Sentinel-1 sensor string (SA1,S1B,S1C,S1D) from scene ID + + Parameters + ---------- + scene_id : str + Sentinel-1 scene ID + e.g. S1A_EW_GRDM_1SDH_20220612T120348_20220612T120452_043629_053582_0F6 + + Returns + ------- + str + Sensor string. Should be one of S1A, S1B, S1C, or S1D + + Raises + ------ + ValueError + Did not find any of S1A, S1B, S1C, or S1D in the scene ID """ - Extracts start_date and end_date from the given scene ID. + # Expect files to be prefaced with any of S1A, S1B, S1C, or S1D, followed by underscore + pattern=r"^(S1[A|B|C|D])_" + + match = re.match(pattern, scene_id) + + if not match: + raise ValueError("No valid sensor was found in the scene ID. Valid sensors are S1A, S1B, S1C, or S1D") + + return match.group(1) + + +def parse_scene_file_dates(scene_id: str) -> tuple[datetime, datetime]: + """Extracts start_date and end_date from the given scene ID. + + Parameters + ---------- + scene_id : str + Sentinel-1 scene ID + e.g. S1A_EW_GRDM_1SDH_20220612T120348_20220612T120452_043629_053582_0F6 + + Returns + ------- + tuple[datetime, datetime] + A tuple containing the start and stop date for the scene as datetimes + e.g. (datetime(2022,06,12,12,3,48), datetime(2022,06,12,12,4,52)) + + Raises + ------ + ValueError + Did not find a match to the expected date pattern of start_date followed by end_date in the scene ID """ # Regex pattern to match the dates pattern = (r"(?P\d{8}T\d{6})_" @@ -23,8 +69,25 @@ def parse_scene_file_dates(scene_id: str) -> tuple[datetime, datetime]: return (start_date, stop_date) def find_scene_file_from_id(scene_id: str) -> Path: - """ - Finds the path to the scene on GADI based on the scene ID + """Finds the path to the scene on GADI based on the scene ID + + Parameters + ---------- + scene_id : str + Sentinel-1 scene ID + e.g. S1A_EW_GRDM_1SDH_20220612T120348_20220612T120452_043629_053582_0F6 + + Returns + ------- + Path + Location of scene on NCI GADI + + Raises + ------ + RuntimeError + Found more than one file -- expects one + RuntimeError + Found no files -- expects one. Or another Error """ # Parse the scene dates -- only start date is needed for search diff --git a/tests/test_orbits.py b/tests/test_orbits.py index 16ec842..f1b23f8 100644 --- a/tests/test_orbits.py +++ b/tests/test_orbits.py @@ -2,7 +2,7 @@ parse_orbit_file_dates, find_latest_orbit_for_scene ) - +from pathlib import Path import pytest import dataclasses from datetime import datetime @@ -33,3 +33,33 @@ class Orbit: def test_parse_orbit_file_dates(orbit: Orbit): date_tuple = (orbit.published_date, orbit.start_date, orbit.stop_date) assert parse_orbit_file_dates(orbit.file) == date_tuple + + +@dataclasses.dataclass +class Scene: + scene_id: str + latest_orbit: Path + latest_res_orbit: Path + latest_poe_orbit: Path + +scene_1 = Scene( + scene_id="S1B_EW_GRDM_1SDH_20191130T165626_20191130T165726_019159_0242A2_2F58", + latest_orbit=Path("/g/data/fj7/Copernicus/Sentinel-1/POEORB/S1B/S1B_OPER_AUX_POEORB_OPOD_20191220T110516_V20191129T225942_20191201T005942.EOF"), + latest_res_orbit=Path("/g/data/fj7/Copernicus/Sentinel-1/RESORB/S1B/S1B_OPER_AUX_RESORB_OPOD_20191130T210136_V20191130T154804_20191130T190534.EOF"), + latest_poe_orbit=Path("/g/data/fj7/Copernicus/Sentinel-1/POEORB/S1B/S1B_OPER_AUX_POEORB_OPOD_20191220T110516_V20191129T225942_20191201T005942.EOF") +) + +scene_2 = Scene( + scene_id="S1A_EW_GRDM_1SDH_20220612T120348_20220612T120452_043629_053582_0F66", + latest_orbit=Path("/g/data/fj7/Copernicus/Sentinel-1/POEORB/S1A/S1A_OPER_AUX_POEORB_OPOD_20220702T081845_V20220611T225942_20220613T005942.EOF"), + latest_res_orbit=Path("/g/data/fj7/Copernicus/Sentinel-1/RESORB/S1A/S1A_OPER_AUX_RESORB_OPOD_20220612T143829_V20220612T104432_20220612T140202.EOF"), + latest_poe_orbit=Path("/g/data/fj7/Copernicus/Sentinel-1/POEORB/S1A/S1A_OPER_AUX_POEORB_OPOD_20220702T081845_V20220611T225942_20220613T005942.EOF") +) + +scenes = [scene_1, scene_2] + +@pytest.mark.parametrize("scene", scenes) +def test_find_latest_orbit_for_scene(scene: Scene): + assert find_latest_orbit_for_scene(scene.scene_id) == scene.latest_orbit + assert find_latest_orbit_for_scene(scene.scene_id, orbit_type="RES") == scene.latest_res_orbit + assert find_latest_orbit_for_scene(scene.scene_id, orbit_type="POE") == scene.latest_poe_orbit From f905c136f45549f2ddd6dd18384e5bbceebf6722 Mon Sep 17 00:00:00 2001 From: Caitlin Adams <25995927+caitlinadams@users.noreply.github.com> Date: Thu, 9 Jan 2025 08:56:53 +1100 Subject: [PATCH 5/8] Add tests for scene functions --- tests/test_scenes.py | 52 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/test_scenes.py diff --git a/tests/test_scenes.py b/tests/test_scenes.py new file mode 100644 index 0000000..4e2399e --- /dev/null +++ b/tests/test_scenes.py @@ -0,0 +1,52 @@ +import datetime +from sar_antarctica.nci.preparation.scenes import ( + parse_scene_file_dates, + parse_scene_file_sensor, + find_scene_file_from_id +) + +import dataclasses +from datetime import datetime +from pathlib import Path +import pytest + +@dataclasses.dataclass +class Scene: + id: str + file: Path + sensor: str + start_date: datetime + stop_date: datetime + +scene_1 = Scene( + id="S1A_EW_GRDM_1SDH_20200330T165825_20200330T165929_031907_03AF02_8570", + file=Path("/g/data/fj7/Copernicus/Sentinel-1/C-SAR/GRD/2020/2020-03/70S050E-75S055E/S1A_EW_GRDM_1SDH_20200330T165825_20200330T165929_031907_03AF02_8570.zip"), + sensor="S1A", + start_date=datetime(2020,3,30,16,58,25), + stop_date=datetime(2020,3,30,16,59,29) +) + +scene_2 = Scene( + id="S1B_EW_GRDM_1SDH_20210914T112333_20210914T112403_028693_036C96_3EA8", + file=Path("/g/data/fj7/Copernicus/Sentinel-1/C-SAR/GRD/2021/2021-09/60S120E-65S125E/S1B_EW_GRDM_1SDH_20210914T112333_20210914T112403_028693_036C96_3EA8.zip"), + sensor="S1B", + start_date=datetime(2021,9,14,11,23,33), + stop_date=datetime(2021,9,14,11,24,3) +) + +scenes = [scene_1, scene_2] + +@pytest.mark.parametrize("scene", scenes) +def test_parse_scene_file_dates(scene: Scene): + date_tuple = (scene.start_date, scene.stop_date) + assert parse_scene_file_dates(scene.id) == date_tuple + + +@pytest.mark.parametrize("scene", scenes) +def test_parse_scene_file_sensor(scene: Scene): + assert parse_scene_file_sensor(scene.id) == scene.sensor + + +@pytest.mark.parametrize("scene", scenes) +def test_find_scene_file_from_id(scene: Scene): + assert find_scene_file_from_id(scene.id) == scene.file \ No newline at end of file From 1b2e425c90d9c9fd94c18c4913294513627790ab Mon Sep 17 00:00:00 2001 From: Caitlin Adams <25995927+caitlinadams@users.noreply.github.com> Date: Fri, 10 Jan 2025 09:55:53 +1100 Subject: [PATCH 6/8] Split filesystem tests from codebase tests --- tests/filesystem/test_filesystem.py | 54 +++++++++++++++++++ tests/{ => sar_antarctica}/test_dem.py | 0 tests/sar_antarctica/test_orbits.py | 33 ++++++++++++ tests/{ => sar_antarctica}/test_scenes.py | 4 -- tests/test_orbits.py | 65 ----------------------- 5 files changed, 87 insertions(+), 69 deletions(-) create mode 100644 tests/filesystem/test_filesystem.py rename tests/{ => sar_antarctica}/test_dem.py (100%) create mode 100644 tests/sar_antarctica/test_orbits.py rename tests/{ => sar_antarctica}/test_scenes.py (89%) delete mode 100644 tests/test_orbits.py diff --git a/tests/filesystem/test_filesystem.py b/tests/filesystem/test_filesystem.py new file mode 100644 index 0000000..5220d69 --- /dev/null +++ b/tests/filesystem/test_filesystem.py @@ -0,0 +1,54 @@ +from sar_antarctica.nci.preparation.orbits import find_latest_orbit_for_scene +from sar_antarctica.nci.preparation.scenes import find_scene_file_from_id + +import dataclasses +from datetime import datetime +from pathlib import Path +import pytest + +@dataclasses.dataclass +class Scene: + id: str + file: Path + sensor: str + start_date: datetime + stop_date: datetime + latest_orbit: Path + latest_poe_orbit: Path + latest_res_orbit: Path + + +scene_1 = Scene( + id="S1A_EW_GRDM_1SDH_20220612T120348_20220612T120452_043629_053582_0F66", + file=Path("/g/data/fj7/Copernicus/Sentinel-1/C-SAR/GRD/2022/2022-06/65S115E-70S120E/S1A_EW_GRDM_1SDH_20220612T120348_20220612T120452_043629_053582_0F66.zip"), + sensor="S1A", + start_date=datetime(2022,6,12,12,3,48), + stop_date=datetime(2022,6,12,12,4,52), + latest_orbit=Path("/g/data/fj7/Copernicus/Sentinel-1/POEORB/S1A/S1A_OPER_AUX_POEORB_OPOD_20220702T081845_V20220611T225942_20220613T005942.EOF"), + latest_poe_orbit=Path("/g/data/fj7/Copernicus/Sentinel-1/POEORB/S1A/S1A_OPER_AUX_POEORB_OPOD_20220702T081845_V20220611T225942_20220613T005942.EOF"), + latest_res_orbit=Path("/g/data/fj7/Copernicus/Sentinel-1/RESORB/S1A/S1A_OPER_AUX_RESORB_OPOD_20220612T143829_V20220612T104432_20220612T140202.EOF"), +) + +scene_2 = Scene( + id="S1B_EW_GRDM_1SDH_20191130T165626_20191130T165726_019159_0242A2_2F58", + file=Path("/g/data/fj7/Copernicus/Sentinel-1/C-SAR/GRD/2019/2019-11/65S160E-70S165E/S1B_EW_GRDM_1SDH_20191130T165626_20191130T165726_019159_0242A2_2F58.zip"), + sensor="S1B", + start_date=datetime(2019,11,30,16,56,26), + stop_date=datetime(2019,11,30,16,57,26), + latest_orbit=Path("/g/data/fj7/Copernicus/Sentinel-1/POEORB/S1B/S1B_OPER_AUX_POEORB_OPOD_20191220T110516_V20191129T225942_20191201T005942.EOF"), + latest_poe_orbit=Path("/g/data/fj7/Copernicus/Sentinel-1/POEORB/S1B/S1B_OPER_AUX_POEORB_OPOD_20191220T110516_V20191129T225942_20191201T005942.EOF"), + latest_res_orbit=Path("/g/data/fj7/Copernicus/Sentinel-1/RESORB/S1B/S1B_OPER_AUX_RESORB_OPOD_20191130T210136_V20191130T154804_20191130T190534.EOF"), +) + +scenes = [scene_1, scene_2] + +@pytest.mark.parametrize("scene", scenes) +def test_find_latest_orbit_for_scene(scene: Scene): + assert find_latest_orbit_for_scene(scene.id) == scene.latest_orbit + assert find_latest_orbit_for_scene(scene.id, orbit_type="RES") == scene.latest_res_orbit + assert find_latest_orbit_for_scene(scene.id, orbit_type="POE") == scene.latest_poe_orbit + + +@pytest.mark.parametrize("scene", scenes) +def test_find_scene_file_from_id(scene: Scene): + assert find_scene_file_from_id(scene.id) == scene.file \ No newline at end of file diff --git a/tests/test_dem.py b/tests/sar_antarctica/test_dem.py similarity index 100% rename from tests/test_dem.py rename to tests/sar_antarctica/test_dem.py diff --git a/tests/sar_antarctica/test_orbits.py b/tests/sar_antarctica/test_orbits.py new file mode 100644 index 0000000..6c62f40 --- /dev/null +++ b/tests/sar_antarctica/test_orbits.py @@ -0,0 +1,33 @@ +from sar_antarctica.nci.preparation.orbits import parse_orbit_file_dates + +from pathlib import Path +import pytest +import dataclasses +from datetime import datetime + +@dataclasses.dataclass +class Orbit: + file: str + published_date: datetime + start_date: datetime + stop_date: datetime + +orbit_1 = Orbit( + file="S1A_OPER_AUX_POEORB_OPOD_20141207T123431_V20141115T225944_20141117T005944.EOF", + published_date=datetime(2014, 12, 7,12,34,31), + start_date=datetime(2014,11,15,22,59,44), + stop_date=datetime(2014,11,17,0,59,44) +) +orbit_2 = Orbit( + file="S1A_OPER_AUX_POEORB_OPOD_20191220T120706_V20191129T225942_20191201T005942.EOF", + published_date=datetime(2019,12,20,12,7,6), + start_date=datetime(2019,11,29,22,59,42), + stop_date=datetime(2019,12,1,0,59,42) +) + +orbits = [orbit_1, orbit_2] + +@pytest.mark.parametrize("orbit", orbits) +def test_parse_orbit_file_dates(orbit: Orbit): + date_tuple = (orbit.published_date, orbit.start_date, orbit.stop_date) + assert parse_orbit_file_dates(orbit.file) == date_tuple diff --git a/tests/test_scenes.py b/tests/sar_antarctica/test_scenes.py similarity index 89% rename from tests/test_scenes.py rename to tests/sar_antarctica/test_scenes.py index 4e2399e..1f85849 100644 --- a/tests/test_scenes.py +++ b/tests/sar_antarctica/test_scenes.py @@ -2,7 +2,6 @@ from sar_antarctica.nci.preparation.scenes import ( parse_scene_file_dates, parse_scene_file_sensor, - find_scene_file_from_id ) import dataclasses @@ -47,6 +46,3 @@ def test_parse_scene_file_sensor(scene: Scene): assert parse_scene_file_sensor(scene.id) == scene.sensor -@pytest.mark.parametrize("scene", scenes) -def test_find_scene_file_from_id(scene: Scene): - assert find_scene_file_from_id(scene.id) == scene.file \ No newline at end of file diff --git a/tests/test_orbits.py b/tests/test_orbits.py deleted file mode 100644 index f1b23f8..0000000 --- a/tests/test_orbits.py +++ /dev/null @@ -1,65 +0,0 @@ -from sar_antarctica.nci.preparation.orbits import ( - parse_orbit_file_dates, - find_latest_orbit_for_scene -) -from pathlib import Path -import pytest -import dataclasses -from datetime import datetime - -@dataclasses.dataclass -class Orbit: - file: str - published_date: datetime - start_date: datetime - stop_date: datetime - -orbit_1 = Orbit( - file="S1A_OPER_AUX_POEORB_OPOD_20141207T123431_V20141115T225944_20141117T005944.EOF", - published_date=datetime(2014, 12, 7,12,34,31), - start_date=datetime(2014,11,15,22,59,44), - stop_date=datetime(2014,11,17,0,59,44) -) -orbit_2 = Orbit( - file="S1A_OPER_AUX_POEORB_OPOD_20191220T120706_V20191129T225942_20191201T005942.EOF", - published_date=datetime(2019,12,20,12,7,6), - start_date=datetime(2019,11,29,22,59,42), - stop_date=datetime(2019,12,1,0,59,42) -) - -orbits = [orbit_1, orbit_2] - -@pytest.mark.parametrize("orbit", orbits) -def test_parse_orbit_file_dates(orbit: Orbit): - date_tuple = (orbit.published_date, orbit.start_date, orbit.stop_date) - assert parse_orbit_file_dates(orbit.file) == date_tuple - - -@dataclasses.dataclass -class Scene: - scene_id: str - latest_orbit: Path - latest_res_orbit: Path - latest_poe_orbit: Path - -scene_1 = Scene( - scene_id="S1B_EW_GRDM_1SDH_20191130T165626_20191130T165726_019159_0242A2_2F58", - latest_orbit=Path("/g/data/fj7/Copernicus/Sentinel-1/POEORB/S1B/S1B_OPER_AUX_POEORB_OPOD_20191220T110516_V20191129T225942_20191201T005942.EOF"), - latest_res_orbit=Path("/g/data/fj7/Copernicus/Sentinel-1/RESORB/S1B/S1B_OPER_AUX_RESORB_OPOD_20191130T210136_V20191130T154804_20191130T190534.EOF"), - latest_poe_orbit=Path("/g/data/fj7/Copernicus/Sentinel-1/POEORB/S1B/S1B_OPER_AUX_POEORB_OPOD_20191220T110516_V20191129T225942_20191201T005942.EOF") -) - -scene_2 = Scene( - scene_id="S1A_EW_GRDM_1SDH_20220612T120348_20220612T120452_043629_053582_0F66", - latest_orbit=Path("/g/data/fj7/Copernicus/Sentinel-1/POEORB/S1A/S1A_OPER_AUX_POEORB_OPOD_20220702T081845_V20220611T225942_20220613T005942.EOF"), - latest_res_orbit=Path("/g/data/fj7/Copernicus/Sentinel-1/RESORB/S1A/S1A_OPER_AUX_RESORB_OPOD_20220612T143829_V20220612T104432_20220612T140202.EOF"), - latest_poe_orbit=Path("/g/data/fj7/Copernicus/Sentinel-1/POEORB/S1A/S1A_OPER_AUX_POEORB_OPOD_20220702T081845_V20220611T225942_20220613T005942.EOF") -) - -scenes = [scene_1, scene_2] - -@pytest.mark.parametrize("scene", scenes) -def test_find_latest_orbit_for_scene(scene: Scene): - assert find_latest_orbit_for_scene(scene.scene_id) == scene.latest_orbit - assert find_latest_orbit_for_scene(scene.scene_id, orbit_type="RES") == scene.latest_res_orbit - assert find_latest_orbit_for_scene(scene.scene_id, orbit_type="POE") == scene.latest_poe_orbit From 6ad814a80b141ecdfcaafadd158317971de81eee Mon Sep 17 00:00:00 2001 From: Caitlin Adams <25995927+caitlinadams@users.noreply.github.com> Date: Fri, 10 Jan 2025 09:57:20 +1100 Subject: [PATCH 7/8] Update github workflow to only run codebase tests --- .github/workflows/run-pytest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-pytest.yml b/.github/workflows/run-pytest.yml index 93d8f1a..8686105 100644 --- a/.github/workflows/run-pytest.yml +++ b/.github/workflows/run-pytest.yml @@ -25,4 +25,4 @@ jobs: - name: Run tests shell: micromamba-shell {0} run: | - pytest + pytest pytest tests/sar_antarctica/ From da5aab3ff630a1da3895a8c4d43da21cbc75e3c6 Mon Sep 17 00:00:00 2001 From: Caitlin Adams <25995927+caitlinadams@users.noreply.github.com> Date: Fri, 10 Jan 2025 09:59:49 +1100 Subject: [PATCH 8/8] Fix typo in workflow --- .github/workflows/run-pytest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-pytest.yml b/.github/workflows/run-pytest.yml index 8686105..4f938cb 100644 --- a/.github/workflows/run-pytest.yml +++ b/.github/workflows/run-pytest.yml @@ -25,4 +25,4 @@ jobs: - name: Run tests shell: micromamba-shell {0} run: | - pytest pytest tests/sar_antarctica/ + pytest tests/sar_antarctica/