Skip to content

Commit f040c21

Browse files
committed
added handling of mg2 cloud cover
1 parent 5c48081 commit f040c21

4 files changed

Lines changed: 128 additions & 0 deletions

File tree

505 Bytes
Binary file not shown.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
[
2+
{
3+
"model": "coverages.coveragetype",
4+
"pk": 5,
5+
"fields": {
6+
"name": "MG2"
7+
}
8+
},
9+
{
10+
"model": "coverages.eoobject",
11+
"pk": 22,
12+
"fields": {
13+
"identifier": "MG2_CLOUD_COVERAGE_PRODUCT",
14+
"begin_time": "2024-08-12T10:00:31.342Z",
15+
"end_time": "2024-08-12T10:00:31.342Z",
16+
"footprint": "SRID=4326;POLYGON ((15.2626688586643 48.582734343236,15.2633437132633 48.582734343236,15.2633437132633 48.585342119825,15.2626688586643 48.585342119825,15.2626688586643 48.582734343236))",
17+
"inserted": "2019-01-01T00:00:00.000Z",
18+
"updated": "2019-01-01T00:00:00.000Z"
19+
}
20+
},
21+
{
22+
"model": "coverages.product",
23+
"pk": 22,
24+
"fields": {
25+
"product_type": null,
26+
"package": null
27+
}
28+
},
29+
{
30+
"model": "coverages.eoobject",
31+
"pk": 23,
32+
"fields": {
33+
"identifier": "MG2_CLOUD_COVERAGE",
34+
"begin_time": null,
35+
"end_time": null,
36+
"footprint": "SRID=4326;POLYGON ((15.2626688586643 48.582734343236,15.2633437132633 48.582734343236,15.2633437132633 48.585342119825,15.2626688586643 48.585342119825,15.2626688586643 48.582734343236))",
37+
"inserted": "2019-01-01T00:00:00.000Z",
38+
"updated": "2019-01-01T00:00:00.000Z"
39+
}
40+
},
41+
{
42+
"model": "coverages.coverage",
43+
"pk": 23,
44+
"fields": {
45+
"grid": 1,
46+
"axis_1_origin": null,
47+
"axis_2_origin": null,
48+
"axis_3_origin": null,
49+
"axis_4_origin": null,
50+
"axis_1_size": 5,
51+
"axis_2_size": 29,
52+
"axis_3_size": null,
53+
"axis_4_size": null,
54+
"coverage_type": 5,
55+
"parent_product": 22,
56+
"collections": [],
57+
"mosaics": []
58+
}
59+
},
60+
{
61+
"model": "coverages.arraydataitem",
62+
"pk": 21,
63+
"fields": {
64+
"storage": null,
65+
"location": "autotest/data/MG2_clipped.tif",
66+
"format": "image/tiff",
67+
"coverage": 23,
68+
"field_index": 0,
69+
"band_count": 1,
70+
"subdataset_type": null,
71+
"subdataset_locator": null,
72+
"bands_interpretation": 0
73+
}
74+
}
75+
]

