Skip to content

Commit 5f48a5d

Browse files
authored
Merge pull request #21 from oxfordeo/main
Improve Band common_names and Tile properties
2 parents faa402e + c17cb0b commit 5f48a5d

File tree

5 files changed

+131
-71
lines changed

5 files changed

+131
-71
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def read(*names, **kwargs):
3333

3434
setup(
3535
name="satextractor",
36-
version="0.2.0",
36+
version="0.2.1",
3737
license="BSD-2-Clause",
3838
description="SatExtractor. Extract everything from everywhere.",
3939
url="https://github.com/FrontierDevelopmentLab/sat-extractor",

src/satextractor/models/constellation_info.py

Lines changed: 76 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"B6": {
6565
"band": Band.create(
6666
name="B6",
67-
common_name="swir16",
67+
common_name="swir1",
6868
center_wavelength=1.6,
6969
full_width_half_max=0.08,
7070
),
@@ -73,7 +73,7 @@
7373
"B7": {
7474
"band": Band.create(
7575
name="B7",
76-
common_name="swir22",
76+
common_name="swir2",
7777
center_wavelength=2.2,
7878
full_width_half_max=0.2,
7979
),
@@ -100,7 +100,7 @@
100100
"B10": {
101101
"band": Band.create(
102102
name="B10",
103-
common_name="lwir11",
103+
common_name="tirs1",
104104
center_wavelength=10.9,
105105
full_width_half_max=0.8,
106106
),
@@ -109,7 +109,7 @@
109109
"B11": {
110110
"band": Band.create(
111111
name="B11",
112-
common_name="lwir12",
112+
common_name="tirs2",
113113
center_wavelength=12.0,
114114
full_width_half_max=1.0,
115115
),
@@ -148,7 +148,7 @@
148148
"B4": {
149149
"band": Band.create(
150150
name="B4",
151-
common_name="near infrared",
151+
common_name="nir",
152152
center_wavelength=0.835,
153153
full_width_half_max=0.065,
154154
),
@@ -157,7 +157,7 @@
157157
"B5": {
158158
"band": Band.create(
159159
name="B5",
160-
common_name="shortwave infrared 1",
160+
common_name="swir1",
161161
center_wavelength=1.65,
162162
full_width_half_max=0.10,
163163
),
@@ -184,7 +184,7 @@
184184
"B7": {
185185
"band": Band.create(
186186
name="B7",
187-
common_name="shortwave infrared 2",
187+
common_name="swir2",
188188
center_wavelength=2.215,
189189
full_width_half_max=0.135,
190190
),
@@ -193,7 +193,7 @@
193193
"B8": {
194194
"band": Band.create(
195195
name="B8",
196-
common_name="panchromatic",
196+
common_name="pan",
197197
center_wavelength=0.71,
198198
full_width_half_max=0.24,
199199
),
@@ -232,7 +232,7 @@
232232
"B4": {
233233
"band": Band.create(
234234
name="B4",
235-
common_name="near infrared",
235+
common_name="nir",
236236
center_wavelength=0.835,
237237
full_width_half_max=0.065,
238238
),
@@ -241,7 +241,7 @@
241241
"B5": {
242242
"band": Band.create(
243243
name="B5",
244-
common_name="shortwave infrared 1",
244+
common_name="swir1",
245245
center_wavelength=1.65,
246246
full_width_half_max=0.10,
247247
),
@@ -259,7 +259,7 @@
259259
"B7": {
260260
"band": Band.create(
261261
name="B7",
262-
common_name="shortwave infrared 2",
262+
common_name="swir2",
263263
center_wavelength=2.215,
264264
full_width_half_max=0.135,
265265
),
@@ -270,55 +270,107 @@
270270

271271
SENTINEL2_BAND_INFO = {
272272
"B01": {
273-
"band": Band.create(name="B01", common_name="coastal", center_wavelength=0.443),
273+
"band": Band.create(
274+
name="B01",
275+
common_name="coastal",
276+
center_wavelength=0.443,
277+
),
274278
"gsd": 60.0,
275279
},
276280
"B02": {
277-
"band": Band.create(name="B02", common_name="blue", center_wavelength=0.490),
281+
"band": Band.create(
282+
name="B02",
283+
common_name="blue",
284+
center_wavelength=0.490,
285+
),
278286
"gsd": 10.0,
279287
},
280288
"B03": {
281-
"band": Band.create(name="B03", common_name="green", center_wavelength=0.560),
289+
"band": Band.create(
290+
name="B03",
291+
common_name="green",
292+
center_wavelength=0.560,
293+
),
282294
"gsd": 10.0,
283295
},
284296
"B04": {
285-
"band": Band.create(name="B04", common_name="red", center_wavelength=0.665),
297+
"band": Band.create(
298+
name="B04",
299+
common_name="red",
300+
center_wavelength=0.665,
301+
),
286302
"gsd": 10.0,
287303
},
288304
"B05": {
289-
"band": Band.create(name="B05", common_name="rededge", center_wavelength=0.705),
305+
"band": Band.create(
306+
name="B05",
307+
common_name="rededge1",
308+
center_wavelength=0.705,
309+
),
290310
"gsd": 20.0,
291311
},
292312
"B06": {
293-
"band": Band.create(name="B06", common_name="rededge", center_wavelength=0.740),
313+
"band": Band.create(
314+
name="B06",
315+
common_name="rededge2",
316+
center_wavelength=0.740,
317+
),
294318
"gsd": 20.0,
295319
},
296320
"B07": {
297-
"band": Band.create(name="B07", common_name="rededge", center_wavelength=0.783),
321+
"band": Band.create(
322+
name="B07",
323+
common_name="rededge3",
324+
center_wavelength=0.783,
325+
),
298326
"gsd": 20.0,
299327
},
300328
"B08": {
301-
"band": Band.create(name="B08", common_name="nir", center_wavelength=0.842),
329+
"band": Band.create(
330+
name="B08",
331+
common_name="nir",
332+
center_wavelength=0.842,
333+
),
302334
"gsd": 10.0,
303335
},
304336
"B8A": {
305-
"band": Band.create(name="B8A", common_name="nir08", center_wavelength=0.865),
337+
"band": Band.create(
338+
name="B8A",
339+
common_name="nir08",
340+
center_wavelength=0.865,
341+
),
306342
"gsd": 20.0,
307343
},
308344
"B09": {
309-
"band": Band.create(name="B09", common_name="nir09", center_wavelength=0.945),
345+
"band": Band.create(
346+
name="B09",
347+
common_name="nir09",
348+
center_wavelength=0.945,
349+
),
310350
"gsd": 60.0,
311351
},
312352
"B10": {
313-
"band": Band.create(name="B10", common_name="cirrus", center_wavelength=1.375),
353+
"band": Band.create(
354+
name="B10",
355+
common_name="cirrus",
356+
center_wavelength=1.375,
357+
),
314358
"gsd": 60.0,
315359
},
316360
"B11": {
317-
"band": Band.create(name="B11", common_name="swir16", center_wavelength=1.610),
361+
"band": Band.create(
362+
name="B11",
363+
common_name="swir1",
364+
center_wavelength=1.610,
365+
),
318366
"gsd": 20.0,
319367
},
320368
"B12": {
321-
"band": Band.create(name="B12", common_name="swir22", center_wavelength=2.190),
369+
"band": Band.create(
370+
name="B12",
371+
common_name="swir2",
372+
center_wavelength=2.190,
373+
),
322374
"gsd": 20.0,
323375
},
324376
}

src/satextractor/models/models.py

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import datetime
24
from typing import List
35
from typing import Tuple
@@ -9,18 +11,51 @@
911

1012
@attr.s
1113
class Tile:
12-
id: str = attr.ib()
14+
zone: int = attr.ib()
15+
row: str = attr.ib()
16+
min_x: int = attr.ib()
17+
min_y: int = attr.ib()
18+
max_x: int = attr.ib()
19+
max_y: int = attr.ib()
1320
epsg: str = attr.ib()
14-
bbox: Tuple[float, float, float, float] = attr.ib() # (xmin, ymin, xmax, ymax)
1521

16-
def __attrs_post_init__(self):
17-
self.bbox_size = (
18-
self.bbox[2] - self.bbox[0],
19-
self.bbox[3] - self.bbox[1],
22+
@property
23+
def id(self) -> str:
24+
return f"{self.zone}_{self.row}_{self.bbox_size_x}_{self.xloc}_{self.yloc}"
25+
26+
@property
27+
def xloc(self) -> int:
28+
return int(self.min_x / self.bbox_size_x)
29+
30+
@property
31+
def yloc(self) -> int:
32+
return int(self.min_y / self.bbox_size_y)
33+
34+
@property
35+
def bbox(self) -> Tuple[float, float, float, float]:
36+
return (self.min_x, self.min_y, self.max_x, self.max_y)
37+
38+
@property
39+
def bbox_wgs84(self):
40+
reproj_src_wgs = get_transform_function(str(self.epsg), "WGS84")
41+
return (
42+
*reproj_src_wgs(self.min_x, self.min_y),
43+
*reproj_src_wgs(self.max_x, self.max_y),
2044
)
2145

22-
def contains(self, other):
23-
# type: (Tile)->bool
46+
@property
47+
def bbox_size_x(self) -> int: # in metres
48+
return int(self.max_x - self.min_x)
49+
50+
@property
51+
def bbox_size_y(self) -> int: # in metres
52+
return int(self.max_y - self.min_y)
53+
54+
@property
55+
def bbox_size(self) -> Tuple[int, int]: # in metres
56+
return (self.bbox_size_x, self.bbox_size_y)
57+
58+
def contains(self, other: Tile) -> bool:
2459
return (
2560
self.epsg == other.epsg
2661
and self.bbox[0] <= other.bbox[0]
@@ -29,14 +64,6 @@ def contains(self, other):
2964
and self.bbox[3] >= other.bbox[3]
3065
)
3166

32-
@property
33-
def bbox_wgs84(self):
34-
reproj_src_wgs = get_transform_function(str(self.epsg), "WGS84")
35-
return (
36-
*reproj_src_wgs(self.bbox[0], self.bbox[1]),
37-
*reproj_src_wgs(self.bbox[2], self.bbox[3]),
38-
)
39-
4067

4168
@attr.s
4269
class ExtractionTask:

src/satextractor/preparer/preparer.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,6 @@ def create_zarr_patch_structure(
3232
dtype=np.uint16,
3333
)
3434

35-
mask_path = f"{patch_constellation_path}/mask"
36-
zarr.open_array(
37-
fs_mapper(mask_path),
38-
"w",
39-
shape=(len(sensing_times), len(bands)),
40-
chunks=(1, 1),
41-
dtype=np.uint8,
42-
)
43-
44-
percentiles_path = f"{patch_constellation_path}/percentiles_0to100_5incr"
45-
zarr.open_array(
46-
fs_mapper(percentiles_path),
47-
"w",
48-
shape=(len(sensing_times), len(bands), 21),
49-
chunks=(1, 1, 21),
50-
dtype=np.float32,
51-
)
52-
5335
# Create timestamps array
5436
timestamps_path = f"{patch_constellation_path}/timestamps"
5537
z_dates = zarr.open_array(

src/satextractor/tiler/tiler.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,17 @@ def split_region_in_utm_tiles(
2727
crs_bboxes = utm_splitter.get_bbox_list()
2828
info_bboxes = utm_splitter.get_info_list()
2929

30-
tiles = []
31-
for info, box in zip(info_bboxes, crs_bboxes):
32-
# tile ids are globally unique and take the format shown below
33-
zone = info["utm_zone"]
34-
row = info["utm_row"]
35-
x, y = (int(v / bbox_size) for v in box.lower_left)
36-
tiles.append(
37-
Tile(
38-
id=f"{zone}_{row}_{bbox_size}_{x}_{y}",
39-
epsg=box.crs.epsg,
40-
bbox=(box.min_x, box.min_y, box.max_x, box.max_y),
41-
),
30+
tiles = [
31+
Tile(
32+
zone=info["utm_zone"],
33+
row=info["utm_row"],
34+
min_x=box.min_x,
35+
min_y=box.min_y,
36+
max_x=box.max_x,
37+
max_y=box.max_y,
38+
epsg=box.crs.epsg,
4239
)
40+
for info, box in zip(info_bboxes, crs_bboxes)
41+
]
4342

4443
return tiles

0 commit comments

Comments
 (0)