drb-chunk-sentinel2 0.1.0__tar.gz

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.
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
@@ -0,0 +1,3 @@
1
+ include drb/addons/chunk/sentinel2/cortex.ttl
2
+ include versioneer.py
3
+ include drb/addons/chunk/sentinel2/_version.py
@@ -0,0 +1,266 @@
1
+ Metadata-Version: 2.4
2
+ Name: drb-chunk-sentinel2
3
+ Version: 0.1.0
4
+ Summary: Sentinel-2 product chunk descriptors (drb-chunk)
5
+ Author: GAEL Systems
6
+ Author-email: drb-python@gael.fr
7
+ License: LGPLv3
8
+ Classifier: Programming Language :: Python :: 3.11
9
+ Classifier: Programming Language :: Python :: 3.12
10
+ Classifier: Programming Language :: Python :: 3.13
11
+ Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
12
+ Requires-Python: <3.14,>=3.11
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENCE.txt
15
+ Requires-Dist: rdflib
16
+ Dynamic: license-file
17
+
18
+ # drb-chunk-sentinel2
19
+
20
+ Chunk descriptors for the Sentinel-2 **L2A** product type, built on top of the
21
+ [drb-chunk](../../core/README.md) add-on.
22
+
23
+ ## What it is
24
+
25
+ `drb-chunk-sentinel2` ships a generated `cortex.ttl` that declares **68 chunk
26
+ descriptors**, grouped into **4 collections** (`R10m`, `R20m`, `R60m`, `QI`),
27
+ on the Sentinel-2 L2A class URI:
28
+
29
+ ```
30
+ http://knowledge-base.gael.fr/drb/sentinel-2/product_user_level-2a
31
+ ```
32
+
33
+ Each descriptor is a `drb:chunk` entry linking a logical chunk name (e.g.
34
+ `B04_10m`) and a `drb:collection` (e.g. `R10m`) to an XQuery expression that
35
+ navigates the product tree to the corresponding JP2 raster node.
36
+
37
+ The package does **not** modify the Sentinel-2 topic TTL and registers **no
38
+ entry-point group**. It is a pure descriptor extension merged into the topic
39
+ graph at runtime (see [How attachment works](#how-attachment-works)).
40
+
41
+ **L1C** support is planned — same pattern, different `IMG_DATA` layout — but is
42
+ not present in this release.
43
+
44
+ ---
45
+
46
+ ## Chunks exposed
47
+
48
+ 68 chunks in total, grouped into 4 **collections** (tile 512 × 512). The three
49
+ `IMG_DATA` resolution collections hold the spectral + ancillary bands (named
50
+ `<LAYER>_<RES>`); the `QI` collection holds the `QI_DATA` quality masks and the
51
+ preview.
52
+
53
+ | Collection | Count | Contents |
54
+ |------------|-------|----------|
55
+ | `R10m` | 7 | B02 B03 B04 B08 AOT WVP (uint16) · TCI (uint8 RGB) |
56
+ | `R20m` | 14 | B01–B07 B8A B11 B12 AOT WVP (uint16) · SCL TCI (uint8) |
57
+ | `R60m` | 15 | B01–B07 B8A B09 B11 B12 AOT WVP (uint16) · SCL TCI (uint8) |
58
+ | `QI` | 32 | CLDPRB_{20m,60m}, SNWPRB_{20m,60m}, CLASSI_B00, DETFOO_B01–B12+B8A, QUALIT_B01–B12+B8A, PVI (all uint8) |
59
+
60
+ ### R10m — 10 980 × 10 980 pixels, tile 512 × 512
61
+
62
+ | Chunk name | Band | dtype |
63
+ |------------|-------|--------|
64
+ | `B02_10m` | B02 | uint16 |
65
+ | `B03_10m` | B03 | uint16 |
66
+ | `B04_10m` | B04 | uint16 |
67
+ | `B08_10m` | B08 | uint16 |
68
+ | `AOT_10m` | AOT | uint16 |
69
+ | `WVP_10m` | WVP | uint16 |
70
+ | `TCI_10m` | TCI | uint8 (RGB) |
71
+
72
+ ### R20m — 5 490 × 5 490 pixels
73
+
74
+ | Chunk name | Band | dtype |
75
+ |------------|-------|--------|
76
+ | `B01_20m` | B01 | uint16 |
77
+ | `B02_20m` | B02 | uint16 |
78
+ | `B03_20m` | B03 | uint16 |
79
+ | `B04_20m` | B04 | uint16 |
80
+ | `B05_20m` | B05 | uint16 |
81
+ | `B06_20m` | B06 | uint16 |
82
+ | `B07_20m` | B07 | uint16 |
83
+ | `B8A_20m` | B8A | uint16 |
84
+ | `B11_20m` | B11 | uint16 |
85
+ | `B12_20m` | B12 | uint16 |
86
+ | `AOT_20m` | AOT | uint16 |
87
+ | `WVP_20m` | WVP | uint16 |
88
+ | `SCL_20m` | SCL | uint8 |
89
+ | `TCI_20m` | TCI | uint8 (RGB) |
90
+
91
+ ### R60m — 1 830 × 1 830 pixels
92
+
93
+ | Chunk name | Band | dtype |
94
+ |------------|-------|--------|
95
+ | `B01_60m` | B01 | uint16 |
96
+ | `B02_60m` | B02 | uint16 |
97
+ | `B03_60m` | B03 | uint16 |
98
+ | `B04_60m` | B04 | uint16 |
99
+ | `B05_60m` | B05 | uint16 |
100
+ | `B06_60m` | B06 | uint16 |
101
+ | `B07_60m` | B07 | uint16 |
102
+ | `B8A_60m` | B8A | uint16 |
103
+ | `B09_60m` | B09 | uint16 |
104
+ | `B11_60m` | B11 | uint16 |
105
+ | `B12_60m` | B12 | uint16 |
106
+ | `AOT_60m` | AOT | uint16 |
107
+ | `WVP_60m` | WVP | uint16 |
108
+ | `SCL_60m` | SCL | uint8 |
109
+ | `TCI_60m` | TCI | uint8 (RGB) |
110
+
111
+ ### QI — quality masks & preview (`QI_DATA`)
112
+
113
+ All `uint8`. Probability masks carry a resolution suffix; the per-band
114
+ detector-footprint and quality masks are named after their band.
115
+
116
+ | Chunk name | Layer |
117
+ |------------|-------|
118
+ | `CLDPRB_20m`, `CLDPRB_60m` | cloud probability |
119
+ | `SNWPRB_20m`, `SNWPRB_60m` | snow probability |
120
+ | `CLASSI_B00` | classification mask |
121
+ | `DETFOO_B01`…`DETFOO_B12`, `DETFOO_B8A` | detector footprint (per band) |
122
+ | `QUALIT_B01`…`QUALIT_B12`, `QUALIT_B8A` | quality mask (per band) |
123
+ | `PVI` | preview image |
124
+
125
+ Each chunk's `drb:source` is an XQuery expression of the form:
126
+
127
+ ```
128
+ GRANULE/*/IMG_DATA/R10m/*[fn:matches(fn:name(),'.*_B04_10m\.jp2$')]
129
+ ```
130
+
131
+ > **Note:** the leading `.*` is required because `fn:matches` in drb's XQuery
132
+ > engine uses full-match semantics (`re.fullmatch`), not search semantics.
133
+ > The pattern must match the entire filename, not just a suffix.
134
+
135
+ ---
136
+
137
+ ## How attachment works
138
+
139
+ `cortex.ttl` extends the L2A class **by URI**, targeting
140
+ `sentinel-2:product_user_level-2a`. It does not include a `setup.cfg`
141
+ entry-point group — the TTL is not auto-discovered by the resolver on its own.
142
+
143
+ At runtime the chunk TTL must be **merged into the topic graph** in one of two
144
+ ways (see [Bootstrap](#bootstrap)):
145
+
146
+ - In a **Fuseki** deployment, add the packaged TTL to the named-graph list
147
+ loaded into the dataset.
148
+ - In an **offline** setup, compose it together with the S2-SAFE topic TTL in a
149
+ single `RDFDao([path_to_s2_ttl, cortex_path()])`.
150
+
151
+ Once merged, `drb-chunk` reads the descriptors via `get_dao(topic).graph` and
152
+ makes them available through the standard chunk API.
153
+
154
+ The packaged TTL path is returned by:
155
+
156
+ ```python
157
+ from drb.addons.chunk.sentinel2 import cortex_path
158
+ print(cortex_path()) # /path/to/drb/addons/chunk/sentinel2/cortex.ttl
159
+ ```
160
+
161
+ ---
162
+
163
+ ## Bootstrap
164
+
165
+ ### Mode 1 — Fuseki (recommended for production)
166
+
167
+ Set the environment variables before resolving any node:
168
+
169
+ ```bash
170
+ export FUSEKI_URL=http://localhost:3030
171
+ export DATASET=drb
172
+ export DRB_FUSEKI_GRAPHS="http://drb.gael.fr/graph/kb/drbx-kb-topics-sentinel-2-safe/latest,http://drb.gael.fr/graph/kb/drbx-kb-topics-safe/latest"
173
+ ```
174
+
175
+ `DRB_FUSEKI_GRAPHS` is a comma-separated list of Fuseki named-graph URIs; the
176
+ chunk-descriptor graph (loaded from this package's `cortex.ttl`) must also be
177
+ merged into the same dataset/graph set.
178
+
179
+ ### Mode 2 — Offline vendored TTL
180
+
181
+ Compose the two TTL files into a single `RDFDao` and register it before
182
+ resolving:
183
+
184
+ ```python
185
+ from drb.topics.dao import ManagerDao
186
+ from drb.topics.dao.rdf_dao import RDFDao
187
+ from drb.addons.chunk.sentinel2 import cortex_path
188
+
189
+ s2_ttl = "/path/to/vendored/sentinel-2-safe-topics.ttl"
190
+ # Merge the S2 topic descriptors and the chunk descriptor into one graph.
191
+ ManagerDao().add_dao_instance(RDFDao([s2_ttl, str(cortex_path())]))
192
+ ```
193
+
194
+ See [`examples/demo_s2_l2a_chunk.py`](examples/demo_s2_l2a_chunk.py) for a
195
+ complete runnable demonstration of both modes.
196
+
197
+ ---
198
+
199
+ ## Worked example
200
+
201
+ ```python
202
+ import numpy
203
+ from drb.topics import resolver
204
+ from drb.addons.addon import AddonManager
205
+ from drb.chunk.selection import WindowSelection
206
+
207
+ # 1. Resolve the S3 product (bootstrap the KB topics first; see Bootstrap)
208
+ topic, node = resolver.resolve(
209
+ "s3://my-sentinel2-bucket/"
210
+ "S2A_MSIL2A_20220101T000000_N0400_R000_T19VCG_20220101T000000.SAFE")
211
+
212
+ # 2. Discover the chunks, by collection, declared for this topic
213
+ addon = AddonManager().get_addon("chunk")
214
+ print(addon.available_collections(topic))
215
+ # {'R10m': ['B02_10m', ...], 'R20m': [...], 'R60m': [...], 'QI': [...]}
216
+
217
+ # 3a. Build one chunk and read a 512x512 window
218
+ chunk = addon.apply(node, chunk_name="B04_10m")
219
+ window = WindowSelection(x=0, y=0, w=512, h=512)
220
+ array = chunk.select(window).get_impl(numpy.ndarray)
221
+ print(array.shape) # (1, 512, 512) — single band, uint16
222
+
223
+ # 3b. Or build every chunk of a whole collection at once
224
+ r10m_chunks = addon.apply(node, collection="R10m") # list[Chunk] (7 here)
225
+ ```
226
+
227
+ ---
228
+
229
+ ## Limitations
230
+
231
+ - **Windowing is correct but not partial-fetch:** `WindowSelection` returns the
232
+ right pixel values, but the current implementation materialises the **full JP2
233
+ member** from the archive before slicing. There is no partial network fetch
234
+ (e.g. HTTP range request on a cloud-hosted SAFE). This is a drb-chunk v1
235
+ limitation.
236
+ - **Single-tile materialisation:** each `apply` / `select` call opens one JP2
237
+ node. Multi-tile mosaicking is not supported in this release.
238
+
239
+ See [`docs/evolution-requests.md`](docs/evolution-requests.md) for tracked
240
+ improvement requests.
241
+
242
+ ---
243
+
244
+ ## Regenerating the descriptor
245
+
246
+ The `cortex.ttl` is generated from a band×resolution table embedded in
247
+ `_generate.py`. To regenerate after editing the table:
248
+
249
+ ```bash
250
+ python -m drb.addons.chunk.sentinel2._generate
251
+ ```
252
+
253
+ The file is written next to the module (i.e. `drb/addons/chunk/sentinel2/cortex.ttl`).
254
+ Commit the result.
255
+
256
+ ---
257
+
258
+ ## Installation
259
+
260
+ ```bash
261
+ pip install drb-chunk-sentinel2
262
+ ```
263
+
264
+ Requires `drb-chunk` (installed as a dependency). A working drb-chunk setup
265
+ with either a Fuseki instance or a vendored S2 topic TTL is needed at runtime
266
+ (see [Bootstrap](#bootstrap)).
@@ -0,0 +1,249 @@
1
+ # drb-chunk-sentinel2
2
+
3
+ Chunk descriptors for the Sentinel-2 **L2A** product type, built on top of the
4
+ [drb-chunk](../../core/README.md) add-on.
5
+
6
+ ## What it is
7
+
8
+ `drb-chunk-sentinel2` ships a generated `cortex.ttl` that declares **68 chunk
9
+ descriptors**, grouped into **4 collections** (`R10m`, `R20m`, `R60m`, `QI`),
10
+ on the Sentinel-2 L2A class URI:
11
+
12
+ ```
13
+ http://knowledge-base.gael.fr/drb/sentinel-2/product_user_level-2a
14
+ ```
15
+
16
+ Each descriptor is a `drb:chunk` entry linking a logical chunk name (e.g.
17
+ `B04_10m`) and a `drb:collection` (e.g. `R10m`) to an XQuery expression that
18
+ navigates the product tree to the corresponding JP2 raster node.
19
+
20
+ The package does **not** modify the Sentinel-2 topic TTL and registers **no
21
+ entry-point group**. It is a pure descriptor extension merged into the topic
22
+ graph at runtime (see [How attachment works](#how-attachment-works)).
23
+
24
+ **L1C** support is planned — same pattern, different `IMG_DATA` layout — but is
25
+ not present in this release.
26
+
27
+ ---
28
+
29
+ ## Chunks exposed
30
+
31
+ 68 chunks in total, grouped into 4 **collections** (tile 512 × 512). The three
32
+ `IMG_DATA` resolution collections hold the spectral + ancillary bands (named
33
+ `<LAYER>_<RES>`); the `QI` collection holds the `QI_DATA` quality masks and the
34
+ preview.
35
+
36
+ | Collection | Count | Contents |
37
+ |------------|-------|----------|
38
+ | `R10m` | 7 | B02 B03 B04 B08 AOT WVP (uint16) · TCI (uint8 RGB) |
39
+ | `R20m` | 14 | B01–B07 B8A B11 B12 AOT WVP (uint16) · SCL TCI (uint8) |
40
+ | `R60m` | 15 | B01–B07 B8A B09 B11 B12 AOT WVP (uint16) · SCL TCI (uint8) |
41
+ | `QI` | 32 | CLDPRB_{20m,60m}, SNWPRB_{20m,60m}, CLASSI_B00, DETFOO_B01–B12+B8A, QUALIT_B01–B12+B8A, PVI (all uint8) |
42
+
43
+ ### R10m — 10 980 × 10 980 pixels, tile 512 × 512
44
+
45
+ | Chunk name | Band | dtype |
46
+ |------------|-------|--------|
47
+ | `B02_10m` | B02 | uint16 |
48
+ | `B03_10m` | B03 | uint16 |
49
+ | `B04_10m` | B04 | uint16 |
50
+ | `B08_10m` | B08 | uint16 |
51
+ | `AOT_10m` | AOT | uint16 |
52
+ | `WVP_10m` | WVP | uint16 |
53
+ | `TCI_10m` | TCI | uint8 (RGB) |
54
+
55
+ ### R20m — 5 490 × 5 490 pixels
56
+
57
+ | Chunk name | Band | dtype |
58
+ |------------|-------|--------|
59
+ | `B01_20m` | B01 | uint16 |
60
+ | `B02_20m` | B02 | uint16 |
61
+ | `B03_20m` | B03 | uint16 |
62
+ | `B04_20m` | B04 | uint16 |
63
+ | `B05_20m` | B05 | uint16 |
64
+ | `B06_20m` | B06 | uint16 |
65
+ | `B07_20m` | B07 | uint16 |
66
+ | `B8A_20m` | B8A | uint16 |
67
+ | `B11_20m` | B11 | uint16 |
68
+ | `B12_20m` | B12 | uint16 |
69
+ | `AOT_20m` | AOT | uint16 |
70
+ | `WVP_20m` | WVP | uint16 |
71
+ | `SCL_20m` | SCL | uint8 |
72
+ | `TCI_20m` | TCI | uint8 (RGB) |
73
+
74
+ ### R60m — 1 830 × 1 830 pixels
75
+
76
+ | Chunk name | Band | dtype |
77
+ |------------|-------|--------|
78
+ | `B01_60m` | B01 | uint16 |
79
+ | `B02_60m` | B02 | uint16 |
80
+ | `B03_60m` | B03 | uint16 |
81
+ | `B04_60m` | B04 | uint16 |
82
+ | `B05_60m` | B05 | uint16 |
83
+ | `B06_60m` | B06 | uint16 |
84
+ | `B07_60m` | B07 | uint16 |
85
+ | `B8A_60m` | B8A | uint16 |
86
+ | `B09_60m` | B09 | uint16 |
87
+ | `B11_60m` | B11 | uint16 |
88
+ | `B12_60m` | B12 | uint16 |
89
+ | `AOT_60m` | AOT | uint16 |
90
+ | `WVP_60m` | WVP | uint16 |
91
+ | `SCL_60m` | SCL | uint8 |
92
+ | `TCI_60m` | TCI | uint8 (RGB) |
93
+
94
+ ### QI — quality masks & preview (`QI_DATA`)
95
+
96
+ All `uint8`. Probability masks carry a resolution suffix; the per-band
97
+ detector-footprint and quality masks are named after their band.
98
+
99
+ | Chunk name | Layer |
100
+ |------------|-------|
101
+ | `CLDPRB_20m`, `CLDPRB_60m` | cloud probability |
102
+ | `SNWPRB_20m`, `SNWPRB_60m` | snow probability |
103
+ | `CLASSI_B00` | classification mask |
104
+ | `DETFOO_B01`…`DETFOO_B12`, `DETFOO_B8A` | detector footprint (per band) |
105
+ | `QUALIT_B01`…`QUALIT_B12`, `QUALIT_B8A` | quality mask (per band) |
106
+ | `PVI` | preview image |
107
+
108
+ Each chunk's `drb:source` is an XQuery expression of the form:
109
+
110
+ ```
111
+ GRANULE/*/IMG_DATA/R10m/*[fn:matches(fn:name(),'.*_B04_10m\.jp2$')]
112
+ ```
113
+
114
+ > **Note:** the leading `.*` is required because `fn:matches` in drb's XQuery
115
+ > engine uses full-match semantics (`re.fullmatch`), not search semantics.
116
+ > The pattern must match the entire filename, not just a suffix.
117
+
118
+ ---
119
+
120
+ ## How attachment works
121
+
122
+ `cortex.ttl` extends the L2A class **by URI**, targeting
123
+ `sentinel-2:product_user_level-2a`. It does not include a `setup.cfg`
124
+ entry-point group — the TTL is not auto-discovered by the resolver on its own.
125
+
126
+ At runtime the chunk TTL must be **merged into the topic graph** in one of two
127
+ ways (see [Bootstrap](#bootstrap)):
128
+
129
+ - In a **Fuseki** deployment, add the packaged TTL to the named-graph list
130
+ loaded into the dataset.
131
+ - In an **offline** setup, compose it together with the S2-SAFE topic TTL in a
132
+ single `RDFDao([path_to_s2_ttl, cortex_path()])`.
133
+
134
+ Once merged, `drb-chunk` reads the descriptors via `get_dao(topic).graph` and
135
+ makes them available through the standard chunk API.
136
+
137
+ The packaged TTL path is returned by:
138
+
139
+ ```python
140
+ from drb.addons.chunk.sentinel2 import cortex_path
141
+ print(cortex_path()) # /path/to/drb/addons/chunk/sentinel2/cortex.ttl
142
+ ```
143
+
144
+ ---
145
+
146
+ ## Bootstrap
147
+
148
+ ### Mode 1 — Fuseki (recommended for production)
149
+
150
+ Set the environment variables before resolving any node:
151
+
152
+ ```bash
153
+ export FUSEKI_URL=http://localhost:3030
154
+ export DATASET=drb
155
+ export DRB_FUSEKI_GRAPHS="http://drb.gael.fr/graph/kb/drbx-kb-topics-sentinel-2-safe/latest,http://drb.gael.fr/graph/kb/drbx-kb-topics-safe/latest"
156
+ ```
157
+
158
+ `DRB_FUSEKI_GRAPHS` is a comma-separated list of Fuseki named-graph URIs; the
159
+ chunk-descriptor graph (loaded from this package's `cortex.ttl`) must also be
160
+ merged into the same dataset/graph set.
161
+
162
+ ### Mode 2 — Offline vendored TTL
163
+
164
+ Compose the two TTL files into a single `RDFDao` and register it before
165
+ resolving:
166
+
167
+ ```python
168
+ from drb.topics.dao import ManagerDao
169
+ from drb.topics.dao.rdf_dao import RDFDao
170
+ from drb.addons.chunk.sentinel2 import cortex_path
171
+
172
+ s2_ttl = "/path/to/vendored/sentinel-2-safe-topics.ttl"
173
+ # Merge the S2 topic descriptors and the chunk descriptor into one graph.
174
+ ManagerDao().add_dao_instance(RDFDao([s2_ttl, str(cortex_path())]))
175
+ ```
176
+
177
+ See [`examples/demo_s2_l2a_chunk.py`](examples/demo_s2_l2a_chunk.py) for a
178
+ complete runnable demonstration of both modes.
179
+
180
+ ---
181
+
182
+ ## Worked example
183
+
184
+ ```python
185
+ import numpy
186
+ from drb.topics import resolver
187
+ from drb.addons.addon import AddonManager
188
+ from drb.chunk.selection import WindowSelection
189
+
190
+ # 1. Resolve the S3 product (bootstrap the KB topics first; see Bootstrap)
191
+ topic, node = resolver.resolve(
192
+ "s3://my-sentinel2-bucket/"
193
+ "S2A_MSIL2A_20220101T000000_N0400_R000_T19VCG_20220101T000000.SAFE")
194
+
195
+ # 2. Discover the chunks, by collection, declared for this topic
196
+ addon = AddonManager().get_addon("chunk")
197
+ print(addon.available_collections(topic))
198
+ # {'R10m': ['B02_10m', ...], 'R20m': [...], 'R60m': [...], 'QI': [...]}
199
+
200
+ # 3a. Build one chunk and read a 512x512 window
201
+ chunk = addon.apply(node, chunk_name="B04_10m")
202
+ window = WindowSelection(x=0, y=0, w=512, h=512)
203
+ array = chunk.select(window).get_impl(numpy.ndarray)
204
+ print(array.shape) # (1, 512, 512) — single band, uint16
205
+
206
+ # 3b. Or build every chunk of a whole collection at once
207
+ r10m_chunks = addon.apply(node, collection="R10m") # list[Chunk] (7 here)
208
+ ```
209
+
210
+ ---
211
+
212
+ ## Limitations
213
+
214
+ - **Windowing is correct but not partial-fetch:** `WindowSelection` returns the
215
+ right pixel values, but the current implementation materialises the **full JP2
216
+ member** from the archive before slicing. There is no partial network fetch
217
+ (e.g. HTTP range request on a cloud-hosted SAFE). This is a drb-chunk v1
218
+ limitation.
219
+ - **Single-tile materialisation:** each `apply` / `select` call opens one JP2
220
+ node. Multi-tile mosaicking is not supported in this release.
221
+
222
+ See [`docs/evolution-requests.md`](docs/evolution-requests.md) for tracked
223
+ improvement requests.
224
+
225
+ ---
226
+
227
+ ## Regenerating the descriptor
228
+
229
+ The `cortex.ttl` is generated from a band×resolution table embedded in
230
+ `_generate.py`. To regenerate after editing the table:
231
+
232
+ ```bash
233
+ python -m drb.addons.chunk.sentinel2._generate
234
+ ```
235
+
236
+ The file is written next to the module (i.e. `drb/addons/chunk/sentinel2/cortex.ttl`).
237
+ Commit the result.
238
+
239
+ ---
240
+
241
+ ## Installation
242
+
243
+ ```bash
244
+ pip install drb-chunk-sentinel2
245
+ ```
246
+
247
+ Requires `drb-chunk` (installed as a dependency). A working drb-chunk setup
248
+ with either a Fuseki instance or a vendored S2 topic TTL is needed at runtime
249
+ (see [Bootstrap](#bootstrap)).
@@ -0,0 +1,17 @@
1
+ """Sentinel-2 chunk descriptor package.
2
+
3
+ Ships a generated ``cortex.ttl`` that declares ``drb:chunk`` on the
4
+ Sentinel-2 L2A product class. It carries no engine and registers no
5
+ entry point: the descriptor is merged into the topic graph at bootstrap
6
+ and read by the ``drb-chunk`` add-on through ``get_dao(topic).graph``.
7
+ """
8
+ from importlib.resources import files
9
+
10
+ from . import _version
11
+
12
+ __version__ = _version.get_versions()['version']
13
+
14
+
15
+ def cortex_path() -> str:
16
+ """Return the filesystem path to the packaged cortex.ttl descriptor."""
17
+ return str(files("drb.addons.chunk.sentinel2") / "cortex.ttl")