Skip to content

Commit 172e62f

Browse files
[gamma] compatibility with GAMMA version 20250625
1 parent 95b79cc commit 172e62f

File tree

3 files changed

+140
-133
lines changed

3 files changed

+140
-133
lines changed

pyroSAR/gamma/parser.py

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,17 @@ def parse_command(command, indent=' '):
5858
# for all other commands stderr is just appended to stdout
5959
out += err
6060

61-
warning = None
62-
pattern = r'([\w\.]+ (?:has been|was) re(?:named to|placed(?: that [ \*\n]*|) by)(?: the ISP program|) [\w\.]+)'
63-
match = re.search(pattern, out)
64-
if match:
65-
warning = "raise DeprecationWarning('{}')".format(match.group())
61+
# raise a warning when the command has been deprecated
62+
# extract all lines starting and ending with three asterisks
63+
matches = re.findall(r'^\*{3}\s*(.*?)\s*\*{3}$', out, re.MULTILINE)
64+
if matches:
65+
# join the lines and search for a deprecation message
66+
cleaned = ' '.join(matches)
67+
pattern = (r'([\w\.]+ (?:has been|was) re(?:named to|placed(?: that [ \*\n]*|) by)'
68+
r'(?:[ \*\n]*|)(?: the ISP program|) [\w\.]+)')
69+
match = re.search(pattern, cleaned)
70+
if match:
71+
raise DeprecationWarning(match.group())
6672

6773
if re.search(r"Can't locate FILE/Path\.pm in @INC", out):
6874
raise RuntimeError('unable to parse Perl script')
@@ -139,6 +145,8 @@ def parse_command(command, indent=' '):
139145
'mk_base_calc': [('<RSLC_tab>', '<SLC_tab>')],
140146
'mk_cpd_all': [('dtab', 'data_tab')],
141147
'mk_cpx_ref_2d': [('diff_tab', 'cpx_tab')],
148+
'mk_diff_tc_2d': [('<def>', '<def_rate>'),
149+
('def (input)', 'def_rate (input)')],
142150
'mk_dispmap2_2d': [('RMLI_image', 'MLI'),
143151
('RMLI_par', 'MLI_par'),
144152
('MLI_image', 'MLI'),
@@ -166,6 +174,7 @@ def parse_command(command, indent=' '):
166174
('MLI_image', 'MLI')],
167175
'mk_rasmph_all': [('RMLI_image', 'MLI'),
168176
('MLI_image', 'MLI')],
177+
'mk_tab2': [('--linenumber', 'linenumber')],
169178
'mk_unw_2d': [('unw_mask1', 'unw_mask')],
170179
'mk_unw_ref_2d': [('diff_tab', 'DIFF_tab')],
171180
'MLI2pt': [('MLI_TAB', 'MLI_tab'),
@@ -358,9 +367,6 @@ def replace(inlist, replacement):
358367
if command_base in replacements.keys():
359368
arg_req = replace(arg_req, replacements[command_base])
360369
arg_opt = replace(arg_opt, replacements[command_base])
361-
362-
if command_base in ['par_CS_geo', 'par_KS_geo']:
363-
out = re.sub('[ ]*trunk.*', '', out, flags=re.DOTALL)
364370
###########################################
365371
# check if there are any double parameters
366372

@@ -379,22 +385,23 @@ def replace(inlist, replacement):
379385
######################################################################################
380386
# create the function argument string for the Python function
381387

382-
# optional arguments are parametrized with '-' as default value, e.g. arg_opt='-'
388+
# optional arguments are parametrized with '-' as default value, e.g., arg_opt='-'
389+
argstr_function = ', '.join(arg_req + [x + "='-'" for x in arg_opt])
383390
# a '-' in the parameter name is replaced with '_'
384-
# example: "arg1, arg2, arg3='-'"
385-
argstr_function = re.sub(r'([^\'])-([^\'])', r'\1_\2', ', '.join(arg_req + [x + "='-'" for x in arg_opt])) \
386-
.replace(', def=', ', drm=')
391+
argstr_function = re.sub(r'([^\'])-([^\'])', r'\1_\2', argstr_function)
392+
# replace unsupported 'def' parameter name with 'drm'
393+
argstr_function = argstr_function.replace(', def=', ', drm=')
387394

388395
# some commands have different defaults than '-'
389396
replacements_defaults = {'S1_import_SLC_from_zipfiles': {'OPOD_dir': '.'}}
390397

391398
if command_base in replacements_defaults.keys():
392399
for key, value in replacements_defaults[command_base].items():
393-
old = "{}='-'".format(key)
400+
old = f"{key}='-'"
394401
if isinstance(value, str):
395-
new = "{0}='{1}'".format(key, value)
402+
new = f"{key}='{value}'"
396403
else:
397-
new = "{0}={1}".format(key, value)
404+
new = f"{key}={value}"
398405
argstr_function = argstr_function.replace(old, new)
399406

400407
# create the function definition string
@@ -417,12 +424,13 @@ def replace(inlist, replacement):
417424
('max', '-b', None),
418425
('rmax', '-R', None),
419426
('mode', '-m', None),
420-
('update', '-u', False)]}
427+
('update', '-u', False)],
428+
'mk_tab2': [('linenumber', '--linenumber', False)]}
421429