autotest/autotest_services/tests/wps/test_v20_cloud_coverage.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,3 +307,35 @@ def getRequest(self):
307307
</wps:Execute>
308308
"""
309309
return (params, "xml")
310+
311+
class WPS20ExecuteCloudCoverageOnMG2Mask(
312+
ContentTypeCheckMixIn, testbase.JSONTestCase
313+
):
314+
fixtures = testbase.JSONTestCase.fixtures + ["mg2_cloud_coverages.json"]
315+
316+
expectedContentType = "application/json; charset=utf-8"
317+
318+
def getRequest(self):
319+
params = """<wps:Execute
320+
version="2.0.0"
321+
service="WPS"
322+
response="raw"
323+
mode="sync"
324+
xmlns:wps="http://www.opengis.net/wps/2.0"
325+
xmlns:ows="http://www.opengis.net/ows/2.0" >
326+
<ows:Identifier>CloudCoverage</ows:Identifier>
327+
<wps:Input id="begin_time">
328+
<wps:Data>2024-07-24T00:00:00</wps:Data>
329+
</wps:Input>
330+
<wps:Input id="end_time">
331+
<wps:Data>2024-09-07T23:59:59.999999</wps:Data>
332+
</wps:Input>
333+
<wps:Input id="geometry">
334+
<wps:Data>
335+
<wps:ComplexData mimeType="text/plain">POLYGON ((15.26296613234851 48.58522462654059, 15.26296735097763 48.58522820523471, 15.26296950923901 48.58513721140181, 15.26293893596117 48.58494329218298, 15.26293562146881 48.58491266740388, 15.2628906951924 48.5845887096719, 15.26288918309506 48.58458090727659, 15.26285420179431 48.58435611129113, 15.26284224281491 48.58428649235474, 15.26278921072745 48.58391615404845, 15.26278178059723 48.58390601986801, 15.26277314522215 48.58362419997486, 15.26274651286159 48.58346674304842, 15.26272692413581 48.58329819402794, 15.26266885866426 48.58295276970647, 15.26298491336765 48.58273434323597, 15.26305158064178 48.5832916822765, 15.26308885283483 48.58361765545947, 15.26309211355407 48.58364684163951, 15.26309580485187 48.58370930916529, 15.26316843092786 48.58427725612233, 15.26321277587909 48.58457837134077, 15.26326042238476 48.58489886540605, 15.26334371326326 48.58534211982499, 15.26303031950466 48.58529113679988, 15.26296684142374 48.58523271205242, 15.26296613234851 48.58522462654059))</wps:ComplexData>
336+
</wps:Data>
337+
</wps:Input>
338+
<wps:Output id="result"></wps:Output>
339+
</wps:Execute>
340+
"""
341+
return (params, "xml")

eoxserver/services/ows/wps/processes/get_cloud_coverage.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class CloudCoverageProcess(Component):
117117
# sometimes bit 4 also seems to count things as cloud which don't appear to
118118
# be clouds
119119
CLM_MASK_ONLY_CLOUD = 0b11110000
120+
MG2_MASK_ONLY_CLOUD = 0b00001010
120121

121122
@staticmethod
122123
def execute(
@@ -151,6 +152,14 @@ def execute(
151152
# hopefully this never occurs naturally, so we can use it as no_data
152153
no_data_value = 0b11111111
153154

155+
elif coverages_mg2 := relevant_coverages.filter(coverage_type__name="MG2"):
156+
logger.info("Matched %s MG2 covs for cloud coverage", coverages_mg2.count())
157+
calculation_fun = cloud_coverage_ratio_for_MG2
158+
coverages = coverages_mg2
159+
# MG2 is a bitmask, this value would mean that all types in mask were found
160+
# hopefully this never occurs naturally, so we can use it as no_data
161+
no_data_value = 0b11111111
162+
154163
elif coverages_scl := relevant_coverages.filter(coverage_type__name="SCL"):
155164
logger.info("Matched %s SCL covs for cloud coverage", coverages_scl.count())
156165
calculation_fun = cloud_coverage_ratio_for_SCL
@@ -215,6 +224,18 @@ def cloud_coverage_ratio_for_CLM(histogram: List[int], cloud_mask: Any) -> float
215224
num_pixels = sum(histogram)
216225
return ((num_is_cloud / num_pixels)) if num_pixels != 0 else 0.0
217226

227+
def cloud_coverage_ratio_for_MG2(histogram: List[int], cloud_mask: Any) -> float:
228+
cloud_mask = (
229+
cloud_mask
230+
if cloud_mask is not None
231+
else CloudCoverageProcess.MG2_MASK_ONLY_CLOUD
232+
)
233+
num_is_cloud = sum(
234+
value for index, value in enumerate(histogram) if index & cloud_mask > 0
235+
)
236+
237+
num_pixels = sum(histogram)
238+
return ((num_is_cloud / num_pixels)) if num_pixels != 0 else 0.0
218239

219240
def cloud_coverage_ratio_for_SCL(histogram: List[int], cloud_mask: Any) -> float:
220241
cloud_mask = (

0 commit comments

Comments
 (0)