Commit a39a8df7 authored by Cresson Remi's avatar Cresson Remi
Browse files

Merge branch '9-search' into 'develop'

Resolve "Update drs_search"

Closes #9

See merge request !25
1 merge request!25Resolve "Update drs_search"
Showing with 44 additions and 48 deletions
+44 -48
......@@ -3,8 +3,9 @@ from scenes import save_scenes
from scenes.spot import get_spot67_scenes
# Arguments
parser = argparse.ArgumentParser(description="Test",)
parser = argparse.ArgumentParser(description="Import Spot-6/7 images from DRS into a list of scenes (pickle)",)
parser.add_argument("--root_dirs", nargs='+', help="Root directories containing MS and PAN folders", required=True)
parser.add_argument("--tile_name", help="Filter only images from this tile (optional)")
parser.add_argument("--out_pickle", help="Output pickle file", required=True)
params = parser.parse_args()
......
import argparse
from scenes import utils, sentinel, save_scenes
from scenes import save_scenes
from scenes.sentinel import get_local_scenes
# Arguments
parser = argparse.ArgumentParser(description="Test",)
parser.add_argument("--root_dirs", nargs='+', help="Root directories containing S2 archives (.zip)", required=True)
parser.add_argument("--out_pickle", help="Output pickle file", required=True)
parser.add_argument('--level', default='2A', const='2A', nargs='?', choices=['2A', '3A'], help='Product level')
parser.add_argument("--tile_name", help="(Optional) Tile name")
params = parser.parse_args()
# Get all scenes in the root_dir
product_type = sentinel.Sentinel23AScene if params.level == '2A' else sentinel.Sentinel23AScene
archives = []
for root_dir in params.root_dirs:
archives += utils.find_files_in_all_subdirs(pth=root_dir, pattern="*.zip", case_sensitive=False)
scenes = [product_type(archive=archive) for archive in archives]
# Search all Sentinel-2 scenes
s2_scenes = [get_local_scenes(root_dir=root_dir, tile=params.tile_name) for root_dir in params.root_dirs]
# Save scenes in a pickle file
save_scenes(scenes, params.out_pickle)
save_scenes(s2_scenes, params.out_pickle)
import argparse
from scenes import utils, Index
from scenes import load_scenes, Index, utils
# Arguments
parser = argparse.ArgumentParser(description="Test",)
parser.add_argument("--root_dir", help="Root directory containing MS and PAN folders", required=True)
parser.add_argument("--roi", required=True)
parser = argparse.ArgumentParser(description="Search scenes intesecting an ROI",)
parser.add_argument("--pickle_file", help="List of scenes (serialized in pickle format)", required=True)
parser.add_argument("--roi", help="ROI. Can be a vector or a raster", required=True)
params = parser.parse_args()
# Find pairs of DIMAPS
scenes = drs.get_spot67_scenes(params.root_dir)
# Load scenes list
scenes = load_scenes(params.pickle_file)
# spatial index
print("Indexation...")
idx = Index(scenes)
# search
print("search roi")
print("Search roi")
bbox_fn = utils.get_bbox_wgs84_from_raster if params.roi.lower().endswith(".tif") \
else utils.get_bbox_wgs84_from_vector
matches = idx.find(bbox_wgs84=bbox_fn(params.roi))
print("{} scenes found.".format(len(matches)))
#for scene_match in matches:
# print(scene_match)
print(f"{len(matches)} scenes found.")
for i, scene_match in enumerate(matches):
print(f"Scene #{i}")
print(scene_match)
......@@ -317,7 +317,7 @@ class Sentinel23AScene(Sentinel2SceneBase):
def get_scene(archive):
"""
Return the right sentinel scene instance from the givent archive (L2A or L3A)
Return the right sentinel scene instance from the given archive (L2A or L3A)
Args:
archive: L3A or L3A archive
......
import argparse
import pyotb
from scenes import utils, Index
from scenes.spot import get_spot67_scenes
# Arguments
parser = argparse.ArgumentParser(description="Test",)
parser.add_argument("--root_dir", help="Root directory containing MS and PAN folders", required=True)
parser.add_argument("--roi", required=True)
parser.add_argument("--out", required=True)
params = parser.parse_args()
# Find pairs of DIMAPS
scenes = get_spot67_scenes(params.root_dir)
# spatial index
print("Indexation...")
idx = Index(scenes)
# search
print("search roi")
bbox = utils.get_bbox_wgs84_from_raster(params.roi)
matches = idx.find(bbox_wgs84=bbox)
print("{} scenes found.".format(len(matches)))
# sort
print("sort")
sources_list = [sc.get_imagery().get_xs().resample_over(ref_img=params.roi) for sc in matches]
sources_list.sort(key=lambda src: src.root_imagery.root_scene.acquisition_date)
# stack
print("concatenation")
concat = pyotb.ConcatenateImages({"il": sources_list})
concat.write(params.out)
import scenes.spot as spot
import argparse
# Arguments
parser = argparse.ArgumentParser(description="Test",)
parser.add_argument("--dimap_xs", required=True)
parser.add_argument("--dimap_pan", required=True)
params = parser.parse_args()
# Test spot class
image = spot.Scene(dimap_file_xs=params.dimap_xs, dimap_file_pan=params.dimap_pan)
print(image)
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment