Skip to content

Commit

Permalink
Echo runconfig to separate file instead of mixing with log messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
bhawkins-jpl committed Jun 5, 2020
1 parent a9b5699 commit 15183f7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
2 changes: 2 additions & 0 deletions python/packages/nisar/workflows/defaults/focus.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
# SAS writes output product to the following file. PGE may rename.
# NOTE: R2 needs to handle mixed-mode case with multiple outputs.
SASOutputFile: ./slc.h5
# Echo processor config (including defaults) to file.
SASConfigFile: null
PrimaryExecutable:
# Handy to set to "SLC" until other ISCE tools updated.
Expand Down
20 changes: 19 additions & 1 deletion python/packages/nisar/workflows/focus.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,29 @@ def deep_update(d, u):


def load_config(yaml):
"Load default runconfig, override with user input, and convert to Struct"
parser = YAML()
cfg = parser.load(defaults.focus.runconfig)
with open(yaml) as f:
user = parser.load(f)
deep_update(cfg, user)
log.info(json.dumps(cfg, indent=2, default=str))
return Struct(cfg)


def dump_config(cfg: Struct, filename):
def struct2dict(s: Struct):
d = s.__dict__.copy()
for k in d:
if isinstance(d[k], Struct):
d[k] = struct2dict(d[k])
return d
parser = YAML()
parser.indent = 4
with open(filename, 'w') as f:
d = struct2dict(cfg)
parser.dump(d, f)


def validate_config(x):
# TODO
log.warning("Skipping input validation.")
Expand Down Expand Up @@ -445,6 +459,10 @@ def main(argv):
args = parser.parse_args(argv)
configure_logging()
cfg = validate_config(load_config(args.config))
echofile = cfg.runconfig.groups.ProductPathGroup.SASConfigFile
if echofile:
log.info(f"Logging configuration to file {echofile}.")
dump_config(cfg, echofile)
focus(cfg)


Expand Down
2 changes: 2 additions & 0 deletions share/nisar/examples/slc_workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ runconfig:
# SAS writes output product to the following file. PGE may rename.
# NOTE: R2 needs to handle mixed-mode case with multiple outputs.
SASOutputFile: ./slc.h5
# Echo processor config (including defaults) to file.
SASConfigFile: ./rslc_config.yaml

PrimaryExecutable:
ProductType: RSLC
Expand Down
3 changes: 2 additions & 1 deletion tests/data/REE_L0B_out17.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ runconfig:
ScratchPath: .
# SAS writes output product to the following file. PGE may rename.
# NOTE: R2 needs to handle mixed-mode case with multiple outputs.
SASOutputFile: ./slc.h5
SASOutputFile: ./rslc.h5
SASConfigFile: ./rslc_config.yaml

PrimaryExecutable:
ProductType: SLC
Expand Down

0 comments on commit 15183f7

Please sign in to comment.