eodash_catalog 0.0.1__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 eodash_catalog might be problematic. Click here for more details.
- eodash_catalog/__about__.py +4 -0
- eodash_catalog/__init__.py +3 -0
- eodash_catalog/duration.py +315 -0
- eodash_catalog/generate_indicators.py +1384 -0
- eodash_catalog/sh_endpoint.py +19 -0
- eodash_catalog/utils.py +181 -0
- eodash_catalog-0.0.1.dist-info/METADATA +62 -0
- eodash_catalog-0.0.1.dist-info/RECORD +11 -0
- eodash_catalog-0.0.1.dist-info/WHEEL +4 -0
- eodash_catalog-0.0.1.dist-info/entry_points.txt +2 -0
- eodash_catalog-0.0.1.dist-info/licenses/LICENSE.txt +9 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from oauthlib.oauth2 import BackendApplicationClient
|
|
3
|
+
from requests_oauthlib import OAuth2Session
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def get_SH_token():
|
|
7
|
+
# Your client credentials
|
|
8
|
+
client_id = os.getenv("SH_CLIENT_ID")
|
|
9
|
+
client_secret = os.getenv("SH_CLIENT_SECRET")
|
|
10
|
+
# Create a session
|
|
11
|
+
client = BackendApplicationClient(client_id=client_id)
|
|
12
|
+
oauth = OAuth2Session(client=client)
|
|
13
|
+
# Get token for the session
|
|
14
|
+
token = oauth.fetch_token(
|
|
15
|
+
token_url="https://services.sentinel-hub.com/oauth/token",
|
|
16
|
+
client_secret=client_secret,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
return token["access_token"]
|
eodash_catalog/utils.py
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import re
|
|
3
|
+
from functools import reduce
|
|
4
|
+
from eodash_catalog.duration import Duration
|
|
5
|
+
from decimal import Decimal
|
|
6
|
+
from datetime import datetime, timedelta
|
|
7
|
+
from typing import Iterator
|
|
8
|
+
from six import string_types
|
|
9
|
+
from owslib.wms import WebMapService
|
|
10
|
+
from owslib.wmts import WebMapTileService
|
|
11
|
+
from dateutil import parser
|
|
12
|
+
import threading
|
|
13
|
+
|
|
14
|
+
ISO8601_PERIOD_REGEX = re.compile(
|
|
15
|
+
r"^(?P<sign>[+-])?"
|
|
16
|
+
r"P(?!\b)"
|
|
17
|
+
r"(?P<years>[0-9]+([,.][0-9]+)?Y)?"
|
|
18
|
+
r"(?P<months>[0-9]+([,.][0-9]+)?M)?"
|
|
19
|
+
r"(?P<weeks>[0-9]+([,.][0-9]+)?W)?"
|
|
20
|
+
r"(?P<days>[0-9]+([,.][0-9]+)?D)?"
|
|
21
|
+
r"((?P<separator>T)(?P<hours>[0-9]+([,.][0-9]+)?H)?"
|
|
22
|
+
r"(?P<minutes>[0-9]+([,.][0-9]+)?M)?"
|
|
23
|
+
r"(?P<seconds>[0-9]+([,.][0-9]+)?S)?)?$"
|
|
24
|
+
)
|
|
25
|
+
# regular expression to parse ISO duartion strings.
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def create_geojson_point(lon, lat):
|
|
29
|
+
point = {"type": "Point", "coordinates": [lon, lat]}
|
|
30
|
+
|
|
31
|
+
feature = {"type": "Feature", "geometry": point, "properties": {}}
|
|
32
|
+
|
|
33
|
+
feature_collection = {"type": "FeatureCollection", "features": [feature]}
|
|
34
|
+
|
|
35
|
+
return feature_collection
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def retrieveExtentFromWMSWMTS(capabilties_url, layer, wmts=False):
|
|
39
|
+
times = []
|
|
40
|
+
service = None
|
|
41
|
+
try:
|
|
42
|
+
if not wmts:
|
|
43
|
+
service = WebMapService(capabilties_url, version="1.1.1")
|
|
44
|
+
else:
|
|
45
|
+
service = WebMapTileService(capabilties_url)
|
|
46
|
+
if layer in list(service.contents):
|
|
47
|
+
tps = []
|
|
48
|
+
if not wmts and service[layer].timepositions != None:
|
|
49
|
+
tps = service[layer].timepositions
|
|
50
|
+
elif wmts:
|
|
51
|
+
# specifically taking 'time' dimension
|
|
52
|
+
if time_dimension := service[layer].dimensions.get("time"):
|
|
53
|
+
tps = time_dimension["values"]
|
|
54
|
+
for tp in tps:
|
|
55
|
+
tp_def = tp.split("/")
|
|
56
|
+
if len(tp_def) > 1:
|
|
57
|
+
dates = interval(
|
|
58
|
+
parser.parse(tp_def[0]),
|
|
59
|
+
parser.parse(tp_def[1]),
|
|
60
|
+
parse_duration(tp_def[2]),
|
|
61
|
+
)
|
|
62
|
+
times += [x.strftime("%Y-%m-%dT%H:%M:%SZ") for x in dates]
|
|
63
|
+
else:
|
|
64
|
+
times.append(tp)
|
|
65
|
+
times = [time.replace("\n", "").strip() for time in times]
|
|
66
|
+
# get unique times
|
|
67
|
+
times = reduce(lambda re, x: re + [x] if x not in re else re, times, [])
|
|
68
|
+
except Exception as e:
|
|
69
|
+
print("Issue extracting information from service capabilities")
|
|
70
|
+
template = "An exception of type {0} occurred. Arguments:\n{1!r}"
|
|
71
|
+
message = template.format(type(e).__name__, e.args)
|
|
72
|
+
print(message)
|
|
73
|
+
|
|
74
|
+
bbox = [-180, -90, 180, 90]
|
|
75
|
+
if service and service[layer].boundingBoxWGS84:
|
|
76
|
+
bbox = [float(x) for x in service[layer].boundingBoxWGS84]
|
|
77
|
+
return bbox, times
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def interval(start: datetime, stop: datetime, delta: timedelta) -> Iterator[datetime]:
|
|
81
|
+
while start <= stop:
|
|
82
|
+
yield start
|
|
83
|
+
start += delta
|
|
84
|
+
yield stop
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def parse_duration(datestring):
|
|
88
|
+
"""
|
|
89
|
+
Parses an ISO 8601 durations into datetime.timedelta
|
|
90
|
+
"""
|
|
91
|
+
if not isinstance(datestring, string_types):
|
|
92
|
+
raise TypeError("Expecting a string %r" % datestring)
|
|
93
|
+
match = ISO8601_PERIOD_REGEX.match(datestring)
|
|
94
|
+
if not match:
|
|
95
|
+
# try alternative format:
|
|
96
|
+
if datestring.startswith("P"):
|
|
97
|
+
durdt = parse_datetime(datestring[1:])
|
|
98
|
+
if durdt.year != 0 or durdt.month != 0:
|
|
99
|
+
# create Duration
|
|
100
|
+
ret = Duration(
|
|
101
|
+
days=durdt.day,
|
|
102
|
+
seconds=durdt.second,
|
|
103
|
+
microseconds=durdt.microsecond,
|
|
104
|
+
minutes=durdt.minute,
|
|
105
|
+
hours=durdt.hour,
|
|
106
|
+
months=durdt.month,
|
|
107
|
+
years=durdt.year,
|
|
108
|
+
)
|
|
109
|
+
else: # FIXME: currently not possible in alternative format
|
|
110
|
+
# create timedelta
|
|
111
|
+
ret = timedelta(
|
|
112
|
+
days=durdt.day,
|
|
113
|
+
seconds=durdt.second,
|
|
114
|
+
microseconds=durdt.microsecond,
|
|
115
|
+
minutes=durdt.minute,
|
|
116
|
+
hours=durdt.hour,
|
|
117
|
+
)
|
|
118
|
+
return ret
|
|
119
|
+
raise ISO8601Error("Unable to parse duration string %r" % datestring)
|
|
120
|
+
groups = match.groupdict()
|
|
121
|
+
for key, val in groups.items():
|
|
122
|
+
if key not in ("separator", "sign"):
|
|
123
|
+
if val is None:
|
|
124
|
+
groups[key] = "0n"
|
|
125
|
+
# print groups[key]
|
|
126
|
+
if key in ("years", "months"):
|
|
127
|
+
groups[key] = Decimal(groups[key][:-1].replace(",", "."))
|
|
128
|
+
else:
|
|
129
|
+
# these values are passed into a timedelta object,
|
|
130
|
+
# which works with floats.
|
|
131
|
+
groups[key] = float(groups[key][:-1].replace(",", "."))
|
|
132
|
+
if groups["years"] == 0 and groups["months"] == 0:
|
|
133
|
+
ret = timedelta(
|
|
134
|
+
days=groups["days"],
|
|
135
|
+
hours=groups["hours"],
|
|
136
|
+
minutes=groups["minutes"],
|
|
137
|
+
seconds=groups["seconds"],
|
|
138
|
+
weeks=groups["weeks"],
|
|
139
|
+
)
|
|
140
|
+
if groups["sign"] == "-":
|
|
141
|
+
ret = timedelta(0) - ret
|
|
142
|
+
else:
|
|
143
|
+
ret = Duration(
|
|
144
|
+
years=groups["years"],
|
|
145
|
+
months=groups["months"],
|
|
146
|
+
days=groups["days"],
|
|
147
|
+
hours=groups["hours"],
|
|
148
|
+
minutes=groups["minutes"],
|
|
149
|
+
seconds=groups["seconds"],
|
|
150
|
+
weeks=groups["weeks"],
|
|
151
|
+
)
|
|
152
|
+
if groups["sign"] == "-":
|
|
153
|
+
ret = Duration(0) - ret
|
|
154
|
+
return ret
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def generateDateIsostringsFromInterval(start, end, timedelta_config={}):
|
|
158
|
+
start_dt = datetime.fromisoformat(start)
|
|
159
|
+
if end == "today":
|
|
160
|
+
end = datetime.now().isoformat()
|
|
161
|
+
end_dt = datetime.fromisoformat(end)
|
|
162
|
+
delta = timedelta(**timedelta_config)
|
|
163
|
+
dates = []
|
|
164
|
+
while start_dt <= end_dt:
|
|
165
|
+
dates.append(start_dt.isoformat())
|
|
166
|
+
start_dt += delta
|
|
167
|
+
return dates
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
class RaisingThread(threading.Thread):
|
|
171
|
+
def run(self):
|
|
172
|
+
self._exc = None
|
|
173
|
+
try:
|
|
174
|
+
super().run()
|
|
175
|
+
except Exception as e:
|
|
176
|
+
self._exc = e
|
|
177
|
+
|
|
178
|
+
def join(self, timeout=None):
|
|
179
|
+
super().join(timeout=timeout)
|
|
180
|
+
if self._exc:
|
|
181
|
+
raise self._exc
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: eodash_catalog
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: This package is intended to help create a compatible STAC catalog for the eodash dashboard client. It supports configuration of multiple endpoint types for information extraction.
|
|
5
|
+
Project-URL: Documentation, https://github.com/eodash/eodash_catalog#readme
|
|
6
|
+
Project-URL: Issues, https://github.com/eodash/eodash_catalog/issues
|
|
7
|
+
Project-URL: Source, https://github.com/eodash/eodash_catalog
|
|
8
|
+
Author-email: Daniel Santillan <daniel.santillan@eox.at>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE.txt
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Programming Language :: Python
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
19
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Requires-Dist: click
|
|
22
|
+
Requires-Dist: click<9
|
|
23
|
+
Requires-Dist: lxml<5
|
|
24
|
+
Requires-Dist: mergedeep
|
|
25
|
+
Requires-Dist: oauthlib<3.3
|
|
26
|
+
Requires-Dist: owslib
|
|
27
|
+
Requires-Dist: pygeofilter[backend-native]==0.2.0
|
|
28
|
+
Requires-Dist: pystac-client<0.6
|
|
29
|
+
Requires-Dist: pystac[validation]<=1.8.3
|
|
30
|
+
Requires-Dist: python-dateutil<3
|
|
31
|
+
Requires-Dist: python-dotenv<1.1.0
|
|
32
|
+
Requires-Dist: pyyaml<7
|
|
33
|
+
Requires-Dist: redis<4
|
|
34
|
+
Requires-Dist: requests-oauthlib<1.3.2
|
|
35
|
+
Requires-Dist: requests<3
|
|
36
|
+
Requires-Dist: setuptools<68
|
|
37
|
+
Requires-Dist: spdx-lookup<=0.3.3
|
|
38
|
+
Requires-Dist: structlog<22.0
|
|
39
|
+
Requires-Dist: swiftspec==0.0.2
|
|
40
|
+
Description-Content-Type: text/markdown
|
|
41
|
+
|
|
42
|
+
# eodash_catalog
|
|
43
|
+
|
|
44
|
+
[](https://pypi.org/project/eodash_catalog)
|
|
45
|
+
[](https://pypi.org/project/eodash_catalog)
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
**Table of Contents**
|
|
50
|
+
|
|
51
|
+
- [Installation](#installation)
|
|
52
|
+
- [License](#license)
|
|
53
|
+
|
|
54
|
+
## Installation
|
|
55
|
+
|
|
56
|
+
```console
|
|
57
|
+
pip install eodash_catalog
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## License
|
|
61
|
+
|
|
62
|
+
`eodash_catalog` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
eodash_catalog/__about__.py,sha256=AeSz5Cjqu_4K7yj0vEf_oNhWQxmtS2WHa_T21GxuQAM,137
|
|
2
|
+
eodash_catalog/__init__.py,sha256=_W_9emPYf6FUqc0P8L2SmADx6hGSd7PlQV3yRmCk5uM,115
|
|
3
|
+
eodash_catalog/duration.py,sha256=6rxALD9MZS6rTE1AZgvjrABr7zwg8S-kLc_w9BltvY0,11007
|
|
4
|
+
eodash_catalog/generate_indicators.py,sha256=9iDvwvC4fncE4wTL8zkDbs68cNDFdP5w-UtnuKcF5O8,53130
|
|
5
|
+
eodash_catalog/sh_endpoint.py,sha256=KyZGmVrjZOCIuJizmYSy8VSWrfqqn2r-Ggh_8Q-s2vI,581
|
|
6
|
+
eodash_catalog/utils.py,sha256=tEzX5Nsy9yLpO0m9KWeMx0zRhEhCKStUq5Afche562w,6211
|
|
7
|
+
eodash_catalog-0.0.1.dist-info/METADATA,sha256=_NYrRxE4oAmc-oDC04sThtdexLYVKb-xDV1-CwHJEok,2194
|
|
8
|
+
eodash_catalog-0.0.1.dist-info/WHEEL,sha256=TJPnKdtrSue7xZ_AVGkp9YXcvDrobsjBds1du3Nx6dc,87
|
|
9
|
+
eodash_catalog-0.0.1.dist-info/entry_points.txt,sha256=kuUQrDG1PtYd8kPjf5XM6H_NtQd9Ozwl0jjiGtAvZSM,87
|
|
10
|
+
eodash_catalog-0.0.1.dist-info/licenses/LICENSE.txt,sha256=oJCW5zQxnFD-J0hGz6Zh5Lkpdk1oAndmWhseTmV224E,1107
|
|
11
|
+
eodash_catalog-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present Daniel Santillan <daniel.santillan@eox.at>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|