Commit 2c939225 authored by Gaetano Raffaele's avatar Gaetano Raffaele
Browse files

ENH: added parameter to separate S1A/S1B (useful?).

parent 0422ad35
......@@ -153,16 +153,19 @@ def preClip(infile, outfile, roi_buffered_vector, overwrite=False, verbose=True,
return outfile
isIntersecting = False
dsr = gdal.Open(infile)
in_geom = getRasterExtentAsGeometry(dsr)
dsv = ogr.Open(roi_buffered_vector)
ly = dsv.GetLayer()
roi_geom = ly[0].GetGeometryRef()
lyv = dsv.GetLayer()
for f in lyv:
roi_geom = f.GetGeometryRef()
dsi = ogr.Open(os.path.dirname(infile) + os.sep + os.pardir + os.sep + 'preview' + os.sep + 'map-overlay.kml')
lyi = dsi.GetLayer()
for g in lyi:
in_geom = g.GetGeometryRef()
isIntersecting = in_geom.Intersects(roi_geom)
dsv = None
dsr = None
dsi = None
if (isIntersecting) :
if (isIntersecting):
extroi = otb.Registry.CreateApplication('ExtractROI')
extroi.SetParameterString('in', infile)
extroi.SetParameterString('mode', 'fit')
......@@ -171,7 +174,7 @@ def preClip(infile, outfile, roi_buffered_vector, overwrite=False, verbose=True,
extroi.SetParameterString('ram', str(ram))
extroi.ExecuteAndWriteOutput()
return outfile
else :
else:
if verbose:
print('Pre-clip process skipped, image outside ROI.')
return None
......@@ -430,6 +433,18 @@ def multitempSpeckleFilt(infiles, outdir, window_radius=3, overwrite=False, verb
# subprocess.call(cmd, shell=False)
def separateS1AS1B(safe_files):
safe_files_s1a = []
safe_files_s1b = []
for l in safe_files:
if os.path.basename(l).startswith('S1A'):
safe_files_s1a.append(l)
elif os.path.basename(l).startswith('S1B'):
safe_files_s1b.append(l)
return safe_files_s1a,safe_files_s1b
def separateAscDesc(safe_files):
safe_files_asc = []
safe_files_des = []
......@@ -590,7 +605,7 @@ def raster_epsg(x):
def s1process(indir, outdir, epsg=None,
roi=None, buffer=100, dem=None, geoid=None, orthofit=False,
direction='descending', step='all', force_clip=False, features=None, skip_db_conversion=False,
direction='descending', satellite='both', step='all', force_clip=False, features=None, skip_db_conversion=False,
features_by_date=False, calib_dir=None, cache_dir=Path('~/.moringa/cache').expanduser(),
ram=1024, ncores=1, overwrite=False, verbose=True):
"""Process Sentinel 1 data
......@@ -717,6 +732,15 @@ def s1process(indir, outdir, epsg=None,
else:
sys.exit('Invalid direction parameter.')
if satellite != 'both':
safe_files_s1a, safe_files_s1b = separateAscDesc(safe_files)
if direction == 's1a':
safe_files = safe_files_s1a
elif direction == 's1b':
safe_files = safe_files_s1b
else:
sys.exit('Invalid direction parameter.')
if len(safe_files) == 0:
raise IOError('No .SAFE file found in {}'.format(indir))
......@@ -766,7 +790,8 @@ def s1process(indir, outdir, epsg=None,
for arg in mp_args:
try:
f = preClip(*arg) # 3s/S2tile
files.append(f)
if f is not None:
files.append(f)
except Exception as e:
print(e)
print('Clip went wrong, file skipped: {}'.format(f))
......@@ -871,6 +896,11 @@ def parse_cmd_line(argv=sys.argv[1:]):
choices=['descending', 'ascending', 'both'],
default='descending')
parser.add_argument("--satellite",
help="Choose a single satellite (s1a or s1b).",
choices=['s1a', 's1b', 'both'],
default='both')
parser.add_argument('--step', nargs='+', help='Specify one or more processing steps.',
choices=['all', 'clip', 'calib', 'ortho', 'filter'], default='all')
......
Markdown is supported
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