422430
# replace arg default like arg='-' with arg=None or arg=False
423431
if command_base in flag_args:
424432
for arg in flag_args[command_base]:
425-
fun_def = re.sub('{}=\'-\''.format(arg[0]), '{0}={1}'.format(arg[0], arg[2]), fun_def)
433+
fun_def = re.sub(f'{arg[0]}=\'-\'', f'{arg[0]}={arg[2]}', fun_def)
426434
######################################################################################
427435
# create the process call argument string
428436

@@ -440,7 +448,7 @@ def replace(inlist, replacement):
440448
key = replacements[command_base][0][1]
441449
if isinstance(key, list):
442450
key = key[0]
443-
proc_args_tmp.insert(proc_args_tmp.index(key), 'len({})'.format(key))
451+
proc_args_tmp.insert(proc_args_tmp.index(key), f'len({key})')
444452

445453
if command_base == 'validate':
446454
index = proc_args_tmp.index('classes_inv')
@@ -469,10 +477,7 @@ def replace(inlist, replacement):
469477
# create the process call string
470478
proc_str = "process(cmd, logpath=logpath, outdir=outdir{inlist}, shellscript=shellscript)" \
471479
.format(inlist=', inlist=inlist' if command_base in inlist else '')
472-
if warning is not None:
473-
fun_proc = warning
474-
else:
475-
fun_proc = '{0}\n{1}'.format(cmd_str, proc_str)
480+
fun_proc = '{0}\n{1}'.format(cmd_str, proc_str)
476481

477482
if command_base == 'lin_comb_cpx':
478483
fun_proc = fun_proc.replace('factors_r, factors_i', 'zip(factors_r, factors_i)')
@@ -564,7 +569,7 @@ def replace(inlist, replacement):
564569
description = re.split(r'\n+\s*', description.strip('\n'))
565570

566571
# escape * characters (which are treated as special characters for bullet lists by sphinx)
567-
description = [x.replace('*', r'\*') for x in description]
572+
description = [x.replace('*', r'\\*') for x in description]
568573

569574
# convert all lines starting with an integer number or 'NOTE' to bullet list items
570575
latest = None
@@ -652,7 +657,7 @@ def parse_module(bindir, outfile):
652657

