datacosmos 0.0.4__py3-none-any.whl → 0.0.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of datacosmos might be problematic. Click here for more details.
- config/config.py +1 -2
- config/models/m2m_authentication_config.py +8 -4
- datacosmos/stac/item/item_client.py +2 -19
- datacosmos/stac/item/models/catalog_search_parameters.py +16 -10
- datacosmos/uploader/dataclasses/upload_path.py +4 -4
- {datacosmos-0.0.4.dist-info → datacosmos-0.0.5.dist-info}/METADATA +2 -1
- {datacosmos-0.0.4.dist-info → datacosmos-0.0.5.dist-info}/RECORD +10 -11
- {datacosmos-0.0.4.dist-info → datacosmos-0.0.5.dist-info}/WHEEL +1 -1
- datacosmos/stac/item/models/search_parameters.py +0 -58
- {datacosmos-0.0.4.dist-info → datacosmos-0.0.5.dist-info}/licenses/LICENSE.md +0 -0
- {datacosmos-0.0.4.dist-info → datacosmos-0.0.5.dist-info}/top_level.txt +0 -0
config/config.py
CHANGED
|
@@ -6,7 +6,7 @@ and supports environment variable-based overrides.
|
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
8
|
import os
|
|
9
|
-
from typing import ClassVar,
|
|
9
|
+
from typing import ClassVar, Optional
|
|
10
10
|
|
|
11
11
|
import yaml
|
|
12
12
|
from pydantic import field_validator
|
|
@@ -29,7 +29,6 @@ class Config(BaseSettings):
|
|
|
29
29
|
stac: Optional[URL] = None
|
|
30
30
|
datacosmos_cloud_storage: Optional[URL] = None
|
|
31
31
|
mission_id: int = 0
|
|
32
|
-
environment: Literal["local", "test", "prod"] = "test"
|
|
33
32
|
|
|
34
33
|
DEFAULT_AUTH_TYPE: ClassVar[str] = "m2m"
|
|
35
34
|
DEFAULT_AUTH_TOKEN_URL: ClassVar[str] = "https://login.open-cosmos.com/oauth/token"
|
|
@@ -6,7 +6,7 @@ without user interaction.
|
|
|
6
6
|
|
|
7
7
|
from typing import Literal
|
|
8
8
|
|
|
9
|
-
from pydantic import BaseModel
|
|
9
|
+
from pydantic import BaseModel, Field
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class M2MAuthenticationConfig(BaseModel):
|
|
@@ -16,8 +16,12 @@ class M2MAuthenticationConfig(BaseModel):
|
|
|
16
16
|
with client credentials.
|
|
17
17
|
"""
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
DEFAULT_TYPE: Literal["m2m"] = "m2m"
|
|
20
|
+
DEFAULT_TOKEN_URL: str = "https://login.open-cosmos.com/oauth/token"
|
|
21
|
+
DEFAULT_AUDIENCE: str = "https://beeapp.open-cosmos.com"
|
|
22
|
+
|
|
23
|
+
type: Literal["m2m"] = Field(default=DEFAULT_TYPE)
|
|
20
24
|
client_id: str
|
|
21
|
-
token_url: str
|
|
22
|
-
audience: str
|
|
25
|
+
token_url: str = Field(default=DEFAULT_TOKEN_URL)
|
|
26
|
+
audience: str = Field(default=DEFAULT_AUDIENCE)
|
|
23
27
|
client_secret: str
|
|
@@ -14,7 +14,6 @@ from datacosmos.stac.item.models.catalog_search_parameters import (
|
|
|
14
14
|
)
|
|
15
15
|
from datacosmos.stac.item.models.datacosmos_item import DatacosmosItem
|
|
16
16
|
from datacosmos.stac.item.models.item_update import ItemUpdate
|
|
17
|
-
from datacosmos.stac.item.models.search_parameters import SearchParameters
|
|
18
17
|
from datacosmos.utils.http_response.check_api_response import check_api_response
|
|
19
18
|
|
|
20
19
|
|
|
@@ -45,23 +44,6 @@ class ItemClient:
|
|
|
45
44
|
check_api_response(response)
|
|
46
45
|
return Item.from_dict(response.json())
|
|
47
46
|
|
|
48
|
-
def fetch_collection_items(
|
|
49
|
-
self, collection_id: str, parameters: Optional[SearchParameters] = None
|
|
50
|
-
) -> Generator[Item, None, None]:
|
|
51
|
-
"""Fetch all items in a collection with optional filtering.
|
|
52
|
-
|
|
53
|
-
Args:
|
|
54
|
-
collection_id (str): The ID of the collection.
|
|
55
|
-
parameters (Optional[SearchParameters]): Filtering parameters (spatial, temporal, etc.).
|
|
56
|
-
|
|
57
|
-
Yields:
|
|
58
|
-
Item: Parsed STAC item.
|
|
59
|
-
"""
|
|
60
|
-
if parameters is None:
|
|
61
|
-
parameters = SearchParameters(collections=[collection_id])
|
|
62
|
-
|
|
63
|
-
return self.search_items(parameters)
|
|
64
|
-
|
|
65
47
|
def search_items(
|
|
66
48
|
self, parameters: CatalogSearchParameters, project_id: str
|
|
67
49
|
) -> Generator[Item, None, None]:
|
|
@@ -76,6 +58,8 @@ class ItemClient:
|
|
|
76
58
|
url = self.base_url.with_suffix("/search")
|
|
77
59
|
parameters_query = parameters.to_query()
|
|
78
60
|
body = {"project": project_id, "limit": 50, "query": parameters_query}
|
|
61
|
+
if parameters.collections is not None:
|
|
62
|
+
body = body | {"collections": parameters.collections}
|
|
79
63
|
return self._paginate_items(url, body)
|
|
80
64
|
|
|
81
65
|
def create_item(self, collection_id: str, item: Item | DatacosmosItem) -> None:
|
|
@@ -90,7 +74,6 @@ class ItemClient:
|
|
|
90
74
|
"""
|
|
91
75
|
url = self.base_url.with_suffix(f"/collections/{collection_id}/items")
|
|
92
76
|
item_json: dict = item.to_dict()
|
|
93
|
-
|
|
94
77
|
response = self.client.post(url, json=item_json)
|
|
95
78
|
check_api_response(response)
|
|
96
79
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
from datetime import datetime, timedelta
|
|
4
4
|
from typing import Any, List, Optional
|
|
5
5
|
|
|
6
|
-
from pydantic import BaseModel, field_validator, model_validator
|
|
6
|
+
from pydantic import BaseModel, Field, field_validator, model_validator
|
|
7
7
|
|
|
8
8
|
from datacosmos.stac.constants.satellite_name_mapping import SATELLITE_NAME_MAPPING
|
|
9
9
|
from datacosmos.stac.enums.processing_level import ProcessingLevel
|
|
@@ -20,6 +20,11 @@ class CatalogSearchParameters(BaseModel):
|
|
|
20
20
|
satellite: Optional[List[str]] = None
|
|
21
21
|
product_type: Optional[List[ProductType]] = None
|
|
22
22
|
processing_level: Optional[List[ProcessingLevel]] = None
|
|
23
|
+
collections: Optional[list[str]] = Field(
|
|
24
|
+
None,
|
|
25
|
+
description="Array of collection IDs to filter by.",
|
|
26
|
+
example=["collection1", "collection2"],
|
|
27
|
+
)
|
|
23
28
|
|
|
24
29
|
# --- Field Validators ---
|
|
25
30
|
|
|
@@ -58,13 +63,13 @@ class CatalogSearchParameters(BaseModel):
|
|
|
58
63
|
return None
|
|
59
64
|
try:
|
|
60
65
|
dt = datetime.strptime(value, "%m/%d/%Y")
|
|
61
|
-
|
|
62
|
-
raise ValueError("Date must be 5/15/2015 or later.")
|
|
63
|
-
return dt.isoformat() + "Z"
|
|
64
|
-
except ValueError:
|
|
66
|
+
except Exception as e:
|
|
65
67
|
raise ValueError(
|
|
66
68
|
"Invalid start_date format. Use mm/dd/yyyy (e.g., 05/15/2024)"
|
|
67
|
-
)
|
|
69
|
+
) from e
|
|
70
|
+
if dt < datetime(2015, 5, 15):
|
|
71
|
+
raise ValueError("Date must be 5/15/2015 or later.")
|
|
72
|
+
return dt.isoformat() + "Z"
|
|
68
73
|
|
|
69
74
|
@field_validator("end_date", mode="before")
|
|
70
75
|
@classmethod
|
|
@@ -74,15 +79,16 @@ class CatalogSearchParameters(BaseModel):
|
|
|
74
79
|
return None
|
|
75
80
|
try:
|
|
76
81
|
dt = datetime.strptime(value, "%m/%d/%Y")
|
|
77
|
-
if dt < datetime(2015, 5, 15):
|
|
78
|
-
raise ValueError("Date must be 5/15/2015 or later.")
|
|
79
|
-
dt = dt + timedelta(days=1) - timedelta(milliseconds=1)
|
|
80
|
-
return dt.isoformat() + "Z"
|
|
81
82
|
except ValueError:
|
|
82
83
|
raise ValueError(
|
|
83
84
|
"Invalid end_date format. Use mm/dd/yyyy (e.g., 05/15/2024)"
|
|
84
85
|
)
|
|
85
86
|
|
|
87
|
+
if dt < datetime(2015, 5, 15):
|
|
88
|
+
raise ValueError("Date must be 5/15/2015 or later.")
|
|
89
|
+
dt = dt + timedelta(days=1) - timedelta(milliseconds=1)
|
|
90
|
+
return dt.isoformat() + "Z"
|
|
91
|
+
|
|
86
92
|
# --- Model Validator ---
|
|
87
93
|
|
|
88
94
|
@model_validator(mode="after")
|
|
@@ -6,7 +6,7 @@ from pathlib import Path
|
|
|
6
6
|
|
|
7
7
|
import structlog
|
|
8
8
|
|
|
9
|
-
from datacosmos.stac.enums.
|
|
9
|
+
from datacosmos.stac.enums.processing_level import ProcessingLevel
|
|
10
10
|
from datacosmos.stac.item.models.datacosmos_item import DatacosmosItem
|
|
11
11
|
from datacosmos.utils.missions import get_mission_id
|
|
12
12
|
|
|
@@ -18,7 +18,7 @@ class UploadPath:
|
|
|
18
18
|
"""Dataclass for retrieving the upload path of a file."""
|
|
19
19
|
|
|
20
20
|
mission: str
|
|
21
|
-
level:
|
|
21
|
+
level: ProcessingLevel
|
|
22
22
|
day: int
|
|
23
23
|
month: int
|
|
24
24
|
year: int
|
|
@@ -43,7 +43,7 @@ class UploadPath:
|
|
|
43
43
|
dt = datetime.strptime(item.properties["datetime"], "%Y-%m-%dT%H:%M:%SZ")
|
|
44
44
|
path = UploadPath(
|
|
45
45
|
mission=mission,
|
|
46
|
-
level=
|
|
46
|
+
level=ProcessingLevel(item.properties["processing:level"].upper()),
|
|
47
47
|
day=dt.day,
|
|
48
48
|
month=dt.month,
|
|
49
49
|
year=dt.year,
|
|
@@ -60,7 +60,7 @@ class UploadPath:
|
|
|
60
60
|
raise ValueError(f"Invalid path {path}")
|
|
61
61
|
return cls(
|
|
62
62
|
mission=parts[0],
|
|
63
|
-
level=
|
|
63
|
+
level=ProcessingLevel(parts[1]),
|
|
64
64
|
day=int(parts[4]),
|
|
65
65
|
month=int(parts[3]),
|
|
66
66
|
year=int(parts[2]),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: datacosmos
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.5
|
|
4
4
|
Summary: A library for interacting with DataCosmos from Python code
|
|
5
5
|
Author-email: Open Cosmos <support@open-cosmos.com>
|
|
6
6
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -14,6 +14,7 @@ Requires-Dist: requests-oauthlib==1.3.1
|
|
|
14
14
|
Requires-Dist: pydantic==2.10.6
|
|
15
15
|
Requires-Dist: pystac==1.12.1
|
|
16
16
|
Requires-Dist: pyyaml==6.0.2
|
|
17
|
+
Requires-Dist: structlog==25.3.0
|
|
17
18
|
Provides-Extra: dev
|
|
18
19
|
Requires-Dist: black==22.3.0; extra == "dev"
|
|
19
20
|
Requires-Dist: ruff==0.9.5; extra == "dev"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
config/__init__.py,sha256=KCsaTb9-ZgFui1GM8wZFIPLJy0D0O8l8Z1Sv3NRD9UM,140
|
|
2
|
-
config/config.py,sha256=
|
|
2
|
+
config/config.py,sha256=vtimmFY2zOXV3OjT7sS5P0p1sW_-ecB5VCF6cseSk4g,7165
|
|
3
3
|
config/models/__init__.py,sha256=r3lThPkyKjBjUZXRNscFzOrmn_-m_i9DvG3RePfCFYc,41
|
|
4
|
-
config/models/m2m_authentication_config.py,sha256=
|
|
4
|
+
config/models/m2m_authentication_config.py,sha256=n76N4bakpPPycTOeKpiM8pazYtNqiJGMzZXmI_ogbHM,847
|
|
5
5
|
config/models/url.py,sha256=fwr2C06e_RDS8AWxOV_orVxMWhc57bzYoWSjFxQbkwg,835
|
|
6
6
|
datacosmos/__init__.py,sha256=dVHKpbz5FVtfoJAWHRdsUENG6H-vs4UrkuwnIvOGJr4,66
|
|
7
7
|
datacosmos/datacosmos_client.py,sha256=sivVYf45QEHTkUO62fnb1fnObKVmUngTR1Ga-ZRnoQE,4967
|
|
@@ -20,19 +20,18 @@ datacosmos/stac/enums/processing_level.py,sha256=5gHG-0kG5rCUxmXYwF3t94ALKk6zUqg
|
|
|
20
20
|
datacosmos/stac/enums/product_type.py,sha256=7lL0unJ1hxevW8Pepn9rmydUUWIORu2x4MEtp6rSFbA,196
|
|
21
21
|
datacosmos/stac/enums/season.py,sha256=QvUzXBYtPEfixhlbV0SAw2u_HK3tRFEnHKshJyIatdg,241
|
|
22
22
|
datacosmos/stac/item/__init__.py,sha256=lRuD_yp-JxoLqBA23q0XMkCNImf4T-X3BJnSw9u_3Yk,200
|
|
23
|
-
datacosmos/stac/item/item_client.py,sha256=
|
|
23
|
+
datacosmos/stac/item/item_client.py,sha256=mFcbXqV1Ascd5hUSlZFzNgni_DncHAIyIvhtUHpgHI0,6457
|
|
24
24
|
datacosmos/stac/item/models/__init__.py,sha256=bcOrOcIxGxGBrRVIyQVxSM3C3Xj_qzxIHgQeWo6f7Q8,34
|
|
25
25
|
datacosmos/stac/item/models/asset.py,sha256=mvg_fenYCGOTMGwXXpK2nyqBk5RMsUYxl6KhQTWW_b0,631
|
|
26
|
-
datacosmos/stac/item/models/catalog_search_parameters.py,sha256=
|
|
26
|
+
datacosmos/stac/item/models/catalog_search_parameters.py,sha256=3HrUm37VezujwuCR45jhMryS5m1FGc1XmX8-fdTy4jU,4870
|
|
27
27
|
datacosmos/stac/item/models/datacosmos_item.py,sha256=AImz0GRxrpZfIETdzzNfaKX35wpr39Q4f4u0z6r8eys,1745
|
|
28
28
|
datacosmos/stac/item/models/eo_band.py,sha256=YC3Scn_wFhIo51pIVcJeuJienF7JGWoEv39JngDM6rI,309
|
|
29
29
|
datacosmos/stac/item/models/item_update.py,sha256=_CpjQn9SsfedfuxlHSiGeptqY4M-p15t9YX__mBRueI,2088
|
|
30
30
|
datacosmos/stac/item/models/raster_band.py,sha256=CoEVs-YyPE5Fse0He9DdOs4dGZpzfCsCuVzOcdXa_UM,354
|
|
31
|
-
datacosmos/stac/item/models/search_parameters.py,sha256=yMmcb-Tr2as8585MD5wuZLWcqzwtRRkj07WBkootVS0,2022
|
|
32
31
|
datacosmos/uploader/__init__.py,sha256=ZtfCVJ_pWKKh2F1r_NArnbG3_JtpcEiXcA_tmSwSKmQ,128
|
|
33
32
|
datacosmos/uploader/datacosmos_uploader.py,sha256=LUtBDvAjZI7AYxKnC9TZQDP4z6lV2aHusz92XqivFGw,4398
|
|
34
33
|
datacosmos/uploader/dataclasses/__init__.py,sha256=IjcyA8Vod-z1_Gi1FMZhK58Owman0foL25Hs0YtkYYs,43
|
|
35
|
-
datacosmos/uploader/dataclasses/upload_path.py,sha256=
|
|
34
|
+
datacosmos/uploader/dataclasses/upload_path.py,sha256=X8zkfw3_FO9qTiKHu-nL_uDmQJYfaov6e4Y2-f-opaU,3204
|
|
36
35
|
datacosmos/utils/__init__.py,sha256=XQbAnoqJrPpnSpEzAbjh84yqYWw8cBM8mNp8ynTG-54,50
|
|
37
36
|
datacosmos/utils/constants.py,sha256=f7pOqCpdXk7WFGoaTyuCpr65jb-TtfhoVGuYTz3_T6Y,272
|
|
38
37
|
datacosmos/utils/missions.py,sha256=7GOnrjxB8V11C_Jr3HHI4vpXifgkOSeirNjIDx17C58,940
|
|
@@ -42,8 +41,8 @@ datacosmos/utils/http_response/check_api_response.py,sha256=dKWW01jn2_lWV0xpOBAB
|
|
|
42
41
|
datacosmos/utils/http_response/models/__init__.py,sha256=Wj8YT6dqw7rAz_rctllxo5Or_vv8DwopvQvBzwCTvpw,45
|
|
43
42
|
datacosmos/utils/http_response/models/datacosmos_error.py,sha256=Uqi2uM98nJPeCbM7zngV6vHSk97jEAb_nkdDEeUjiQM,740
|
|
44
43
|
datacosmos/utils/http_response/models/datacosmos_response.py,sha256=oV4n-sue7K1wwiIQeHpxdNU8vxeqF3okVPE2rydw5W0,336
|
|
45
|
-
datacosmos-0.0.
|
|
46
|
-
datacosmos-0.0.
|
|
47
|
-
datacosmos-0.0.
|
|
48
|
-
datacosmos-0.0.
|
|
49
|
-
datacosmos-0.0.
|
|
44
|
+
datacosmos-0.0.5.dist-info/licenses/LICENSE.md,sha256=vpbRI-UUbZVQfr3VG_CXt9HpRnL1b5kt8uTVbirxeyI,1486
|
|
45
|
+
datacosmos-0.0.5.dist-info/METADATA,sha256=vng8nMwWZjm4IZgXymw6cjWEJZOm6LZSahL0vUNUmPA,905
|
|
46
|
+
datacosmos-0.0.5.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
|
|
47
|
+
datacosmos-0.0.5.dist-info/top_level.txt,sha256=Iu5b533Fmdfz0rFKTnuBPjSUOQL2lEkTfHxsokP72s4,18
|
|
48
|
+
datacosmos-0.0.5.dist-info/RECORD,,
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"""Module defining the SearchParameters model for STAC API queries, encapsulating filtering criteria.
|
|
2
|
-
|
|
3
|
-
It includes spatial, temporal, and property-based filters for querying STAC items efficiently.
|
|
4
|
-
"""
|
|
5
|
-
|
|
6
|
-
from typing import Optional, Union
|
|
7
|
-
|
|
8
|
-
from pydantic import BaseModel, Field, model_validator
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class SearchParameters(BaseModel):
|
|
12
|
-
"""Encapsulates the parameters for the STAC search API with validation."""
|
|
13
|
-
|
|
14
|
-
bbox: Optional[list[float]] = Field(
|
|
15
|
-
None,
|
|
16
|
-
description="Bounding box filter [minX, minY, maxX, maxY]. Optional six values for 3D bounding box.",
|
|
17
|
-
example=[-180.0, -90.0, 180.0, 90.0],
|
|
18
|
-
)
|
|
19
|
-
datetime_range: Optional[str] = Field(
|
|
20
|
-
None,
|
|
21
|
-
alias="datetime",
|
|
22
|
-
description=(
|
|
23
|
-
"Temporal filter, either a single RFC 3339 datetime or an interval. "
|
|
24
|
-
'Example: "2025-01-01T00:00:00Z/.."'
|
|
25
|
-
),
|
|
26
|
-
)
|
|
27
|
-
intersects: Optional[dict] = Field(
|
|
28
|
-
None, description="GeoJSON geometry filter, e.g., a Polygon or Point."
|
|
29
|
-
)
|
|
30
|
-
ids: Optional[list[str]] = Field(
|
|
31
|
-
None,
|
|
32
|
-
description="Array of item IDs to filter by.",
|
|
33
|
-
example=["item1", "item2"],
|
|
34
|
-
)
|
|
35
|
-
collections: Optional[list[str]] = Field(
|
|
36
|
-
None,
|
|
37
|
-
description="Array of collection IDs to filter by.",
|
|
38
|
-
example=["collection1", "collection2"],
|
|
39
|
-
)
|
|
40
|
-
limit: Optional[int] = Field(
|
|
41
|
-
None,
|
|
42
|
-
ge=1,
|
|
43
|
-
le=10000,
|
|
44
|
-
description="Maximum number of items per page. Default: 10, Max: 10000.",
|
|
45
|
-
example=10,
|
|
46
|
-
)
|
|
47
|
-
query: Optional[dict[str, dict[str, Union[str, int, float]]]] = Field(
|
|
48
|
-
None,
|
|
49
|
-
description="Additional property filters, e.g., { 'cloud_coverage': { 'lt': 10 } }.",
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
@model_validator(mode="before")
|
|
53
|
-
def validate_bbox(cls, values):
|
|
54
|
-
"""Validate that the `bbox` field contains either 4 or 6 values."""
|
|
55
|
-
bbox = values.get("bbox")
|
|
56
|
-
if bbox and len(bbox) not in {4, 6}:
|
|
57
|
-
raise ValueError("bbox must contain 4 or 6 values.")
|
|
58
|
-
return values
|
|
File without changes
|
|
File without changes
|