From dc7ac3087b01aa614810c922a4761087e1cc29a7 Mon Sep 17 00:00:00 2001 From: Kristof Van Tricht Date: Fri, 21 Jun 2024 17:14:42 +0200 Subject: [PATCH] Add gfmap dependency and migrate imports --- src/worldcereal/__init__.py | 3 +- src/worldcereal/seasons.py | 3 +- src/worldcereal/utils/spatial.py | 56 -------------------------- tests/worldcerealtests/test_seasons.py | 2 +- 4 files changed, 4 insertions(+), 60 deletions(-) delete mode 100644 src/worldcereal/utils/spatial.py diff --git a/src/worldcereal/__init__.py b/src/worldcereal/__init__.py index 9359720d..e8cffa30 100644 --- a/src/worldcereal/__init__.py +++ b/src/worldcereal/__init__.py @@ -1,9 +1,8 @@ #!/usr/bin/env python3 from ._version import __version__ -from .utils.spatial import BoundingBoxExtent -__all__ = ["__version__", "BoundingBoxExtent"] +__all__ = ["__version__"] SUPPORTED_SEASONS = [ "tc-s1", diff --git a/src/worldcereal/seasons.py b/src/worldcereal/seasons.py index c46198e7..b5174503 100644 --- a/src/worldcereal/seasons.py +++ b/src/worldcereal/seasons.py @@ -5,8 +5,9 @@ import numpy as np import pandas as pd from loguru import logger +from openeo_gfmap import BoundingBoxExtent -from worldcereal import SEASONAL_MAPPING, SUPPORTED_SEASONS, BoundingBoxExtent +from worldcereal import SEASONAL_MAPPING, SUPPORTED_SEASONS from worldcereal.data import cropcalendars # from worldcereal.utils import aez as aezloader diff --git a/src/worldcereal/utils/spatial.py b/src/worldcereal/utils/spatial.py deleted file mode 100644 index 370d1761..00000000 --- a/src/worldcereal/utils/spatial.py +++ /dev/null @@ -1,56 +0,0 @@ -""" Definitions of spatial context, either point-based or spatial""" - -from dataclasses import dataclass -from typing import Union - -from geojson import GeoJSON -from shapely.geometry import Polygon, box - -# TODO: once gfmap is on PyPI we need to import the class from there -# instead of duplicating it here. - - -@dataclass -class BoundingBoxExtent: - """Definition of a bounding box as accepted by OpenEO - - Contains the minx, miny, maxx, maxy coordinates expressed as east, south - west, north. The EPSG is also defined. - """ - - west: float - south: float - east: float - north: float - epsg: int = 4326 - - def __dict__(self): - return { - "west": self.west, - "south": self.south, - "east": self.east, - "north": self.north, - "crs": f"EPSG:{self.epsg}", - "srs": f"EPSG:{self.epsg}", - } - - def __iter__(self): - return iter( - [ - ("west", self.west), - ("south", self.south), - ("east", self.east), - ("north", self.north), - ("crs", f"EPSG:{self.epsg}"), - ("srs", f"EPSG:{self.epsg}"), - ] - ) - - def to_geometry(self) -> Polygon: - return box(self.west, self.south, self.east, self.north) - - def to_geojson(self) -> GeoJSON: - return self.to_geometry().__geo_interface__ - - -SpatialContext = Union[GeoJSON, BoundingBoxExtent, str] diff --git a/tests/worldcerealtests/test_seasons.py b/tests/worldcerealtests/test_seasons.py index 516a528c..175e6bb1 100644 --- a/tests/worldcerealtests/test_seasons.py +++ b/tests/worldcerealtests/test_seasons.py @@ -2,8 +2,8 @@ import numpy as np import pandas as pd +from openeo_gfmap import BoundingBoxExtent -from worldcereal import BoundingBoxExtent from worldcereal.seasons import ( circular_median_day_of_year, doy_from_tiff,