Skip to content

Commit

Permalink
Merge pull request #21 from oxfordeo/main
Browse files Browse the repository at this point in the history
Improve Band common_names and Tile properties
  • Loading branch information
frandorr authored Dec 1, 2021
2 parents faa402e + c17cb0b commit 5f48a5d
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 71 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def read(*names, **kwargs):

setup(
name="satextractor",
version="0.2.0",
version="0.2.1",
license="BSD-2-Clause",
description="SatExtractor. Extract everything from everywhere.",
url="https://github.com/FrontierDevelopmentLab/sat-extractor",
Expand Down
100 changes: 76 additions & 24 deletions src/satextractor/models/constellation_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"B6": {
"band": Band.create(
name="B6",
common_name="swir16",
common_name="swir1",
center_wavelength=1.6,
full_width_half_max=0.08,
),
Expand All @@ -73,7 +73,7 @@
"B7": {
"band": Band.create(
name="B7",
common_name="swir22",
common_name="swir2",
center_wavelength=2.2,
full_width_half_max=0.2,
),
Expand All @@ -100,7 +100,7 @@
"B10": {
"band": Band.create(
name="B10",
common_name="lwir11",
common_name="tirs1",
center_wavelength=10.9,
full_width_half_max=0.8,
),
Expand All @@ -109,7 +109,7 @@
"B11": {
"band": Band.create(
name="B11",
common_name="lwir12",
common_name="tirs2",
center_wavelength=12.0,
full_width_half_max=1.0,
),
Expand Down Expand Up @@ -148,7 +148,7 @@
"B4": {
"band": Band.create(
name="B4",
common_name="near infrared",
common_name="nir",
center_wavelength=0.835,
full_width_half_max=0.065,
),
Expand All @@ -157,7 +157,7 @@
"B5": {
"band": Band.create(
name="B5",
common_name="shortwave infrared 1",
common_name="swir1",
center_wavelength=1.65,
full_width_half_max=0.10,
),
Expand All @@ -184,7 +184,7 @@
"B7": {
"band": Band.create(
name="B7",
common_name="shortwave infrared 2",
common_name="swir2",
center_wavelength=2.215,
full_width_half_max=0.135,
),
Expand All @@ -193,7 +193,7 @@
"B8": {
"band": Band.create(
name="B8",
common_name="panchromatic",
common_name="pan",
center_wavelength=0.71,
full_width_half_max=0.24,
),
Expand Down Expand Up @@ -232,7 +232,7 @@
"B4": {
"band": Band.create(
name="B4",
common_name="near infrared",
common_name="nir",
center_wavelength=0.835,
full_width_half_max=0.065,
),
Expand All @@ -241,7 +241,7 @@
"B5": {
"band": Band.create(
name="B5",
common_name="shortwave infrared 1",
common_name="swir1",
center_wavelength=1.65,
full_width_half_max=0.10,
),
Expand All @@ -259,7 +259,7 @@
"B7": {
"band": Band.create(
name="B7",
common_name="shortwave infrared 2",
common_name="swir2",
center_wavelength=2.215,
full_width_half_max=0.135,
),
Expand All @@ -270,55 +270,107 @@

SENTINEL2_BAND_INFO = {
"B01": {
"band": Band.create(name="B01", common_name="coastal", center_wavelength=0.443),
"band": Band.create(
name="B01",
common_name="coastal",
center_wavelength=0.443,
),
"gsd": 60.0,
},
"B02": {
"band": Band.create(name="B02", common_name="blue", center_wavelength=0.490),
"band": Band.create(
name="B02",
common_name="blue",
center_wavelength=0.490,
),
"gsd": 10.0,
},
"B03": {
"band": Band.create(name="B03", common_name="green", center_wavelength=0.560),
"band": Band.create(
name="B03",
common_name="green",
center_wavelength=0.560,
),
"gsd": 10.0,
},
"B04": {
"band": Band.create(name="B04", common_name="red", center_wavelength=0.665),
"band": Band.create(
name="B04",
common_name="red",
center_wavelength=0.665,
),
"gsd": 10.0,
},
"B05": {
"band": Band.create(name="B05", common_name="rededge", center_wavelength=0.705),
"band": Band.create(
name="B05",
common_name="rededge1",
center_wavelength=0.705,
),
"gsd": 20.0,
},
"B06": {
"band": Band.create(name="B06", common_name="rededge", center_wavelength=0.740),
"band": Band.create(
name="B06",
common_name="rededge2",
center_wavelength=0.740,
),
"gsd": 20.0,
},
"B07": {
"band": Band.create(name="B07", common_name="rededge", center_wavelength=0.783),
"band": Band.create(
name="B07",
common_name="rededge3",
center_wavelength=0.783,
),
"gsd": 20.0,
},
"B08": {
"band": Band.create(name="B08", common_name="nir", center_wavelength=0.842),
"band": Band.create(
name="B08",
common_name="nir",
center_wavelength=0.842,
),
"gsd": 10.0,
},
"B8A": {
"band": Band.create(name="B8A", common_name="nir08", center_wavelength=0.865),
"band": Band.create(
name="B8A",
common_name="nir08",
center_wavelength=0.865,
),
"gsd": 20.0,
},
"B09": {
"band": Band.create(name="B09", common_name="nir09", center_wavelength=0.945),
"band": Band.create(
name="B09",
common_name="nir09",
center_wavelength=0.945,
),
"gsd": 60.0,
},
"B10": {
"band": Band.create(name="B10", common_name="cirrus", center_wavelength=1.375),
"band": Band.create(
name="B10",
common_name="cirrus",
center_wavelength=1.375,
),
"gsd": 60.0,
},
"B11": {
"band": Band.create(name="B11", common_name="swir16", center_wavelength=1.610),
"band": Band.create(
name="B11",
common_name="swir1",
center_wavelength=1.610,
),
"gsd": 20.0,
},
"B12": {
"band": Band.create(name="B12", common_name="swir22", center_wavelength=2.190),
"band": Band.create(
name="B12",
common_name="swir2",
center_wavelength=2.190,
),
"gsd": 20.0,
},
}
Expand Down
59 changes: 43 additions & 16 deletions src/satextractor/models/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import datetime
from typing import List
from typing import Tuple
Expand All @@ -9,18 +11,51 @@

@attr.s
class Tile:
id: str = attr.ib()
zone: int = attr.ib()
row: str = attr.ib()
min_x: int = attr.ib()
min_y: int = attr.ib()
max_x: int = attr.ib()
max_y: int = attr.ib()
epsg: str = attr.ib()
bbox: Tuple[float, float, float, float] = attr.ib() # (xmin, ymin, xmax, ymax)

def __attrs_post_init__(self):
self.bbox_size = (
self.bbox[2] - self.bbox[0],
self.bbox[3] - self.bbox[1],
@property
def id(self) -> str:
return f"{self.zone}_{self.row}_{self.bbox_size_x}_{self.xloc}_{self.yloc}"

@property
def xloc(self) -> int:
return int(self.min_x / self.bbox_size_x)

@property
def yloc(self) -> int:
return int(self.min_y / self.bbox_size_y)

@property
def bbox(self) -> Tuple[float, float, float, float]:
return (self.min_x, self.min_y, self.max_x, self.max_y)

@property
def bbox_wgs84(self):
reproj_src_wgs = get_transform_function(str(self.epsg), "WGS84")
return (
*reproj_src_wgs(self.min_x, self.min_y),
*reproj_src_wgs(self.max_x, self.max_y),
)

def contains(self, other):
# type: (Tile)->bool
@property
def bbox_size_x(self) -> int: # in metres
return int(self.max_x - self.min_x)

@property
def bbox_size_y(self) -> int: # in metres
return int(self.max_y - self.min_y)

@property
def bbox_size(self) -> Tuple[int, int]: # in metres
return (self.bbox_size_x, self.bbox_size_y)

def contains(self, other: Tile) -> bool:
return (
self.epsg == other.epsg
and self.bbox[0] <= other.bbox[0]
Expand All @@ -29,14 +64,6 @@ def contains(self, other):
and self.bbox[3] >= other.bbox[3]
)

@property
def bbox_wgs84(self):
reproj_src_wgs = get_transform_function(str(self.epsg), "WGS84")
return (
*reproj_src_wgs(self.bbox[0], self.bbox[1]),
*reproj_src_wgs(self.bbox[2], self.bbox[3]),
)


@attr.s
class ExtractionTask:
Expand Down
18 changes: 0 additions & 18 deletions src/satextractor/preparer/preparer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,6 @@ def create_zarr_patch_structure(
dtype=np.uint16,
)

mask_path = f"{patch_constellation_path}/mask"
zarr.open_array(
fs_mapper(mask_path),
"w",
shape=(len(sensing_times), len(bands)),
chunks=(1, 1),
dtype=np.uint8,
)

percentiles_path = f"{patch_constellation_path}/percentiles_0to100_5incr"
zarr.open_array(
fs_mapper(percentiles_path),
"w",
shape=(len(sensing_times), len(bands), 21),
chunks=(1, 1, 21),
dtype=np.float32,
)

# Create timestamps array
timestamps_path = f"{patch_constellation_path}/timestamps"
z_dates = zarr.open_array(
Expand Down
23 changes: 11 additions & 12 deletions src/satextractor/tiler/tiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,17 @@ def split_region_in_utm_tiles(
crs_bboxes = utm_splitter.get_bbox_list()
info_bboxes = utm_splitter.get_info_list()

tiles = []
for info, box in zip(info_bboxes, crs_bboxes):
# tile ids are globally unique and take the format shown below
zone = info["utm_zone"]
row = info["utm_row"]
x, y = (int(v / bbox_size) for v in box.lower_left)
tiles.append(
Tile(
id=f"{zone}_{row}_{bbox_size}_{x}_{y}",
epsg=box.crs.epsg,
bbox=(box.min_x, box.min_y, box.max_x, box.max_y),
),
tiles = [
Tile(
zone=info["utm_zone"],
row=info["utm_row"],
min_x=box.min_x,
min_y=box.min_y,
max_x=box.max_x,
max_y=box.max_y,
epsg=box.crs.epsg,
)
for info, box in zip(info_bboxes, crs_bboxes)
]

return tiles

0 comments on commit 5f48a5d

Please sign in to comment.