Skip to content

Commit bc52d88

Browse files
iferencikIoan Ferencik
andauthored
add stac item to candidate to be able to run prediction (#486)
Co-authored-by: Ioan Ferencik <[email protected]>
1 parent a04cf1e commit bc52d88

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

rapida/components/landuse/search_utils/mgrstiles.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class Candidate:
2929
tile_geometry: Polygon = None
3030
mgrs_geometry: Polygon = None
3131
mgrs_crs: pyproj.CRS = None
32+
stac_item: dict = None
3233

3334
@property
3435
def quality_score(self) -> float:

rapida/components/landuse/search_utils/s2item.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,6 @@ async def _cleanup_tmp(path: str):
342342
]
343343

344344
try:
345-
logger.info(f'Downloading {dst}')
346345
# 4) Write chunks to TMP (global timeout)
347346
async with aiofiles.open(tmp, "wb") as f:
348347
async with asyncio.timeout(timeout_minutes * 60):

rapida/components/landuse/search_utils/search.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ def create_candidate(it, mgrs_id, ref_ts, mgrs_poly, mgrs_crs):
5353
data_coverage=tile_info["dataCoveragePercentage"],
5454
ref_ts=ref_ts,
5555
mgrs_geometry=mgrs_poly,
56-
mgrs_crs=mgrs_crs
56+
mgrs_crs=mgrs_crs,
57+
stac_item = it
5758
)
5859

5960
def search( client=None, collection="sentinel-2-l1c",
@@ -303,7 +304,8 @@ def fetch_s2_tiles(
303304

304305
from rapida.util.setup_logger import setup_logger
305306
from rapida.components.landuse.search_utils.s2item import Sentinel2Item
306-
307+
from rapida.components.landuse.prediction.landuse import LandusePrediction
308+
from pystac import Item
307309
# logger.setLevel(logging.DEBUG)
308310
logger = setup_logger(level=logging.INFO)
309311
CATALOG_URL = "https://earth-search.aws.element84.com/v1"
@@ -315,7 +317,7 @@ def fetch_s2_tiles(
315317

316318

317319
bbox = 33, -1, 37, 2
318-
320+
bands = LandusePrediction.required_bands
319321

320322

321323
with Progress() as progress:
@@ -327,26 +329,25 @@ def fetch_s2_tiles(
327329
end_date = "2025-08-30"
328330
results = fetch_s2_tiles(bbox=bbox,stac_url=CATALOG_URL,
329331
start_date=start_date, end_date=end_date,
330-
max_cloud_cover=max_cloud_cover, progress=progress,filter_for_dev=['36NWF'])
332+
max_cloud_cover=max_cloud_cover, progress=progress,filter_for_dev=['36MZE'])
333+
331334

332335

333-
bands = ['B01', 'B02', 'B03', 'B04', 'B05']
334-
bands = ['B03']
335336
band_files = {}
336337

337338
for grid, candidates in results.items():
338339
try:
339340
#logger.info(f'{grid}: {[c for c in candidates]}')
340341
s2i = Sentinel2Item(mgrs_grid=grid, s2_tiles=candidates, workdir='/tmp', target_crs='ESRI:54034')
341342
downloaded = s2i.download(bands=bands, progress=progress, force=False)
342-
# for k, v in s2i.vrt.items():
343-
# pass
344-
# with rasterio.open(v) as vsrc:
345-
# print(k, tuple(vsrc.bounds))
346-
# for bname, bfile in downloaded.items():
347-
# if not bname in band_files:
348-
# band_files[bname] = []
349-
# band_files[bname].append(bfile)
343+
img_paths = [downloaded[b] for b in bands]
344+
itm = Item.from_dict(candidates[0].stac_item)
345+
landuse_prediction = LandusePrediction(item=itm)
346+
landuse_prediction.predict(img_paths=img_paths,
347+
output_file_path=f'/tmp/landuse_36MZE.tif',
348+
349+
progress=progress)
350+
350351

351352

352353
except KeyboardInterrupt:

0 commit comments

Comments
 (0)