653658
excludes = ['coord_trans', # doesn't take any parameters and is interactive
654659
'RSAT2_SLC_preproc', # takes option flags
655-
'mk_ASF_CEOS_list', # "cannot create : Directory nonexistent"
660+
'mk_ASF_CEOS_list', # "cannot create: Directory nonexistent"
656661
'2PASS_UNW', # parameter name inconsistencies
657662
'mk_diff_2d', # takes option flags
658663
'gamma_doc' # opens the Gamma documentation
@@ -680,8 +685,8 @@ def parse_module(bindir, outfile):
680685
with open(outfile, 'a') as out:
681686
out.write(outstring)
682687
if len(failed) > 0:
683-
log.info(
684-
'the following functions could not be parsed:\n{0}\n({1} total)'.format('\n'.join(failed), len(failed)))
688+
info = 'the following functions could not be parsed:\n{0}\n({1} total)'
689+
log.info(info.format('\n'.join(failed), len(failed)))
685690

686691

687692
def autoparse():

pyroSAR/gamma/util.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -835,9 +835,9 @@ def geocode(scene, dem, tmpdir, outdir, spacing, scaling='linear', func_geoback=
835835

836836
reference_par = ISPPar(reference + '.par')
837837
######################################################################
838-
# DEM product generation #############################################
838+
# geocoding and DEM product generation ###############################
839839
######################################################################
840-
log.info('creating DEM products')
840+
log.info('geocoding and creating DEM products')
841841
gc_map_wrap(image=reference, namespace=n, dem=dem, spacing=spacing, exist_ok=exist_ok,
842842
logpath=path_log, outdir=tmpdir, shellscript=shellscript)
843843

@@ -850,7 +850,7 @@ def geocode(scene, dem, tmpdir, outdir, spacing, scaling='linear', func_geoback=
850850
logpath=path_log, outdir=tmpdir, shellscript=shellscript)
851851

852852
######################################################################
853-
# lookup table Refinement ############################################
853+
# lookup table refinement ############################################
854854
######################################################################
855855
lut_final = n.lut_init
856856
if refine_lut:
@@ -864,7 +864,7 @@ def geocode(scene, dem, tmpdir, outdir, spacing, scaling='linear', func_geoback=
864864
logpath=path_log,
865865
outdir=tmpdir,
866866
shellscript=shellscript)
867-
# Refinement Lookuptable
867+
# Refinement of lookup table
868868
# for "shift" data offset window size enlarged twice to 512 and 256, for data without shift 256 128
869869
diff.offset_pwrm(MLI_1=n.pix_area_sigma0,
870870
MLI_2=reference,
@@ -906,9 +906,9 @@ def geocode(scene, dem, tmpdir, outdir, spacing, scaling='linear', func_geoback=
906906
logpath=path_log, outdir=tmpdir, shellscript=shellscript)
907907
lut_final = lut_final + '.fine'
908908
######################################################################
909-
# radiometric terrain correction and backward geocoding ##############
909+
# radiometric terrain correction and back-geocoding ##################
910910
######################################################################
911-
log.info('radiometric terrain correction and backward geocoding')
911+
log.info('radiometric terrain correction and back-geocoding')
912912
for image in images:
913913
if 'lat' in locals():
914914
lat.product(data_1=image,
@@ -1242,14 +1242,17 @@ def S1_deburst(burst1, burst2, burst3, name_out, rlks=5, azlks=1,
12421242
outdir=outdir,
12431243
shellscript=shellscript)
12441244

1245-
isp.SLC_mosaic_S1_TOPS(SLC_tab=tab_out,
1246-
SLC=name_out,
1247-
SLC_par=name_out + '.par',
1248-
rlks=rlks,
1249-
azlks=azlks,
1250-
logpath=logpath,
1251-
outdir=outdir,
1252-
shellscript=shellscript)
1245+
new = 'SLC_mosaic_ScanSAR'
1246+
old = 'SLC_mosaic_S1_TOPS'
1247+
slc_mosaic = new if hasattr(isp, new) else old
1248+
getattr(isp, slc_mosaic)(SLC_tab=tab_out,
1249+
SLC=name_out,
1250+
SLC_par=name_out + '.par',
1251+
rlks=rlks,
1252+
azlks=azlks,
1253+
logpath=logpath,
1254+
outdir=outdir,
1255+
shellscript=shellscript)
12531256
if replace:
12541257
for item in [burst1, burst2, burst3]:
12551258
for subitem in [item + x for x in ['', '.par', '.tops_par']]:
@@ -1314,7 +1317,7 @@ def pixel_area_wrap(image, namespace, lut, exist_ok=False,
13141317
'outdir': outdir,
13151318
'shellscript': shellscript}
13161319

1317-
# newer versions of GAMMA enable creating the ratio of ellipsoid based
1320+
# newer versions of GAMMA enable creating the ratio of ellipsoid-based
13181321
# pixel area and DEM-facet pixel area directly with command pixel_area
13191322
if hasarg(diff.pixel_area, 'sig2gam_ratio'):
13201323
namespace.appreciate(['pix_ratio'])
@@ -1351,7 +1354,7 @@ def pixel_area_wrap(image, namespace, lut, exist_ok=False,
13511354
if c1 or c2:
13521355
shutil.copy(src=image + '.hdr', dst=hdr_out)
13531356

1354-
# ratio of ellipsoid based pixel area and DEM-facet pixel area
1357+
# ratio of ellipsoid-based pixel area and DEM-facet pixel area
13551358
c1 = not os.path.isfile(namespace.pix_ratio)
13561359
c2 = os.path.isfile(namespace.pix_ratio) and not exist_ok
13571360
if c1 or c2:
@@ -1366,6 +1369,8 @@ def pixel_area_wrap(image, namespace, lut, exist_ok=False,
13661369
outdir=outdir,
13671370
shellscript=shellscript)
13681371
else:
1372+
for item in ['pix_area_gamma0', 'pix_ellip_sigma0']:
1373+
par2hdr(image + '.par', namespace[item] + '.hdr')
13691374
lat_ratio(data_in1=namespace.pix_ellip_sigma0,
13701375
data_in2=namespace.pix_area_gamma0,
13711376
data_out=namespace.pix_ratio)
@@ -1385,6 +1390,8 @@ def pixel_area_wrap(image, namespace, lut, exist_ok=False,
13851390
outdir=outdir,
13861391
shellscript=shellscript)
13871392
else:
1393+
for item in ['pix_area_gamma0', 'pix_area_sigma0']:
1394+
par2hdr(image + '.par', namespace[item] + '.hdr')
13881395
lat_ratio(data_in1=namespace.pix_area_gamma0,
13891396
data_in2=namespace.pix_area_sigma0,
13901397
data_out=namespace.gs_ratio)
@@ -1395,7 +1402,8 @@ def pixel_area_wrap(image, namespace, lut, exist_ok=False,
13951402
hdr_out = namespace[item] + '.hdr'
13961403
c1 = not os.path.isfile(item)
13971404
c2 = os.path.isfile(hdr_out) and not exist_ok
1398-
par2hdr(image + '.par', hdr_out)
1405+
if c1 or c2:
1406+
par2hdr(image + '.par', hdr_out)
13991407

14001408

14011409
def gc_map_wrap(image, namespace, dem, spacing, exist_ok=False,

0 commit comments

Comments
 (0)