Skip to content

Commit

Permalink
Make season specifier optional
Browse files Browse the repository at this point in the history
  • Loading branch information
kvantricht committed Jun 19, 2024
1 parent 2a78c0d commit 3bc4bc9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/worldcereal/seasons.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,17 @@ def season_doys_to_dates(
return (start_date.strftime("%Y-%m-%d"), end_date.strftime("%Y-%m-%d"))


def get_processing_dates_for_extent(extent: BoundingBoxExtent, season: str, year: int):
def get_processing_dates_for_extent(
extent: BoundingBoxExtent, year: int, season: str = "tc-annual"
):
"""Function to retrieve required temporal range of input products for a
given extent, season and year. Based on the requested season's end date
a temporal range is inferred that spans an entire year.
Args:
extent (BoundingBoxExtent): extent for which to infer dates
season (str): season identifier for which to infer dates
year (int): year in which the end of season needs to be
season (str): season identifier for which to infer dates. Defaults to tc-annual
Raises:
ValueError: invalid season specified
Expand Down
4 changes: 3 additions & 1 deletion tests/worldcerealtests/test_seasons.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ def test_doy_to_date_after():


def test_get_processing_dates_for_extent():
# Test to check if we can infer processing dates for default season
# tc-annual
bounds = (574680, 5621800, 575320, 5622440)
epsg = 32631
year = 2021
extent = BoundingBoxExtent(*bounds, epsg)

start_date, end_date = get_processing_dates_for_extent(extent, "tc-annual", year)
start_date, end_date = get_processing_dates_for_extent(extent, year)

assert pd.to_datetime(end_date).year == year
assert pd.to_datetime(end_date) - pd.to_datetime(start_date) == pd.Timedelta(
Expand Down

0 comments on commit 3bc4bc9

Please sign in to comment.