From 68d1c4703150860325bc7cc917928574d930935a Mon Sep 17 00:00:00 2001 From: ivanzvonkov Date: Fri, 24 Jun 2022 13:00:01 -0400 Subject: [PATCH 1/4] Start date extraction less restrictive --- cropharvest/inference.py | 6 +++--- test/cropharvest/test_inference.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/cropharvest/inference.py b/cropharvest/inference.py index d6a94d5..a93b475 100644 --- a/cropharvest/inference.py +++ b/cropharvest/inference.py @@ -42,9 +42,9 @@ def __init__( @staticmethod def start_date_from_str(path: Union[Path, str]) -> datetime: dates = re.findall(r"\d{4}-\d{2}-\d{2}", str(path)) - if len(dates) != 2: - raise ValueError(f"{path} should have start and end date") - start_date_str, _ = dates + if len(dates) < 1: + raise ValueError(f"{path} should have at least one date") + start_date_str = dates[0] start_date = datetime.strptime(start_date_str, "%Y-%m-%d") return start_date diff --git a/test/cropharvest/test_inference.py b/test/cropharvest/test_inference.py index 9109369..bf468c1 100644 --- a/test/cropharvest/test_inference.py +++ b/test/cropharvest/test_inference.py @@ -1,3 +1,5 @@ +import pytest + from datetime import datetime from pathlib import Path import numpy as np @@ -13,6 +15,19 @@ def test_start_date_from_str(): assert actual_start_date == expected_start_date +def test_start_date_from_str_none(): + with pytest.raises(ValueError): + Inference.start_date_from_str("98-togo") + + +def test_start_date_from_str_more_than_2(): + actual_start_date = Inference.start_date_from_str( + "98-togo_2019-02-06_2020-02-01_2019-02-06_2020-02-01" + ) + expected_start_date = datetime(2019, 2, 6, 0, 0) + assert actual_start_date == expected_start_date + + def test_combine_predictions(): flat_lat = np.array([14.95313164, 14.95313164, 14.95313164, 14.95313164, 14.95313164]) flat_lon = np.array([-86.25070894, -86.25061911, -86.25052928, -86.25043945, -86.25034962]) From 6db1d411d8009a7f82290c0b98a417d769654079 Mon Sep 17 00:00:00 2001 From: ivanzvonkov Date: Fri, 24 Jun 2022 13:12:26 -0400 Subject: [PATCH 2/4] Remove appending dates --- cropharvest/eo/eo.py | 3 +-- test/cropharvest/eo/test_eo.py | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/cropharvest/eo/eo.py b/cropharvest/eo/eo.py index 2290373..c5de0ec 100644 --- a/cropharvest/eo/eo.py +++ b/cropharvest/eo/eo.py @@ -426,7 +426,6 @@ def export_for_bbox( raise ValueError(f"Start date {start_date} is after end date {end_date}") ee_bbox = EEBoundingBox.from_bounding_box(bounding_box=bbox, padding_metres=0) - general_identifier = f"{bbox_name}_{str(start_date)}_{str(end_date)}" if metres_per_polygon is not None: regions = ee_bbox.to_polygons(metres_per_patch=metres_per_polygon) ids = [f"batch_{i}/{i}" for i in range(len(regions))] @@ -438,7 +437,7 @@ def export_for_bbox( for identifier, region in zip(ids, regions): return_obj[identifier] = self._export_for_polygon( polygon=region, - polygon_identifier=f"{general_identifier}/{identifier}", + polygon_identifier=f"{bbox_name}/{identifier}", start_date=start_date, end_date=end_date, file_dimensions=file_dimensions, diff --git a/test/cropharvest/eo/test_eo.py b/test/cropharvest/eo/test_eo.py index 3475e03..11bad78 100644 --- a/test/cropharvest/eo/test_eo.py +++ b/test/cropharvest/eo/test_eo.py @@ -131,7 +131,7 @@ def test_export_for_bbox(mock_export_for_polygon, metres_per_polygon, mock_polyg mock_export_for_polygon.assert_called_with( end_date=end_date, polygon=None, - polygon_identifier=f"Togo_{start_date}_{end_date}/batch/0", + polygon_identifier=f"Togo/batch/0", start_date=start_date, file_dimensions=None, test=True, @@ -143,7 +143,7 @@ def test_export_for_bbox(mock_export_for_polygon, metres_per_polygon, mock_polyg call( end_date=end_date, polygon=None, - polygon_identifier=f"Togo_{start_date}_{end_date}/batch_{i}/{i}", + polygon_identifier=f"Togo/batch_{i}/{i}", start_date=start_date, file_dimensions=None, test=True, From 00ab359e454b270f8a4dff8d2ae03e5b4542fdce Mon Sep 17 00:00:00 2001 From: ivanzvonkov Date: Fri, 24 Jun 2022 13:40:33 -0400 Subject: [PATCH 3/4] Remove extra f --- test/cropharvest/eo/test_eo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cropharvest/eo/test_eo.py b/test/cropharvest/eo/test_eo.py index 11bad78..43640a1 100644 --- a/test/cropharvest/eo/test_eo.py +++ b/test/cropharvest/eo/test_eo.py @@ -131,7 +131,7 @@ def test_export_for_bbox(mock_export_for_polygon, metres_per_polygon, mock_polyg mock_export_for_polygon.assert_called_with( end_date=end_date, polygon=None, - polygon_identifier=f"Togo/batch/0", + polygon_identifier="Togo/batch/0", start_date=start_date, file_dimensions=None, test=True, From e95bcbeeb068c8478987c1cae7294623c6d92002 Mon Sep 17 00:00:00 2001 From: ivanzvonkov Date: Fri, 24 Jun 2022 13:42:15 -0400 Subject: [PATCH 4/4] Relevant for inference --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index f5097a3..0c5b9a6 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ author="Gabriel Tseng", author_email="gabrieltseng95@gmail.com", url="https://github.com/nasaharvest/cropharvest", - version="0.4.0", + version="0.4.1", classifiers=[ "Programming Language :: Python :: 3", "License :: Other/Proprietary License",