diff --git a/setup.py b/setup.py index 9d81af3..87578af 100755 --- a/setup.py +++ b/setup.py @@ -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", diff --git a/src/satextractor/models/constellation_info.py b/src/satextractor/models/constellation_info.py index 272c267..a89b923 100644 --- a/src/satextractor/models/constellation_info.py +++ b/src/satextractor/models/constellation_info.py @@ -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, ), @@ -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, ), @@ -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, ), @@ -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, ), @@ -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, ), @@ -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, ), @@ -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, ), @@ -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, ), @@ -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, ), @@ -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, ), @@ -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, ), @@ -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, }, } diff --git a/src/satextractor/models/models.py b/src/satextractor/models/models.py index 16dc100..774e52a 100644 --- a/src/satextractor/models/models.py +++ b/src/satextractor/models/models.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import datetime from typing import List from typing import Tuple @@ -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] @@ -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: diff --git a/src/satextractor/preparer/preparer.py b/src/satextractor/preparer/preparer.py index 1a34f78..ac82b5b 100644 --- a/src/satextractor/preparer/preparer.py +++ b/src/satextractor/preparer/preparer.py @@ -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( diff --git a/src/satextractor/tiler/tiler.py b/src/satextractor/tiler/tiler.py index e26a75e..c02d8da 100644 --- a/src/satextractor/tiler/tiler.py +++ b/src/satextractor/tiler/tiler.py @@ -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