Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rapida/components/landuse/search_utils/mgrstiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Candidate:
tile_geometry: Polygon = None
mgrs_geometry: Polygon = None
mgrs_crs: pyproj.CRS = None
stac_item: dict = None

@property
def quality_score(self) -> float:
Expand Down
1 change: 0 additions & 1 deletion rapida/components/landuse/search_utils/s2item.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@ async def _cleanup_tmp(path: str):
]

try:
logger.info(f'Downloading {dst}')
# 4) Write chunks to TMP (global timeout)
async with aiofiles.open(tmp, "wb") as f:
async with asyncio.timeout(timeout_minutes * 60):
Expand Down
29 changes: 15 additions & 14 deletions rapida/components/landuse/search_utils/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def create_candidate(it, mgrs_id, ref_ts, mgrs_poly, mgrs_crs):
data_coverage=tile_info["dataCoveragePercentage"],
ref_ts=ref_ts,
mgrs_geometry=mgrs_poly,
mgrs_crs=mgrs_crs
mgrs_crs=mgrs_crs,
stac_item = it
)

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

from rapida.util.setup_logger import setup_logger
from rapida.components.landuse.search_utils.s2item import Sentinel2Item

from rapida.components.landuse.prediction.landuse import LandusePrediction
from pystac import Item
# logger.setLevel(logging.DEBUG)
logger = setup_logger(level=logging.INFO)
CATALOG_URL = "https://earth-search.aws.element84.com/v1"
Expand All @@ -315,7 +317,7 @@ def fetch_s2_tiles(


bbox = 33, -1, 37, 2

bands = LandusePrediction.required_bands


with Progress() as progress:
Expand All @@ -327,26 +329,25 @@ def fetch_s2_tiles(
end_date = "2025-08-30"
results = fetch_s2_tiles(bbox=bbox,stac_url=CATALOG_URL,
start_date=start_date, end_date=end_date,
max_cloud_cover=max_cloud_cover, progress=progress,filter_for_dev=['36NWF'])
max_cloud_cover=max_cloud_cover, progress=progress,filter_for_dev=['36MZE'])



bands = ['B01', 'B02', 'B03', 'B04', 'B05']
bands = ['B03']
band_files = {}

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

progress=progress)



except KeyboardInterrupt:
Expand Down