-
Notifications
You must be signed in to change notification settings - Fork 4
/
conftest.py
152 lines (136 loc) · 4.8 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import json
import os
import urllib
import numpy as np
import openeo
import pystac_client
import pytest
from openeo_test_suite.lib.workflows.parameters import (
bounding_box_32632,
bounding_box_32632_10x10,
temporal_interval,
temporal_interval_one_day,
)
@pytest.fixture
def s2_collection(request) -> str:
"""
Fixture to provide the data collection to test against.
If we provide a string, it will be interpreted as openEO Collection.
If it's an URL, it's interpreted as STAC Collection.
"""
collection = request.config.getoption("--s2-collection")
if not collection:
raise RuntimeError(
"No S2 test collection found. Specify it using the `--s2-collection` command line option."
)
return collection
@pytest.fixture(scope="module")
def auto_authenticate() -> bool:
"""
Fixture to act as parameterizable toggle for authenticating the connection fixture.
Allows per-test/folder configuration of auto-authentication.
"""
return True
@pytest.fixture
def cube_one_day_red(
connection,
s2_collection,
skipper,
) -> openeo.DataCube:
params = {
"spatial_extent": bounding_box_32632,
"temporal_extent": temporal_interval_one_day,
"bands": ["B04"],
}
if "http" in s2_collection:
skipper.skip_if_unsupported_process(["load_stac", "save_result"])
cube = connection.load_stac(s2_collection, **params)
else:
skipper.skip_if_unsupported_process(["load_collection", "save_result"])
cube = connection.load_collection(s2_collection, **params)
return cube
@pytest.fixture
def cube_one_day_red_nir(
connection,
s2_collection,
skipper,
) -> openeo.DataCube:
params = {
"spatial_extent": bounding_box_32632,
"temporal_extent": temporal_interval_one_day,
"bands": ["B04", "B08"],
}
if "http" in s2_collection:
skipper.skip_if_unsupported_process(["load_stac", "save_result"])
cube = connection.load_stac(s2_collection, **params)
else:
skipper.skip_if_unsupported_process(["load_collection", "save_result"])
cube = connection.load_collection(s2_collection, **params)
return cube
@pytest.fixture
def cube_red_nir(
connection,
s2_collection,
skipper,
) -> openeo.DataCube:
params = {
"spatial_extent": bounding_box_32632,
"temporal_extent": temporal_interval,
"bands": ["B04", "B08"],
}
if "http" in s2_collection:
skipper.skip_if_unsupported_process(["load_stac", "save_result"])
cube = connection.load_stac(s2_collection, **params)
else:
skipper.skip_if_unsupported_process(["load_collection", "save_result"])
cube = connection.load_collection(s2_collection, **params)
return cube
@pytest.fixture
def cube_red_10x10(
connection,
s2_collection,
skipper,
) -> openeo.DataCube:
params = {
"spatial_extent": bounding_box_32632_10x10,
"temporal_extent": temporal_interval_one_day,
"bands": ["B04"],
}
if "http" in s2_collection:
skipper.skip_if_unsupported_process(["load_stac", "save_result"])
cube = connection.load_stac(s2_collection, **params)
else:
skipper.skip_if_unsupported_process(["load_collection", "save_result"])
cube = connection.load_collection(s2_collection, **params)
return cube
@pytest.fixture
def collection_dims(
connection,
s2_collection,
):
if "/" in s2_collection:
# I consider it as a STAC url
parsed_url = urllib.parse.urlparse(s2_collection)
if not bool(parsed_url.scheme):
parsed_url = parsed_url._replace(**{"scheme": "https"})
s2_collection_url = parsed_url.geturl()
stac_api = pystac_client.stac_api_io.StacApiIO()
stac_dict = json.loads(stac_api.read_text(s2_collection_url))
else:
# I consider it as an openEO Collection
stac_dict = dict(connection.describe_collection(s2_collection))
collection_dims = dict(b_dim="bands", t_dim="t", x_dim="x", y_dim="y", z_dim="z")
if "cube:dimensions" in stac_dict:
for dim in stac_dict["cube:dimensions"]:
if stac_dict["cube:dimensions"][dim]["type"] == "bands":
collection_dims["b_dim"] = dim
if stac_dict["cube:dimensions"][dim]["type"] == "temporal":
collection_dims["t_dim"] = dim
if stac_dict["cube:dimensions"][dim]["type"] == "spatial":
if stac_dict["cube:dimensions"][dim]["axis"] == "x":
collection_dims["x_dim"] = dim
if stac_dict["cube:dimensions"][dim]["axis"] == "y":
collection_dims["y_dim"] = dim
if stac_dict["cube:dimensions"][dim]["axis"] == "z":
collection_dims["z_dim"] = dim
return collection_dims